|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.alfresco.repo.domain.hibernate.DirtySessionMethodInterceptor
public class DirtySessionMethodInterceptor
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
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 |
---|
public DirtySessionMethodInterceptor()
Method Detail |
---|
public static void setQueryFlushMode(org.hibernate.Session session, org.hibernate.Query query)
session
- the Hibernate sessionquery
- the Hibernate query that will be issuedpublic static void setCriteriaFlushMode(org.hibernate.Session session, org.hibernate.Criteria criteria)
public static void setSessionDirty()
public static void flushSession(org.hibernate.Session session)
session
- the Hibernate sessionpublic static void flushSession(org.hibernate.Session session, boolean force)
session
- the Hibernate sessionforce
- true to force a flush.public java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation invocation) throws java.lang.Throwable
invoke
in interface org.aopalliance.intercept.MethodInterceptor
java.lang.Throwable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |