ch.elca.el4j.services.persistence.hibernate
Class OpenSessionInServiceInterceptor

java.lang.Object
  extended by ch.elca.el4j.services.persistence.hibernate.OpenSessionInServiceInterceptor
All Implemented Interfaces:
Serializable, org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor

public class OpenSessionInServiceInterceptor
extends Object
implements org.aopalliance.intercept.MethodInterceptor, Serializable

This interceptor is similar to OpenSessionInViewInterceptor, but can also be used e.g. for batch job processing where no HTTP requests are used. Another use case is to take this class as a replacement for HibernateInterceptor, now having more control over the flush mode and a single session feature.

Author:
Pham Quoc Ky (QKP)
See Also:
Serialized Form
File-location:
OpenSessionInServiceInterceptor
Last check-in date:
2009-08-04 15:22:05 +0200 (Di, 04. Aug 2009) by swismer for revision 3881

Constructor Summary
OpenSessionInServiceInterceptor()
           
 
Method Summary
protected  void closeSession(Session session)
          Close the given Session.
 FlushMode getFlushMode()
           
protected  Session getSession(SessionFactory sessionFactory)
          Get a Session for the SessionFactory that this filter uses.
 SessionFactory getSessionFactory()
           
 Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
          
 boolean isSingleSession()
           
 void setFlushMode(FlushMode flushMode)
           
 void setSessionFactory(SessionFactory sessionFactory)
           
 void setSingleSession(boolean singleSession)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OpenSessionInServiceInterceptor

public OpenSessionInServiceInterceptor()
Method Detail

isSingleSession

public boolean isSingleSession()
Returns:
the singleSession

setSingleSession

public void setSingleSession(boolean singleSession)
Parameters:
singleSession - the singleSession to set

getSessionFactory

public SessionFactory getSessionFactory()
Returns:
the sessionFactory

setSessionFactory

public void setSessionFactory(SessionFactory sessionFactory)
Parameters:
sessionFactory - the sessionFactory to set

getFlushMode

public FlushMode getFlushMode()
Returns:
the flushMode

setFlushMode

public void setFlushMode(FlushMode flushMode)
Parameters:
flushMode - the flushMode to set

invoke

public Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
              throws Throwable

Specified by:
invoke in interface org.aopalliance.intercept.MethodInterceptor
Throws:
Throwable

getSession

protected Session getSession(SessionFactory sessionFactory)
                      throws DataAccessResourceFailureException
Get a Session for the SessionFactory that this filter uses. Note that this just applies in single session mode!

The default implementation delegates to the SessionFactoryUtils.getSession method and sets the Session's flush mode to "NEVER".

Can be overridden in subclasses for creating a Session with a custom entity interceptor or JDBC exception translator.

Parameters:
sessionFactory - the SessionFactory that this filter uses
Returns:
the Session to use
Throws:
DataAccessResourceFailureException - if the Session could not be created
See Also:
SessionFactoryUtils.getSession(SessionFactory, boolean), FlushMode.COMMIT

closeSession

protected void closeSession(Session session)
Close the given Session. Note that this just applies in single session mode!

Can be overridden in subclasses, e.g. for flushing the Session before closing it. See class-level javadoc for a discussion of flush handling. Note that you should also override getSession accordingly, to set the flush mode to something else than NEVER.

Parameters:
session - the Session used for filtering


Copyright © 2005-2011 ELCA. All Rights Reserved.