Class FirestoreTemplate
- All Implemented Interfaces:
FirestoreReactiveOperations
FirestoreReactiveOperations.- Since:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConstant representing the special property to use when querying by a document ID. -
Constructor Summary
ConstructorsConstructorDescriptionFirestoreTemplate(com.google.firestore.v1.FirestoreGrpc.FirestoreStub firestoreStub, String parent, FirestoreClassMapper classMapper, FirestoreMappingContext mappingContext) Constructor for FirestoreTemplate. -
Method Summary
Modifier and TypeMethodDescriptionbuildResourceName(FirestorePersistentEntity<?> persistentEntity, String resource) Builds the full reference path to a resource such as a document or a sub-collection.<T> reactor.core.publisher.Mono<Long>Count entities of the given domain.<T> reactor.core.publisher.Mono<Long>Count entities of the given domain corresponding to the predicates given in the query builder.<T> reactor.core.publisher.Mono<Void>delete(org.reactivestreams.Publisher<T> entityPublisher) Delete entities provided by publisher.<T> reactor.core.publisher.Mono<Long>Delete all entities of a given domain type.reactor.core.publisher.Mono<Void>deleteById(org.reactivestreams.Publisher<String> idPublisher, Class<?> entityClass) Delete entities of a given domain type using ids published by producer.<T> reactor.core.publisher.Flux<T>Executes a query represented as query builder and returns results of the given domain type.<T> reactor.core.publisher.Mono<Boolean>existsById(org.reactivestreams.Publisher<String> idPublisher, Class<T> entityClass) Test if the entity of the given domain type with a given id exists.<T> reactor.core.publisher.Flux<T>Get all the entities of the given domain type.<T> reactor.core.publisher.Flux<T>findAllById(org.reactivestreams.Publisher<String> idPublisher, Class<T> entityClass) Get an entity of the given domain type by id.<T> reactor.core.publisher.Mono<T>Get an entity of the given domain type by id.int<T> reactor.core.publisher.Mono<T>save(T entity) Saves an instance of an object to Cloud Firestore.<T> reactor.core.publisher.Flux<T>saveAll(org.reactivestreams.Publisher<T> instances) Saves multiple objects to Cloud Firestore.voidsetWriteBufferSize(int bufferWriteSize) Sets how many entities to include in an insert/update/delete buffered operation.voidsetWriteBufferTimeout(Duration bufferTimeout) Sets theDurationfor how long to wait for the entity buffer to fill before sending the buffered entities to Firestore for insert/update/delete operations.withParent(String id, Class<?> entityClass) Creates FirestoreReactiveOperations object with a specified parent document.withParent(T parent) Creates FirestoreReactiveOperations object with a specified parent document.
-
Field Details
-
NAME_FIELD
Constant representing the special property to use when querying by a document ID.
-
-
Constructor Details
-
FirestoreTemplate
public FirestoreTemplate(com.google.firestore.v1.FirestoreGrpc.FirestoreStub firestoreStub, String parent, FirestoreClassMapper classMapper, FirestoreMappingContext mappingContext) Constructor for FirestoreTemplate.- Parameters:
firestoreStub- Firestore gRPC stubparent- the parent resource. For example: projects/{project_id}/databases/{database_id}/documentsclassMapper- aFirestoreClassMapperused for conversionmappingContext- Mapping Context
-
-
Method Details
-
setWriteBufferTimeout
Sets theDurationfor how long to wait for the entity buffer to fill before sending the buffered entities to Firestore for insert/update/delete operations.- Parameters:
bufferTimeout- duration to wait for entity buffer to fill before sending to Firestore. (default = 500ms)
-
getWriteBufferTimeout
-
setWriteBufferSize
public void setWriteBufferSize(int bufferWriteSize) Sets how many entities to include in an insert/update/delete buffered operation.The maximum buffer size is 500. In most cases users should leave this at the maximum value.
- Parameters:
bufferWriteSize- the entity buffer size for buffered operations (default = 500)
-
getWriteBufferSize
public int getWriteBufferSize() -
existsById
public <T> reactor.core.publisher.Mono<Boolean> existsById(org.reactivestreams.Publisher<String> idPublisher, Class<T> entityClass) Description copied from interface:FirestoreReactiveOperationsTest if the entity of the given domain type with a given id exists. Uses the first emitted element to perform the query.- Specified by:
existsByIdin interfaceFirestoreReactiveOperations- Type Parameters:
T- the type param of the domain type.- Parameters:
idPublisher- publisher that provides an id.entityClass- the domain type of the entity.- Returns:
Monoemittingtrueif an entity with the given id exists,falseotherwise.
-
findById
public <T> reactor.core.publisher.Mono<T> findById(org.reactivestreams.Publisher<String> idPublisher, Class<T> entityClass) Description copied from interface:FirestoreReactiveOperationsGet an entity of the given domain type by id. Uses the first emitted element to perform the query.- Specified by:
findByIdin interfaceFirestoreReactiveOperations- Type Parameters:
T- the type param of the domain type.- Parameters:
idPublisher- publisher that provides an id.entityClass- the domain type of the entity.- Returns:
Monoemitting the found entity.
-
findAllById
public <T> reactor.core.publisher.Flux<T> findAllById(org.reactivestreams.Publisher<String> idPublisher, Class<T> entityClass) Description copied from interface:FirestoreReactiveOperationsGet an entity of the given domain type by id.- Specified by:
findAllByIdin interfaceFirestoreReactiveOperations- Type Parameters:
T- the type param of the domain type.- Parameters:
idPublisher- publisher that provides ids.entityClass- the domain type of the entity.- Returns:
Fluxemitting the found entities.
-
save
public <T> reactor.core.publisher.Mono<T> save(T entity) Description copied from interface:FirestoreReactiveOperationsSaves an instance of an object to Cloud Firestore. Behaves as an insert only (not update).- Specified by:
savein interfaceFirestoreReactiveOperations- Type Parameters:
T- the type of the object to save.- Parameters:
entity- the instance to save.- Returns:
Monoemitting the saved entity.
-
saveAll
public <T> reactor.core.publisher.Flux<T> saveAll(org.reactivestreams.Publisher<T> instances) Saves multiple objects to Cloud Firestore. Not atomic. Behaves as insert or update.The buffer size and buffer timeout settings for
saveAll(org.reactivestreams.Publisher<T>)can be modified by callingsetWriteBufferSize(int)andsetWriteBufferTimeout(java.time.Duration).- Specified by:
saveAllin interfaceFirestoreReactiveOperations- Type Parameters:
T- the type of the objects to save.- Parameters:
instances- the objects to save.- Returns:
Fluxemitting the saved entities.
-
findAll
Description copied from interface:FirestoreReactiveOperationsGet all the entities of the given domain type.- Specified by:
findAllin interfaceFirestoreReactiveOperations- Type Parameters:
T- the type param of the domain type.- Parameters:
clazz- the domain type to get.- Returns:
Monoemitting the found entities.
-
count
Description copied from interface:FirestoreReactiveOperationsCount entities of the given domain. Note that Firestore doesn't support "count" operation natively, so id query will be executed and all ids will be retrieved so they could be counted.- Specified by:
countin interfaceFirestoreReactiveOperations- Type Parameters:
T- the type param of the domain type.- Parameters:
entityClass- the domain type of entities.- Returns:
Monoemitting the number of entities.
-
count
public <T> reactor.core.publisher.Mono<Long> count(Class<T> entityClass, com.google.firestore.v1.StructuredQuery.Builder queryBuilder) Description copied from interface:FirestoreReactiveOperationsCount entities of the given domain corresponding to the predicates given in the query builder. Note that Firestore doesn't support "count" operation natively, so id query will be executed and all ids will be retrieved so they could be counted.- Specified by:
countin interfaceFirestoreReactiveOperations- Type Parameters:
T- the type param of the domain type.- Parameters:
entityClass- the domain type of entities.queryBuilder- the query builder that contains predicates; note that id projection and the collection name will be set during execution- Returns:
Monoemitting the number of entities.
-
deleteAll
Delete all entities of a given domain type.The buffer size and buffer timeout settings for
saveAll(org.reactivestreams.Publisher<T>)can be modified by callingsetWriteBufferSize(int)andsetWriteBufferTimeout(java.time.Duration).- Specified by:
deleteAllin interfaceFirestoreReactiveOperations- Type Parameters:
T- the type param of the domain type.- Parameters:
clazz- the domain type to delete from Cloud Datastore.- Returns:
Monoemitting the number of deleted entities.
-
delete
public <T> reactor.core.publisher.Mono<Void> delete(org.reactivestreams.Publisher<T> entityPublisher) Delete entities provided by publisher.The buffer size and buffer timeout settings for
saveAll(org.reactivestreams.Publisher<T>)can be modified by callingsetWriteBufferSize(int)andsetWriteBufferTimeout(java.time.Duration).- Specified by:
deletein interfaceFirestoreReactiveOperations- Type Parameters:
T- the type param of the domain type.- Parameters:
entityPublisher- publisher that provides entities to be removed.- Returns:
Monosignaling when operation has completed.
-
deleteById
public reactor.core.publisher.Mono<Void> deleteById(org.reactivestreams.Publisher<String> idPublisher, Class<?> entityClass) Delete entities of a given domain type using ids published by producer.The buffer size and buffer timeout settings for
saveAll(org.reactivestreams.Publisher<T>)can be modified by callingsetWriteBufferSize(int)andsetWriteBufferTimeout(java.time.Duration).- Specified by:
deleteByIdin interfaceFirestoreReactiveOperations- Parameters:
idPublisher- publisher that provides ids of entities to be removed.entityClass- the domain type of entities.- Returns:
Monosignaling when operation has completed.
-
execute
public <T> reactor.core.publisher.Flux<T> execute(com.google.firestore.v1.StructuredQuery.Builder builder, Class<T> entityType) Description copied from interface:FirestoreReactiveOperationsExecutes a query represented as query builder and returns results of the given domain type.- Specified by:
executein interfaceFirestoreReactiveOperations- Type Parameters:
T- the type param of the domain type.- Parameters:
builder- the query builder.entityType- the domain type of entities.- Returns:
Fluxemitting the found entities.
-
withParent
Description copied from interface:FirestoreReactiveOperationsCreates FirestoreReactiveOperations object with a specified parent document. All operations and queries will be scoped to that parent document's subcollections. By default, FirestoreReactiveOperations uses the root document as the parent.- Specified by:
withParentin interfaceFirestoreReactiveOperations- Parameters:
id- the id of the Document entityentityClass- the class of the Document entity- Returns:
- template with a given parent.
-
withParent
Description copied from interface:FirestoreReactiveOperationsCreates FirestoreReactiveOperations object with a specified parent document. The parent doesn't have to exist in Firestore, but should have a non-empty id field. All operations and queries will be scoped to that parent's subcollections. By default, FirestoreReactiveOperations uses the root document as the parent.- Specified by:
withParentin interfaceFirestoreReactiveOperations- Type Parameters:
T- the type param of the parent.- Parameters:
parent- the query builder.- Returns:
- template with a given parent.
-
buildResourceName
Description copied from interface:FirestoreReactiveOperationsBuilds the full reference path to a resource such as a document or a sub-collection. This method uses the root collection as the parent (projects/{project_id}/databases/{database_id}/documents/{collection_name}/)- Specified by:
buildResourceNamein interfaceFirestoreReactiveOperations- Parameters:
persistentEntity- a Firestore persistent entityresource- the resource name or path to the resource.- Returns:
- a
Stringrepresenting the reference path.
-
getMappingContext
-
getClassMapper
-