17
17
package com .mongodb .client .model .changestream ;
18
18
19
19
import com .mongodb .MongoNamespace ;
20
+ import com .mongodb .lang .Nullable ;
20
21
import org .bson .BsonDocument ;
22
+ import org .bson .BsonTimestamp ;
21
23
import org .bson .codecs .Codec ;
22
24
import org .bson .codecs .configuration .CodecRegistry ;
23
25
import org .bson .codecs .pojo .annotations .BsonCreator ;
@@ -41,6 +43,7 @@ public final class ChangeStreamDocument<TDocument> {
41
43
private final MongoNamespace namespace ;
42
44
private final TDocument fullDocument ;
43
45
private final BsonDocument documentKey ;
46
+ private final BsonTimestamp clusterTime ;
44
47
private final OperationType operationType ;
45
48
private final UpdateDescription updateDescription ;
46
49
@@ -53,18 +56,43 @@ public final class ChangeStreamDocument<TDocument> {
53
56
* @param fullDocument the fullDocument
54
57
* @param operationType the operation type
55
58
* @param updateDescription the update description
59
+ * @deprecated Prefer {@link #ChangeStreamDocument(BsonDocument, MongoNamespace, Object, BsonDocument, BsonTimestamp, OperationType,
60
+ * UpdateDescription)}
61
+ */
62
+ @ Deprecated
63
+ public ChangeStreamDocument (@ BsonProperty ("resumeToken" ) final BsonDocument resumeToken ,
64
+ @ BsonProperty ("namespace" ) final MongoNamespace namespace ,
65
+ @ BsonProperty ("fullDocument" ) final TDocument fullDocument ,
66
+ @ BsonProperty ("documentKey" ) final BsonDocument documentKey ,
67
+ @ BsonProperty ("operationType" ) final OperationType operationType ,
68
+ @ BsonProperty ("updateDescription" ) final UpdateDescription updateDescription ) {
69
+ this (resumeToken , namespace , fullDocument , documentKey , null , operationType , updateDescription );
70
+ }
71
+
72
+ /**
73
+ * Creates a new instance
74
+ *
75
+ * @param resumeToken the resume token
76
+ * @param namespace the namespace
77
+ * @param documentKey a document containing the _id of the changed document
78
+ * @param clusterTime the cluster time at which the change occurred
79
+ * @param fullDocument the fullDocument
80
+ * @param operationType the operation type
81
+ * @param updateDescription the update description
56
82
*/
57
83
@ BsonCreator
58
84
public ChangeStreamDocument (@ BsonProperty ("resumeToken" ) final BsonDocument resumeToken ,
59
85
@ BsonProperty ("namespace" ) final MongoNamespace namespace ,
60
86
@ BsonProperty ("fullDocument" ) final TDocument fullDocument ,
61
87
@ BsonProperty ("documentKey" ) final BsonDocument documentKey ,
88
+ @ Nullable @ BsonProperty ("clusterTime" ) final BsonTimestamp clusterTime ,
62
89
@ BsonProperty ("operationType" ) final OperationType operationType ,
63
90
@ BsonProperty ("updateDescription" ) final UpdateDescription updateDescription ) {
64
91
this .resumeToken = resumeToken ;
65
92
this .namespace = namespace ;
66
93
this .documentKey = documentKey ;
67
94
this .fullDocument = fullDocument ;
95
+ this .clusterTime = clusterTime ;
68
96
this .operationType = operationType ;
69
97
this .updateDescription = updateDescription ;
70
98
}
@@ -111,6 +139,18 @@ public BsonDocument getDocumentKey() {
111
139
return documentKey ;
112
140
}
113
141
142
+ /**
143
+ * Gets the cluster time at which the change occurred.
144
+ *
145
+ * @return the cluster time at which the change occurred
146
+ * @since 3.8
147
+ * @mongodb.server.release 4.0
148
+ */
149
+ @ Nullable
150
+ public BsonTimestamp getClusterTime () {
151
+ return clusterTime ;
152
+ }
153
+
114
154
/**
115
155
* Returns the operationType
116
156
*
@@ -165,6 +205,9 @@ public boolean equals(final Object o) {
165
205
if (documentKey != null ? !documentKey .equals (that .documentKey ) : that .documentKey != null ) {
166
206
return false ;
167
207
}
208
+ if (clusterTime != null ? !clusterTime .equals (that .clusterTime ) : that .clusterTime != null ) {
209
+ return false ;
210
+ }
168
211
if (operationType != that .operationType ) {
169
212
return false ;
170
213
}
@@ -181,6 +224,7 @@ public int hashCode() {
181
224
result = 31 * result + (namespace != null ? namespace .hashCode () : 0 );
182
225
result = 31 * result + (fullDocument != null ? fullDocument .hashCode () : 0 );
183
226
result = 31 * result + (documentKey != null ? documentKey .hashCode () : 0 );
227
+ result = 31 * result + (clusterTime != null ? clusterTime .hashCode () : 0 );
184
228
result = 31 * result + (operationType != null ? operationType .hashCode () : 0 );
185
229
result = 31 * result + (updateDescription != null ? updateDescription .hashCode () : 0 );
186
230
return result ;
@@ -193,6 +237,7 @@ public String toString() {
193
237
+ ", namespace=" + namespace
194
238
+ ", fullDocument=" + fullDocument
195
239
+ ", documentKey=" + documentKey
240
+ + ", clusterTime=" + clusterTime
196
241
+ ", operationType=" + operationType
197
242
+ ", updateDescription=" + updateDescription
198
243
+ "}" ;
0 commit comments