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
ConstructorDescriptionReactiveCosmosTemplate
(CosmosAsyncClient client, String databaseName, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter) InitializationReactiveCosmosTemplate
(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 TypeMethodDescriptioncount
(SqlQuerySpec querySpec, String containerName) Countcount
(CosmosQuery query, String containerName) CountCountcreateContainerIfNotExists
(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 queryDelete all items in a containerdeleteById
(String containerName, Object id, PartitionKey partitionKey) Deletes the item with id and partition key.void
deleteContainer
(String containerName) Delete container with container namedeleteEntity
(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>
findAll
(PartitionKey partitionKey, Class<T> domainType) 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>
findById
(Object id, Class<T> domainType, PartitionKey partitionKey) Find by id<T> Mono<T>
Find by idgetContainerName
(Class<?> domainType) Get container namegetContainerProperties
(String containerName) Get properties for specified containerTo get converter<T> Mono<T>
Insert<T> Mono<T>
insert
(String containerName, T objectToSave, PartitionKey partitionKey) Insert<T> Mono<T>
insert
(T objectToSave) Insert<T> Mono<T>
insert
(T objectToSave, PartitionKey partitionKey) InsertreplaceContainerProperties
(String containerName, CosmosContainerProperties properties) Replace container properties for the specified container<T> Flux<T>
runQuery
(SqlQuerySpec querySpec, Class<?> domainType, Class<T> returnType) Run the query.<T> Flux<T>
runQuery
(SqlQuerySpec querySpec, org.springframework.data.domain.Sort sort, Class<?> domainType, Class<T> returnType) Run the query.void
setApplicationContext
(org.springframework.context.ApplicationContext applicationContext) <T> Mono<T>
Upsert<T> Mono<T>
upsert
(T object) Upsert
-
Constructor Details
-
ReactiveCosmosTemplate
public ReactiveCosmosTemplate(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(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<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
Description copied from interface:ReactiveCosmosOperations
Get properties for specified container- Specified by:
getContainerProperties
in interfaceReactiveCosmosOperations
- Parameters:
containerName
- String- Returns:
- CosmosContainerProperties
-
replaceContainerProperties
public Mono<CosmosContainerProperties> replaceContainerProperties(String containerName, 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
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
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
-
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
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
-
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- 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
-
getConverter
Description copied from interface:ReactiveCosmosOperations
To get converter- Specified by:
getConverter
in interfaceReactiveCosmosOperations
- Returns:
- MappingCosmosConverter
-
runQuery
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(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 domain class- Returns:
- the container name
-