Class HibernateCacheLoader
- java.lang.Object
-
- com.tangosol.util.Base
-
- com.oracle.coherence.hibernate.cachestore.HibernateCacheLoader
-
- All Implemented Interfaces:
com.tangosol.net.cache.CacheLoader
- Direct Known Subclasses:
HibernateCacheStore
public class HibernateCacheLoader extends com.tangosol.util.Base implements com.tangosol.net.cache.CacheLoader
Data-driven CacheLoader implementation for Hibernate tablesThese methods all follow the pattern of:
- open session
- begin transaction
- do work
- commit transaction (or rollback on exception and rethrow)
- close session
- Author:
- jp 2005.09.15, pp 2009.01.23, rs 2013.09.05
-
-
Constructor Summary
Constructors Constructor Description HibernateCacheLoader()
Default constructor.HibernateCacheLoader(String sEntityName)
Constructor which accepts an entityName.HibernateCacheLoader(String sEntityName, File configurationFile)
Constructor which accepts an entityName and a Hibernate configuration resource.HibernateCacheLoader(String sEntityName, String sResource)
Constructor which accepts an entityName and a Hibernate configuration resource.HibernateCacheLoader(String sEntityName, org.hibernate.SessionFactory sessionFactory)
Constructor which accepts an entityName and a HibernateSessionFactory
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
closeSession(org.hibernate.Session session)
Close a Hibernate Session.protected Object
createEntityFromId(Object id, org.hibernate.engine.spi.SessionImplementor sessionImplementor)
Create a transient entity instance given an entity idprotected void
ensureInitialized()
Called by all API-implementing methods for lazy initialization.protected org.hibernate.metadata.ClassMetadata
getEntityClassMetadata()
Get the Hibernate ClassMetadata for the Hibernate entityprotected String
getEntityName()
Get the Hibernate entity nameprotected String
getLoadAllQuery()
Get the parameterized loadAll HQL query stringorg.hibernate.SessionFactory
getSessionFactory()
Get the Hibernate SessionFactory.protected void
initialize()
Initializer (must be called post-constructor)Object
load(Object key)
Load a Hibernate entity given an id (key)Map
loadAll(Collection keys)
Load a collection of Hibernate entities given a set of ids (keys)protected org.hibernate.Session
openSession()
Open a Hibernate Session.protected void
setEntityClassMetadata(org.hibernate.metadata.ClassMetadata entityClassMetadata)
Get the Hibernate ClassMetadata for the Hibernate entityvoid
setEntityName(String sEntityName)
Set the Hibernate entity name.protected void
setLoadAllQuery(String sLoadAllQuery)
Get the parameterized loadAll HQL query stringvoid
setSessionFactory(org.hibernate.SessionFactory sessionFactory)
Set the Hibernate SessionFactory to be used by this CacheLoader.protected void
validateIdentifier(Serializable id, Object entity, org.hibernate.engine.spi.SessionImplementor sessionImplementor)
Ensure that there are no conflicts between an explicit and implicit key.-
Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
-
-
-
-
Field Detail
-
PARAM_IDS
protected static final String PARAM_IDS
Name of the "ids" named parameter in HQL bulk queries- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HibernateCacheLoader
public HibernateCacheLoader()
Default constructor. If using this constructor, it is expected that theentityName
andsessionFactory
attributes will be set prior to usage.
-
HibernateCacheLoader
public HibernateCacheLoader(String sEntityName)
Constructor which accepts an entityName. Configures Hibernate using the default Hibernate configuration. The current implementation parses this file once-per-instance (there is typically a single instance per).- Parameters:
sEntityName
- the Hibernate entity (i.e., the HQL table name)
-
HibernateCacheLoader
public HibernateCacheLoader(String sEntityName, String sResource)
Constructor which accepts an entityName and a Hibernate configuration resource. The current implementation instantiates a SessionFactory per instance (implying one instance per CacheStore-backed NamedCache).- Parameters:
sEntityName
- Hibernate entity (i.e. the HQL table name)sResource
- Hibernate config classpath resource (e.g. hibernate.cfg.xml)
-
HibernateCacheLoader
public HibernateCacheLoader(String sEntityName, File configurationFile)
Constructor which accepts an entityName and a Hibernate configuration resource. The current implementation instantiates a SessionFactory per instance (implying one instance per CacheStore-backed NamedCache).- Parameters:
sEntityName
- Hibernate entity (i.e. the HQL table name)configurationFile
- Hibernate config file (e.g. hibernate.cfg.xml)
-
HibernateCacheLoader
public HibernateCacheLoader(String sEntityName, org.hibernate.SessionFactory sessionFactory)
Constructor which accepts an entityName and a HibernateSessionFactory
. This allows for external configuration of the SessionFactory (for instance using Spring.)- Parameters:
sEntityName
- Hibernate entity (i.e. the HQL table name)sessionFactory
- Hibernate SessionFactory
-
-
Method Detail
-
getSessionFactory
public org.hibernate.SessionFactory getSessionFactory()
Get the Hibernate SessionFactory.- Returns:
- the Hibernate SessionFactory
-
setSessionFactory
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
Set the Hibernate SessionFactory to be used by this CacheLoader. This attribute can only be set once during the lifecycle of an instance.- Parameters:
sessionFactory
- the Hibernate SessionFactory- Throws:
IllegalStateException
- if the session factory has already been set
-
getEntityName
protected String getEntityName()
Get the Hibernate entity name- Returns:
- the entity name
-
setEntityName
public void setEntityName(String sEntityName)
Set the Hibernate entity name. This attribute can only be set once during the lifecycle of an instance.- Parameters:
sEntityName
- the entity name- Throws:
IllegalStateException
- if the entity name has already been set
-
initialize
protected void initialize()
Initializer (must be called post-constructor)We do this specifically so that derived classes can safely create override methods that depend on a fully constructed object state. Will only be called once per instance and prior to the main body of any API methods. This should not be directly called by derived classes. If this method is overridden, super must be called at the end of the overriding method.
-
ensureInitialized
protected void ensureInitialized()
Called by all API-implementing methods for lazy initialization. This should never be called from a constructor.
-
load
public Object load(Object key)
Load a Hibernate entity given an id (key)- Specified by:
load
in interfacecom.tangosol.net.cache.CacheLoader
- Parameters:
key
- the cache key; specifically, the entity id- Returns:
- the corresponding Hibernate entity instance
-
loadAll
public Map loadAll(Collection keys)
Load a collection of Hibernate entities given a set of ids (keys)- Specified by:
loadAll
in interfacecom.tangosol.net.cache.CacheLoader
- Parameters:
keys
- the cache keys; specifically, the entity ids- Returns:
- the corresponding Hibernate entity instances
-
openSession
protected org.hibernate.Session openSession()
Open a Hibernate Session.- Returns:
- the Hibernate Session object
-
closeSession
protected void closeSession(org.hibernate.Session session)
Close a Hibernate Session.- Parameters:
session
- the Hibernate Session object
-
getEntityClassMetadata
protected org.hibernate.metadata.ClassMetadata getEntityClassMetadata()
Get the Hibernate ClassMetadata for the Hibernate entity- Returns:
- the ClassMetadata object
-
setEntityClassMetadata
protected void setEntityClassMetadata(org.hibernate.metadata.ClassMetadata entityClassMetadata)
Get the Hibernate ClassMetadata for the Hibernate entity- Parameters:
entityClassMetadata
- the ClassMetadata object
-
getLoadAllQuery
protected String getLoadAllQuery()
Get the parameterized loadAll HQL query string- Returns:
- a parameterized HQL query string
-
setLoadAllQuery
protected void setLoadAllQuery(String sLoadAllQuery)
Get the parameterized loadAll HQL query string- Parameters:
sLoadAllQuery
- a parameterized HQL query string
-
createEntityFromId
protected Object createEntityFromId(Object id, org.hibernate.engine.spi.SessionImplementor sessionImplementor)
Create a transient entity instance given an entity id- Parameters:
id
- the Hibernate entity idsessionImplementor
- the Hibernate SessionImplementor- Returns:
- the Hibernate entity (may return null)
-
validateIdentifier
protected void validateIdentifier(Serializable id, Object entity, org.hibernate.engine.spi.SessionImplementor sessionImplementor)
Ensure that there are no conflicts between an explicit and implicit key.- Parameters:
id
- the explicit keyentity
- an entity (containing an implicit key)sessionImplementor
- the Hibernate SessionImplementor
-
-