org.alfresco.repo.domain.hibernate
Class DirtySessionMethodInterceptor

java.lang.Object
  extended by org.alfresco.repo.domain.hibernate.DirtySessionMethodInterceptor
All Implemented Interfaces:
org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor

public class DirtySessionMethodInterceptor
extends java.lang.Object
implements org.aopalliance.intercept.MethodInterceptor

This method interceptor determines if a Hibernate flush is required and performs the flush if necessary. The primary purpose is to avoid the Hibernate "flush if required" checks that occur every time a query is made to the database - whether or not any actual modifications have been made to the session.

Write methods (methods that modify the Hibernate Session) will flag the transaction as dirty. Methods that query the database can set the flush mode without knowing whether the session is dirty or not.

The interceptor uses the DirtySessionAnnotation. If the annotation is not used, then no session dirty checks will be done but a WARN message will be output.

The flush data is kept as a transaction-local resource. For this reason, all calls must be made in the context of a transaction. For the same reason, the methods on the FlushData are not synchronized as access is only available by one thread.

It is also possible to flush the session manually. Using this method allows the dirty count to be updated properly, thus avoiding unecessary flushing.

To trace failures caused by data flushes, it is necessary to track methods called and values passed that lead to the session being marked as dirty. If the flush fails or if a method call fails then the stacks and method values will be dumped. Turn on trace debugging for this:

    log4j.logger.org.alfresco.repo.domain.hibernate.DirtySessionMethodInterceptor.trace=DEBUG
 

Since:
2.1.5
See Also:
DirtySessionMethodInterceptor.setQueryFlushMode(Session, Query), DirtySessionMethodInterceptor.flushSession(Session)

Constructor Summary
DirtySessionMethodInterceptor()
          Default constructor
 
Method Summary
static void flushSession(org.hibernate.Session session)
          Flush and reset the dirty count for the current transaction.
static void flushSession(org.hibernate.Session session, boolean force)
          Flush and reset the dirty count for the current transaction.
 java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
           
static void setCriteriaFlushMode(org.hibernate.Session session, org.hibernate.Criteria criteria)
           
static void setQueryFlushMode(org.hibernate.Session session, org.hibernate.Query query)
          Set the query flush mode according to whether the session is dirty or not.
static void setSessionDirty()
          Manually mark the session as dirty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DirtySessionMethodInterceptor

public DirtySessionMethodInterceptor()
Default constructor

Method Detail

setQueryFlushMode

public static void setQueryFlushMode(org.hibernate.Session session,
                                     org.hibernate.Query query)
Set the query flush mode according to whether the session is dirty or not.

Parameters:
session - the Hibernate session
query - the Hibernate query that will be issued

setCriteriaFlushMode

public static void setCriteriaFlushMode(org.hibernate.Session session,
                                        org.hibernate.Criteria criteria)

setSessionDirty

public static void setSessionDirty()
Manually mark the session as dirty.


flushSession

public static void flushSession(org.hibernate.Session session)
Flush and reset the dirty count for the current transaction. The session is only flushed if it currently dirty.

Parameters:
session - the Hibernate session

flushSession

public static void flushSession(org.hibernate.Session session,
                                boolean force)
Flush and reset the dirty count for the current transaction. Use this one if you know that the session has changeds that might not have been recorded by the DAO interceptors.

Parameters:
session - the Hibernate session
force - true to force a flush.

invoke

public java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
                        throws java.lang.Throwable
Specified by:
invoke in interface org.aopalliance.intercept.MethodInterceptor
Throws:
java.lang.Throwable


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