CosmosTemplate Class
- java.
lang. Object - com.
azure. spring. data. cosmos. core. CosmosTemplate
- com.
Implements
public class CosmosTemplate
implements CosmosOperations, org.springframework.context.ApplicationContextAware
Template class for cosmos db
Constructor Summary
Method Summary
Methods inherited from java.lang.Object
Constructor Details
CosmosTemplate
public CosmosTemplate(CosmosAsyncClient client, String databaseName, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter)
Initialization
Parameters:
CosmosTemplate
public CosmosTemplate(CosmosAsyncClient client, String databaseName, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter, IsNewAwareAuditingHandler cosmosAuditingHandler)
Initialization
Parameters:
CosmosTemplate
public CosmosTemplate(CosmosFactory cosmosFactory, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter)
Initialization
Parameters:
CosmosTemplate
public CosmosTemplate(CosmosFactory cosmosFactory, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter, IsNewAwareAuditingHandler cosmosAuditingHandler)
Initialization
Parameters:
Method Details
<S,T>deleteEntities
public void <S,T>deleteEntities(CosmosEntityInformation<T,?> information, Iterable entities)
Deletes the entities using bulk
Parameters:
<S,T>insertAll
public Iterable <S,T>insertAll(CosmosEntityInformation<T,?> information, Iterable entities)
Insert all items with bulk.
Parameters:
Returns:
<T,ID>findByIds
public Iterable<T> <T,ID>findByIds(Iterable<ID> ids, Class<T> domainType, String containerName)
Find by ids
Parameters:
count
public long <T>count(CosmosQuery query, String containerName)
Count
Parameters:
count
public long <T>count(SqlQuerySpec querySpec, String containerName)
Count
Parameters:
count
public long count(String containerName)
Count
Parameters:
createContainerIfNotExists
public CosmosContainerProperties createContainerIfNotExists(CosmosEntityInformation information)
Creates container if not exists
Parameters:
delete
public Iterable<T> <T>delete(CosmosQuery query, Class<T> 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:
Returns:
deleteAll
public void deleteAll(String containerName, Class<?> domainType)
Delete the DocumentQuery, delete all the items in the given container.
Parameters:
deleteById
public void deleteById(String containerName, Object id, PartitionKey partitionKey)
Deletes the item by id and partition key.
Parameters:
deleteContainer
public void deleteContainer(String containerName)
Delete container
Parameters:
deleteEntity
public void <T>deleteEntity(String containerName, T entity)
Deletes the entity
Parameters:
exists
public Boolean <T>exists(CosmosQuery query, Class<T> domainType, String containerName)
Checks if document query items exist
Parameters:
Returns:
find
public Iterable<T> <T>find(CosmosQuery query, Class<T> domainType, String containerName)
Finds the document query items
Parameters:
Returns:
findAll
public Iterable<T> <T>findAll(Class<T> domainType)
Find the DocumentQuery, find all the items specified by domain type.
Parameters:
Returns:
findAll
public Page<T> <T>findAll(Pageable pageable, Class<T> domainType, String containerName)
Find all items in a given container with partition key
Parameters:
findAll
public Iterable<T> <T>findAll(PartitionKey partitionKey, Class<T> domainType)
Find the DocumentQuery, find all the items specified by domain type in the given container.
Parameters:
findAll
public Iterable<T> <T>findAll(String containerName, Class<T> domainType)
Find the DocumentQuery, find all the items specified by domain type in the given container.
Parameters:
Returns:
findById
public T <T>findById(Object id, Class<T> domainType)
Finds item by id
Parameters:
Returns:
findById
public T <T>findById(Object id, Class<T> domainType, PartitionKey partitionKey)
Finds item by id
Parameters:
findById
public T <T>findById(String containerName, Object id, Class<T> domainType)
Finds item by id
Parameters:
Returns:
getContainerName
public String getContainerName(Class<?> domainType)
To get container name by domainType
Parameters:
getContainerNameOverride
public String getContainerNameOverride(String containerName)
Check if an overridden version of containerName is present, and if so, return it
Parameters:
Returns:
getContainerProperties
public CosmosContainerProperties getContainerProperties(String containerName)
Get properties for specified container
Parameters:
getConverter
public MappingCosmosConverter getConverter()
To get converter
insert
public T <T>insert(String containerName, T objectToSave)
Inserts item into the given container
Parameters:
Returns:
insert
public T <T>insert(String containerName, T objectToSave, PartitionKey partitionKey)
Inserts item into the given container
Parameters:
Returns:
insert
public T <T>insert(T objectToSave, PartitionKey partitionKey)
Inserts item
Parameters:
Returns:
paginationQuery
public Page<T> <T>paginationQuery(CosmosQuery query, Class<T> domainType, String containerName)
Pagination query
Parameters:
patch
public T <T>patch(Object id, PartitionKey partitionKey, Class<T> domainType, CosmosPatchOperations patchOperations)
Patches item applies partial update (patch) to an item
Parameters:
Returns:
patch
public T <T>patch(Object id, PartitionKey partitionKey, Class<T> domainType, CosmosPatchOperations patchOperations, CosmosPatchItemRequestOptions options)
applies partial update (patch) to an item with CosmosPatchItemRequestOptions
Parameters:
Returns:
replaceContainerProperties
public CosmosContainerProperties replaceContainerProperties(String containerName, CosmosContainerProperties properties)
Replace container properties for the specified container
Parameters:
runPaginationQuery
public Page<T> <T>runPaginationQuery(SqlQuerySpec querySpec, Pageable pageable, Class<?> domainType, Class<T> returnType)
Run the query.
Parameters:
runQuery
public Iterable<T> <T>runQuery(SqlQuerySpec querySpec, Class<?> domainType, Class<T> returnType)
Run the query.
Parameters:
runQuery
public Iterable<T> <T>runQuery(SqlQuerySpec querySpec, Sort sort, Class<?> domainType, Class<T> returnType)
Run the query.
Parameters:
runSliceQuery
public Slice<T> <T>runSliceQuery(SqlQuerySpec querySpec, Pageable pageable, Class<?> domainType, Class<T> returnType)
Run custom SQL query
Parameters:
setApplicationContext
public void setApplicationContext(ApplicationContext applicationContext)
Sets the application context
Parameters:
Throws:
sliceQuery
public Slice<T> <T>sliceQuery(CosmosQuery query, Class<T> domainType, String containerName)
Slice query
Parameters:
upsert
public void <T>upsert(String containerName, T object)
Upserts an item into container with partition key
Parameters:
upsert
public void <T>upsert(T object)
Upserts an item with partition key
Parameters:
upsertAndReturnEntity
public T <T>upsertAndReturnEntity(String containerName, T object)
Upserts an item and return item properties
Parameters:
Returns: