20
20
import com .mongodb .assertions .Assertions ;
21
21
import com .mongodb .lang .Nullable ;
22
22
import org .bson .BsonDocument ;
23
+ import org .bson .BsonInt64 ;
23
24
import org .bson .BsonString ;
24
25
import org .bson .BsonTimestamp ;
25
26
import org .bson .codecs .Codec ;
@@ -49,6 +50,8 @@ public final class ChangeStreamDocument<TDocument> {
49
50
private final BsonTimestamp clusterTime ;
50
51
private final OperationType operationType ;
51
52
private final UpdateDescription updateDescription ;
53
+ private final BsonInt64 txnNumber ;
54
+ private final BsonDocument lsid ;
52
55
53
56
/**
54
57
* Creates a new instance
@@ -135,7 +138,7 @@ public ChangeStreamDocument(@BsonProperty("resumeToken") final BsonDocument resu
135
138
*
136
139
* @since 3.11
137
140
*/
138
- @ BsonCreator
141
+ @ Deprecated
139
142
public ChangeStreamDocument (@ BsonProperty ("operationType" ) final OperationType operationType ,
140
143
@ BsonProperty ("resumeToken" ) final BsonDocument resumeToken ,
141
144
@ Nullable @ BsonProperty ("ns" ) final BsonDocument namespaceDocument ,
@@ -144,6 +147,37 @@ public ChangeStreamDocument(@BsonProperty("operationType") final OperationType o
144
147
@ Nullable @ BsonProperty ("documentKey" ) final BsonDocument documentKey ,
145
148
@ Nullable @ BsonProperty ("clusterTime" ) final BsonTimestamp clusterTime ,
146
149
@ 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 ) {
147
181
this .resumeToken = resumeToken ;
148
182
this .namespaceDocument = namespaceDocument ;
149
183
this .destinationNamespaceDocument = destinationNamespaceDocument ;
@@ -152,6 +186,8 @@ public ChangeStreamDocument(@BsonProperty("operationType") final OperationType o
152
186
this .clusterTime = clusterTime ;
153
187
this .operationType = operationType ;
154
188
this .updateDescription = updateDescription ;
189
+ this .txnNumber = txnNumber ;
190
+ this .lsid = lsid ;
155
191
}
156
192
157
193
private static BsonDocument namespaceToDocument (final MongoNamespace namespace ) {
@@ -321,6 +357,30 @@ public UpdateDescription getUpdateDescription() {
321
357
return updateDescription ;
322
358
}
323
359
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
+
324
384
/**
325
385
* Creates the codec for the specific ChangeStreamOutput type
326
386
*
@@ -371,6 +431,12 @@ public boolean equals(final Object o) {
371
431
if (updateDescription != null ? !updateDescription .equals (that .updateDescription ) : that .updateDescription != null ) {
372
432
return false ;
373
433
}
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
+ }
374
440
375
441
return true ;
376
442
}
@@ -385,6 +451,8 @@ public int hashCode() {
385
451
result = 31 * result + (clusterTime != null ? clusterTime .hashCode () : 0 );
386
452
result = 31 * result + (operationType != null ? operationType .hashCode () : 0 );
387
453
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 );
388
456
return result ;
389
457
}
390
458
@@ -399,6 +467,8 @@ public String toString() {
399
467
+ ", documentKey=" + documentKey
400
468
+ ", clusterTime=" + clusterTime
401
469
+ ", updateDescription=" + updateDescription
470
+ + ", txnNumber=" + txnNumber
471
+ + ", lsid=" + lsid
402
472
+ "}" ;
403
473
}
404
474
}
0 commit comments