Interface CosmosOperations

  • All Known Implementing Classes:
    CosmosTemplate

    public interface CosmosOperations
    Interface for cosmosDB operations
    • Method Detail

      • getContainerName

        String getContainerName​(Class<?> domainType)
        To get container name by domainType
        Parameters:
        domainType - class type
        Returns:
        String
      • createContainerIfNotExists

        CosmosContainerProperties createContainerIfNotExists​(CosmosEntityInformation<?,​?> information)
        Creates container if not exists
        Parameters:
        information - CosmosEntityInformation
        Returns:
        CosmosContainerProperties
      • getContainerProperties

        CosmosContainerProperties getContainerProperties​(String containerName)
        Get properties for specified container
        Parameters:
        containerName - String
        Returns:
        CosmosContainerProperties
      • replaceContainerProperties

        CosmosContainerProperties replaceContainerProperties​(String containerName,
                                                             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​(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,
                       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,
                     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
      • insert

        <T> T insert​(String containerName,
                     T objectToSave,
                     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
      • 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,
                        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
      • deleteAll

        void deleteAll​(String containerName,
                       Class<?> domainType)
        Delete all items in a container
        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
        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​(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​(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
      • runQuery

        <T> Iterable<T> runQuery​(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​(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​(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