public CosmosTemplate(CosmosFactory cosmosFactory, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter)
Initialization
Parameters:
cosmosFactory
- must not be null
cosmosConfig
- must not be null
mappingCosmosConverter
- must not be null
CosmosTemplate
public CosmosTemplate(CosmosFactory cosmosFactory, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter, IsNewAwareAuditingHandler cosmosAuditingHandler)
Initialization
Parameters:
cosmosFactory
- must not be null
cosmosConfig
- must not be null
mappingCosmosConverter
- must not be null
cosmosAuditingHandler
- can be null
Method Details
<S,T>deleteEntities
public void deleteEntities(CosmosEntityInformation information, Iterable entities)
Deletes the entities using bulk
Parameters:
information
- the CosmosEntityInformation
entities
- the Iterable entities to be inserted
<S,T>insertAll
public IterableinsertAll(CosmosEntityInformation information, Iterable entities)
Insert all items with bulk.
Parameters:
information
- the CosmosEntityInformation
entities
- the Iterable entities to be inserted
Returns:
Flux of result
<T,ID>findByIds
public IterablefindByIds(Iterable ids, Class domainType, String containerName)
Find by ids
Parameters:
ids
domainType
containerName
count
public long count(SqlQuerySpec querySpec, String containerName)
Count
Parameters:
querySpec
containerName
count
public long count(CosmosQuery query, String containerName)
Count
Parameters:
query
containerName
delete
public Iterabledelete(CosmosQuery query, Class domainType, String containerName)
Delete the DocumentQuery, need to query the domains at first, then delete the item from the result. The cosmos db Sql API do _NOT_ support DELETE query, we cannot add one DeleteQueryGenerator. Uses bulk if possible.
Parameters:
query
- The representation for query method.
domainType
- Class of domain
containerName
- Container name of database
Returns:
All the deleted items as List.
deleteEntity
public void deleteEntity(String containerName, T entity)
Deletes the entity
Parameters:
containerName
- the container name
entity
- the entity object
exists
public Boolean exists(CosmosQuery query, Class domainType, String containerName)
Checks if document query items exist
Parameters:
query
- The representation for query method.
domainType
- Class of domain
containerName
- Container name of database
Returns:
if items exist
find
public Iterablefind(CosmosQuery query, Class domainType, String containerName)
Finds the document query items
Parameters:
query
- The representation for query method.
domainType
- Class of domain
containerName
- Container name of database
Returns:
All the found items as List.
findAll
public IterablefindAll(PartitionKey partitionKey, Class domainType)
Find the DocumentQuery, find all the items specified by domain type in the given container.
Parameters:
partitionKey
domainType
findAll
public IterablefindAll(Class domainType)
Find the DocumentQuery, find all the items specified by domain type.
Parameters:
domainType
- the domain type
Returns:
found results in a List
findAll
public IterablefindAll(String containerName, Class domainType)
Find the DocumentQuery, find all the items specified by domain type in the given container.
Parameters:
containerName
- the container name
domainType
- the domain type
Returns:
found results in a List
findAll
public PagefindAll(Pageable pageable, Class domainType, String containerName)
Find all items in a given container with partition key
Parameters:
pageable
domainType
containerName
findById
public T findById(Object id, Class domainType)
Finds item by id
Parameters:
id
- must not be null
domainType
- must not be null
Returns:
found item
findById
public T findById(Object id, Class domainType, PartitionKey partitionKey)
Finds item by id
Parameters:
id
domainType
partitionKey
findById
public T findById(String containerName, Object id, Class domainType)
Finds item by id
Parameters:
containerName
- must not be null
id
- must not be null
domainType
- must not be null
Returns:
found item
insert
public T insert(T objectToSave, PartitionKey partitionKey)
Inserts item
Parameters:
objectToSave
- must not be null
partitionKey
- must not be null
Returns:
the inserted item
insert
public T insert(String containerName, T objectToSave)
Inserts item into the given container
Parameters:
containerName
- must not be null
objectToSave
- must not be null
Returns:
the inserted item
insert
public T insert(String containerName, T objectToSave, PartitionKey partitionKey)
Inserts item into the given container
Parameters:
containerName
- must not be null
objectToSave
- must not be null
partitionKey
- must not be null
Returns:
the inserted item
paginationQuery
public PagepaginationQuery(CosmosQuery query, Class domainType, String containerName)
Pagination query
Parameters:
query
domainType
containerName
patch
public T 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
patchOperations
- must not be null
Returns:
the patched item
patch
public T 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
runPaginationQuery
public PagerunPaginationQuery(SqlQuerySpec querySpec, Pageable pageable, Class domainType, Class returnType)
Run the query.
Parameters:
querySpec
pageable
domainType
returnType
runQuery
public IterablerunQuery(SqlQuerySpec querySpec, Class domainType, Class returnType)
Run the query.
Parameters:
querySpec
domainType
returnType
runQuery
public IterablerunQuery(SqlQuerySpec querySpec, Sort sort, Class domainType, Class returnType)
Run the query.
Parameters:
querySpec
sort
domainType
returnType
runSliceQuery
public SlicerunSliceQuery(SqlQuerySpec querySpec, Pageable pageable, Class domainType, Class returnType)
Run custom SQL query
Parameters:
querySpec
pageable
domainType
returnType
sliceQuery
public SlicesliceQuery(CosmosQuery query, Class domainType, String containerName)
Slice query
Parameters:
query
domainType
containerName
upsert
public void upsert(T object)
Upserts an item with partition key
Parameters:
object
- upsert object
upsert
public void upsert(String containerName, T object)
Upserts an item into container with partition key
Parameters:
containerName
- the container name
object
- upsert object
upsertAndReturnEntity
public T upsertAndReturnEntity(String containerName, T object)
Upserts an item and return item properties
Parameters:
containerName
- the container name
object
- upsert object
Returns:
upsert object entity
count
public long count(String containerName)
Count
Parameters:
containerName
createContainerIfNotExists
public CosmosContainerProperties createContainerIfNotExists(CosmosEntityInformation information)
Creates container if not exists
Parameters:
information
deleteAll
public void deleteAll(String containerName, Class domainType)
Delete the DocumentQuery, delete all the items in the given container.
Parameters:
containerName
- Container name of database
domainType
- the domain type
deleteById
public void deleteById(String containerName, Object id, PartitionKey partitionKey)
Deletes the item by 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
Parameters:
containerName
getContainerName
public String getContainerName(Class domainType)
To get container name by domainType
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 CosmosContainerProperties getContainerProperties(String containerName)
Get properties for specified container
Parameters:
containerName
getConverter
public MappingCosmosConverter getConverter()
To get converter
replaceContainerProperties
public CosmosContainerProperties replaceContainerProperties(String containerName, CosmosContainerProperties properties)
Replace container properties for the specified container
Parameters:
containerName
properties
setApplicationContext
public void setApplicationContext(ApplicationContext applicationContext)
Sets the application context
Parameters:
applicationContext
- must not be null
Throws:
org.springframework.beans.BeansException
- the bean exception