Interface CosmosOperations
- All Known Implementing Classes:
CosmosTemplate
public interface CosmosOperations
Interface for cosmosDB operations
-
Method Summary
Modifier and TypeMethodDescription<T> long
Count<T> long
count
(CosmosQuery query, String containerName) Countlong
Countcom.azure.cosmos.models.CosmosContainerProperties
createContainerIfNotExists
(CosmosEntityInformation<?, ?> information) Creates container if not exists<T> Iterable
<T> delete
(CosmosQuery query, Class<T> domainType, String containerName) Delete items matching query.void
Delete all items in a container.void
deleteById
(String containerName, Object id, com.azure.cosmos.models.PartitionKey partitionKey) Delete an item by idvoid
deleteContainer
(String containerName) Delete container<S extends T,
T>
voiddeleteEntities
(CosmosEntityInformation<T, ?> information, Iterable<S> entities) Delete using a list of entities with bulk<T> void
deleteEntity
(String containerName, T entity) Delete using entity<T> Boolean
exists
(CosmosQuery query, Class<T> domainType, String containerName) Exists<T> Iterable
<T> find
(CosmosQuery query, Class<T> domainType, String containerName) Find query<T> Iterable
<T> Find the DocumentQuery, find all the items specified by domain type in the given container.<T> Iterable
<T> Find the DocumentQuery, find all the items specified by domain type.<T> Iterable
<T> Find the DocumentQuery, find all the items specified by domain type in the given container.<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> T
Finds item by id<T> T
Finds item by id<T> T
Finds item by id<T,
ID> Iterable <T> Find by idsgetContainerName
(Class<?> domainType) To get container name by domainTypecom.azure.cosmos.models.CosmosContainerProperties
getContainerProperties
(String containerName) Get properties for specified containerTo get converter<T> T
Inserts item<T> T
Inserts item<T> T
insert
(T objectToSave, com.azure.cosmos.models.PartitionKey partitionKey) Inserts item<S extends T,
T>
Iterable<S> insertAll
(CosmosEntityInformation<T, ?> information, Iterable<S> entities) Insert items using bulk operations.<T> org.springframework.data.domain.Page
<T> paginationQuery
(CosmosQuery query, Class<T> domainType, String containerName) Pagination query<T> T
patch
(Object id, com.azure.cosmos.models.PartitionKey partitionKey, Class<T> domainType, com.azure.cosmos.models.CosmosPatchOperations patchOperations) patches item<T> T
patch
(Object id, com.azure.cosmos.models.PartitionKey partitionKey, Class<T> domainType, com.azure.cosmos.models.CosmosPatchOperations patchOperations, com.azure.cosmos.models.CosmosPatchItemRequestOptions options) patches itemcom.azure.cosmos.models.CosmosContainerProperties
replaceContainerProperties
(String containerName, com.azure.cosmos.models.CosmosContainerProperties properties) Replace container properties for the specified container<T> org.springframework.data.domain.Page
<T> runPaginationQuery
(com.azure.cosmos.models.SqlQuerySpec querySpec, org.springframework.data.domain.Pageable pageable, Class<?> domainType, Class<T> returnType) Run the query.<T> Iterable
<T> Run the query.<T> Iterable
<T> runQuery
(com.azure.cosmos.models.SqlQuerySpec querySpec, org.springframework.data.domain.Sort sort, Class<?> domainType, Class<T> returnType) Run the query.<T> org.springframework.data.domain.Slice
<T> runSliceQuery
(com.azure.cosmos.models.SqlQuerySpec querySpec, org.springframework.data.domain.Pageable pageable, Class<?> domainType, Class<T> returnType) Run custom SQL query<T> org.springframework.data.domain.Slice
<T> sliceQuery
(CosmosQuery query, Class<T> domainType, String containerName) Slice querylong
Sum<T> void
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
-
Method Details
-
getContainerName
To get container name by domainType- Parameters:
domainType
- class type- Returns:
- String
-
createContainerIfNotExists
com.azure.cosmos.models.CosmosContainerProperties createContainerIfNotExists(CosmosEntityInformation<?, ?> information) Creates container if not exists- Parameters:
information
- CosmosEntityInformation- Returns:
- CosmosContainerProperties
-
getContainerProperties
Get properties for specified container- Parameters:
containerName
- String- Returns:
- CosmosContainerProperties
-
replaceContainerProperties
com.azure.cosmos.models.CosmosContainerProperties replaceContainerProperties(String containerName, com.azure.cosmos.models.CosmosContainerProperties properties) Replace container properties for the specified container- Parameters:
containerName
- Stringproperties
- CosmosContainerProperties- Returns:
- CosmosContainerProperties
-
findAll
Find the DocumentQuery, find all the items specified by domain type.- Type Parameters:
T
- class type of domain- Parameters:
domainType
- the domain type- Returns:
- results in an Iterable
-
findAll
Find the DocumentQuery, find all the items specified by domain type in the given container.- Type Parameters:
T
- class type of domain- Parameters:
containerName
- the container namedomainType
- the domain type- Returns:
- results in an Iterable
-
findAll
Find the DocumentQuery, find all the items specified by domain type in the given container.- Type Parameters:
T
- class type of domain- Parameters:
partitionKey
- the partition keydomainType
- the domain type- Returns:
- results in an Iterable
-
findById
Finds item by id- Type Parameters:
T
- type class of domain type- Parameters:
id
- must not be nulldomainType
- must not be null- Returns:
- found item
-
findById
Finds item by id- Type Parameters:
T
- type class of domain type- Parameters:
containerName
- must not be nullid
- must not be nulldomainType
- must not be null- Returns:
- found item
-
findById
Finds item by id- Type Parameters:
T
- type class of domain type- Parameters:
id
- must not be nulldomainType
- must not be nullpartitionKey
- must not be null- Returns:
- found item
-
insert
<T> T insert(T objectToSave, com.azure.cosmos.models.PartitionKey partitionKey) Inserts item- Type Parameters:
T
- type class of domain type- Parameters:
objectToSave
- must not be nullpartitionKey
- must not be null- Returns:
- the inserted item
-
patch
<T> T patch(Object id, com.azure.cosmos.models.PartitionKey partitionKey, Class<T> domainType, com.azure.cosmos.models.CosmosPatchOperations patchOperations) patches item- Type Parameters:
T
- type class of domain type- Parameters:
id
- must not be nullpartitionKey
- must not be nulldomainType
- must not be nullpatchOperations
- must not be null, max operations is 10- Returns:
- the patched item
-
patch
<T> T patch(Object id, com.azure.cosmos.models.PartitionKey partitionKey, Class<T> domainType, com.azure.cosmos.models.CosmosPatchOperations patchOperations, com.azure.cosmos.models.CosmosPatchItemRequestOptions options) patches item- Type Parameters:
T
- type class of domain type- Parameters:
id
- must not be nullpartitionKey
- must not be nulldomainType
- must not be nullpatchOperations
- must not be null, max operations is 10options
- Optional CosmosPatchItemRequestOptions, e.g. options.setFilterPredicate("FROM products p WHERE p.used = false");- Returns:
- the patched item
-
insert
<T> T insert(String containerName, T objectToSave, com.azure.cosmos.models.PartitionKey partitionKey) Inserts item- Type Parameters:
T
- type class of domain type- Parameters:
containerName
- must not be nullobjectToSave
- must not be nullpartitionKey
- must not be null- Returns:
- the inserted item
-
insertAll
<S extends T,T> Iterable<S> insertAll(CosmosEntityInformation<T, ?> information, Iterable<S> entities) Insert items using bulk operations.- Type Parameters:
S
- type class of domain typeT
- type class of domain type- Parameters:
information
- must not be nullentities
- must not be null- Returns:
- the inserted item
-
insert
Inserts item- Type Parameters:
T
- type class of domain type- Parameters:
containerName
- must not be nullobjectToSave
- must not be null- Returns:
- the inserted item
-
upsert
<T> void upsert(T object) Upserts an item with partition key- Type Parameters:
T
- type of upsert object- Parameters:
object
- upsert object
-
upsert
Upserts an item into container with partition key- Type Parameters:
T
- type of upsert object- Parameters:
containerName
- the container nameobject
- upsert object
-
upsertAndReturnEntity
Upserts an item and return item properties- Type Parameters:
T
- type of upsert object- Parameters:
containerName
- the container nameobject
- upsert object- Returns:
- upsert object entity
-
deleteById
Delete an item by id- Parameters:
containerName
- the container nameid
- the idpartitionKey
- the partition key
-
deleteEntity
Delete using entity- Type Parameters:
T
- type class of domain type- Parameters:
containerName
- the container nameentity
- the entity object
-
deleteEntities
<S extends T,T> void deleteEntities(CosmosEntityInformation<T, ?> information, Iterable<S> entities) Delete using a list of entities with bulk- Type Parameters:
S
- type class of domain typeT
- type class of domain type- Parameters:
information
- must not be nullentities
- must not be null
-
deleteAll
Delete all items in a container. Uses bulk if possible.- Parameters:
containerName
- the container namedomainType
- the domainType
-
deleteContainer
Delete container- Parameters:
containerName
- the container name
-
delete
Delete items matching query. Uses bulk if possible.- Type Parameters:
T
- type class of domainType- Parameters:
query
- the document querydomainType
- type classcontainerName
- the container name- Returns:
- deleted items in a Iterable
-
find
Find query- Type Parameters:
T
- type class of domainType- Parameters:
query
- the document querydomainType
- type classcontainerName
- the container name- Returns:
- results in an Iterable
-
findByIds
Find by ids- Type Parameters:
T
- type of domainTypeID
- type of ID- Parameters:
ids
- iterable of idsdomainType
- type classcontainerName
- the container name- Returns:
- results in an Iterable
-
exists
Exists- Type Parameters:
T
- type of domainType- Parameters:
query
- the document querydomainType
- type classcontainerName
- the container name- Returns:
- Boolean
-
findAll
<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- Type Parameters:
T
- type of domainType- Parameters:
pageable
- Pageable objectdomainType
- the domainTypecontainerName
- the container name- Returns:
- results as Page
-
paginationQuery
<T> org.springframework.data.domain.Page<T> paginationQuery(CosmosQuery query, Class<T> domainType, String containerName) Pagination query- Type Parameters:
T
- type class of domainType- Parameters:
query
- the document querydomainType
- type classcontainerName
- the container name- Returns:
- results as Page
-
sliceQuery
<T> org.springframework.data.domain.Slice<T> sliceQuery(CosmosQuery query, Class<T> domainType, String containerName) Slice query- Type Parameters:
T
- type class of domainType- Parameters:
query
- the document querydomainType
- type classcontainerName
- the container name- Returns:
- results as Slice
-
runSliceQuery
<T> org.springframework.data.domain.Slice<T> runSliceQuery(com.azure.cosmos.models.SqlQuerySpec querySpec, org.springframework.data.domain.Pageable pageable, Class<?> domainType, Class<T> returnType) Run custom SQL query- Type Parameters:
T
- the type parameter- Parameters:
querySpec
- the query specpageable
- the pageabledomainType
- the domain typereturnType
- the return type- Returns:
- the Page
-
count
Count- Parameters:
containerName
- the container name- Returns:
- count result
-
count
Count- Type Parameters:
T
- type class of domainType- Parameters:
query
- the document querycontainerName
- the container name- Returns:
- count result
-
count
Count- Type Parameters:
T
- type class of domainType- Parameters:
querySpec
- the document query speccontainerName
- the container name- Returns:
- count result
-
sum
Sum- Parameters:
querySpec
- the document query speccontainerName
- the container name- Returns:
- sum result
-
getConverter
MappingCosmosConverter getConverter()To get converter- Returns:
- MappingCosmosConverter
-
runQuery
<T> Iterable<T> runQuery(com.azure.cosmos.models.SqlQuerySpec querySpec, Class<?> domainType, Class<T> returnType) Run the query.- Type Parameters:
T
- the type parameter- Parameters:
querySpec
- the query specdomainType
- the domain typereturnType
- the return type- Returns:
- the Iterable
-
runQuery
<T> Iterable<T> runQuery(com.azure.cosmos.models.SqlQuerySpec querySpec, org.springframework.data.domain.Sort sort, Class<?> domainType, Class<T> returnType) Run the query.- Type Parameters:
T
- the type parameter- Parameters:
querySpec
- the query specsort
- the sort orderdomainType
- the domain typereturnType
- the return type- Returns:
- the Iterable
-
runPaginationQuery
<T> org.springframework.data.domain.Page<T> runPaginationQuery(com.azure.cosmos.models.SqlQuerySpec querySpec, org.springframework.data.domain.Pageable pageable, Class<?> domainType, Class<T> returnType) Run the query.- Type Parameters:
T
- the type parameter- Parameters:
querySpec
- the query specpageable
- the pageabledomainType
- the domain typereturnType
- the return type- Returns:
- the Page
-