Skip navigation links

Oracle® Coherence Java API Reference
Release 12.1.2.0.3

E26043-02


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, pp 2009.01.23

Field Summary
protected static java.lang.String PARAM_IDS
          Name of the "ids" named parameter in HQL bulk queries

 

Constructor Summary
HibernateCacheLoader()
          Default constructor.
HibernateCacheLoader(java.lang.String sEntityName)
          Constructor which accepts an entityName.
HibernateCacheLoader(java.lang.String sEntityName, java.io.File configurationFile)
          Constructor which accepts an entityName and a Hibernate configuration resource.
HibernateCacheLoader(java.lang.String sEntityName, org.hibernate.SessionFactory sessionFactory)
          Constructor which accepts an entityName and a Hibernate SessionFactory.
HibernateCacheLoader(java.lang.String sEntityName, java.lang.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  java.lang.Object createEntityFromId(java.lang.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  java.lang.String getEntityName()
          Get the Hibernate entity name
protected  java.lang.String getLoadAllQuery()
          Get the parameterized loadAll HQL query string
 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.

 java.lang.Object load(java.lang.Object key)
          Load a Hibernate entity given an id (key)
 java.util.Map loadAll(java.util.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
 void setEntityName(java.lang.String sEntityName)
          Set the Hibernate entity name.
protected  void setLoadAllQuery(java.lang.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(java.io.Serializable id, java.lang.Object entity)
          Ensure that there are no conflicts between an explicit and implicit key.

 

Field Detail

PARAM_IDS

protected static final java.lang.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 the entityName and sessionFactory attributes will be set prior to usage.

HibernateCacheLoader

public HibernateCacheLoader(java.lang.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(java.lang.String sEntityName,
                            java.lang.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(java.lang.String sEntityName,
                            java.io.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(java.lang.String sEntityName,
                            org.hibernate.SessionFactory sessionFactory)
Constructor which accepts an entityName and a Hibernate SessionFactory. 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:
java.lang.IllegalStateException - if the session factory has already been set

getEntityName

protected java.lang.String getEntityName()
Get the Hibernate entity name
Returns:
the entity name

setEntityName

public void setEntityName(java.lang.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:
java.lang.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 java.lang.Object load(java.lang.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 java.util.Map loadAll(java.util.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

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 java.lang.String getLoadAllQuery()
Get the parameterized loadAll HQL query string
Returns:
a parameterized HQL query string

setLoadAllQuery

protected void setLoadAllQuery(java.lang.String sLoadAllQuery)
Get the parameterized loadAll HQL query string
Parameters:
sLoadAllQuery - a parameterized HQL query string

createEntityFromId

protected java.lang.Object createEntityFromId(java.lang.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(java.io.Serializable id,
                                  java.lang.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)

Skip navigation links

Oracle® Coherence Java API Reference
Release 12.1.2.0.3

E26043-02


Copyright © 2000, 2014, Oracle and/or its affiliates. All rights reserved.