Class ReactiveCosmosTemplate

java.lang.Object
com.azure.spring.data.cosmos.core.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 Details

    • 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 Details

    • 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
    • createContainerIfNotExists

      public Mono<CosmosContainerResponse> createContainerIfNotExists(CosmosEntityInformation<?,?> information)
      Creates a container if it doesn't already exist
      Specified by:
      createContainerIfNotExists in interface ReactiveCosmosOperations
      Parameters:
      information - the CosmosEntityInformation
      Returns:
      Mono containing CosmosContainerResponse
    • getContainerProperties

      public Mono<CosmosContainerProperties> getContainerProperties(String containerName)
      Description copied from interface: ReactiveCosmosOperations
      Get properties for specified container
      Specified by:
      getContainerProperties in interface ReactiveCosmosOperations
      Parameters:
      containerName - String
      Returns:
      CosmosContainerProperties
    • replaceContainerProperties

      public Mono<CosmosContainerProperties> replaceContainerProperties(String containerName, CosmosContainerProperties properties)
      Description copied from interface: ReactiveCosmosOperations
      Replace container properties for the specified container
      Specified by:
      replaceContainerProperties in interface ReactiveCosmosOperations
      Parameters:
      containerName - String
      properties - CosmosContainerProperties
      Returns:
      CosmosContainerProperties
    • 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, T 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
    • existsById

      public Mono<Boolean> existsById(Object id, Class<?> domainType, String containerName)
      Exists
      Specified by:
      existsById in interface ReactiveCosmosOperations
      Parameters:
      id - the id
      domainType - the entity class
      containerName - the container name
      Returns:
      Mono with a boolean or error
    • count

      public Mono<Long> count(String containerName)
      Count
      Specified by:
      count in interface ReactiveCosmosOperations
      Parameters:
      containerName - the container name
      Returns:
      Mono with the count or error
    • count

      public Mono<Long> count(CosmosQuery query, String containerName)
      Count
      Specified by:
      count in interface ReactiveCosmosOperations
      Parameters:
      query - the document query
      containerName - the container name
      Returns:
      Mono with count or error
    • count

      public Mono<Long> count(SqlQuerySpec querySpec, String containerName)
      Count
      Specified by:
      count in interface ReactiveCosmosOperations
      Parameters:
      querySpec - the document query spec
      containerName - the container name
      Returns:
      Mono with count or error
    • getConverter

      public MappingCosmosConverter getConverter()
      Description copied from interface: ReactiveCosmosOperations
      To get converter
      Specified by:
      getConverter in interface ReactiveCosmosOperations
      Returns:
      MappingCosmosConverter
    • runQuery

      public <T> Flux<T> runQuery(SqlQuerySpec querySpec, 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
      domainType - the domain type
      returnType - the return type
      Returns:
      the flux
    • 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
    • getContainerName

      public String getContainerName(Class<?> domainType)
      Description copied from interface: ReactiveCosmosOperations
      Get container name
      Specified by:
      getContainerName in interface ReactiveCosmosOperations
      Parameters:
      domainType - the domain class
      Returns:
      the container name