Class FirestoreTemplate
- All Implemented Interfaces:
FirestoreReactiveOperations
FirestoreReactiveOperations
.- Since:
- 1.2
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Constant representing the special property to use when querying by a document ID. -
Constructor Summary
ConstructorDescriptionFirestoreTemplate
(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.void
setWriteBufferSize
(int bufferWriteSize) Sets how many entities to include in an insert/update/delete buffered operation.void
setWriteBufferTimeout
(Duration bufferTimeout) Sets theDuration
for 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
- aFirestoreClassMapper
used for conversionmappingContext
- Mapping Context
-
-
Method Details
-
setWriteBufferTimeout
Sets theDuration
for 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:FirestoreReactiveOperations
Test if the entity of the given domain type with a given id exists. Uses the first emitted element to perform the query.- Specified by:
existsById
in 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:
Mono
emittingtrue
if an entity with the given id exists,false
otherwise.
-
findById
public <T> reactor.core.publisher.Mono<T> findById(org.reactivestreams.Publisher<String> idPublisher, Class<T> entityClass) Description copied from interface:FirestoreReactiveOperations
Get an entity of the given domain type by id. Uses the first emitted element to perform the query.- Specified by:
findById
in 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:
Mono
emitting the found entity.
-
findAllById
public <T> reactor.core.publisher.Flux<T> findAllById(org.reactivestreams.Publisher<String> idPublisher, Class<T> entityClass) Description copied from interface:FirestoreReactiveOperations
Get an entity of the given domain type by id.- Specified by:
findAllById
in 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:
Flux
emitting the found entities.
-
save
public <T> reactor.core.publisher.Mono<T> save(T entity) Description copied from interface:FirestoreReactiveOperations
Saves an instance of an object to Cloud Firestore. Behaves as an insert only (not update).- Specified by:
save
in interfaceFirestoreReactiveOperations
- Type Parameters:
T
- the type of the object to save.- Parameters:
entity
- the instance to save.- Returns:
Mono
emitting 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:
saveAll
in interfaceFirestoreReactiveOperations
- Type Parameters:
T
- the type of the objects to save.- Parameters:
instances
- the objects to save.- Returns:
Flux
emitting the saved entities.
-
findAll
Description copied from interface:FirestoreReactiveOperations
Get all the entities of the given domain type.- Specified by:
findAll
in interfaceFirestoreReactiveOperations
- Type Parameters:
T
- the type param of the domain type.- Parameters:
clazz
- the domain type to get.- Returns:
Mono
emitting the found entities.
-
count
Description copied from interface:FirestoreReactiveOperations
Count 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:
count
in interfaceFirestoreReactiveOperations
- Type Parameters:
T
- the type param of the domain type.- Parameters:
entityClass
- the domain type of entities.- Returns:
Mono
emitting 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:FirestoreReactiveOperations
Count 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:
count
in 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:
Mono
emitting 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:
deleteAll
in interfaceFirestoreReactiveOperations
- Type Parameters:
T
- the type param of the domain type.- Parameters:
clazz
- the domain type to delete from Cloud Datastore.- Returns:
Mono
emitting 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:
delete
in interfaceFirestoreReactiveOperations
- Type Parameters:
T
- the type param of the domain type.- Parameters:
entityPublisher
- publisher that provides entities to be removed.- Returns:
Mono
signaling 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:
deleteById
in interfaceFirestoreReactiveOperations
- Parameters:
idPublisher
- publisher that provides ids of entities to be removed.entityClass
- the domain type of entities.- Returns:
Mono
signaling 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:FirestoreReactiveOperations
Executes a query represented as query builder and returns results of the given domain type.- Specified by:
execute
in interfaceFirestoreReactiveOperations
- Type Parameters:
T
- the type param of the domain type.- Parameters:
builder
- the query builder.entityType
- the domain type of entities.- Returns:
Flux
emitting the found entities.
-
withParent
Description copied from interface:FirestoreReactiveOperations
Creates 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:
withParent
in 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:FirestoreReactiveOperations
Creates 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:
withParent
in 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:FirestoreReactiveOperations
Builds 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:
buildResourceName
in interfaceFirestoreReactiveOperations
- Parameters:
persistentEntity
- a Firestore persistent entityresource
- the resource name or path to the resource.- Returns:
- a
String
representing the reference path.
-
getMappingContext
-
getClassMapper
-