public class CosmosTemplate extends Object implements CosmosOperations, org.springframework.context.ApplicationContextAware
| Constructor and Description |
|---|
CosmosTemplate(CosmosAsyncClient client,
String databaseName,
CosmosConfig cosmosConfig,
MappingCosmosConverter mappingCosmosConverter)
Initialization
|
CosmosTemplate(CosmosAsyncClient client,
String databaseName,
CosmosConfig cosmosConfig,
MappingCosmosConverter mappingCosmosConverter,
org.springframework.data.auditing.IsNewAwareAuditingHandler cosmosAuditingHandler)
Initialization
|
CosmosTemplate(CosmosFactory cosmosFactory,
CosmosConfig cosmosConfig,
MappingCosmosConverter mappingCosmosConverter)
Initialization
|
CosmosTemplate(CosmosFactory cosmosFactory,
CosmosConfig cosmosConfig,
MappingCosmosConverter mappingCosmosConverter,
org.springframework.data.auditing.IsNewAwareAuditingHandler cosmosAuditingHandler)
Initialization
|
| Modifier and Type | Method and Description |
|---|---|
<T> long |
count(CosmosQuery query,
String containerName)
Count
|
<T> long |
count(SqlQuerySpec querySpec,
String containerName)
Count
|
long |
count(String containerName)
Count
|
CosmosContainerProperties |
createContainerIfNotExists(CosmosEntityInformation<?,?> information)
Creates container if not exists
|
<T> Iterable<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.
|
void |
deleteAll(String containerName,
Class<?> domainType)
Delete the DocumentQuery, delete all the items in the given container.
|
void |
deleteById(String containerName,
Object id,
PartitionKey partitionKey)
Deletes the item by id and partition key.
|
void |
deleteContainer(String containerName)
Delete container
|
<T> void |
deleteEntity(String containerName,
T entity)
Deletes the entity
|
<T> Boolean |
exists(CosmosQuery query,
Class<T> domainType,
String containerName)
Checks if document query items exist
|
<T> Iterable<T> |
find(CosmosQuery query,
Class<T> domainType,
String containerName)
Finds the document query items
|
<T> Iterable<T> |
findAll(Class<T> domainType)
Find the DocumentQuery, find all the items specified by domain type.
|
<T> org.springframework.data.domain.Page<T> |
findAll(org.springframework.data.domain.Pageable pageable,
Class<T> domainType,
String containerName)
Find all items in a given container with partition key
|
<T> Iterable<T> |
findAll(PartitionKey partitionKey,
Class<T> domainType)
Find the DocumentQuery, find all the items specified by domain type in the given container.
|
<T> Iterable<T> |
findAll(String containerName,
Class<T> domainType)
Find the DocumentQuery, find all the items specified by domain type in the given container.
|
<T> T |
findById(Object id,
Class<T> domainType)
Finds item by id
|
<T> T |
findById(Object id,
Class<T> domainType,
PartitionKey partitionKey)
Finds item by id
|
<T> T |
findById(String containerName,
Object id,
Class<T> domainType)
Finds item by id
|
<T,ID> Iterable<T> |
findByIds(Iterable<ID> ids,
Class<T> domainType,
String containerName)
Find by ids
|
String |
getContainerName(Class<?> domainType)
To get container name by domainType
|
CosmosContainerProperties |
getContainerProperties(String containerName)
Get properties for specified container
|
MappingCosmosConverter |
getConverter()
To get converter
|
<T> T |
insert(String containerName,
T objectToSave)
Inserts item into the given container
|
<T> T |
insert(String containerName,
T objectToSave,
PartitionKey partitionKey)
Inserts item into the given container
|
<T> T |
insert(T objectToSave,
PartitionKey partitionKey)
Inserts item
|
<T> org.springframework.data.domain.Page<T> |
paginationQuery(CosmosQuery query,
Class<T> domainType,
String containerName)
Pagination query
|
CosmosContainerProperties |
replaceContainerProperties(String containerName,
CosmosContainerProperties properties)
Replace container properties for the specified container
|
<T> org.springframework.data.domain.Page<T> |
runPaginationQuery(SqlQuerySpec querySpec,
org.springframework.data.domain.Pageable pageable,
Class<?> domainType,
Class<T> returnType)
Run the query.
|
<T> Iterable<T> |
runQuery(SqlQuerySpec querySpec,
Class<?> domainType,
Class<T> returnType)
Run the query.
|
<T> Iterable<T> |
runQuery(SqlQuerySpec querySpec,
org.springframework.data.domain.Sort sort,
Class<?> domainType,
Class<T> returnType)
Run the query.
|
<T> org.springframework.data.domain.Slice<T> |
runSliceQuery(SqlQuerySpec querySpec,
org.springframework.data.domain.Pageable pageable,
Class<?> domainType,
Class<T> returnType)
Run custom SQL query
|
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
Sets the application context
|
<T> org.springframework.data.domain.Slice<T> |
sliceQuery(CosmosQuery query,
Class<T> domainType,
String containerName)
Slice query
|
<T> void |
upsert(String containerName,
T object)
Upserts an item into container with partition key
|
<T> void |
upsert(T object)
Upserts an item with partition key
|
<T> T |
upsertAndReturnEntity(String containerName,
T object)
Upserts an item and return item properties
|
public CosmosTemplate(CosmosAsyncClient client, String databaseName, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter, org.springframework.data.auditing.IsNewAwareAuditingHandler cosmosAuditingHandler)
client - must not be nulldatabaseName - must not be nullcosmosConfig - must not be nullmappingCosmosConverter - must not be nullcosmosAuditingHandler - can be nullpublic CosmosTemplate(CosmosAsyncClient client, String databaseName, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter)
client - must not be nulldatabaseName - must not be nullcosmosConfig - must not be nullmappingCosmosConverter - must not be nullpublic CosmosTemplate(CosmosFactory cosmosFactory, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter, org.springframework.data.auditing.IsNewAwareAuditingHandler cosmosAuditingHandler)
cosmosFactory - must not be nullcosmosConfig - must not be nullmappingCosmosConverter - must not be nullcosmosAuditingHandler - can be nullpublic CosmosTemplate(CosmosFactory cosmosFactory, CosmosConfig cosmosConfig, MappingCosmosConverter mappingCosmosConverter)
cosmosFactory - must not be nullcosmosConfig - must not be nullmappingCosmosConverter - must not be nullpublic void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
throws org.springframework.beans.BeansException
setApplicationContext in interface org.springframework.context.ApplicationContextAwareapplicationContext - must not be nullorg.springframework.beans.BeansException - the bean exceptionpublic <T> T insert(T objectToSave,
PartitionKey partitionKey)
insert in interface CosmosOperationsT - type class of domain typeobjectToSave - must not be nullpartitionKey - must not be nullpublic <T> T insert(String containerName, T objectToSave)
insert in interface CosmosOperationsT - type class of domain typecontainerName - must not be nullobjectToSave - must not be nullpublic <T> T insert(String containerName, T objectToSave, PartitionKey partitionKey)
insert in interface CosmosOperationsT - type class of domain typecontainerName - must not be nullobjectToSave - must not be nullpartitionKey - must not be nullpublic <T> T findById(Object id, Class<T> domainType)
findById in interface CosmosOperationsT - type class of domain typeid - must not be nulldomainType - must not be nullpublic <T> T findById(Object id, Class<T> domainType, PartitionKey partitionKey)
CosmosOperationsfindById in interface CosmosOperationsT - type class of domain typeid - must not be nulldomainType - must not be nullpartitionKey - must not be nullpublic <T> T findById(String containerName, Object id, Class<T> domainType)
findById in interface CosmosOperationsT - type class of domain typecontainerName - must not be nullid - must not be nulldomainType - must not be nullpublic <T> void upsert(T object)
upsert in interface CosmosOperationsT - type of upsert objectobject - upsert objectpublic <T> void upsert(String containerName, T object)
upsert in interface CosmosOperationsT - type of upsert objectcontainerName - the container nameobject - upsert objectpublic <T> T upsertAndReturnEntity(String containerName, T object)
upsertAndReturnEntity in interface CosmosOperationsT - type of upsert objectcontainerName - the container nameobject - upsert objectpublic <T> Iterable<T> findAll(Class<T> domainType)
findAll in interface CosmosOperationsT - class type of domaindomainType - the domain typepublic <T> Iterable<T> findAll(String containerName, Class<T> domainType)
findAll in interface CosmosOperationsT - class type of domaincontainerName - the container namedomainType - the domain typepublic <T> Iterable<T> findAll(PartitionKey partitionKey, Class<T> domainType)
CosmosOperationsfindAll in interface CosmosOperationsT - class type of domainpartitionKey - the partition keydomainType - the domain typepublic void deleteAll(@NonNull
String containerName,
@NonNull
Class<?> domainType)
deleteAll in interface CosmosOperationscontainerName - Container name of databasedomainType - the domain typepublic void deleteContainer(@NonNull
String containerName)
CosmosOperationsdeleteContainer in interface CosmosOperationscontainerName - the container namepublic String getContainerName(Class<?> domainType)
CosmosOperationsgetContainerName in interface CosmosOperationsdomainType - class typepublic CosmosContainerProperties createContainerIfNotExists(CosmosEntityInformation<?,?> information)
CosmosOperationscreateContainerIfNotExists in interface CosmosOperationsinformation - CosmosEntityInformationpublic CosmosContainerProperties getContainerProperties(String containerName)
CosmosOperationsgetContainerProperties in interface CosmosOperationscontainerName - Stringpublic CosmosContainerProperties replaceContainerProperties(String containerName, CosmosContainerProperties properties)
CosmosOperationsreplaceContainerProperties in interface CosmosOperationscontainerName - Stringproperties - CosmosContainerPropertiespublic void deleteById(String containerName, Object id, PartitionKey partitionKey)
deleteById in interface CosmosOperationscontainerName - Container name of databaseid - item idpartitionKey - the partition keypublic <T> void deleteEntity(String containerName, T entity)
deleteEntity in interface CosmosOperationsT - type class of domain typecontainerName - the container nameentity - the entity objectpublic <T,ID> Iterable<T> findByIds(Iterable<ID> ids, Class<T> domainType, String containerName)
CosmosOperationsfindByIds in interface CosmosOperationsT - type of domainTypeID - type of IDids - iterable of idsdomainType - type classcontainerName - the container namepublic <T> Iterable<T> find(@NonNull CosmosQuery query, @NonNull Class<T> domainType, String containerName)
find in interface CosmosOperationsT - class of domainTypequery - The representation for query method.domainType - Class of domaincontainerName - Container name of databasepublic <T> Boolean exists(@NonNull CosmosQuery query, @NonNull Class<T> domainType, String containerName)
exists in interface CosmosOperationsT - class of domainTypequery - The representation for query method.domainType - Class of domaincontainerName - Container name of databasepublic <T> Iterable<T> delete(@NonNull CosmosQuery query, @NonNull Class<T> domainType, @NonNull String containerName)
delete in interface CosmosOperationsT - class of domainTypequery - The representation for query method.domainType - Class of domaincontainerName - Container name of databasepublic <T> org.springframework.data.domain.Page<T> findAll(org.springframework.data.domain.Pageable pageable,
Class<T> domainType,
String containerName)
CosmosOperationsfindAll in interface CosmosOperationsT - type of domainTypepageable - Pageable objectdomainType - the domainTypecontainerName - the container namepublic <T> org.springframework.data.domain.Page<T> runPaginationQuery(SqlQuerySpec querySpec, org.springframework.data.domain.Pageable pageable, Class<?> domainType, Class<T> returnType)
CosmosOperationsrunPaginationQuery in interface CosmosOperationsT - the type parameterquerySpec - the query specpageable - the pageabledomainType - the domain typereturnType - the return typepublic <T> org.springframework.data.domain.Page<T> paginationQuery(CosmosQuery query, Class<T> domainType, String containerName)
CosmosOperationspaginationQuery in interface CosmosOperationsT - type class of domainTypequery - the document querydomainType - type classcontainerName - the container namepublic <T> org.springframework.data.domain.Slice<T> sliceQuery(CosmosQuery query, Class<T> domainType, String containerName)
CosmosOperationssliceQuery in interface CosmosOperationsT - type class of domainTypequery - the document querydomainType - type classcontainerName - the container namepublic <T> org.springframework.data.domain.Slice<T> runSliceQuery(SqlQuerySpec querySpec, org.springframework.data.domain.Pageable pageable, Class<?> domainType, Class<T> returnType)
CosmosOperationsrunSliceQuery in interface CosmosOperationsT - the type parameterquerySpec - the query specpageable - the pageabledomainType - the domain typereturnType - the return typepublic long count(String containerName)
CosmosOperationscount in interface CosmosOperationscontainerName - the container namepublic <T> long count(CosmosQuery query, String containerName)
CosmosOperationscount in interface CosmosOperationsT - type class of domainTypequery - the document querycontainerName - the container namepublic <T> long count(SqlQuerySpec querySpec, String containerName)
CosmosOperationscount in interface CosmosOperationsT - type class of domainTypequerySpec - the document query speccontainerName - the container namepublic MappingCosmosConverter getConverter()
CosmosOperationsgetConverter in interface CosmosOperationspublic <T> Iterable<T> runQuery(SqlQuerySpec querySpec, Class<?> domainType, Class<T> returnType)
CosmosOperationsrunQuery in interface CosmosOperationsT - the type parameterquerySpec - the query specdomainType - the domain typereturnType - the return typepublic <T> Iterable<T> runQuery(SqlQuerySpec querySpec, org.springframework.data.domain.Sort sort, Class<?> domainType, Class<T> returnType)
CosmosOperationsrunQuery in interface CosmosOperationsT - the type parameterquerySpec - the query specsort - the sort orderdomainType - the domain typereturnType - the return typeVisit the Azure for Java Developers site for more Java documentation, including quick starts, tutorials, and code samples.