Class ReactiveCosmosTemplate

  • All Implemented Interfaces:
    ReactiveCosmosOperations, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

    public class ReactiveCosmosTemplate
    extends Object
    implements ReactiveCosmosOperations, org.springframework.context.ApplicationContextAware
    Template class of reactive cosmos
    • Constructor Detail

      • ReactiveCosmosTemplate

        public ReactiveCosmosTemplate​(CosmosAsyncClient client,
                                      String databaseName,
                                      CosmosConfig cosmosConfig,
                                      MappingCosmosConverter mappingCosmosConverter,
                                      org.springframework.data.auditing.IsNewAwareAuditingHandler cosmosAuditingHandler)
        Initialization
        Parameters:
        client - must not be null
        databaseName - must not be null
        cosmosConfig - must not be null
        mappingCosmosConverter - must not be null
        cosmosAuditingHandler - can be null
      • ReactiveCosmosTemplate

        public ReactiveCosmosTemplate​(CosmosAsyncClient client,
                                      String databaseName,
                                      CosmosConfig cosmosConfig,
                                      MappingCosmosConverter mappingCosmosConverter)
        Initialization
        Parameters:
        client - must not be null
        databaseName - must not be null
        cosmosConfig - must not be null
        mappingCosmosConverter - must not be null
      • ReactiveCosmosTemplate

        public ReactiveCosmosTemplate​(CosmosFactory cosmosFactory,
                                      CosmosConfig cosmosConfig,
                                      MappingCosmosConverter mappingCosmosConverter,
                                      org.springframework.data.auditing.IsNewAwareAuditingHandler cosmosAuditingHandler)
        Constructor
        Parameters:
        cosmosFactory - the cosmos db factory
        cosmosConfig - the cosmos config
        mappingCosmosConverter - the mappingCosmosConverter
        cosmosAuditingHandler - the auditing handler
      • ReactiveCosmosTemplate

        public ReactiveCosmosTemplate​(CosmosFactory cosmosFactory,
                                      CosmosConfig cosmosConfig,
                                      MappingCosmosConverter mappingCosmosConverter)
        Initialization
        Parameters:
        cosmosFactory - must not be null
        cosmosConfig - must not be null
        mappingCosmosConverter - must not be null
    • Method Detail

      • setApplicationContext

        public void setApplicationContext​(@NonNull
                                          org.springframework.context.ApplicationContext applicationContext)
                                   throws org.springframework.beans.BeansException
        Specified by:
        setApplicationContext in interface org.springframework.context.ApplicationContextAware
        Parameters:
        applicationContext - the application context
        Throws:
        org.springframework.beans.BeansException - the bean exception
      • findAll

        public <T> Flux<T> findAll​(String containerName,
                                   Class<T> domainType)
        Find all items in a given container
        Specified by:
        findAll in interface ReactiveCosmosOperations
        Type Parameters:
        T - type of domainType
        Parameters:
        containerName - the containerName
        domainType - the domainType
        Returns:
        Flux with all the found items or error
      • findAll

        public <T> Flux<T> findAll​(Class<T> domainType)
        Find all items in a given container
        Specified by:
        findAll in interface ReactiveCosmosOperations
        Type Parameters:
        T - type of domainType
        Parameters:
        domainType - the domainType
        Returns:
        Flux with all the found items or error
      • findAll

        public <T> Flux<T> findAll​(PartitionKey partitionKey,
                                   Class<T> domainType)
        Description copied from interface: ReactiveCosmosOperations
        Find all items in a given container with partition key
        Specified by:
        findAll in interface ReactiveCosmosOperations
        Type Parameters:
        T - type of domainType
        Parameters:
        partitionKey - partition Key
        domainType - the domainType
        Returns:
        Flux of results
      • findById

        public <T> Mono<T> findById​(Object id,
                                    Class<T> domainType)
        Find by id
        Specified by:
        findById in interface ReactiveCosmosOperations
        Type Parameters:
        T - type of domainType
        Parameters:
        id - the id
        domainType - the domainType
        Returns:
        Mono with the item or error
      • findById

        public <T> Mono<T> findById​(String containerName,
                                    Object id,
                                    Class<T> domainType)
        Find by id
        Specified by:
        findById in interface ReactiveCosmosOperations
        Type Parameters:
        T - type of domainType
        Parameters:
        containerName - the container name
        id - the id
        domainType - the entity class
        Returns:
        Mono with the item or error
      • findById

        public <T> Mono<T> findById​(Object id,
                                    Class<T> domainType,
                                    PartitionKey partitionKey)
        Find by id
        Specified by:
        findById in interface ReactiveCosmosOperations
        Type Parameters:
        T - type of domainType
        Parameters:
        id - the id
        domainType - the entity class
        partitionKey - partition Key
        Returns:
        Mono with the item or error
      • insert

        public <T> Mono<T> insert​(T objectToSave,
                                  PartitionKey partitionKey)
        Insert
        Specified by:
        insert in interface ReactiveCosmosOperations
        Type Parameters:
        T - type of inserted objectToSave
        Parameters:
        objectToSave - the object to save
        partitionKey - the partition key
        Returns:
        Mono with the item or error
      • insert

        public <T> Mono<T> insert​(T objectToSave)
        Insert
        Type Parameters:
        T - type of inserted objectToSave
        Parameters:
        objectToSave - the object to save
        Returns:
        Mono with the item or error
      • insert

        public <T> Mono<T> insert​(String containerName,
                                  Object objectToSave,
                                  PartitionKey partitionKey)
        Insert
        Specified by:
        insert in interface ReactiveCosmosOperations
        Type Parameters:
        T - type of inserted objectToSave
        Parameters:
        containerName - the container name
        objectToSave - the object to save
        partitionKey - the partition key
        Returns:
        Mono with the item or error
      • insert

        public <T> Mono<T> insert​(String containerName,
                                  T objectToSave)
        Insert
        Specified by:
        insert in interface ReactiveCosmosOperations
        Type Parameters:
        T - type of inserted objectToSave
        Parameters:
        containerName - the container name
        objectToSave - the object to save
        Returns:
        Mono with the item or error
      • upsert

        public <T> Mono<T> upsert​(T object)
        Upsert
        Specified by:
        upsert in interface ReactiveCosmosOperations
        Type Parameters:
        T - type class of object
        Parameters:
        object - the object to upsert
        Returns:
        Mono with the item or error
      • upsert

        public <T> Mono<T> upsert​(String containerName,
                                  T object)
        Upsert
        Specified by:
        upsert in interface ReactiveCosmosOperations
        Type Parameters:
        T - type class of object
        Parameters:
        containerName - the container name
        object - the object to save
        Returns:
        Mono with the item or error
      • deleteById

        public Mono<Void> deleteById​(String containerName,
                                     Object id,
                                     PartitionKey partitionKey)
        Deletes the item with id and partition key.
        Specified by:
        deleteById in interface ReactiveCosmosOperations
        Parameters:
        containerName - Container name of database
        id - item id
        partitionKey - the partition key
        Returns:
        void Mono
      • deleteEntity

        public <T> Mono<Void> deleteEntity​(String containerName,
                                           T entity)
        Deletes the entity
        Specified by:
        deleteEntity in interface ReactiveCosmosOperations
        Type Parameters:
        T - type class of domain type
        Parameters:
        containerName - Container name of database
        entity - the entity to delete
        Returns:
        void Mono
      • deleteAll

        public Mono<Void> deleteAll​(@NonNull
                                    String containerName,
                                    @NonNull
                                    Class<?> domainType)
        Delete all items in a container
        Specified by:
        deleteAll in interface ReactiveCosmosOperations
        Parameters:
        containerName - the container name
        domainType - the domainType
        Returns:
        void Mono
      • delete

        public <T> Flux<T> delete​(CosmosQuery query,
                                  Class<T> domainType,
                                  String containerName)
        Delete items matching query
        Specified by:
        delete in interface ReactiveCosmosOperations
        Type Parameters:
        T - type class of domainType
        Parameters:
        query - the document query
        domainType - the entity class
        containerName - the container name
        Returns:
        Mono
      • find

        public <T> Flux<T> find​(CosmosQuery query,
                                Class<T> domainType,
                                String containerName)
        Find items
        Specified by:
        find in interface ReactiveCosmosOperations
        Type Parameters:
        T - type class of domainType
        Parameters:
        query - the document query
        domainType - the entity class
        containerName - the container name
        Returns:
        Flux with found items or error
      • exists

        public Mono<Boolean> exists​(CosmosQuery query,
                                    Class<?> domainType,
                                    String containerName)
        Exists
        Specified by:
        exists in interface ReactiveCosmosOperations
        Parameters:
        query - the document query
        domainType - the entity class
        containerName - the container name
        Returns:
        Mono with a boolean or error
      • runQuery

        public <T> Flux<T> runQuery​(SqlQuerySpec querySpec,
                                    org.springframework.data.domain.Sort sort,
                                    Class<?> domainType,
                                    Class<T> returnType)
        Description copied from interface: ReactiveCosmosOperations
        Run the query.
        Specified by:
        runQuery in interface ReactiveCosmosOperations
        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 flux
      • deleteContainer

        public void deleteContainer​(@NonNull
                                    String containerName)
        Delete container with container name
        Specified by:
        deleteContainer in interface ReactiveCosmosOperations
        Parameters:
        containerName - the container name