Class SimpleCosmosRepository<T,ID extends Serializable>

java.lang.Object
com.azure.spring.data.cosmos.repository.support.SimpleCosmosRepository<T,ID>
All Implemented Interfaces:
CosmosRepository<T,ID>, org.springframework.data.repository.CrudRepository<T,ID>, org.springframework.data.repository.PagingAndSortingRepository<T,ID>, org.springframework.data.repository.Repository<T,ID>

public class SimpleCosmosRepository<T,ID extends Serializable> extends Object implements CosmosRepository<T,ID>
Repository class for simple Cosmos operation
  • Constructor Details

    • SimpleCosmosRepository

      public SimpleCosmosRepository(CosmosEntityInformation<T,ID> metadata, CosmosOperations dbOperations)
      Initialization
      Parameters:
      metadata - for cosmos entity information
      dbOperations - for cosmosDB operation
  • Method Details

    • save

      public <S extends T> S save(S entity)
      save entity without partition
      Specified by:
      save in interface org.springframework.data.repository.CrudRepository<T,ID extends Serializable>
      Type Parameters:
      S - type of entity
      Parameters:
      entity - to be saved
      Returns:
      entity
    • saveAll

      public <S extends T> Iterable<S> saveAll(Iterable<S> entities)
      batch save entities
      Specified by:
      saveAll in interface org.springframework.data.repository.CrudRepository<T,ID extends Serializable>
      Type Parameters:
      S - type of entities
      Parameters:
      entities - Batch entities
      Returns:
      return the saved entities
    • findAll

      public Iterable<T> findAll()
      find all entities from one container without configuring partition key value
      Specified by:
      findAll in interface org.springframework.data.repository.CrudRepository<T,ID extends Serializable>
      Returns:
      return Iterable of the found entities List
    • findAllById

      public Iterable<T> findAllById(Iterable<ID> ids)
      find entities based on id list from one container without partitions
      Specified by:
      findAllById in interface org.springframework.data.repository.CrudRepository<T,ID extends Serializable>
      Parameters:
      ids - id list used to find entities
      Returns:
      return a List of all found entities
    • findById

      public Optional<T> findById(ID id)
      find one entity per id without partitions
      Specified by:
      findById in interface org.springframework.data.repository.CrudRepository<T,ID extends Serializable>
      Parameters:
      id - an id used to find entity
      Returns:
      return the searching result
    • findById

      public Optional<T> findById(ID id, PartitionKey partitionKey)
      Description copied from interface: CosmosRepository
      Retrieves an entity by its id.
      Specified by:
      findById in interface CosmosRepository<T,ID extends Serializable>
      Parameters:
      id - must not be null.
      partitionKey - partition key value of entity, must not be null.
      Returns:
      the entity with the given id or Optional#empty() if none found
    • count

      public long count()
      return count of documents in one container without partitions
      Specified by:
      count in interface org.springframework.data.repository.CrudRepository<T,ID extends Serializable>
      Returns:
      count of documents in one container without partitions
    • deleteById

      public void deleteById(ID id)
      delete one document per id without configuring partition key value
      Specified by:
      deleteById in interface org.springframework.data.repository.CrudRepository<T,ID extends Serializable>
      Parameters:
      id - an id used to specify the deleted document
    • deleteById

      public void deleteById(ID id, PartitionKey partitionKey)
      Description copied from interface: CosmosRepository
      Deletes an entity by its id and partition key.
      Specified by:
      deleteById in interface CosmosRepository<T,ID extends Serializable>
      Parameters:
      id - must not be null.
      partitionKey - partition key value of the entity, must not be null.
    • delete

      public void delete(T entity)
      delete one document per entity
      Specified by:
      delete in interface org.springframework.data.repository.CrudRepository<T,ID extends Serializable>
      Parameters:
      entity - the entity used to specify a document
    • deleteAllById

      public void deleteAllById(Iterable<? extends ID> ids)
      Specified by:
      deleteAllById in interface org.springframework.data.repository.CrudRepository<T,ID extends Serializable>
    • deleteAll

      public void deleteAll()
      delete all the domains of a container
      Specified by:
      deleteAll in interface org.springframework.data.repository.CrudRepository<T,ID extends Serializable>
    • deleteAll

      public void deleteAll(Iterable<? extends T> entities)
      delete list of entities without partitions
      Specified by:
      deleteAll in interface org.springframework.data.repository.CrudRepository<T,ID extends Serializable>
      Parameters:
      entities - list of entities to be deleted
    • existsById

      public boolean existsById(ID primaryKey)
      check if an entity exists per id without partition
      Specified by:
      existsById in interface org.springframework.data.repository.CrudRepository<T,ID extends Serializable>
      Parameters:
      primaryKey - an id to specify an entity
      Returns:
      if the entity exists
    • findAll

      public Iterable<T> findAll(@NonNull org.springframework.data.domain.Sort sort)
      Returns all entities sorted by the given options.
      Specified by:
      findAll in interface org.springframework.data.repository.PagingAndSortingRepository<T,ID extends Serializable>
      Parameters:
      sort - the Sort option for queries.
      Returns:
      all entities sorted by the given options
    • findAll

      public org.springframework.data.domain.Page<T> findAll(org.springframework.data.domain.Pageable pageable)
      FindQuerySpecGenerator Returns a Page of entities meeting the paging restriction provided in the Pageable object.
      Specified by:
      findAll in interface org.springframework.data.repository.PagingAndSortingRepository<T,ID extends Serializable>
      Parameters:
      pageable - the Pageable object providing paging restriction
      Returns:
      a page of entities
    • findAll

      public Iterable<T> findAll(PartitionKey partitionKey)
      Description copied from interface: CosmosRepository
      Returns list of items in a specific partition
      Specified by:
      findAll in interface CosmosRepository<T,ID extends Serializable>
      Parameters:
      partitionKey - partition key value
      Returns:
      Iterable of items with partition key value