Package tenapull.data.persistence
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
-
Nested Class Summary
-
Field Summary
Fields Modifier and Type Field Description protected InstancesTracker<java.lang.Integer,POJO>
instances
An instances tracker mapping primary key ids to the "canonical" instance representing that record. -
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractPojoLookupDao(java.lang.Class<POJO> pojoType)
Instantiates a new Abstract pojo lookup dao. -
Method Summary
Modifier and Type Method Description 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 invokedprotected abstract POJO
finalizeResult(POJO pojo, POJO result)
Perform any needed final operations on the "canonical" pojo before returning it to the caller of getOrCreate.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 listPOJO
getOrCreate(POJO pojo)
Get or create the "canonical" pojo representing the pojo provided.protected POJO
searchForInstanceId(POJO pojo, int id)
Search for pojo with instance id.Methods inherited from class tenapull.data.persistence.Dao
borrowSessionsFrom, checkedUnproxy, delete, delete, findByExactPojo, findByPojoNonNull, findByPropertyEqual, findByPropertyEqual, get, getAccessMap, getAll, getAttributeMap, getById, getGetterMap, getIdMap, getLogger, getPojoType, getSession, hasActiveSession, holdSession, insert, insert, keyValueSearch, lenderHasActiveSession, makeExactPojoSearchMap, makePojoNonNullSearchMap, mapSearch, releaseSession, saveOrUpdate, saveOrUpdate, toString, unproxy
-
Field Details
-
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.IllegalArgumentExceptionInstantiates 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
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
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
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
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 pojoid
- the primary key id- Returns:
- the pojo which matches the record
-
finalizeResult
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 pojoresult
- the result- Returns:
- the pojo
-