org.hibernate.event.def
Class DefaultLoadEventListener

java.lang.Object
  extended byorg.hibernate.event.def.AbstractReassociateEventListener
      extended byorg.hibernate.event.def.AbstractLockUpgradeEventListener
          extended byorg.hibernate.event.def.DefaultLoadEventListener
All Implemented Interfaces:
LoadEventListener, Serializable

public class DefaultLoadEventListener
extends AbstractLockUpgradeEventListener
implements LoadEventListener

Defines the default load event listeners used by hibernate for loading entities in response to generated load events.

Author:
Steve Ebersole
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.hibernate.event.LoadEventListener
LoadEventListener.LoadType
 
Field Summary
static LockMode DEFAULT_LOCK_MODE
           
 
Fields inherited from interface org.hibernate.event.LoadEventListener
GET, IMMEDIATE_LOAD, INTERNAL_LOAD_EAGER, INTERNAL_LOAD_LAZY, INTERNAL_LOAD_NULLABLE, LOAD, RELOAD
 
Constructor Summary
DefaultLoadEventListener()
           
 
Method Summary
protected  Object doLoad(LoadEvent event, EntityPersister persister, EntityKey keyToLoad, LoadEventListener.LoadType options)
          Coordinates the efforts to load a given entity.
protected  Object load(LoadEvent event, EntityPersister persister, EntityKey keyToLoad, LoadEventListener.LoadType options)
          Perfoms the load of an entity.
protected  Object loadFromDatasource(LoadEvent event, EntityPersister persister, EntityKey keyToLoad, LoadEventListener.LoadType options)
          Performs the process of loading an entity from the configured underlying datasource.
protected  Object loadFromSecondLevelCache(LoadEvent event, EntityPersister persister, LoadEventListener.LoadType options)
          Attempts to load the entity from the second-level cache.
protected  Object loadFromSessionCache(LoadEvent event, EntityKey keyToLoad, LoadEventListener.LoadType options)
          Attempts to locate the entity in the session-level cache.
protected  Object lockAndLoad(LoadEvent event, EntityPersister persister, EntityKey keyToLoad, LoadEventListener.LoadType options, SessionImplementor source)
          If the class to be loaded has been configured with a cache, then lock given id in that cache and then perform the load.
 void onLoad(LoadEvent event, LoadEventListener.LoadType loadType)
          Handle the given load event.
protected  Object proxyOrLoad(LoadEvent event, EntityPersister persister, EntityKey keyToLoad, LoadEventListener.LoadType options)
          Based on configured options, will either return a pre-existing proxy, generate a new proxy, or perform an actual load.
 
Methods inherited from class org.hibernate.event.def.AbstractLockUpgradeEventListener
upgradeLock
 
Methods inherited from class org.hibernate.event.def.AbstractReassociateEventListener
reassociate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LOCK_MODE

public static final LockMode DEFAULT_LOCK_MODE
Constructor Detail

DefaultLoadEventListener

public DefaultLoadEventListener()
Method Detail

onLoad

public void onLoad(LoadEvent event,
                   LoadEventListener.LoadType loadType)
            throws HibernateException
Handle the given load event.

Specified by:
onLoad in interface LoadEventListener
Parameters:
event - The load event to be handled.
Returns:
The result (i.e., the loaded entity).
Throws:
HibernateException

load

protected Object load(LoadEvent event,
                      EntityPersister persister,
                      EntityKey keyToLoad,
                      LoadEventListener.LoadType options)
               throws HibernateException
Perfoms the load of an entity.

Returns:
The loaded entity.
Throws:
HibernateException

proxyOrLoad

protected Object proxyOrLoad(LoadEvent event,
                             EntityPersister persister,
                             EntityKey keyToLoad,
                             LoadEventListener.LoadType options)
                      throws HibernateException
Based on configured options, will either return a pre-existing proxy, generate a new proxy, or perform an actual load.

Returns:
The result of the proxy/load operation.
Throws:
HibernateException

lockAndLoad

protected Object lockAndLoad(LoadEvent event,
                             EntityPersister persister,
                             EntityKey keyToLoad,
                             LoadEventListener.LoadType options,
                             SessionImplementor source)
                      throws HibernateException
If the class to be loaded has been configured with a cache, then lock given id in that cache and then perform the load.

Returns:
The loaded entity
Throws:
HibernateException

doLoad

protected Object doLoad(LoadEvent event,
                        EntityPersister persister,
                        EntityKey keyToLoad,
                        LoadEventListener.LoadType options)
                 throws HibernateException
Coordinates the efforts to load a given entity. First, an attempt is made to load the entity from the session-level cache. If not found there, an attempt is made to locate it in second-level cache. Lastly, an attempt is made to load it directly from the datasource.

Returns:
The loaded entity.
Throws:
HibernateException

loadFromDatasource

protected Object loadFromDatasource(LoadEvent event,
                                    EntityPersister persister,
                                    EntityKey keyToLoad,
                                    LoadEventListener.LoadType options)
                             throws HibernateException
Performs the process of loading an entity from the configured underlying datasource.

Returns:
The object loaded from the datasource, or null if not found.
Throws:
HibernateException

loadFromSessionCache

protected Object loadFromSessionCache(LoadEvent event,
                                      EntityKey keyToLoad,
                                      LoadEventListener.LoadType options)
                               throws HibernateException
Attempts to locate the entity in the session-level cache. If checkDeleted was set to true, then if the entity is found in the session-level cache, it's current status within the session cache is checked to see if it has previously been scheduled for deletion.

Returns:
The entity from the session-level cache, or null.
Throws:
HibernateException

loadFromSecondLevelCache

protected Object loadFromSecondLevelCache(LoadEvent event,
                                          EntityPersister persister,
                                          LoadEventListener.LoadType options)
                                   throws HibernateException
Attempts to load the entity from the second-level cache.

Returns:
The entity from the second-level cache, or null.
Throws:
HibernateException