Class ReactiveCosmosTemplate
java.lang.Object
com.azure.spring.data.cosmos.core.ReactiveCosmosTemplate
- All Implemented Interfaces:
ReactiveCosmosOperations
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
public class ReactiveCosmosTemplate
extends Object
implements ReactiveCosmosOperations, org.springframework.context.ApplicationContextAware
Template class of reactive cosmos
-
Constructor Summary
ConstructorsConstructorDescriptionReactiveCosmosTemplate
(com.azure.cosmos.CosmosAsyncClient client, String databaseName, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter) InitializationReactiveCosmosTemplate
(com.azure.cosmos.CosmosAsyncClient client, String databaseName, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter, org.springframework.data.auditing.IsNewAwareAuditingHandler cosmosAuditingHandler) InitializationReactiveCosmosTemplate
(CosmosFactory cosmosFactory, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter) InitializationReactiveCosmosTemplate
(CosmosFactory cosmosFactory, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter, org.springframework.data.auditing.IsNewAwareAuditingHandler cosmosAuditingHandler) Constructor -
Method Summary
Modifier and TypeMethodDescriptionCountcount
(CosmosQuery query, String containerName) CountCountMono
<com.azure.cosmos.models.CosmosContainerResponse> createContainerIfNotExists
(CosmosEntityInformation<?, ?> information) Creates a container if it doesn't already exist<T> Flux
<T> delete
(CosmosQuery query, Class<T> domainType, String containerName) Delete items matching query with bulk if PK existsDelete all items in a containerdeleteById
(String containerName, Object id, com.azure.cosmos.models.PartitionKey partitionKey) Deletes the item with id and partition key.void
deleteContainer
(String containerName) Delete container with container namedeleteEntities
(CosmosEntityInformation<T, ?> entityInformation, Iterable<S> entities) Delete all items with bulk.deleteEntities
(CosmosEntityInformation<T, ?> entityInformation, Flux<S> entities) Delete all items with bulk.deleteEntity
(String containerName, T entity) Deletes the entityexists
(CosmosQuery query, Class<?> domainType, String containerName) ExistsexistsById
(Object id, Class<?> domainType, String containerName) Exists<T> Flux
<T> find
(CosmosQuery query, Class<T> domainType, String containerName) Find items<T> Flux
<T> Find all items in a given container with partition key<T> Flux
<T> Find all items in a given container<T> Flux
<T> Find all items in a given container<T> Mono
<T> Find by id<T> Mono
<T> Find by id<T> Mono
<T> Find by idgetContainerName
(Class<?> domainType) Get container namegetContainerNameOverride
(String containerName) Check if an overridden version of containerName is present, and if so, return itMono
<com.azure.cosmos.models.CosmosContainerProperties> getContainerProperties
(String containerName) Get properties for specified containerTo get converter<T> Mono
<T> Insert<T> Mono
<T> Insert<T> Mono
<T> insert
(T objectToSave) Insert<T> Mono
<T> insert
(T objectToSave, com.azure.cosmos.models.PartitionKey partitionKey) Insert<S extends T,
T>
Flux<S> insertAll
(CosmosEntityInformation<T, ?> entityInformation, Iterable<S> entities) Insert all items with bulk.<S extends T,
T>
Flux<S> insertAll
(CosmosEntityInformation<T, ?> entityInformation, Flux<S> entities) Insert all items with bulk.<T> Mono
<T> patch
(Object id, com.azure.cosmos.models.PartitionKey partitionKey, Class<T> domainType, com.azure.cosmos.models.CosmosPatchOperations patchOperations) Patches item applies partial update (patch) to an item<T> Mono
<T> patch
(Object id, com.azure.cosmos.models.PartitionKey partitionKey, Class<T> domainType, com.azure.cosmos.models.CosmosPatchOperations patchOperations, com.azure.cosmos.models.CosmosPatchItemRequestOptions options) applies partial update (patch) to an item with CosmosPatchItemRequestOptionsMono
<com.azure.cosmos.models.CosmosContainerProperties> replaceContainerProperties
(String containerName, com.azure.cosmos.models.CosmosContainerProperties properties) Replace container properties for the specified container<T> Flux
<T> Run the query.<T> Flux
<T> runQuery
(com.azure.cosmos.models.SqlQuerySpec querySpec, org.springframework.data.domain.Sort sort, Class<?> domainType, Class<T> returnType) Run the query.void
setApplicationContext
(org.springframework.context.ApplicationContext applicationContext) Sum<T> Mono
<T> Upsert<T> Mono
<T> upsert
(T object) Upsert
-
Constructor Details
-
ReactiveCosmosTemplate
public ReactiveCosmosTemplate(com.azure.cosmos.CosmosAsyncClient client, String databaseName, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter, org.springframework.data.auditing.IsNewAwareAuditingHandler cosmosAuditingHandler) Initialization- Parameters:
client
- must not be nulldatabaseName
- must not be nullcosmosConfig
- must not be nullmappingCosmosConverter
- must not be nullcosmosAuditingHandler
- can be null
-
ReactiveCosmosTemplate
public ReactiveCosmosTemplate(com.azure.cosmos.CosmosAsyncClient client, String databaseName, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter) Initialization- Parameters:
client
- must not be nulldatabaseName
- must not be nullcosmosConfig
- must not be nullmappingCosmosConverter
- must not be null
-
ReactiveCosmosTemplate
public ReactiveCosmosTemplate(CosmosFactory cosmosFactory, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter, org.springframework.data.auditing.IsNewAwareAuditingHandler cosmosAuditingHandler) Constructor- Parameters:
cosmosFactory
- the cosmos db factorycosmosConfig
- the cosmos configmappingCosmosConverter
- the mappingCosmosConvertercosmosAuditingHandler
- the auditing handler
-
ReactiveCosmosTemplate
public ReactiveCosmosTemplate(CosmosFactory cosmosFactory, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter) Initialization- Parameters:
cosmosFactory
- must not be nullcosmosConfig
- must not be nullmappingCosmosConverter
- must not be null
-
-
Method Details
-
setApplicationContext
public void setApplicationContext(@NonNull org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
- Parameters:
applicationContext
- the application context- Throws:
org.springframework.beans.BeansException
- the bean exception
-
createContainerIfNotExists
public Mono<com.azure.cosmos.models.CosmosContainerResponse> createContainerIfNotExists(CosmosEntityInformation<?, ?> information) Creates a container if it doesn't already exist- Specified by:
createContainerIfNotExists
in interfaceReactiveCosmosOperations
- Parameters:
information
- the CosmosEntityInformation- Returns:
- Mono containing CosmosContainerResponse
-
getContainerProperties
public Mono<com.azure.cosmos.models.CosmosContainerProperties> getContainerProperties(String containerName) Description copied from interface:ReactiveCosmosOperations
Get properties for specified container- Specified by:
getContainerProperties
in interfaceReactiveCosmosOperations
- Parameters:
containerName
- String- Returns:
- CosmosContainerProperties
-
replaceContainerProperties
public Mono<com.azure.cosmos.models.CosmosContainerProperties> replaceContainerProperties(String containerName, com.azure.cosmos.models.CosmosContainerProperties properties) Description copied from interface:ReactiveCosmosOperations
Replace container properties for the specified container- Specified by:
replaceContainerProperties
in interfaceReactiveCosmosOperations
- Parameters:
containerName
- Stringproperties
- CosmosContainerProperties- Returns:
- CosmosContainerProperties
-
findAll
Find all items in a given container- Specified by:
findAll
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- type of domainType- Parameters:
containerName
- the containerNamedomainType
- the domainType- Returns:
- Flux with all the found items or error
-
findAll
Find all items in a given container- Specified by:
findAll
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- type of domainType- Parameters:
domainType
- the domainType- Returns:
- Flux with all the found items or error
-
findAll
Description copied from interface:ReactiveCosmosOperations
Find all items in a given container with partition key- Specified by:
findAll
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- type of domainType- Parameters:
partitionKey
- partition KeydomainType
- the domainType- Returns:
- Flux of results
-
findById
Find by id- Specified by:
findById
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- type of domainType- Parameters:
id
- the iddomainType
- the domainType- Returns:
- Mono with the item or error
-
findById
Find by id- Specified by:
findById
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- type of domainType- Parameters:
containerName
- the container nameid
- the iddomainType
- the entity class- Returns:
- Mono with the item or error
-
findById
public <T> Mono<T> findById(Object id, Class<T> domainType, com.azure.cosmos.models.PartitionKey partitionKey) Find by id- Specified by:
findById
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- type of domainType- Parameters:
id
- the iddomainType
- the entity classpartitionKey
- partition Key- Returns:
- Mono with the item or error
-
insert
Insert- Specified by:
insert
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- type of inserted objectToSave- Parameters:
objectToSave
- the object to savepartitionKey
- the partition key- Returns:
- Mono with the item or error
-
insert
Insert- Type Parameters:
T
- type of inserted objectToSave- Parameters:
objectToSave
- the object to save- Returns:
- Mono with the item or error
-
insert
public <T> Mono<T> insert(String containerName, T objectToSave, com.azure.cosmos.models.PartitionKey partitionKey) Insert- Specified by:
insert
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- type of inserted objectToSave- Parameters:
containerName
- the container nameobjectToSave
- the object to savepartitionKey
- the partition key- Returns:
- Mono with the item or error
-
insert
Insert- Specified by:
insert
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- type of inserted objectToSave- Parameters:
containerName
- the container nameobjectToSave
- the object to save- Returns:
- Mono with the item or error
-
insertAll
public <S extends T,T> Flux<S> insertAll(CosmosEntityInformation<T, ?> entityInformation, Iterable<S> entities) Insert all items with bulk.- Specified by:
insertAll
in interfaceReactiveCosmosOperations
- Type Parameters:
S
- type class of domain typeT
- type class of domain type- Parameters:
entityInformation
- the CosmosEntityInformationentities
- the Iterable entities to be inserted- Returns:
- Flux of result
-
insertAll
public <S extends T,T> Flux<S> insertAll(CosmosEntityInformation<T, ?> entityInformation, Flux<S> entities) Insert all items with bulk.- Specified by:
insertAll
in interfaceReactiveCosmosOperations
- Type Parameters:
S
- type class of domain typeT
- type class of domain type- Parameters:
entityInformation
- the CosmosEntityInformationentities
- the Flux of entities to be inserted- Returns:
- Flux of result
-
patch
public <T> Mono<T> patch(Object id, com.azure.cosmos.models.PartitionKey partitionKey, Class<T> domainType, com.azure.cosmos.models.CosmosPatchOperations patchOperations) Patches item applies partial update (patch) to an item- Specified by:
patch
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- type class of domain type- Parameters:
id
- must not be nullpartitionKey
- must not be nulldomainType
- must not be nullpatchOperations
- must not be null- Returns:
- the patched item
-
patch
public <T> Mono<T> patch(Object id, com.azure.cosmos.models.PartitionKey partitionKey, Class<T> domainType, com.azure.cosmos.models.CosmosPatchOperations patchOperations, com.azure.cosmos.models.CosmosPatchItemRequestOptions options) applies partial update (patch) to an item with CosmosPatchItemRequestOptions- Specified by:
patch
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- type class of domain type- Parameters:
id
- must not be nullpartitionKey
- must not be nulldomainType
- must not be nullpatchOperations
- must not be nulloptions
- Optional CosmosPatchItemRequestOptions, e.g. options.setFilterPredicate("FROM products p WHERE p.used = false");- Returns:
- the patched item
-
upsert
Upsert- Specified by:
upsert
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- type class of object- Parameters:
object
- the object to upsert- Returns:
- Mono with the item or error
-
upsert
Upsert- Specified by:
upsert
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- type class of object- Parameters:
containerName
- the container nameobject
- the object to save- Returns:
- Mono with the item or error
-
deleteById
public Mono<Void> deleteById(String containerName, Object id, com.azure.cosmos.models.PartitionKey partitionKey) Deletes the item with id and partition key.- Specified by:
deleteById
in interfaceReactiveCosmosOperations
- Parameters:
containerName
- Container name of databaseid
- item idpartitionKey
- the partition key- Returns:
- void Mono
-
deleteEntity
Deletes the entity- Specified by:
deleteEntity
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- type class of domain type- Parameters:
containerName
- Container name of databaseentity
- the entity to delete- Returns:
- void Mono
-
deleteEntities
public <S extends T,T> Mono<Void> deleteEntities(CosmosEntityInformation<T, ?> entityInformation, Iterable<S> entities) Delete all items with bulk.- Specified by:
deleteEntities
in interfaceReactiveCosmosOperations
- Type Parameters:
S
- type class of domain typeT
- type class of domain type- Parameters:
entityInformation
- the CosmosEntityInformationentities
- the Iterable entities to be deleted- Returns:
- void Mono
-
deleteEntities
public <S extends T,T> Mono<Void> deleteEntities(CosmosEntityInformation<T, ?> entityInformation, Flux<S> entities) Delete all items with bulk.- Specified by:
deleteEntities
in interfaceReactiveCosmosOperations
- Type Parameters:
S
- type class of domain typeT
- type class of domain type- Parameters:
entityInformation
- the CosmosEntityInformationentities
- the Iterable entities to be deleted- Returns:
- void Mono
-
deleteAll
Delete all items in a container- Specified by:
deleteAll
in interfaceReactiveCosmosOperations
- Parameters:
containerName
- the container namedomainType
- the domainType- Returns:
- void Mono
-
delete
Delete items matching query with bulk if PK exists- Specified by:
delete
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- type class of domainType- Parameters:
query
- the document querydomainType
- the entity classcontainerName
- the container name- Returns:
- Mono
-
find
Find items- Specified by:
find
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- type class of domainType- Parameters:
query
- the document querydomainType
- the entity classcontainerName
- the container name- Returns:
- Flux with found items or error
-
exists
Exists- Specified by:
exists
in interfaceReactiveCosmosOperations
- Parameters:
query
- the document querydomainType
- the entity classcontainerName
- the container name- Returns:
- Mono with a boolean or error
-
existsById
Exists- Specified by:
existsById
in interfaceReactiveCosmosOperations
- Parameters:
id
- the iddomainType
- the entity classcontainerName
- the container name- Returns:
- Mono with a boolean or error
-
count
Count- Specified by:
count
in interfaceReactiveCosmosOperations
- Parameters:
containerName
- the container name- Returns:
- Mono with the count or error
-
count
Count- Specified by:
count
in interfaceReactiveCosmosOperations
- Parameters:
query
- the document querycontainerName
- the container name- Returns:
- Mono with count or error
-
count
Count- Specified by:
count
in interfaceReactiveCosmosOperations
- Parameters:
querySpec
- the document query speccontainerName
- the container name- Returns:
- Mono with count or error
-
sum
Sum- Specified by:
sum
in interfaceReactiveCosmosOperations
- Parameters:
querySpec
- the document query speccontainerName
- the container name- Returns:
- Mono with sum or error
-
getConverter
Description copied from interface:ReactiveCosmosOperations
To get converter- Specified by:
getConverter
in interfaceReactiveCosmosOperations
- Returns:
- MappingCosmosConverter
-
runQuery
public <T> Flux<T> runQuery(com.azure.cosmos.models.SqlQuerySpec querySpec, Class<?> domainType, Class<T> returnType) Description copied from interface:ReactiveCosmosOperations
Run the query.- Specified by:
runQuery
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- the type parameter- Parameters:
querySpec
- the query specdomainType
- the domain typereturnType
- the return type- Returns:
- the flux
-
runQuery
public <T> Flux<T> runQuery(com.azure.cosmos.models.SqlQuerySpec querySpec, org.springframework.data.domain.Sort sort, Class<?> domainType, Class<T> returnType) Description copied from interface:ReactiveCosmosOperations
Run the query.- Specified by:
runQuery
in interfaceReactiveCosmosOperations
- Type Parameters:
T
- the type parameter- Parameters:
querySpec
- the query specsort
- the sort orderdomainType
- the domain typereturnType
- the return type- Returns:
- the flux
-
deleteContainer
Delete container with container name- Specified by:
deleteContainer
in interfaceReactiveCosmosOperations
- Parameters:
containerName
- the container name
-
getContainerName
Description copied from interface:ReactiveCosmosOperations
Get container name- Specified by:
getContainerName
in interfaceReactiveCosmosOperations
- Parameters:
domainType
- the domainType- Returns:
- container name
-
getContainerNameOverride
Check if an overridden version of containerName is present, and if so, return it- Parameters:
containerName
- Container name of database- Returns:
- containerName
-