Interface EntityLookupCache.EntityLookupCallbackDAO<K1 extends Serializable,V1,VK1 extends Serializable>

All Known Implementing Classes:
EntityLookupCache.EntityLookupCallbackDAOAdaptor
Enclosing class:
EntityLookupCache<K extends Serializable,V,VK extends Serializable>

public static interface EntityLookupCache.EntityLookupCallbackDAO<K1 extends Serializable,V1,VK1 extends Serializable>
Interface to support lookups of the entities using keys and values.
  • Method Summary

    Modifier and Type
    Method
    Description
    createValue(V1 value)
    Create an entity using the given values.
    int
    Delete an entity for the given key.
    int
    Delete an entity for the given value.
    Find an entity for a given key.
    findByValue(V1 value)
    Find and entity using the given value key.
    getValueKey(V1 value)
    Resolve the given value into a unique value key that can be used to find the entity's ID.
    int
    updateValue(K1 key, V1 value)
    Update the entity identified by the given key.
  • Method Details

    • getValueKey

      VK1 getValueKey(V1 value)
      Resolve the given value into a unique value key that can be used to find the entity's ID. A return value should be small and efficient; don't return a value if this is not possible.

      Implementations will often return the value itself, provided that the value is both serializable and has a good equals and hashCode.

      Were no adequate key can be generated for the value, then null can be returned. In this case, the findByValue method might not even do a search and just return null itself i.e. if it is difficult to look the value up in storage then it is probably difficult to generate a cache key from it, too.. In this scenario, the cache will be purely for key-based lookups

      Parameters:
      value - the full value being keyed (never null)
      Returns:
      Returns the business key representing the entity, or null if an economical key cannot be generated.
    • findByKey

      Pair<K1,V1> findByKey(K1 key)
      Find an entity for a given key.
      Parameters:
      key - the key (ID) used to identify the entity (never null)
      Returns:
      Return the entity or null if no entity is exists for the ID
    • findByValue

      Pair<K1,V1> findByValue(V1 value)
      Find and entity using the given value key. The equals and hashCode methods of the value object should respect case-sensitivity in the same way that this lookup treats case-sensitivity i.e. if the equals method is case-sensitive then this method should look the entity up using a case-sensitive search.

      Since this is a cache backed by some sort of database, null values are allowed by the cache. The implementation of this method can throw an exception if null is not appropriate for the use-case.

      If the search is impossible or expensive, this method should just return null. This would usually be the case if the getValueKey method also returned null i.e. if it is difficult to look the value up in storage then it is probably difficult to generate a cache key from it, too.

      Parameters:
      value - the value (business object) used to identify the entity (null allowed).
      Returns:
      Return the entity or null if no entity matches the given value
    • createValue

      Pair<K1,V1> createValue(V1 value)
      Create an entity using the given values. It is valid to assume that the entity does not exist within the current transaction at least.

      Since persistence mechanisms often allow null values, these can be expected here. The implementation must throw an exception if null is not allowed for the specific use-case.

      Parameters:
      value - the value (business object) used to identify the entity (null allowed).
      Returns:
      Return the newly-created entity ID-value pair
    • updateValue

      int updateValue(K1 key, V1 value)
      Update the entity identified by the given key.

      It is up to the client code to decide if a 0 return value indicates a concurrency violation or not.

      Parameters:
      key - the existing key (ID) used to identify the entity (never null)
      value - the new value
      Returns:
      Returns the row update count.
      Throws:
      UnsupportedOperationException - if entity updates are not supported
    • deleteByKey

      int deleteByKey(K1 key)
      Delete an entity for the given key.

      It is up to the client code to decide if a 0 return value indicates a concurrency violation or not.

      Parameters:
      key - the key (ID) used to identify the entity (never null)
      Returns:
      Returns the row deletion count.
      Throws:
      UnsupportedOperationException - if entity deletion is not supported
    • deleteByValue

      int deleteByValue(V1 value)
      Delete an entity for the given value.

      It is up to the client code to decide if a 0 return value indicates a concurrency violation or not.

      Parameters:
      value - the value (business object) used to identify the enitity (null allowed)
      Returns:
      Returns the row deletion count.
      Throws:
      UnsupportedOperationException - if entity deletion is not supported