Class KeyValueTemplate

java.lang.Object
org.springframework.data.keyvalue.core.KeyValueTemplate
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.DisposableBean, org.springframework.context.ApplicationEventPublisherAware, KeyValueOperations

public class KeyValueTemplate extends Object implements KeyValueOperations, org.springframework.context.ApplicationEventPublisherAware
Basic implementation of KeyValueOperations.
Author:
Christoph Strobl, Oliver Gierke, Thomas Darimont, Mark Paluch, Mert Zeybekler, Adeyemi Abass
  • Constructor Details

  • Method Details

    • setExceptionTranslator

      public void setExceptionTranslator(org.springframework.dao.support.PersistenceExceptionTranslator exceptionTranslator)
      Set the PersistenceExceptionTranslator used for converting RuntimeException.
      Parameters:
      exceptionTranslator - must not be null.
    • setEventTypesToPublish

      public void setEventTypesToPublish(Set<Class<? extends KeyValueEvent>> eventTypesToPublish)
      Define the event types to publish via ApplicationEventPublisher.
      Parameters:
      eventTypesToPublish - use null or Collections.emptySet() to stop publishing.
    • setApplicationEventPublisher

      public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
      Specified by:
      setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAware
    • insert

      public <T> T insert(T objectToInsert)
      Description copied from interface: KeyValueOperations
      Add given object. Object needs to have id property to which a generated value will be assigned.
      Specified by:
      insert in interface KeyValueOperations
      Returns:
      the inserted object.
    • insert

      public <T> T insert(Object id, T objectToInsert)
      Description copied from interface: KeyValueOperations
      Add object with given id.
      Specified by:
      insert in interface KeyValueOperations
      Parameters:
      id - must not be null.
      objectToInsert - must not be null.
      Returns:
      the inserted object.
    • update

      public <T> T update(T objectToUpdate)
      Specified by:
      update in interface KeyValueOperations
      Parameters:
      objectToUpdate - must not be null.
      Returns:
      the updated object.
    • update

      public <T> T update(Object id, T objectToUpdate)
      Specified by:
      update in interface KeyValueOperations
      Parameters:
      id - must not be null.
      objectToUpdate - must not be null.
      Returns:
      the updated object.
    • findAll

      public <T> Iterable<T> findAll(Class<T> type)
      Description copied from interface: KeyValueOperations
      Get all elements of given type. Respects KeySpace if present and therefore returns all elements that can be assigned to requested type.
      Specified by:
      findAll in interface KeyValueOperations
      Parameters:
      type - must not be null.
      Returns:
      empty iterable if no elements found.
    • findById

      public <T> Optional<T> findById(Object id, Class<T> type)
      Description copied from interface: KeyValueOperations
      Get element of given type with given id. Respects KeySpace if present and therefore returns all elements that can be assigned to requested type.
      Specified by:
      findById in interface KeyValueOperations
      Parameters:
      id - must not be null.
      type - must not be null.
      Returns:
      Optional.empty() if not found.
    • delete

      public void delete(Class<?> type)
      Description copied from interface: KeyValueOperations
      Remove all elements of type. Respects KeySpace if present and therefore removes all elements that can be assigned to requested type.
      Specified by:
      delete in interface KeyValueOperations
      Parameters:
      type - must not be null.
    • delete

      public <T> T delete(T objectToDelete)
      Specified by:
      delete in interface KeyValueOperations
      Parameters:
      objectToDelete - must not be null.
      Returns:
    • delete

      public <T> T delete(Object id, Class<T> type)
      Description copied from interface: KeyValueOperations
      Delete item of type with given id.
      Specified by:
      delete in interface KeyValueOperations
      Parameters:
      id - must not be null.
      type - must not be null.
      Returns:
      the deleted item or null if no match found.
    • count

      public long count(Class<?> type)
      Description copied from interface: KeyValueOperations
      Total number of elements with given type available. Respects KeySpace if present and therefore counts all elements that can be assigned to requested type.
      Specified by:
      count in interface KeyValueOperations
      Parameters:
      type - must not be null.
      Returns:
    • execute

      @Nullable public <T> T execute(KeyValueCallback<T> action)
      Description copied from interface: KeyValueOperations
      Execute operation against underlying store.
      Specified by:
      execute in interface KeyValueOperations
      Parameters:
      action - must not be null.
      Returns:
    • executeRequired

      protected <T> T executeRequired(KeyValueCallback<T> action)
      Execute KeyValueCallback and require a non-null return value.
      Type Parameters:
      T -
      Parameters:
      action -
      Returns:
    • find

      public <T> Iterable<T> find(KeyValueQuery<?> query, Class<T> type)
      Description copied from interface: KeyValueOperations
      Get all elements matching the given query.
      Respects KeySpace if present and therefore returns all elements that can be assigned to requested type..
      Specified by:
      find in interface KeyValueOperations
      Parameters:
      query - must not be null.
      type - must not be null.
      Returns:
      empty iterable if no match found.
    • findAll

      public <T> Iterable<T> findAll(org.springframework.data.domain.Sort sort, Class<T> type)
      Description copied from interface: KeyValueOperations
      Get all elements ordered by sort. Respects KeySpace if present and therefore returns all elements that can be assigned to requested type.
      Specified by:
      findAll in interface KeyValueOperations
      Parameters:
      sort - must not be null.
      type - must not be null.
      Returns:
    • findInRange

      public <T> Iterable<T> findInRange(long offset, int rows, Class<T> type)
      Description copied from interface: KeyValueOperations
      Get all elements in given range. Respects KeySpace if present and therefore returns all elements that can be assigned to requested type.
      Specified by:
      findInRange in interface KeyValueOperations
      type - must not be null.
      Returns:
    • findInRange

      public <T> Iterable<T> findInRange(long offset, int rows, org.springframework.data.domain.Sort sort, Class<T> type)
      Description copied from interface: KeyValueOperations
      Get all elements in given range ordered by sort. Respects KeySpace if present and therefore returns all elements that can be assigned to requested type.
      Specified by:
      findInRange in interface KeyValueOperations
      Returns:
    • count

      public long count(KeyValueQuery<?> query, Class<?> type)
      Description copied from interface: KeyValueOperations
      Total number of elements matching given query. Respects KeySpace if present and therefore counts all elements that can be assigned to requested type.
      Specified by:
      count in interface KeyValueOperations
      Returns:
    • exists

      public boolean exists(KeyValueQuery<?> query, Class<?> type)
      Description copied from interface: KeyValueOperations
      Determine whether result of given KeyValueQuery contains at least one element.
      Specified by:
      exists in interface KeyValueOperations
      Returns:
    • getMappingContext

      public org.springframework.data.mapping.context.MappingContext<?,?> getMappingContext()
      Specified by:
      getMappingContext in interface KeyValueOperations
      Returns:
      mapping context in use.
    • getKeyValueAdapter

      public KeyValueAdapter getKeyValueAdapter()
      Specified by:
      getKeyValueAdapter in interface KeyValueOperations
      Returns:
      KeyValueAdapter in use.
    • destroy

      public void destroy() throws Exception
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
      Throws:
      Exception