@@ -124,8 +124,8 @@ public void accept(CloudEvent event) throws InvalidProtocolBufferException {
124
124
// For cross region replication to work properly two additional attributes must
125
125
// be written to the document to indicate what region the replicated attribute
126
126
// came from and the timestamp of when the record was updated
127
- record .put (CrossFireSync .TIMESTAMP_FIELD , updatedTime );
128
- record .put (CrossFireSync .SOURCE_DATABASE_FIELD , pubsubDatabase );
127
+ record .put (CrossFireSyncAttributes .TIMESTAMP_FIELD , updatedTime );
128
+ record .put (CrossFireSyncAttributes .SOURCE_DATABASE_FIELD , pubsubDatabase );
129
129
130
130
// Perform the update
131
131
this .updateTransaction (documentReference , updatedTime , record );
@@ -141,9 +141,9 @@ public void accept(CloudEvent event) throws InvalidProtocolBufferException {
141
141
// Prepare the updates, set the deleted flag instead of actually deleting so the
142
142
// delete in the remote regions will not redundantly cascade to other regions.
143
143
Map <String , Object > updates = new HashMap <>();
144
- updates .put (CrossFireSync .TIMESTAMP_FIELD , deleteTimestamp );
145
- updates .put (CrossFireSync .DELETE_FIELD , true );
146
- updates .put (CrossFireSync .SOURCE_DATABASE_FIELD , pubsubDatabase );
144
+ updates .put (CrossFireSyncAttributes .TIMESTAMP_FIELD , deleteTimestamp );
145
+ updates .put (CrossFireSyncAttributes .DELETE_FIELD , true );
146
+ updates .put (CrossFireSyncAttributes .SOURCE_DATABASE_FIELD , pubsubDatabase );
147
147
148
148
boolean flagged = this .deleteFlagTransaction (documentReference , updates );
149
149
@@ -159,6 +159,15 @@ public void accept(CloudEvent event) throws InvalidProtocolBufferException {
159
159
logger .info ("Pub/Sub message: " + event );
160
160
}
161
161
162
+ /**
163
+ * Update a Firestore document with a transaction.
164
+ *
165
+ * @param documentReference The document reference
166
+ * @param updatedTime The updated time
167
+ * @param record The record to update
168
+ * @throws InterruptedException If the transaction is interrupted
169
+ * @throws ExecutionException If the transaction fails
170
+ */
162
171
void updateTransaction (DocumentReference documentReference , Timestamp updatedTime ,
163
172
Map <String , Object > record ) throws InterruptedException , ExecutionException {
164
173
ApiFuture <Void > transaction = db .runTransaction ((Transaction .Function <Void >) t -> {
@@ -171,9 +180,10 @@ void updateTransaction(DocumentReference documentReference, Timestamp updatedTim
171
180
shouldWrite = true ;
172
181
} else {
173
182
// Check if the timestamp is older or not present
174
- Timestamp existingTimestamp = snapshot .contains (CrossFireSync .TIMESTAMP_FIELD )
175
- ? snapshot .getTimestamp (CrossFireSync .TIMESTAMP_FIELD )
176
- : null ;
183
+ Timestamp existingTimestamp =
184
+ snapshot .contains (CrossFireSyncAttributes .TIMESTAMP_FIELD )
185
+ ? snapshot .getTimestamp (CrossFireSyncAttributes .TIMESTAMP_FIELD )
186
+ : null ;
177
187
if (existingTimestamp == null || updatedTime .compareTo (existingTimestamp ) > 0 ) {
178
188
shouldWrite = true ;
179
189
}
@@ -191,6 +201,15 @@ void updateTransaction(DocumentReference documentReference, Timestamp updatedTim
191
201
transaction .get ();
192
202
}
193
203
204
+ /**
205
+ * Flag a Firestore document for deletion with a transaction.
206
+ *
207
+ * @param documentReference The document reference
208
+ * @param updates The updates to apply
209
+ * @return True if the document was flagged for deletion
210
+ * @throws InterruptedException If the transaction is interrupted
211
+ * @throws ExecutionException If the transaction fails
212
+ */
194
213
boolean deleteFlagTransaction (DocumentReference documentReference , Map <String , Object > updates )
195
214
throws InterruptedException , ExecutionException {
196
215
ApiFuture <Boolean > transaction = db .runTransaction ((Transaction .Function <Boolean >) t -> {
0 commit comments