Class HashLookupDao<POJO extends HashLookupPojo<POJO>>

java.lang.Object
tenapull.data.persistence.Dao<POJO>
tenapull.data.persistence.AbstractPojoLookupDao<POJO>
tenapull.data.persistence.HashLookupDao<POJO>
Type Parameters:
POJO - the type parameter
Direct Known Subclasses:
StringHashLookupDao

public class HashLookupDao<POJO extends HashLookupPojo<POJO>>
extends AbstractPojoLookupDao<POJO>
Dao used for object lookups that are indexed by their hash. In addition to the instances tracker (organized by primary key id) inherited from AbstractPojoLookupDao, this also includes a second instances tracker organized by
  • Field Details

  • Constructor Details

    • HashLookupDao

      public HashLookupDao​(java.lang.Class<POJO> pojoType) throws java.lang.IllegalArgumentException
      Instantiates a new Hash lookup dao for the provided pojo type
      Parameters:
      pojoType - the pojo type
      Throws:
      java.lang.IllegalArgumentException - if a dao has already been instantiated for the provided pojoType
  • Method Details

    • getByHash

      public POJO getByHash​(Hash hash)
      Gets the canonical instance representing the provided hash, if one exists
      Parameters:
      hash - the hash
      Returns:
      the by hash
    • checkedGetOrCreate

      protected POJO checkedGetOrCreate​(POJO pojo)
      Description copied from class: AbstractPojoLookupDao
      Abstract method to be implemented by subclasses, which is invoked after the instance array has already been checked for the instance without success (assuming the pojo had a primary key id set) and the pojo has already had its _prepare method invoked
      Specified by:
      checkedGetOrCreate in class AbstractPojoLookupDao<POJO extends HashLookupPojo<POJO>>
      Parameters:
      pojo - the pojo
      Returns:
      the pojo
    • searchForInstanceId

      protected POJO searchForInstanceId​(POJO pojo, int id)
      Description copied from class: AbstractPojoLookupDao
      Search for pojo with instance id. This is used by the initial getOrCreate before invoking checkedGetOrCreate, and its behavior may be overridden by subclass implementions if there are other criteria to match (e.g. a natural key such as a hash or a map lookup)
      Overrides:
      searchForInstanceId in class AbstractPojoLookupDao<POJO extends HashLookupPojo<POJO>>
      Parameters:
      pojo - the pojo
      id - the primary key id
      Returns:
      the pojo which matches the record
    • tryMatchFilter

      protected POJO tryMatchFilter​(POJO pojo)
      Attempts to use the _match function to find a matching pojo, so that calculating the hash can be skipped when possible
      Parameters:
      pojo - the pojo
      Returns:
      the pojo
    • useHash

      protected POJO useHash​(POJO pojo)
      Obtains the hash of the pojo and uses it to find a matching pojo if one exists, otherwise attempts to find it in the database. If none can be found, the new record is inserted to the DB and the passed pojo is used as the new canonical instance for this record
      Parameters:
      pojo - the pojo
      Returns:
      the pojo
    • finalizeResult

      protected POJO finalizeResult​(POJO pojo, POJO result)
      Description copied from class: AbstractPojoLookupDao
      Perform any needed final operations on the "canonical" pojo before returning it to the caller of getOrCreate. Typically, if the canonical pojo were a different instance than the one provided, the _set method would be called on the canonical instance to update it so it reflects the values of the new instance
      Specified by:
      finalizeResult in class AbstractPojoLookupDao<POJO extends HashLookupPojo<POJO>>
      Parameters:
      pojo - the pojo
      result - the result
      Returns:
      the pojo
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class Dao<POJO extends HashLookupPojo<POJO>>
    • get

      public static <P extends DbPojo,​ D extends Dao<P>> D get​(java.lang.Class<P> lookupPojoType)
      Get HashLookupDao for the provided pojo type.
      Type Parameters:
      P - the type parameter
      D - the type parameter
      Parameters:
      lookupPojoType - the lookup pojo type
      Returns:
      the d