@@ -59,6 +59,7 @@ public final class ChangeStreamDocument<TDocument> {
59
59
private final BsonInt64 txnNumber ;
60
60
private final BsonDocument lsid ;
61
61
private final BsonDateTime wallTime ;
62
+ private final SplitEvent splitEvent ;
62
63
@ BsonExtraElements
63
64
private final BsonDocument extraElements ;
64
65
@@ -77,12 +78,14 @@ public final class ChangeStreamDocument<TDocument> {
77
78
* @param txnNumber the transaction number
78
79
* @param lsid the identifier for the session associated with the transaction
79
80
* @param wallTime the wall time of the server at the moment the change occurred
81
+ * @param splitEvent the split event
80
82
* @param extraElements any extra elements that are part of the change stream document but not otherwise mapped to fields
81
83
*
82
- * @since 4.7
84
+ * @since 4.11
83
85
*/
84
86
@ BsonCreator
85
- public ChangeStreamDocument (@ BsonProperty ("operationType" ) final String operationTypeString ,
87
+ public ChangeStreamDocument (
88
+ @ Nullable @ BsonProperty ("operationType" ) final String operationTypeString ,
86
89
@ BsonProperty ("resumeToken" ) final BsonDocument resumeToken ,
87
90
@ Nullable @ BsonProperty ("ns" ) final BsonDocument namespaceDocument ,
88
91
@ Nullable @ BsonProperty ("to" ) final BsonDocument destinationNamespaceDocument ,
@@ -94,6 +97,7 @@ public ChangeStreamDocument(@BsonProperty("operationType") final String operatio
94
97
@ Nullable @ BsonProperty ("txnNumber" ) final BsonInt64 txnNumber ,
95
98
@ Nullable @ BsonProperty ("lsid" ) final BsonDocument lsid ,
96
99
@ Nullable @ BsonProperty ("wallTime" ) final BsonDateTime wallTime ,
100
+ @ Nullable @ BsonProperty ("splitEvent" ) final SplitEvent splitEvent ,
97
101
@ Nullable @ BsonProperty final BsonDocument extraElements ) {
98
102
this .resumeToken = resumeToken ;
99
103
this .namespaceDocument = namespaceDocument ;
@@ -103,14 +107,52 @@ public ChangeStreamDocument(@BsonProperty("operationType") final String operatio
103
107
this .fullDocument = fullDocument ;
104
108
this .clusterTime = clusterTime ;
105
109
this .operationTypeString = operationTypeString ;
106
- this .operationType = OperationType .fromString (operationTypeString );
110
+ this .operationType = operationTypeString == null ? null : OperationType .fromString (operationTypeString );
107
111
this .updateDescription = updateDescription ;
108
112
this .txnNumber = txnNumber ;
109
113
this .lsid = lsid ;
110
114
this .wallTime = wallTime ;
115
+ this .splitEvent = splitEvent ;
111
116
this .extraElements = extraElements ;
112
117
}
113
118
119
+ /**
120
+ * Creates a new instance
121
+ *
122
+ * @param operationTypeString the operation type
123
+ * @param resumeToken the resume token
124
+ * @param namespaceDocument the BsonDocument representing the namespace
125
+ * @param destinationNamespaceDocument the BsonDocument representing the destinatation namespace
126
+ * @param fullDocument the full document
127
+ * @param fullDocumentBeforeChange the full document before change
128
+ * @param documentKey a document containing the _id of the changed document
129
+ * @param clusterTime the cluster time at which the change occured
130
+ * @param updateDescription the update description
131
+ * @param txnNumber the transaction number
132
+ * @param lsid the identifier for the session associated with the transaction
133
+ * @param wallTime the wall time of the server at the moment the change occurred
134
+ * @param extraElements any extra elements that are part of the change stream document but not otherwise mapped to fields
135
+ *
136
+ * @since 4.7
137
+ */
138
+ @ Deprecated
139
+ public ChangeStreamDocument (@ BsonProperty ("operationType" ) final String operationTypeString ,
140
+ @ BsonProperty ("resumeToken" ) final BsonDocument resumeToken ,
141
+ @ Nullable @ BsonProperty ("ns" ) final BsonDocument namespaceDocument ,
142
+ @ Nullable @ BsonProperty ("to" ) final BsonDocument destinationNamespaceDocument ,
143
+ @ Nullable @ BsonProperty ("fullDocument" ) final TDocument fullDocument ,
144
+ @ Nullable @ BsonProperty ("fullDocumentBeforeChange" ) final TDocument fullDocumentBeforeChange ,
145
+ @ Nullable @ BsonProperty ("documentKey" ) final BsonDocument documentKey ,
146
+ @ Nullable @ BsonProperty ("clusterTime" ) final BsonTimestamp clusterTime ,
147
+ @ Nullable @ BsonProperty ("updateDescription" ) final UpdateDescription updateDescription ,
148
+ @ Nullable @ BsonProperty ("txnNumber" ) final BsonInt64 txnNumber ,
149
+ @ Nullable @ BsonProperty ("lsid" ) final BsonDocument lsid ,
150
+ @ Nullable @ BsonProperty ("wallTime" ) final BsonDateTime wallTime ,
151
+ @ Nullable @ BsonProperty final BsonDocument extraElements ) {
152
+ this (operationTypeString , resumeToken , namespaceDocument , destinationNamespaceDocument , fullDocument , fullDocumentBeforeChange , documentKey ,
153
+ clusterTime , updateDescription , txnNumber , lsid , wallTime , null , extraElements );
154
+ }
155
+
114
156
/**
115
157
* Creates a new instance
116
158
*
@@ -139,7 +181,7 @@ public ChangeStreamDocument(@BsonProperty("operationType") final String operatio
139
181
@ Nullable @ BsonProperty ("txnNumber" ) final BsonInt64 txnNumber ,
140
182
@ Nullable @ BsonProperty ("lsid" ) final BsonDocument lsid ) {
141
183
this (operationTypeString , resumeToken , namespaceDocument , destinationNamespaceDocument , fullDocument , null , documentKey ,
142
- clusterTime , updateDescription , txnNumber , lsid , null , null );
184
+ clusterTime , updateDescription , txnNumber , lsid , null , null , null );
143
185
}
144
186
145
187
/**
@@ -170,7 +212,7 @@ public ChangeStreamDocument(final OperationType operationType,
170
212
final BsonInt64 txnNumber ,
171
213
final BsonDocument lsid ) {
172
214
this (operationType .getValue (), resumeToken , namespaceDocument , destinationNamespaceDocument , fullDocument , null , documentKey ,
173
- clusterTime , updateDescription , txnNumber , lsid , null , null );
215
+ clusterTime , updateDescription , txnNumber , lsid , null , null , null );
174
216
}
175
217
176
218
/**
@@ -360,26 +402,30 @@ public BsonTimestamp getClusterTime() {
360
402
361
403
/**
362
404
* Returns the operation type as a string.
363
- *
364
405
* <p>
365
406
* This method is useful when using a driver release that has not yet been updated to include a newer operation type in the
366
407
* {@link OperationType} enum. In that case, {@link #getOperationType()} will return {@link OperationType#OTHER} and this method can
367
408
* be used to retrieve the actual operation type as a string value.
368
- * </p>
409
+ * <p>
410
+ * May return null only if <code>$changeStreamSplitLargeEvent</code> is used.
369
411
*
370
412
* @return the operation type as a string
371
413
* @since 4.6
372
414
* @see #getOperationType()
373
415
*/
416
+ @ Nullable
374
417
public String getOperationTypeString () {
375
418
return operationTypeString ;
376
419
}
377
420
378
421
/**
379
- * Returns the operationType
422
+ * Returns the operationType.
423
+ * <p>
424
+ * May return null only if <code>$changeStreamSplitLargeEvent</code> is used.
380
425
*
381
426
* @return the operationType
382
427
*/
428
+ @ Nullable
383
429
public OperationType getOperationType () {
384
430
return operationType ;
385
431
}
@@ -430,6 +476,18 @@ public BsonDateTime getWallTime() {
430
476
return wallTime ;
431
477
}
432
478
479
+ /**
480
+ * The split event.
481
+ *
482
+ * @return the split event
483
+ * @since 4.11
484
+ * @mongodb.server.release 6.0.9
485
+ */
486
+ @ Nullable
487
+ public SplitEvent getSplitEvent () {
488
+ return splitEvent ;
489
+ }
490
+
433
491
/**
434
492
* Any extra elements that are part of the change stream document but not otherwise mapped to fields.
435
493
*
@@ -462,64 +520,42 @@ public boolean equals(final Object o) {
462
520
if (o == null || getClass () != o .getClass ()) {
463
521
return false ;
464
522
}
465
-
466
523
ChangeStreamDocument <?> that = (ChangeStreamDocument <?>) o ;
467
-
468
- if (!Objects .equals (resumeToken , that .resumeToken )) {
469
- return false ;
470
- }
471
- if (!Objects .equals (namespaceDocument , that .namespaceDocument )) {
472
- return false ;
473
- }
474
- if (!Objects .equals (destinationNamespaceDocument , that .destinationNamespaceDocument )) {
475
- return false ;
476
- }
477
- if (!Objects .equals (fullDocument , that .fullDocument )) {
478
- return false ;
479
- }
480
- if (!Objects .equals (fullDocumentBeforeChange , that .fullDocumentBeforeChange )) {
481
- return false ;
482
- }
483
- if (!Objects .equals (documentKey , that .documentKey )) {
484
- return false ;
485
- }
486
- if (!Objects .equals (operationTypeString , that .operationTypeString )) {
487
- return false ;
488
- }
489
- if (!Objects .equals (clusterTime , that .clusterTime )) {
490
- return false ;
491
- }
492
- if (!Objects .equals (updateDescription , that .updateDescription )) {
493
- return false ;
494
- }
495
- if (!Objects .equals (txnNumber , that .txnNumber )) {
496
- return false ;
497
- }
498
- if (!Objects .equals (lsid , that .lsid )) {
499
- return false ;
500
- }
501
- if (!Objects .equals (wallTime , that .wallTime )) {
502
- return false ;
503
- }
504
-
505
- return true ;
524
+ return Objects .equals (resumeToken , that .resumeToken )
525
+ && Objects .equals (namespaceDocument , that .namespaceDocument )
526
+ && Objects .equals (destinationNamespaceDocument , that .destinationNamespaceDocument )
527
+ && Objects .equals (fullDocument , that .fullDocument )
528
+ && Objects .equals (fullDocumentBeforeChange , that .fullDocumentBeforeChange )
529
+ && Objects .equals (documentKey , that .documentKey )
530
+ && Objects .equals (clusterTime , that .clusterTime )
531
+ && Objects .equals (operationTypeString , that .operationTypeString )
532
+ // operationType covered by operationTypeString
533
+ && Objects .equals (updateDescription , that .updateDescription )
534
+ && Objects .equals (txnNumber , that .txnNumber )
535
+ && Objects .equals (lsid , that .lsid )
536
+ && Objects .equals (wallTime , that .wallTime )
537
+ && Objects .equals (splitEvent , that .splitEvent )
538
+ && Objects .equals (extraElements , that .extraElements );
506
539
}
507
540
508
541
@ Override
509
542
public int hashCode () {
510
- int result = resumeToken != null ? resumeToken .hashCode () : 0 ;
511
- result = 31 * result + (namespaceDocument != null ? namespaceDocument .hashCode () : 0 );
512
- result = 31 * result + (destinationNamespaceDocument != null ? destinationNamespaceDocument .hashCode () : 0 );
513
- result = 31 * result + (fullDocument != null ? fullDocument .hashCode () : 0 );
514
- result = 31 * result + (fullDocumentBeforeChange != null ? fullDocumentBeforeChange .hashCode () : 0 );
515
- result = 31 * result + (documentKey != null ? documentKey .hashCode () : 0 );
516
- result = 31 * result + (clusterTime != null ? clusterTime .hashCode () : 0 );
517
- result = 31 * result + (operationTypeString != null ? operationTypeString .hashCode () : 0 );
518
- result = 31 * result + (updateDescription != null ? updateDescription .hashCode () : 0 );
519
- result = 31 * result + (txnNumber != null ? txnNumber .hashCode () : 0 );
520
- result = 31 * result + (lsid != null ? lsid .hashCode () : 0 );
521
- result = 31 * result + (wallTime != null ? wallTime .hashCode () : 0 );
522
- return result ;
543
+ return Objects .hash (
544
+ resumeToken ,
545
+ namespaceDocument ,
546
+ destinationNamespaceDocument ,
547
+ fullDocument ,
548
+ fullDocumentBeforeChange ,
549
+ documentKey ,
550
+ clusterTime ,
551
+ operationTypeString ,
552
+ // operationType covered by operationTypeString
553
+ updateDescription ,
554
+ txnNumber ,
555
+ lsid ,
556
+ wallTime ,
557
+ splitEvent ,
558
+ extraElements );
523
559
}
524
560
525
561
@ Override
@@ -536,6 +572,7 @@ public String toString() {
536
572
+ ", updateDescription=" + updateDescription
537
573
+ ", txnNumber=" + txnNumber
538
574
+ ", lsid=" + lsid
575
+ + ", splitEvent=" + splitEvent
539
576
+ ", wallTime=" + wallTime
540
577
+ "}" ;
541
578
}
0 commit comments