org.alfresco.repo.domain.hibernate
Class SessionSizeResourceManager

java.lang.Object
  extended by org.springframework.dao.support.DaoSupport
      extended by org.springframework.orm.hibernate3.support.HibernateDaoSupport
          extended by org.alfresco.repo.domain.hibernate.SessionSizeResourceManager
All Implemented Interfaces:
MethodResourceManager, org.springframework.beans.factory.InitializingBean

public class SessionSizeResourceManager
extends org.springframework.orm.hibernate3.support.HibernateDaoSupport
implements MethodResourceManager

A Hibernate-specific resource manager that ensures that the current Session's entity count doesn't exceed a given threshold.

NOTE: VERY IMPORTANT
Do not, under any circumstances, attach an instance of this class to an API that passes stateful objects back and forth. There must be no Session-linked objects up the stack from where this instance resides. Failure to observe this will most likely result in data loss of a sporadic nature.

See Also:
org.alfresco.repo.domain.hibernate.HibernateNodeTest#testPostCommitClearIssue()

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.alfresco.util.resource.MethodResourceManager
MethodResourceManager.MethodStatistics
 
Field Summary
static java.lang.String KEY_COMMIT_STARTED
           
 
Constructor Summary
SessionSizeResourceManager()
          Default public constructor required for bean instantiation.
 
Method Summary
static void clear(org.hibernate.Session session)
          Clear the session now.
static boolean isDisableInTransaction()
           
 void manageResources(java.util.Map methodStatsByMethod, long transactionElapsedTimeNs, java.lang.reflect.Method currentMethod)
          Check and free any required resources for an imminent.
static void setCommitStarted()
           
static void setDisableInTransaction()
          Disable resource management for the duration of the current transaction.
static void setEnableInTransaction()
          Enable resource management for the duration of the current transaction.
 void setReadThreshold(int threshold)
          Set the Session.clear() threshold for read-only transactions.
 void setRetentionFactor(int retentionFactor)
          Set the number of entities retained in the session for each one flushed; default 3.
 void setWriteThreshold(int threshold)
          Set the Session.clear() threshold for read-write transactions.
 
Methods inherited from class org.springframework.orm.hibernate3.support.HibernateDaoSupport
checkDaoConfig, convertHibernateAccessException, createHibernateTemplate, getHibernateTemplate, getSession, getSession, getSessionFactory, releaseSession, setHibernateTemplate, setSessionFactory
 
Methods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_COMMIT_STARTED

public static final java.lang.String KEY_COMMIT_STARTED
See Also:
Constant Field Values
Constructor Detail

SessionSizeResourceManager

public SessionSizeResourceManager()
Default public constructor required for bean instantiation.

Method Detail

setDisableInTransaction

public static void setDisableInTransaction()
Disable resource management for the duration of the current transaction. This is temporary and relies on an active transaction.


setEnableInTransaction

public static void setEnableInTransaction()
Enable resource management for the duration of the current transaction. This is temporary and relies on an active transaction.


isDisableInTransaction

public static boolean isDisableInTransaction()
Returns:
Returns true if the resource management must be ignored in the current transaction. If false, the global setting will take effect.
See Also:
SessionSizeResourceManager.setDisableInTransaction()

setRetentionFactor

public void setRetentionFactor(int retentionFactor)
Set the number of entities retained in the session for each one flushed; default 3. Set this to zero to remove all entities when the session is trimmed.

Parameters:
retentionFactor - the number of entities to keep for each entity removed

setReadThreshold

public void setReadThreshold(int threshold)
Set the Session.clear() threshold for read-only transactions. If the number of entities and collections in the current session exceeds this number, then the session will be cleared.

Have you read the disclaimer?

Parameters:
threshold - the maximum number of entities and associations to keep in memory during read-only operations
See Also:
SessionSizeResourceManager.writeThreshold

setWriteThreshold

public void setWriteThreshold(int threshold)
Set the Session.clear() threshold for read-write transactions. If the number of entities and collections in the current session exceeds this number, then the session will be cleared.

Have you read the disclaimer?

Parameters:
threshold - the maximum number of entities and associations to keep in memory during write operations
See Also:
SessionSizeResourceManager.writeThreshold

setCommitStarted

public static void setCommitStarted()

manageResources

public void manageResources(java.util.Map methodStatsByMethod,
                            long transactionElapsedTimeNs,
                            java.lang.reflect.Method currentMethod)
Description copied from interface: MethodResourceManager
Check and free any required resources for an imminent. Details of the current transaction and some gathered information about previous calls to associated methods is also provided.

Specified by:
manageResources in interface MethodResourceManager
Parameters:
methodStatsByMethod - all known methods and their basic call stats
transactionElapsedTimeNs - the elapsed time in the current transaction
currentMethod - the method about to be called

clear

public static void clear(org.hibernate.Session session)
Clear the session now.

Parameters:
session -


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.