ReactiveCosmosTemplate Class

  • java.lang.Object
    • com.azure.spring.data.cosmos.core.ReactiveCosmosTemplate

Implements

ReactiveCosmosOperations org.springframework.context.ApplicationContextAware

public class ReactiveCosmosTemplate
implements ReactiveCosmosOperations, org.springframework.context.ApplicationContextAware

Template class of reactive cosmos

Constructor Summary

Constructor Description
ReactiveCosmosTemplate(CosmosAsyncClient client, String databaseName, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter)

Initialization

ReactiveCosmosTemplate(CosmosAsyncClient client, String databaseName, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter, IsNewAwareAuditingHandler cosmosAuditingHandler)

Initialization

ReactiveCosmosTemplate(CosmosFactory cosmosFactory, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter)

Initialization

ReactiveCosmosTemplate(CosmosFactory cosmosFactory, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter, IsNewAwareAuditingHandler cosmosAuditingHandler)

Constructor

Method Summary

Modifier and Type Method and Description
Mono<Void> <S,T>deleteEntities(CosmosEntityInformation<T,?> entityInformation, Iterable<S> entities)

Delete all items with bulk.

Mono<Void> <S,T>deleteEntities(CosmosEntityInformation<T,?> entityInformation, Flux<S> entities)

Delete all items with bulk.

Flux<S> <S,T>insertAll(CosmosEntityInformation<T,?> entityInformation, Iterable<S> entities)

Insert all items with bulk.

Flux<S> <S,T>insertAll(CosmosEntityInformation<T,?> entityInformation, Flux<S> entities)

Insert all items with bulk.

Flux<T> delete(CosmosQuery query, Class<T> domainType, String containerName)

Delete items matching query with bulk if PK exists

Mono<Void> deleteEntity(String containerName, T entity)

Deletes the entity

Flux<T> find(CosmosQuery query, Class<T> domainType, String containerName)

Find items

Flux<T> findAll(PartitionKey partitionKey, Class<T> domainType)

Find all items in a given container with partition key

Flux<T> findAll(Class<T> domainType)

Find all items in a given container

Flux<T> findAll(String containerName, Class<T> domainType)

Find all items in a given container

Mono<T> findById(Object id, Class<T> domainType)

Find by id

Mono<T> findById(Object id, Class<T> domainType, PartitionKey partitionKey)

Find by id

Mono<T> findById(String containerName, Object id, Class<T> domainType)

Find by id

Mono<T> insert(T objectToSave)

Insert

Mono<T> insert(T objectToSave, PartitionKey partitionKey)

Insert

Mono<T> insert(String containerName, T objectToSave)

Insert

Mono<T> insert(String containerName, T objectToSave, PartitionKey partitionKey)

Insert

Mono<T> patch(Object id, PartitionKey partitionKey, Class<T> domainType, CosmosPatchOperations patchOperations)

Patches item applies partial update (patch) to an item

Mono<T> patch(Object id, PartitionKey partitionKey, Class<T> domainType, CosmosPatchOperations patchOperations, CosmosPatchItemRequestOptions options)

applies partial update (patch) to an item with CosmosPatchItemRequestOptions

Flux<T> runQuery(SqlQuerySpec querySpec, Class<?> domainType, Class<T> returnType)

Run the query.

Flux<T> runQuery(SqlQuerySpec querySpec, Sort sort, Class<?> domainType, Class<T> returnType)

Run the query.

Mono<T> upsert(T object)

Upsert

Mono<T> upsert(String containerName, T object)

Upsert

Mono<Long> count(SqlQuerySpec querySpec, String containerName)

Count

Mono<Long> count(CosmosQuery query, String containerName)

Count

Mono<Long> count(String containerName)

Count

Mono<CosmosContainerResponse> createContainerIfNotExists(CosmosEntityInformation<?,?> information)

Creates a container if it doesn't already exist

Mono<Void> deleteAll(String containerName, Class<?> domainType)

Delete all items in a container

Mono<Void> deleteById(String containerName, Object id, PartitionKey partitionKey)

Deletes the item with id and partition key.

void deleteContainer(String containerName)

Delete container with container name

Mono<Boolean> exists(CosmosQuery query, Class<?> domainType, String containerName)

Exists

Mono<Boolean> existsById(Object id, Class<?> domainType, String containerName)

Exists

String getContainerName(Class<?> domainType)

Get container name

String getContainerNameOverride(String containerName)

Check if an overridden version of containerName is present, and if so, return it

