2020import com .mongodb .assertions .Assertions ;
2121import com .mongodb .lang .Nullable ;
2222import org .bson .BsonDocument ;
23+ import org .bson .BsonInt64 ;
2324import org .bson .BsonString ;
2425import org .bson .BsonTimestamp ;
2526import org .bson .codecs .Codec ;
@@ -49,6 +50,8 @@ public final class ChangeStreamDocument<TDocument> {
4950 private final BsonTimestamp clusterTime ;
5051 private final OperationType operationType ;
5152 private final UpdateDescription updateDescription ;
53+ private final BsonInt64 txnNumber ;
54+ private final BsonDocument lsid ;
5255
5356 /**
5457 * Creates a new instance
@@ -135,7 +138,7 @@ public ChangeStreamDocument(@BsonProperty("resumeToken") final BsonDocument resu
135138 *
136139 * @since 3.11
137140 */
138- @ BsonCreator
141+ @ Deprecated
139142 public ChangeStreamDocument (@ BsonProperty ("operationType" ) final OperationType operationType ,
140143 @ BsonProperty ("resumeToken" ) final BsonDocument resumeToken ,
141144 @ Nullable @ BsonProperty ("ns" ) final BsonDocument namespaceDocument ,
@@ -144,6 +147,37 @@ public ChangeStreamDocument(@BsonProperty("operationType") final OperationType o
144147 @ Nullable @ BsonProperty ("documentKey" ) final BsonDocument documentKey ,
145148 @ Nullable @ BsonProperty ("clusterTime" ) final BsonTimestamp clusterTime ,
146149 @ Nullable @ BsonProperty ("updateDescription" ) final UpdateDescription updateDescription ) {
150+ this (operationType , resumeToken , namespaceDocument , destinationNamespaceDocument , fullDocument , documentKey , clusterTime ,
151+ updateDescription , null , null );
152+ }
153+
154+ /**
155+ * Creates a new instance
156+ *
157+ * @param operationType the operation type
158+ * @param resumeToken the resume token
159+ * @param namespaceDocument the BsonDocument representing the namespace
160+ * @param destinationNamespaceDocument the BsonDocument representing the destinatation namespace
161+ * @param fullDocument the full document
162+ * @param documentKey a document containing the _id of the changed document
163+ * @param clusterTime the cluster time at which the change occured
164+ * @param updateDescription the update description
165+ * @param txnNumber the transaction number
166+ * @param lsid the identifier for the session associated with the transaction
167+ *
168+ * @since 3.11
169+ */
170+ @ BsonCreator
171+ public ChangeStreamDocument (@ BsonProperty ("operationType" ) final OperationType operationType ,
172+ @ BsonProperty ("resumeToken" ) final BsonDocument resumeToken ,
173+ @ Nullable @ BsonProperty ("ns" ) final BsonDocument namespaceDocument ,
174+ @ Nullable @ BsonProperty ("to" ) final BsonDocument destinationNamespaceDocument ,
175+ @ Nullable @ BsonProperty ("fullDocument" ) final TDocument fullDocument ,
176+ @ Nullable @ BsonProperty ("documentKey" ) final BsonDocument documentKey ,
177+ @ Nullable @ BsonProperty ("clusterTime" ) final BsonTimestamp clusterTime ,
178+ @ Nullable @ BsonProperty ("updateDescription" ) final UpdateDescription updateDescription ,
179+ @ Nullable @ BsonProperty ("txnNumber" ) final BsonInt64 txnNumber ,
180+ @ Nullable @ BsonProperty ("lsid" ) final BsonDocument lsid ) {
147181 this .resumeToken = resumeToken ;
148182 this .namespaceDocument = namespaceDocument ;
149183 this .destinationNamespaceDocument = destinationNamespaceDocument ;
@@ -152,6 +186,8 @@ public ChangeStreamDocument(@BsonProperty("operationType") final OperationType o
152186 this .clusterTime = clusterTime ;
153187 this .operationType = operationType ;
154188 this .updateDescription = updateDescription ;
189+ this .txnNumber = txnNumber ;
190+ this .lsid = lsid ;
155191 }
156192
157193 private static BsonDocument namespaceToDocument (final MongoNamespace namespace ) {
@@ -321,6 +357,30 @@ public UpdateDescription getUpdateDescription() {
321357 return updateDescription ;
322358 }
323359
360+ /**
361+ * Returns the transaction number
362+ *
363+ * @return the transaction number, or null if not part of a multi-document transaction
364+ * @since 3.11
365+ * @mongodb.server.release 4.0
366+ */
367+ @ Nullable
368+ public BsonInt64 getTxnNumber () {
369+ return txnNumber ;
370+ }
371+
372+ /**
373+ * Returns the identifier for the session associated with the transaction
374+ *
375+ * @return the lsid, or null if not part of a multi-document transaction
376+ * @since 3.11
377+ * @mongodb.server.release 4.0
378+ */
379+ @ Nullable
380+ public BsonDocument getLsid () {
381+ return lsid ;
382+ }
383+
324384 /**
325385 * Creates the codec for the specific ChangeStreamOutput type
326386 *
@@ -371,6 +431,12 @@ public boolean equals(final Object o) {
371431 if (updateDescription != null ? !updateDescription .equals (that .updateDescription ) : that .updateDescription != null ) {
372432 return false ;
373433 }
434+ if (txnNumber != null ? !txnNumber .equals (that .txnNumber ) : that .txnNumber != null ) {
435+ return false ;
436+ }
437+ if (lsid != null ? !lsid .equals (that .lsid ) : that .lsid != null ) {
438+ return false ;
439+ }
374440
375441 return true ;
376442 }
@@ -385,6 +451,8 @@ public int hashCode() {
385451 result = 31 * result + (clusterTime != null ? clusterTime .hashCode () : 0 );
386452 result = 31 * result + (operationType != null ? operationType .hashCode () : 0 );
387453 result = 31 * result + (updateDescription != null ? updateDescription .hashCode () : 0 );
454+ result = 31 * result + (txnNumber != null ? txnNumber .hashCode () : 0 );
455+ result = 31 * result + (lsid != null ? lsid .hashCode () : 0 );
388456 return result ;
389457 }
390458
@@ -399,6 +467,8 @@ public String toString() {
399467 + ", documentKey=" + documentKey
400468 + ", clusterTime=" + clusterTime
401469 + ", updateDescription=" + updateDescription
470+ + ", txnNumber=" + txnNumber
471+ + ", lsid=" + lsid
402472 + "}" ;
403473 }
404474}
0 commit comments