1717package com .mongodb .client .model .changestream ;
1818
1919import com .mongodb .MongoNamespace ;
20+ import com .mongodb .lang .Nullable ;
2021import org .bson .BsonDocument ;
22+ import org .bson .BsonTimestamp ;
2123import org .bson .codecs .Codec ;
2224import org .bson .codecs .configuration .CodecRegistry ;
2325import org .bson .codecs .pojo .annotations .BsonCreator ;
@@ -41,6 +43,7 @@ public final class ChangeStreamDocument<TDocument> {
4143 private final MongoNamespace namespace ;
4244 private final TDocument fullDocument ;
4345 private final BsonDocument documentKey ;
46+ private final BsonTimestamp clusterTime ;
4447 private final OperationType operationType ;
4548 private final UpdateDescription updateDescription ;
4649
@@ -53,18 +56,43 @@ public final class ChangeStreamDocument<TDocument> {
5356 * @param fullDocument the fullDocument
5457 * @param operationType the operation type
5558 * @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
5682 */
5783 @ BsonCreator
5884 public ChangeStreamDocument (@ BsonProperty ("resumeToken" ) final BsonDocument resumeToken ,
5985 @ BsonProperty ("namespace" ) final MongoNamespace namespace ,
6086 @ BsonProperty ("fullDocument" ) final TDocument fullDocument ,
6187 @ BsonProperty ("documentKey" ) final BsonDocument documentKey ,
88+ @ Nullable @ BsonProperty ("clusterTime" ) final BsonTimestamp clusterTime ,
6289 @ BsonProperty ("operationType" ) final OperationType operationType ,
6390 @ BsonProperty ("updateDescription" ) final UpdateDescription updateDescription ) {
6491 this .resumeToken = resumeToken ;
6592 this .namespace = namespace ;
6693 this .documentKey = documentKey ;
6794 this .fullDocument = fullDocument ;
95+ this .clusterTime = clusterTime ;
6896 this .operationType = operationType ;
6997 this .updateDescription = updateDescription ;
7098 }
@@ -111,6 +139,18 @@ public BsonDocument getDocumentKey() {
111139 return documentKey ;
112140 }
113141
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+
114154 /**
115155 * Returns the operationType
116156 *
@@ -165,6 +205,9 @@ public boolean equals(final Object o) {
165205 if (documentKey != null ? !documentKey .equals (that .documentKey ) : that .documentKey != null ) {
166206 return false ;
167207 }
208+ if (clusterTime != null ? !clusterTime .equals (that .clusterTime ) : that .clusterTime != null ) {
209+ return false ;
210+ }
168211 if (operationType != that .operationType ) {
169212 return false ;
170213 }
@@ -181,6 +224,7 @@ public int hashCode() {
181224 result = 31 * result + (namespace != null ? namespace .hashCode () : 0 );
182225 result = 31 * result + (fullDocument != null ? fullDocument .hashCode () : 0 );
183226 result = 31 * result + (documentKey != null ? documentKey .hashCode () : 0 );
227+ result = 31 * result + (clusterTime != null ? clusterTime .hashCode () : 0 );
184228 result = 31 * result + (operationType != null ? operationType .hashCode () : 0 );
185229 result = 31 * result + (updateDescription != null ? updateDescription .hashCode () : 0 );
186230 return result ;
@@ -193,6 +237,7 @@ public String toString() {
193237 + ", namespace=" + namespace
194238 + ", fullDocument=" + fullDocument
195239 + ", documentKey=" + documentKey
240+ + ", clusterTime=" + clusterTime
196241 + ", operationType=" + operationType
197242 + ", updateDescription=" + updateDescription
198243 + "}" ;
0 commit comments