Class AbstractPojoLookupDao<POJO extends DbPojo>

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

public abstract class AbstractPojoLookupDao<POJO extends DbPojo>
extends Dao<POJO>
Abstract dao which implements some methods and functionality common to all lookup daos
  • Field Details

    • instances

      protected final InstancesTracker<java.lang.Integer,​POJO extends DbPojo> instances
      An instances tracker mapping primary key ids to the "canonical" instance representing that record. This is needed because HIBERNATE WILL THROW EXCEPTIONS if the same record is NOT represented by the same instance during an insert. Since the same DB record is OFTEN referenced multiple times in a single ScanResponse, it becomes necessary to keep careful track of which instance is the "canonical" representation of which record, to keep Hibernate happy.
  • Constructor Details

    • AbstractPojoLookupDao

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

    • getOrCreate

      public java.util.List<POJO> getOrCreate​(java.util.List<POJO> list)
      Get or create the "canonical" pojos representing each of the the given pojos in the list
      Parameters:
      list - the list
      Returns:
      the or create
    • getOrCreate

      public POJO getOrCreate​(POJO pojo)
      Get or create the "canonical" pojo representing the pojo provided. This is needed because HIBERNATE WILL THROW EXCEPTIONS if the same record is NOT represented by the same instance during an insert. Since the same DB record is OFTEN referenced multiple times in a single ScanResponse, it becomes necessary to keep careful track of which instance is the "canonical" representation of which record, to keep Hibernate happy.
      Parameters:
      pojo - the pojo that needs to persisted, made the canonical instance, or replaced with the correct canonical instance
      Returns:
      the canonical pojo to use for persisting a DB record
    • checkedGetOrCreate

      protected abstract POJO checkedGetOrCreate​(POJO pojo)
      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
      Parameters:
      pojo - the pojo
      Returns:
      the pojo
    • searchForInstanceId

      protected POJO searchForInstanceId​(POJO pojo, int id)
      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)
      Parameters:
      pojo - the pojo
      id - the primary key id
      Returns:
      the pojo which matches the record
    • finalizeResult

      protected abstract POJO finalizeResult​(POJO pojo, POJO result)
      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
      Parameters:
      pojo - the pojo
      result - the result
      Returns:
      the pojo