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
Constructors Constructor Description ReactiveCosmosTemplate(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Mono<Long>count(SqlQuerySpec querySpec, String containerName)CountMono<Long>count(CosmosQuery query, String containerName)CountMono<Long>count(String containerName)CountMono<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 queryMono<Void>deleteAll(String containerName, Class<?> domainType)Delete all items in a containerMono<Void>deleteById(String containerName, Object id, PartitionKey partitionKey)Deletes the item with id and partition key.voiddeleteContainer(String containerName)Delete container with container name<T> Mono<Void>deleteEntity(String containerName, T entity)Deletes the entityMono<Boolean>exists(CosmosQuery query, Class<?> domainType, String containerName)ExistsMono<Boolean>existsById(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>findAll(Class<T> domainType)Find all items in a given container<T> Flux<T>findAll(String containerName, Class<T> domainType)Find all items in a given container<T> Mono<T>findById(Object id, Class<T> domainType)Find by id<T> Mono<T>findById(Object id, Class<T> domainType, PartitionKey partitionKey)Find by id<T> Mono<T>findById(String containerName, Object id, Class<T> domainType)Find by idStringgetContainerName(Class<?> domainType)Get container nameMono<CosmosContainerProperties>getContainerProperties(String containerName)Get properties for specified containerMappingCosmosConvertergetConverter()To get converter<T> Mono<T>insert(String containerName, Object objectToSave, PartitionKey partitionKey)Insert<T> Mono<T>insert(String containerName, T objectToSave)Insert<T> Mono<T>insert(T objectToSave)Insert<T> Mono<T>insert(T objectToSave, PartitionKey partitionKey)InsertMono<CosmosContainerProperties>replaceContainerProperties(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.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)<T> Mono<T>upsert(String containerName, T object)Upsert<T> Mono<T>upsert(T object)Upsert
-
-
-
Constructor Detail
-
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 Detail
-
setApplicationContext
public void setApplicationContext(@NonNull org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException- Specified by:
setApplicationContextin 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:
createContainerIfNotExistsin interfaceReactiveCosmosOperations- Parameters:
information- the CosmosEntityInformation- Returns:
- Mono containing CosmosContainerResponse
-
getContainerProperties
public Mono<CosmosContainerProperties> getContainerProperties(String containerName)
Description copied from interface:ReactiveCosmosOperationsGet properties for specified container- Specified by:
getContainerPropertiesin interfaceReactiveCosmosOperations- Parameters:
containerName- String- Returns:
- CosmosContainerProperties
-
replaceContainerProperties
public Mono<CosmosContainerProperties> replaceContainerProperties(String containerName, CosmosContainerProperties properties)
Description copied from interface:ReactiveCosmosOperationsReplace container properties for the specified container- Specified by:
replaceContainerPropertiesin interfaceReactiveCosmosOperations- Parameters:
containerName- Stringproperties- CosmosContainerProperties- Returns:
- CosmosContainerProperties
-
findAll
public <T> Flux<T> findAll(String containerName, Class<T> domainType)
Find all items in a given container- Specified by:
findAllin interfaceReactiveCosmosOperations- Type Parameters:
T- type of domainType- Parameters:
containerName- the containerNamedomainType- the domainType- Returns:
- Flux with all the found items or error
-
findAll
public <T> Flux<T> findAll(Class<T> domainType)
Find all items in a given container- Specified by:
findAllin interfaceReactiveCosmosOperations- Type Parameters:
T- type of domainType- Parameters:
domainType- the domainType- Returns:
- Flux with all the found items or error
-
findAll
public <T> Flux<T> findAll(PartitionKey partitionKey, Class<T> domainType)
Description copied from interface:ReactiveCosmosOperationsFind all items in a given container with partition key- Specified by:
findAllin interfaceReactiveCosmosOperations- Type Parameters:
T- type of domainType- Parameters:
partitionKey- partition KeydomainType- the domainType- Returns:
- Flux of results
-
findById
public <T> Mono<T> findById(Object id, Class<T> domainType)
Find by id- Specified by:
findByIdin interfaceReactiveCosmosOperations- Type Parameters:
T- type of domainType- Parameters:
id- the iddomainType- the domainType- Returns:
- Mono with the item or error
-
findById
public <T> Mono<T> findById(String containerName, Object id, Class<T> domainType)
Find by id- Specified by:
findByIdin 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, PartitionKey partitionKey)
Find by id- Specified by:
findByIdin interfaceReactiveCosmosOperations- Type Parameters:
T- type of domainType- Parameters:
id- the iddomainType- the entity classpartitionKey- partition Key- Returns:
- Mono with the item or error
-
insert
public <T> Mono<T> insert(T objectToSave, PartitionKey partitionKey)
Insert- Specified by:
insertin 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
public <T> Mono<T> insert(T objectToSave)
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, Object objectToSave, PartitionKey partitionKey)
Insert- Specified by:
insertin 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
public <T> Mono<T> insert(String containerName, T objectToSave)
Insert- Specified by:
insertin 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
public <T> Mono<T> upsert(T object)
Upsert- Specified by:
upsertin interfaceReactiveCosmosOperations- Type Parameters:
T- type class of object- Parameters:
object- the object to upsert- Returns:
- Mono with the item or error
-
upsert
public <T> Mono<T> upsert(String containerName, T object)
Upsert- Specified by:
upsertin 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, PartitionKey partitionKey)
Deletes the item with id and partition key.- Specified by:
deleteByIdin interfaceReactiveCosmosOperations- Parameters:
containerName- Container name of databaseid- item idpartitionKey- the partition key- Returns:
- void Mono
-
deleteEntity
public <T> Mono<Void> deleteEntity(String containerName, T entity)
Deletes the entity- Specified by:
deleteEntityin interfaceReactiveCosmosOperations- Type Parameters:
T- type class of domain type- Parameters:
containerName- Container name of databaseentity- the entity to delete- Returns:
- void Mono
-
deleteAll
public Mono<Void> deleteAll(@NonNull String containerName, @NonNull Class<?> domainType)
Delete all items in a container- Specified by:
deleteAllin interfaceReactiveCosmosOperations- Parameters:
containerName- the container namedomainType- the domainType- Returns:
- void Mono
-
delete
public <T> Flux<T> delete(CosmosQuery query, Class<T> domainType, String containerName)
Delete items matching query- Specified by:
deletein interfaceReactiveCosmosOperations- Type Parameters:
T- type class of domainType- Parameters:
query- the document querydomainType- the entity classcontainerName- the container name- Returns:
- Mono
-
find
public <T> Flux<T> find(CosmosQuery query, Class<T> domainType, String containerName)
Find items- Specified by:
findin 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
public Mono<Boolean> exists(CosmosQuery query, Class<?> domainType, String containerName)
Exists- Specified by:
existsin interfaceReactiveCosmosOperations- Parameters:
query- the document querydomainType- the entity classcontainerName- the container name- Returns:
- Mono with a boolean or error
-
existsById
public Mono<Boolean> existsById(Object id, Class<?> domainType, String containerName)
Exists- Specified by:
existsByIdin interfaceReactiveCosmosOperations- Parameters:
id- the iddomainType- the entity classcontainerName- the container name- Returns:
- Mono with a boolean or error
-
count
public Mono<Long> count(String containerName)
Count- Specified by:
countin interfaceReactiveCosmosOperations- Parameters:
containerName- the container name- Returns:
- Mono with the count or error
-
count
public Mono<Long> count(CosmosQuery query, String containerName)
Count- Specified by:
countin interfaceReactiveCosmosOperations- Parameters:
query- the document querycontainerName- the container name- Returns:
- Mono with count or error
-
count
public Mono<Long> count(SqlQuerySpec querySpec, String containerName)
Count- Specified by:
countin interfaceReactiveCosmosOperations- Parameters:
querySpec- the document query speccontainerName- the container name- Returns:
- Mono with count or error
-
getConverter
public MappingCosmosConverter getConverter()
Description copied from interface:ReactiveCosmosOperationsTo get converter- Specified by:
getConverterin interfaceReactiveCosmosOperations- Returns:
- MappingCosmosConverter
-
runQuery
public <T> Flux<T> runQuery(SqlQuerySpec querySpec, Class<?> domainType, Class<T> returnType)
Description copied from interface:ReactiveCosmosOperationsRun the query.- Specified by:
runQueryin 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:ReactiveCosmosOperationsRun the query.- Specified by:
runQueryin 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
public void deleteContainer(@NonNull String containerName)Delete container with container name- Specified by:
deleteContainerin interfaceReactiveCosmosOperations- Parameters:
containerName- the container name
-
getContainerName
public String getContainerName(Class<?> domainType)
Description copied from interface:ReactiveCosmosOperationsGet container name- Specified by:
getContainerNamein interfaceReactiveCosmosOperations- Parameters:
domainType- the domain class- Returns:
- the container name
-
-