Mono<CosmosContainerProperties> getContainerProperties(String containerName)

Get properties for specified container

MappingCosmosConverter getConverter()

To get converter

Mono<CosmosContainerProperties> replaceContainerProperties(String containerName, CosmosContainerProperties properties)

Replace container properties for the specified container

void setApplicationContext(ApplicationContext applicationContext)

Methods inherited from java.lang.Object

Constructor Details

ReactiveCosmosTemplate

public ReactiveCosmosTemplate(CosmosAsyncClient client, String databaseName, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter)

Initialization

Parameters:

client - must not be null
databaseName - must not be null
cosmosConfig - must not be null
mappingCosmosConverter - must not be null

ReactiveCosmosTemplate

public ReactiveCosmosTemplate(CosmosAsyncClient client, String databaseName, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter, IsNewAwareAuditingHandler cosmosAuditingHandler)

Initialization

Parameters:

client - must not be null
databaseName - must not be null
cosmosConfig - must not be null
mappingCosmosConverter - must not be null
cosmosAuditingHandler - can be null

ReactiveCosmosTemplate

public ReactiveCosmosTemplate(CosmosFactory cosmosFactory, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter)

Initialization

Parameters:

cosmosFactory - must not be null
cosmosConfig - must not be null
mappingCosmosConverter - must not be null

ReactiveCosmosTemplate

public ReactiveCosmosTemplate(CosmosFactory cosmosFactory, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter, IsNewAwareAuditingHandler cosmosAuditingHandler)

Constructor

Parameters:

cosmosFactory - the cosmos db factory
cosmosConfig - the cosmos config
mappingCosmosConverter - the mappingCosmosConverter
cosmosAuditingHandler - the auditing handler

Method Details

<S,T>deleteEntities

public Mono deleteEntities(CosmosEntityInformation entityInformation, Iterable entities)

Delete all items with bulk.

Parameters:

entityInformation - the CosmosEntityInformation
entities - the Iterable entities to be deleted

Returns:

void Mono

<S,T>deleteEntities

public Mono deleteEntities(CosmosEntityInformation entityInformation, Flux entities)

Delete all items with bulk.

Parameters:

entityInformation - the CosmosEntityInformation
entities - the Iterable entities to be deleted

Returns:

void Mono

<S,T>insertAll

public Flux insertAll(CosmosEntityInformation entityInformation, Iterable entities)

Insert all items with bulk.

Parameters:

entityInformation - the CosmosEntityInformation
entities - the Iterable entities to be inserted

Returns:

Flux of result

<S,T>insertAll

public Flux insertAll(CosmosEntityInformation entityInformation, Flux entities)

Insert all items with bulk.

Parameters:

entityInformation - the CosmosEntityInformation
entities - the Flux of entities to be inserted

Returns:

Flux of result

delete

public Flux delete(CosmosQuery query, Class domainType, String containerName)

Delete items matching query with bulk if PK exists

Parameters:

query - the document query
domainType - the entity class
containerName - the container name

Returns:

Mono

deleteEntity

public Mono deleteEntity(String containerName, T entity)

Deletes the entity

Parameters:

containerName - Container name of database
entity - the entity to delete

Returns:

void Mono

find

public Flux find(CosmosQuery query, Class domainType, String containerName)

Find items

Parameters:

query - the document query
domainType - the entity class
containerName - the container name

Returns:

Flux with found items or error

findAll

public Flux findAll(PartitionKey partitionKey, Class domainType)

Find all items in a given container with partition key

Parameters:

partitionKey
domainType

findAll

public Flux findAll(Class domainType)

Find all items in a given container

Parameters:

domainType - the domainType

Returns:

Flux with all the found items or error

findAll

public Flux findAll(String containerName, Class domainType)

Find all items in a given container

Parameters:

containerName - the containerName
domainType - the domainType

Returns:

Flux with all the found items or error

findById

public Mono findById(Object id, Class domainType)

Find by id

Parameters:

id - the id
domainType - the domainType

Returns:

Mono with the item or error

findById

public Mono findById(Object id, Class domainType, PartitionKey partitionKey)

Find by id

Parameters:

id - the id
domainType - the entity class
partitionKey - partition Key

Returns:

Mono with the item or error

findById

public Mono findById(String containerName, Object id, Class domainType)

Find by id

Parameters:

containerName - the container name
id - the id
domainType - the entity class

Returns:

Mono with the item or error

insert

public Mono insert(T objectToSave)

Insert

Parameters:

