Interface CrudOperations<V extends AbstractEntity & UpdatableEntity,M>

Type Parameters:
V - Type of the value stored in the storage
M - Type of the model object
All Known Implementing Classes:
ConcurrentHashMapCrudOperations, FileCrudOperations, HotRodCrudOperations, SingleUseObjectConcurrentHashMapCrudOperations, SingleUseObjectHotRodCrudOperations

public interface CrudOperations<V extends AbstractEntity & UpdatableEntity,M>
Interface for CRUD operations on the storage. The operations may not respect transactional boundaries if the underlying storage does not support it.
  • Method Summary

    Modifier and Type
    Method
    Description
    create(V value)
    Creates an object in the storage.
    boolean
    Deletes object with the given key from the storage, if exists, no-op otherwise.
    long
    delete(QueryParameters<M> queryParameters)
    Deletes objects that match the given criteria.
    default String
    Determines first available key from the value upon creation.
    default boolean
    Returns true if the object with the given key exists in the storage.
    default boolean
    exists(QueryParameters<M> queryParameters)
    Returns true if at least one object is satisfying given criteria from the storage.
    long
    getCount(QueryParameters<M> queryParameters)
    Returns the number of objects satisfying given criteria from the storage.
    read(String key)
    Returns object with the given key from the storage or null if object does not exist.
    read(QueryParameters<M> queryParameters)
    Returns stream of objects satisfying given criteria from the storage.
    update(V value)
    Updates the object with the key of the value's ID in the storage if it already exists.
  • Method Details

    • create

      V create(V value)
      Creates an object in the storage.
      ID of the value may be prescribed in id of the value. If the id is null or its format is not matching the store internal format for ID, then the value's ID will be generated and returned in the id of the return value.
      Parameters:
      value - Entity to create in the store
      Returns:
      Entity representing the value in the store. It may or may not be the same instance as value
      Throws:
      NullPointerException - if value is null
      See Also:
    • read

      V read(String key)
      Returns object with the given key from the storage or null if object does not exist.
      If V implements ExpirableEntity this method should not return entities that are expired. See ExpirableEntity JavaDoc for more details. TODO: Consider returning Optional<V> instead.
      Parameters:
      key - Key of the object. Must not be null.
      Returns:
      See description
      Throws:
      NullPointerException - if the key is null
    • update

      V update(V value)
      Updates the object with the key of the value's ID in the storage if it already exists.
      Parameters:
      value - Updated value
      Returns:
      the previous value associated with the specified key, or null if there was no mapping for the key. (A null return can also indicate that the map previously associated null with the key, if the implementation supports null values.)
      Throws:
      NullPointerException - if the object or its id is null
      See Also:
    • delete

      boolean delete(String key)
      Deletes object with the given key from the storage, if exists, no-op otherwise.
      Parameters:
      key -
      Returns:
      Returns true if the object has been deleted or result cannot be determined, false otherwise.
    • delete

      long delete(QueryParameters<M> queryParameters)
      Deletes objects that match the given criteria.
      Parameters:
      queryParameters - parameters for the query like firstResult, maxResult, requested ordering, etc.
      Returns:
      Number of removed objects (might return -1 if not supported)
    • read

      Stream<V> read(QueryParameters<M> queryParameters)
      Returns stream of objects satisfying given criteria from the storage. The criteria are specified in the given criteria builder based on model properties.
      If V implements ExpirableEntity this method should not return entities that are expired. See ExpirableEntity JavaDoc for more details.
      Parameters:
      queryParameters - parameters for the query like firstResult, maxResult, requested ordering, etc.
      Returns:
      Stream of objects. Never returns null.
    • getCount

      long getCount(QueryParameters<M> queryParameters)
      Returns the number of objects satisfying given criteria from the storage. The criteria are specified in the given criteria builder based on model properties.
      Parameters:
      queryParameters - parameters for the query like firstResult, maxResult, requested ordering, etc.
      Returns:
      Number of objects. Never returns null.
    • exists

      default boolean exists(String key)
      Returns true if the object with the given key exists in the storage. false otherwise.
      Parameters:
      key - Key of the object. Must not be null.
      Returns:
      See description
      Throws:
      NullPointerException - if the key is null
    • exists

      default boolean exists(QueryParameters<M> queryParameters)
      Returns true if at least one object is satisfying given criteria from the storage. false otherwise. The criteria are specified in the given criteria builder based on model properties.
      Parameters:
      queryParameters - parameters for the query
      Returns:
      See description
    • determineKeyFromValue

      default String determineKeyFromValue(V value)
      Determines first available key from the value upon creation.
      Parameters:
      value -
      Returns: