use of com.google.firestore.v1.Write in project spring-cloud-gcp by spring-cloud.
the class FirestoreTemplate method deleteDocumentsByName.
private Flux<String> deleteDocumentsByName(Flux<String> documentNames) {
return Mono.subscriberContext().flatMapMany(ctx -> {
Optional<TransactionContext> transactionContext = ctx.getOrEmpty(TransactionContext.class);
if (transactionContext.isPresent()) {
ReactiveFirestoreResourceHolder holder = (ReactiveFirestoreResourceHolder) transactionContext.get().getResources().get(this.firestore);
List<Write> writes = holder.getWrites();
// In a transaction, all write operations should be sent in the commit request, so we just collect them
return Flux.from(documentNames).doOnNext(t -> writes.add(createDeleteWrite(t)));
}
return commitWrites(documentNames, this::createDeleteWrite);
});
}
use of com.google.firestore.v1.Write in project spring-cloud-gcp by spring-cloud.
the class FirestoreTemplate method saveAll.
/**
* {@inheritDoc}
*
* <p>The buffer size and buffer timeout settings for {@link #saveAll} can be modified by calling
* {@link #setWriteBufferSize} and {@link #setWriteBufferTimeout}.
*/
@Override
public <T> Flux<T> saveAll(Publisher<T> instances) {
return Mono.subscriberContext().flatMapMany(ctx -> {
Optional<TransactionContext> transactionContext = ctx.getOrEmpty(TransactionContext.class);
if (transactionContext.isPresent()) {
ReactiveFirestoreResourceHolder holder = (ReactiveFirestoreResourceHolder) transactionContext.get().getResources().get(this.firestore);
List<Write> writes = holder.getWrites();
// In a transaction, all write operations should be sent in the commit request, so we just collect them
return Flux.from(instances).doOnNext(t -> writes.add(createUpdateWrite(t)));
}
return commitWrites(instances, this::createUpdateWrite);
});
}
use of com.google.firestore.v1.Write in project spring-cloud-gcp by spring-cloud.
the class FirestoreTemplate method createUpdateWrite.
private <T> Write createUpdateWrite(T entity) {
Builder builder = Write.newBuilder();
if (getIdValue(entity) == null) {
builder.setCurrentDocument(Precondition.newBuilder().setExists(false).build());
}
String resourceName = buildResourceName(entity);
Document document = getClassMapper().entityToDocument(entity, resourceName);
return builder.setUpdate(document).build();
}
use of com.google.firestore.v1.Write in project beam by apache.
the class DatastoreV1Test method testWriteValidationFailsWithNoProject.
@Test
public void testWriteValidationFailsWithNoProject() throws Exception {
Write write = DatastoreIO.v1().write();
thrown.expect(NullPointerException.class);
thrown.expectMessage("projectId ValueProvider");
write.validate(null);
}
use of com.google.firestore.v1.Write in project beam by apache.
the class DatastoreV1Test method testWriteValidationFailsWithNoProjectInStaticValueProvider.
@Test
public void testWriteValidationFailsWithNoProjectInStaticValueProvider() throws Exception {
Write write = DatastoreIO.v1().write().withProjectId(StaticValueProvider.<String>of(null));
thrown.expect(NullPointerException.class);
thrown.expectMessage("projectId");
write.validate(null);
}
Aggregations