objectToSave - the object to save

Returns:

Mono with the item or error

insert

public Mono insert(T objectToSave, PartitionKey partitionKey)

Insert

Parameters:

objectToSave - the object to save
partitionKey - the partition key

Returns:

Mono with the item or error

insert

public Mono insert(String containerName, T objectToSave)

Insert

Parameters:

containerName - the container name
objectToSave - the object to save

Returns:

Mono with the item or error

insert

public Mono insert(String containerName, T objectToSave, PartitionKey partitionKey)

Insert

Parameters:

containerName - the container name
objectToSave - the object to save
partitionKey - the partition key

Returns:

Mono with the item or error

patch

public Mono patch(Object id, PartitionKey partitionKey, Class domainType, CosmosPatchOperations patchOperations)

Patches item applies partial update (patch) to an item

Parameters:

id - must not be null
partitionKey - must not be null
domainType - must not be null
patchOperations - must not be null

Returns:

the patched item

patch

public Mono patch(Object id, PartitionKey partitionKey, Class domainType, CosmosPatchOperations patchOperations, CosmosPatchItemRequestOptions options)

applies partial update (patch) to an item with CosmosPatchItemRequestOptions

Parameters:

id - must not be null
partitionKey - must not be null
domainType - must not be null
patchOperations - must not be null
options - Optional CosmosPatchItemRequestOptions, e.g. options.setFilterPredicate("FROM products p WHERE p.used = false");

Returns:

the patched item

runQuery

public Flux runQuery(SqlQuerySpec querySpec, Class domainType, Class returnType)

Run the query.

Parameters:

querySpec
domainType
returnType

runQuery

public Flux runQuery(SqlQuerySpec querySpec, Sort sort, Class domainType, Class returnType)

Run the query.

Parameters:

querySpec
sort
domainType
returnType

upsert

public Mono upsert(T object)

Upsert

Parameters:

object - the object to upsert

Returns:

Mono with the item or error

upsert

public Mono upsert(String containerName, T object)

Upsert

Parameters:

containerName - the container name
object - the object to save

Returns:

Mono with the item or error

count

public Mono count(SqlQuerySpec querySpec, String containerName)

Count

Parameters:

querySpec - the document query spec
containerName - the container name

Returns:

Mono with count or error

count

public Mono count(CosmosQuery query, String containerName)

Count

Parameters:

query - the document query
containerName - the container name

Returns:

Mono with count or error

count

public Mono count(String containerName)

Count

Parameters:

containerName - the container name

Returns:

Mono with the count or error

createContainerIfNotExists

public Mono createContainerIfNotExists(CosmosEntityInformation information)

Creates a container if it doesn't already exist

Parameters:

information - the CosmosEntityInformation

Returns:

Mono containing CosmosContainerResponse

deleteAll

public Mono deleteAll(String containerName, Class domainType)

Delete all items in a container

Parameters:

containerName - the container name
domainType - the domainType

Returns:

void Mono

deleteById

public Mono deleteById(String containerName, Object id, PartitionKey partitionKey)

Deletes the item with id and partition key.

Parameters:

containerName - Container name of database
id - item id
partitionKey - the partition key

deleteContainer

public void deleteContainer(String containerName)

Delete container with container name

Parameters:

containerName - the container name

exists

public Mono exists(CosmosQuery query, Class domainType, String containerName)

Exists

Parameters:

query - the document query
domainType - the entity class
containerName - the container name

Returns:

Mono with a boolean or error

existsById

public Mono existsById(Object id, Class domainType, String containerName)

Exists

Parameters:

id - the id
domainType - the entity class
containerName - the container name

Returns:

Mono with a boolean or error

getContainerName

public String getContainerName(Class domainType)

Get container name

Parameters:

domainType

getContainerNameOverride

public String getContainerNameOverride(String containerName)

Check if an overridden version of containerName is present, and if so, return it

Parameters:

containerName - Container name of database

Returns:

containerName

getContainerProperties

public Mono getContainerProperties(String containerName)

Get properties for specified container

Parameters:

containerName

getConverter

public MappingCosmosConverter getConverter()

To get converter

replaceContainerProperties

public Mono replaceContainerProperties(String containerName, CosmosContainerProperties properties)

Replace container properties for the specified container

Parameters:

containerName
properties

setApplicationContext

public void setApplicationContext(ApplicationContext applicationContext)

Parameters:

applicationContext - the application context

Throws:

org.springframework.beans.BeansException - the bean exception

Applies to