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 tables.
These 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, Gunnar Hillert
-
Nested Class Summary
Nested classes/interfaces inherited from class com.tangosol.util.Base
com.tangosol.util.Base.LoggingWriter
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
Name of the "ids" named parameter in HQL bulk queries.Fields inherited from class com.tangosol.util.Base
LOG_ALWAYS, LOG_CONFIG, LOG_DEBUG, LOG_ERR, LOG_INFO, LOG_MAX, LOG_MIN, LOG_QUIET, LOG_WARN, POWER_0, POWER_G, POWER_K, POWER_M, POWER_T, UNIT_D, UNIT_H, UNIT_M, UNIT_MS, UNIT_NS, UNIT_S, UNIT_US
-
Constructor Summary
ConstructorDescriptionDefault constructor.HibernateCacheLoader
(String entityName) Constructor which accepts an entityName.HibernateCacheLoader
(String entityName, File configurationFile) Constructor which accepts an entityName and a Hibernate configuration resource.HibernateCacheLoader
(String entityName, String resource) Constructor which accepts an entityName and a Hibernate configuration resource.HibernateCacheLoader
(String entityName, org.hibernate.SessionFactory sessionFactory) Constructor which accepts an entityName and a HibernateSessionFactory
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
closeSession
(org.hibernate.Session session) Close a Hibernate Session.protected Object
createEntityFromId
(Object id, org.hibernate.engine.spi.SharedSessionContractImplementor sessionImplementor) Create a transient entity instance given an entity id.protected void
Called by all API-implementing methods for lazy initialization.protected org.hibernate.persister.entity.EntityPersister
Get the Hibernate ClassMetadata for the Hibernate entity.protected String
Get the Hibernate entity name.protected String
Get the parameterized loadAll HQL query string.org.hibernate.SessionFactory
Get the Hibernate SessionFactory.protected void
Initializer (must be called post-constructor).Load a Hibernate entity given an id (key).Load a collection of Hibernate entities given a set of ids (keys).protected org.hibernate.Session
Open a Hibernate Session.protected void
setEntityClassMetadata
(org.hibernate.persister.entity.EntityPersister entityPersister) Get the Hibernate EntityPersister for the Hibernate entity.void
setEntityName
(String entityName) Set the Hibernate entity name.protected void
setLoadAllQuery
(String sLoadAllQuery) Get the parameterized loadAll HQL query string.void
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.SharedSessionContractImplementor 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
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.tangosol.net.cache.CacheLoader
loadAll
-
Field Details
-
PARAM_IDS
Name of the "ids" named parameter in HQL bulk queries.- See Also:
-
-
Constructor Details
-
HibernateCacheLoader
public HibernateCacheLoader()Default constructor. If using this constructor, it is expected that theentityName
andsessionFactory
attributes will be set prior to usage. -
HibernateCacheLoader
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:
entityName
- the Hibernate entity (i.e., the HQL table name)
-
HibernateCacheLoader
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:
entityName
- the Hibernate entity (i.e. the HQL table name)resource
- the Hibernate config classpath resource (e.g. hibernate.cfg.xml)
-
HibernateCacheLoader
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:
entityName
- the Hibernate entity (i.e. the HQL table name)configurationFile
- the Hibernate config file (e.g. hibernate.cfg.xml)
-
HibernateCacheLoader
Constructor which accepts an entityName and a HibernateSessionFactory
. This allows for external configuration of the SessionFactory (for instance using Spring).- Parameters:
entityName
- the Hibernate entity (i.e. the HQL table name)sessionFactory
- the Hibernate SessionFactory
-
-
Method Details
-
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
Get the Hibernate entity name.- Returns:
- the entity name
-
setEntityName
Set the Hibernate entity name. This attribute can only be set once during the lifecycle of an instance.- Parameters:
entityName
- 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
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
Load a collection of Hibernate entities given a set of ids (keys).- Parameters:
keys
- the cache keys; specifically, the entity ids. By default, entities will be returned in the order of the provided List of keys- 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.persister.entity.EntityPersister getEntityClassMetadata()Get the Hibernate ClassMetadata for the Hibernate entity.- Returns:
- the ClassMetadata object
-
setEntityClassMetadata
protected void setEntityClassMetadata(org.hibernate.persister.entity.EntityPersister entityPersister) Get the Hibernate EntityPersister for the Hibernate entity.- Parameters:
entityPersister
- the EntityPersister object
-
getLoadAllQuery
Get the parameterized loadAll HQL query string.- Returns:
- a parameterized HQL query string
-
setLoadAllQuery
Get the parameterized loadAll HQL query string.- Parameters:
sLoadAllQuery
- a parameterized HQL query string
-