Interface CosmosOperations

All Known Implementing Classes:
CosmosTemplate

public interface CosmosOperations
Interface for cosmosDB operations
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> long
    count(com.azure.cosmos.models.SqlQuerySpec querySpec, String containerName)
    Count
    <T> long
    count(CosmosQuery query, String containerName)
    Count
    long
    count(String containerName)
    Count
    com.azure.cosmos.models.CosmosContainerProperties
    Creates container if not exists
    <T> Iterable<T>
    delete(CosmosQuery query, Class<T> domainType, String containerName)
    Delete items matching query.
    void
    deleteAll(String containerName, Class<?> domainType)
    Delete all items in a container.
    void
    deleteById(String containerName, Object id, com.azure.cosmos.models.PartitionKey partitionKey)
    Delete an item by id
    void
    deleteContainer(String containerName)
    Delete container
    <S extends T, T>
    void
    deleteEntities(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>
    findAll(com.azure.cosmos.models.PartitionKey partitionKey, Class<T> domainType)
    Find the DocumentQuery, find all the items specified by domain type in the given container.
    <T> Iterable<T>
    findAll(Class<T> domainType)
    Find the DocumentQuery, find all the items specified by domain type.
    <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> 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
    findById(Object id, Class<T> domainType)
    Finds item by id
    <T> T
    findById(Object id, Class<T> domainType, com.azure.cosmos.models.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
    getContainerName(Class<?> domainType)
    To get container name by domainType
    com.azure.cosmos.models.CosmosContainerProperties
    Get properties for specified container
    To get converter
    <T> T
    insert(String containerName, T objectToSave)
    Inserts item
    <T> T
    insert(String containerName, T objectToSave, com.azure.cosmos.models.PartitionKey partitionKey)
    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 item
    com.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>
    runQuery(com.azure.cosmos.models.SqlQuerySpec querySpec, Class<?> domainType, Class<T> returnType)
    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 query
    long
    sum(com.azure.cosmos.models.SqlQuerySpec querySpec, String containerName)
    Sum
    <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
  • Method Details

    • getContainerName

      String getContainerName(Class<?> domainType)
      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

      com.azure.cosmos.models.CosmosContainerProperties getContainerProperties(String containerName)
      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 - String
      properties - CosmosContainerProperties
      Returns:
      CosmosContainerProperties
    • findAll

      <T> Iterable<T> findAll(Class<T> domainType)
      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

      <T> Iterable<T> findAll(String containerName, Class<T> domainType)
      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 name
      domainType - the domain type
      Returns:
      results in an Iterable
    • findAll

      <T> Iterable<T> findAll(com.azure.cosmos.models.PartitionKey partitionKey, Class<T> domainType)
      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 key
      domainType - the domain type
      Returns:
      results in an Iterable
    • findById

      <T> T findById(Object id, Class<T> domainType)
      Finds item by id
      Type Parameters:
      T - type class of domain type
      Parameters:
      id - must not be null
      domainType - must not be null
      Returns:
      found item
    • findById

      <T> T findById(String containerName, Object id, Class<T> domainType)
      Finds item by id
      Type Parameters:
      T - type class of domain type
      Parameters:
      containerName - must not be null
      id - must not be null
      domainType - must not be null
      Returns:
      found item
    • findById

      <T> T findById(Object id, Class<T> domainType, com.azure.cosmos.models.PartitionKey partitionKey)
      Finds item by id
      Type Parameters:
      T - type class of domain type
      Parameters:
      id - must not be null
      domainType - must not be null
      partitionKey - 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 null
      partitionKey - 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 null
      partitionKey - must not be null
      domainType - must not be null
      patchOperations - 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 null
      partitionKey - must not be null
      domainType - must not be null
      patchOperations - must not be null, max operations is 10
      options - 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 null
      objectToSave - must not be null
      partitionKey - 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 type
      T - type class of domain type
      Parameters:
      information - must not be null
      entities - must not be null
      Returns:
      the inserted item
    • insert

      <T> T insert(String containerName, T objectToSave)
      Inserts item
      Type Parameters:
      T - type class of domain type
      Parameters:
      containerName - must not be null
      objectToSave - 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

      <T> void upsert(String containerName, T object)
      Upserts an item into container with partition key
      Type Parameters:
      T - type of upsert object
      Parameters:
      containerName - the container name
      object - upsert object
    • upsertAndReturnEntity

      <T> T upsertAndReturnEntity(String containerName, T object)
      Upserts an item and return item properties
      Type Parameters:
      T - type of upsert object
      Parameters:
      containerName - the container name
      object - upsert object
      Returns:
      upsert object entity
    • deleteById

      void deleteById(String containerName, Object id, com.azure.cosmos.models.PartitionKey partitionKey)
      Delete an item by id
      Parameters:
      containerName - the container name
      id - the id
      partitionKey - the partition key
    • deleteEntity

      <T> void deleteEntity(String containerName, T entity)
      Delete using entity
      Type Parameters:
      T - type class of domain type
      Parameters:
      containerName - the container name
      entity - 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 type
      T - type class of domain type
      Parameters:
      information - must not be null
      entities - must not be null
    • deleteAll

      void deleteAll(String containerName, Class<?> domainType)
      Delete all items in a container. Uses bulk if possible.
      Parameters:
      containerName - the container name
      domainType - the domainType
    • deleteContainer

      void deleteContainer(String containerName)
      Delete container
      Parameters:
      containerName - the container name
    • delete

      <T> Iterable<T> delete(CosmosQuery query, Class<T> domainType, String containerName)
      Delete items matching query. Uses bulk if possible.
      Type Parameters:
      T - type class of domainType
      Parameters:
      query - the document query
      domainType - type class
      containerName - the container name
      Returns:
      deleted items in a Iterable
    • find

      <T> Iterable<T> find(CosmosQuery query, Class<T> domainType, String containerName)
      Find query
      Type Parameters:
      T - type class of domainType
      Parameters:
      query - the document query
      domainType - type class
      containerName - the container name
      Returns:
      results in an Iterable
    • findByIds

      <T, ID> Iterable<T> findByIds(Iterable<ID> ids, Class<T> domainType, String containerName)
      Find by ids
      Type Parameters:
      T - type of domainType
      ID - type of ID
      Parameters:
      ids - iterable of ids
      domainType - type class
      containerName - the container name
      Returns:
      results in an Iterable
    • exists

      <T> Boolean exists(CosmosQuery query, Class<T> domainType, String containerName)
      Exists
      Type Parameters:
      T - type of domainType
      Parameters:
      query - the document query
      domainType - type class
      containerName - 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 object
      domainType - the domainType
      containerName - 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 query
      domainType - type class
      containerName - 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 query
      domainType - type class
      containerName - 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 spec
      pageable - the pageable
      domainType - the domain type
      returnType - the return type
      Returns:
      the Page
    • count

      long count(String containerName)
      Count
      Parameters:
      containerName - the container name
      Returns:
      count result
    • count

      <T> long count(CosmosQuery query, String containerName)
      Count
      Type Parameters:
      T - type class of domainType
      Parameters:
      query - the document query
      containerName - the container name
      Returns:
      count result
    • count

      <T> long count(com.azure.cosmos.models.SqlQuerySpec querySpec, String containerName)
      Count
      Type Parameters:
      T - type class of domainType
      Parameters:
      querySpec - the document query spec
      containerName - the container name
      Returns:
      count result
    • sum

      long sum(com.azure.cosmos.models.SqlQuerySpec querySpec, String containerName)
      Sum
      Parameters:
      querySpec - the document query spec
      containerName - 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 spec
      domainType - the domain type
      returnType - 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 spec
      sort - the sort order
      domainType - the domain type
      returnType - 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 spec
      pageable - the pageable
      domainType - the domain type
      returnType - the return type
      Returns:
      the Page