public class FirestoreTemplate extends Object implements FirestoreReactiveOperations
FirestoreReactiveOperations
.Modifier and Type | Field and Description |
---|---|
static String |
NAME_FIELD
Constant representing the special property to use when querying by a document ID.
|
Constructor and Description |
---|
FirestoreTemplate(com.google.firestore.v1.FirestoreGrpc.FirestoreStub firestoreStub,
String parent,
FirestoreClassMapper classMapper,
FirestoreMappingContext mappingContext)
Constructor for FirestoreTemplate.
|
Modifier and Type | Method and Description |
---|---|
String |
buildResourceName(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(Class<T> entityClass)
Count entities of the given domain.
|
<T> reactor.core.publisher.Mono<Long> |
count(Class<T> entityClass,
com.google.firestore.v1.StructuredQuery.Builder queryBuilder)
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> |
deleteAll(Class<T> clazz)
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> |
execute(com.google.firestore.v1.StructuredQuery.Builder builder,
Class<T> entityType)
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> |
findAll(Class<T> clazz)
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> |
findById(org.reactivestreams.Publisher<String> idPublisher,
Class<T> entityClass)
Get an entity of the given domain type by id.
|
FirestoreClassMapper |
getClassMapper() |
FirestoreMappingContext |
getMappingContext() |
int |
getWriteBufferSize() |
Duration |
getWriteBufferTimeout() |
<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 the
Duration for how long to wait for the entity buffer to fill before sending
the buffered entities to Firestore for insert/update/delete operations. |
FirestoreReactiveOperations |
withParent(String id,
Class<?> entityClass)
Creates FirestoreReactiveOperations object with a specified parent document.
|
<T> FirestoreReactiveOperations |
withParent(T parent)
Creates FirestoreReactiveOperations object with a specified parent document.
|
public static final String NAME_FIELD
public FirestoreTemplate(com.google.firestore.v1.FirestoreGrpc.FirestoreStub firestoreStub, String parent, FirestoreClassMapper classMapper, FirestoreMappingContext mappingContext)
firestoreStub
- Firestore gRPC stubparent
- the parent resource. For example:
projects/{project_id}/databases/{database_id}/documentsclassMapper
- a FirestoreClassMapper
used for conversionmappingContext
- Mapping Contextpublic void setWriteBufferTimeout(Duration bufferTimeout)
Duration
for how long to wait for the entity buffer to fill before sending
the buffered entities to Firestore for insert/update/delete operations.bufferTimeout
- duration to wait for entity buffer to fill before sending to Firestore.
(default = 500ms)public Duration getWriteBufferTimeout()
public void setWriteBufferSize(int bufferWriteSize)
The maximum buffer size is 500. In most cases users should leave this at the maximum value.
bufferWriteSize
- the entity buffer size for buffered operations (default = 500)public int getWriteBufferSize()
public <T> reactor.core.publisher.Mono<Boolean> existsById(org.reactivestreams.Publisher<String> idPublisher, Class<T> entityClass)
FirestoreReactiveOperations
existsById
in interface FirestoreReactiveOperations
T
- the type param of the domain type.idPublisher
- publisher that provides an id.entityClass
- the domain type of the entity.Mono
emitting true
if an entity with the given id exists, false
otherwise.public <T> reactor.core.publisher.Mono<T> findById(org.reactivestreams.Publisher<String> idPublisher, Class<T> entityClass)
FirestoreReactiveOperations
findById
in interface FirestoreReactiveOperations
T
- the type param of the domain type.idPublisher
- publisher that provides an id.entityClass
- the domain type of the entity.Mono
emitting the found entity.public <T> reactor.core.publisher.Flux<T> findAllById(org.reactivestreams.Publisher<String> idPublisher, Class<T> entityClass)
FirestoreReactiveOperations
findAllById
in interface FirestoreReactiveOperations
T
- the type param of the domain type.idPublisher
- publisher that provides ids.entityClass
- the domain type of the entity.Flux
emitting the found entities.public <T> reactor.core.publisher.Mono<T> save(T entity)
FirestoreReactiveOperations
save
in interface FirestoreReactiveOperations
T
- the type of the object to save.entity
- the instance to save.Mono
emitting the saved entity.public <T> reactor.core.publisher.Flux<T> saveAll(org.reactivestreams.Publisher<T> instances)
The buffer size and buffer timeout settings for saveAll(org.reactivestreams.Publisher<T>)
can be modified by calling
setWriteBufferSize(int)
and setWriteBufferTimeout(java.time.Duration)
.
saveAll
in interface FirestoreReactiveOperations
T
- the type of the objects to save.instances
- the objects to save.Flux
emitting the saved entities.public <T> reactor.core.publisher.Flux<T> findAll(Class<T> clazz)
FirestoreReactiveOperations
findAll
in interface FirestoreReactiveOperations
T
- the type param of the domain type.clazz
- the domain type to get.Mono
emitting the found entities.public <T> reactor.core.publisher.Mono<Long> count(Class<T> entityClass)
FirestoreReactiveOperations
count
in interface FirestoreReactiveOperations
T
- the type param of the domain type.entityClass
- the domain type of entities.Mono
emitting the number of entities.public <T> reactor.core.publisher.Mono<Long> count(Class<T> entityClass, com.google.firestore.v1.StructuredQuery.Builder queryBuilder)
FirestoreReactiveOperations
count
in interface FirestoreReactiveOperations
T
- the type param of the domain type.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 executionMono
emitting the number of entities.public <T> reactor.core.publisher.Mono<Long> deleteAll(Class<T> clazz)
The buffer size and buffer timeout settings for saveAll(org.reactivestreams.Publisher<T>)
can be modified by calling
setWriteBufferSize(int)
and setWriteBufferTimeout(java.time.Duration)
.
deleteAll
in interface FirestoreReactiveOperations
T
- the type param of the domain type.clazz
- the domain type to delete from Cloud Datastore.Mono
emitting the number of deleted entities.public <T> reactor.core.publisher.Mono<Void> delete(org.reactivestreams.Publisher<T> entityPublisher)
The buffer size and buffer timeout settings for saveAll(org.reactivestreams.Publisher<T>)
can be modified by calling
setWriteBufferSize(int)
and setWriteBufferTimeout(java.time.Duration)
.
delete
in interface FirestoreReactiveOperations
T
- the type param of the domain type.entityPublisher
- publisher that provides entities to be removed.Mono
signaling when operation has completed.public reactor.core.publisher.Mono<Void> deleteById(org.reactivestreams.Publisher<String> idPublisher, Class<?> entityClass)
The buffer size and buffer timeout settings for saveAll(org.reactivestreams.Publisher<T>)
can be modified by calling
setWriteBufferSize(int)
and setWriteBufferTimeout(java.time.Duration)
.
deleteById
in interface FirestoreReactiveOperations
idPublisher
- publisher that provides ids of entities to be removed.entityClass
- the domain type of entities.Mono
signaling when operation has completed.public <T> reactor.core.publisher.Flux<T> execute(com.google.firestore.v1.StructuredQuery.Builder builder, Class<T> entityType)
FirestoreReactiveOperations
execute
in interface FirestoreReactiveOperations
T
- the type param of the domain type.builder
- the query builder.entityType
- the domain type of entities.Flux
emitting the found entities.public FirestoreReactiveOperations withParent(String id, Class<?> entityClass)
FirestoreReactiveOperations
withParent
in interface FirestoreReactiveOperations
id
- the id of the Document entityentityClass
- the class of the Document entitypublic <T> FirestoreReactiveOperations withParent(T parent)
FirestoreReactiveOperations
withParent
in interface FirestoreReactiveOperations
T
- the type param of the parent.parent
- the query builder.public String buildResourceName(FirestorePersistentEntity<?> persistentEntity, String resource)
FirestoreReactiveOperations
buildResourceName
in interface FirestoreReactiveOperations
persistentEntity
- a Firestore persistent entityresource
- the resource name or path to the resource.String
representing the reference path.public FirestoreMappingContext getMappingContext()
public FirestoreClassMapper getClassMapper()
Copyright © 2021. All rights reserved.