Package tenapull.data.persistence
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
-
Nested Class Summary
-
Field Summary
Fields Modifier and Type Field Description protected InstancesTracker<Hash,POJO>
instancesByHash
The "canonical" pojo instances organized by hash. -
Constructor Summary
Constructors Constructor Description HashLookupDao(java.lang.Class<POJO> pojoType)
Instantiates a new Hash lookup dao for the provided pojo type -
Method Summary
Modifier and Type Method Description protected 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 POJO
finalizeResult(POJO pojo, POJO result)
Perform any needed final operations on the "canonical" pojo before returning it to the caller of getOrCreate.static <P extends DbPojo, D extends Dao<P>>
Dget(java.lang.Class<P> lookupPojoType)
Get HashLookupDao for the provided pojo type.POJO
getByHash(Hash hash)
Gets the canonical instance representing the provided hash, if one existsprotected POJO
searchForInstanceId(POJO pojo, int id)
Search for pojo with instance id.java.lang.String
toString()
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 possibleprotected 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.Methods inherited from class tenapull.data.persistence.AbstractPojoLookupDao
getOrCreate, getOrCreate
Methods inherited from class tenapull.data.persistence.Dao
borrowSessionsFrom, checkedUnproxy, delete, delete, findByExactPojo, findByPojoNonNull, findByPropertyEqual, findByPropertyEqual, getAccessMap, getAll, getAttributeMap, getById, getGetterMap, getIdMap, getLogger, getPojoType, getSession, hasActiveSession, holdSession, insert, insert, keyValueSearch, lenderHasActiveSession, makeExactPojoSearchMap, makePojoNonNullSearchMap, mapSearch, releaseSession, saveOrUpdate, saveOrUpdate, unproxy
-
Field Details
-
instancesByHash
The "canonical" pojo instances organized by hash.
-
-
Constructor Details
-
HashLookupDao
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
Gets the canonical instance representing the provided hash, if one exists- Parameters:
hash
- the hash- Returns:
- the by hash
-
checkedGetOrCreate
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 classAbstractPojoLookupDao<POJO extends HashLookupPojo<POJO>>
- Parameters:
pojo
- the pojo- Returns:
- the pojo
-
searchForInstanceId
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 classAbstractPojoLookupDao<POJO extends HashLookupPojo<POJO>>
- Parameters:
pojo
- the pojoid
- the primary key id- Returns:
- the pojo which matches the record
-
tryMatchFilter
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
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
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 classAbstractPojoLookupDao<POJO extends HashLookupPojo<POJO>>
- Parameters:
pojo
- the pojoresult
- the result- Returns:
- the pojo
-
toString
public java.lang.String toString()- Overrides:
toString
in classDao<POJO extends HashLookupPojo<POJO>>
-
get
Get HashLookupDao for the provided pojo type.- Type Parameters:
P
- the type parameterD
- the type parameter- Parameters:
lookupPojoType
- the lookup pojo type- Returns:
- the d
-