CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation

com.tangosol.coherence.hibernate
Class HibernateCacheLoader

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.coherence.hibernate.HibernateCacheLoader
All Implemented Interfaces:
CacheLoader
Direct Known Subclasses:
HibernateCacheStore

public class HibernateCacheLoader
extends Base
implements CacheLoader

Data-driven CacheLoader implementation for Hibernate tables

These methods all follow the pattern of: 1) open session 2) begin transaction 3) do work 4) commit transaction (or rollback on exception and rethrow) 5) close session

Author:
jp 2005.09.15

Field Summary
protected static String PARAM_IDS
          Name of the "ids" named parameter in HQL bulk queries
 
Constructor Summary
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.
 
Method Summary
protected  void closeSession(org.hibernate.Session session)
          Close a Hibernate Session.
protected  Object createEntityFromId(Object id)
          Create a transient entity instance given an entity id
protected  void ensureInitialized()
          Called by all API-implementing methods for lazy initialization.
protected  org.hibernate.metadata.ClassMetadata getEntityClassMetadata()
          Get the Hibernate ClassMetadata for the Hibernate entity
protected  String getEntityName()
          Get the Hibernate entity name
protected  String getLoadAllQuery()
          Get the parameterized loadAll HQL query string
protected  org.hibernate.SessionFactory getSessionFactory()
          Get the Hibernate SessionFactory.
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.

 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 entity
protected  void setLoadAllQuery(String sLoadAllQuery)
          Get the parameterized loadAll HQL query string
protected  void validateIdentifier(Serializable id, Object entity)
          Ensure that there are no conflicts between an explicit and implicit key.
 

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(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)
Method Detail

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 interface 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 interface 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

getSessionFactory

protected org.hibernate.SessionFactory getSessionFactory()
Get the Hibernate SessionFactory.

Returns:
the Hibernate SessionFactory

getEntityName

protected String getEntityName()
Get the Hibernate entity name

Returns:
the entity name

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)
Create a transient entity instance given an entity id

Parameters:
id - the Hibernate entity id
Returns:
the Hibernate entity (may return null)

validateIdentifier

protected void validateIdentifier(Serializable id,
                                  Object entity)
Ensure that there are no conflicts between an explicit and implicit key.

Parameters:
id - the explicit key
entity - an entity (containing an implicit key)

CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation