org.nuiton.web.struts2.interceptor
Class TopiaTransactionInterceptor

java.lang.Object
  extended by com.opensymphony.xwork2.interceptor.AbstractInterceptor
      extended by org.nuiton.web.struts2.interceptor.TopiaTransactionInterceptor
All Implemented Interfaces:
com.opensymphony.xwork2.interceptor.Interceptor, Serializable

public abstract class TopiaTransactionInterceptor
extends com.opensymphony.xwork2.interceptor.AbstractInterceptor

The aim of this Interceptor is to manage a transaction all along a action which implements TopiaTransactionAware contract.

Technicaly, the action will receive only a proxy of a transaction and a real transaction will only be created as soon as a method will be asked on it.

The interceptor is abstract and let user to implement the way how to open a new transaction via the method beginTransaction().

Note that the transaction pushed in the action can be limited using a list of methods to exclude on it. The list of methods to forbid can be customized using the interceptor parameter excludeMethods.

Note also that the transaction is commited and closed after all stack of interceptor consumed, this means that the transaction will still be opened while rendering the result, this is a particular interesting thing to avoid pre-loading of entities due to lazy strategy of hibernate for example. With this mecanism you can feel free to just obtain the obtain from database via a DAO and then really load it in the rendering result.

If you do not want any commit for a given action, just put on the class a commit

This interceptor, as it provides connection to database should be in the interceptor stack before any other interceptor requiring access to database. For example, it is a common behaviour to do such calls in a prepare method, so make sure to place this interceptor before the prepare interceptor.

Interceptor parameters:

Since:
1.2
Author:
tchemit
See Also:
Serialized Form

Nested Class Summary
static interface TopiaTransactionInterceptor.NoCommit
          To specify on your action that you never want any commit.
 class TopiaTransactionInterceptor.TopiaTransactionProxyInvocationHandler
          Handler of a proxy on a TopiaContext.
 
Field Summary
static String[] DEFAULT_EXCLUDE_METHODS
           
protected  Set<String> excludeMethods
          names of methods to forbid access while using proxy.
 
Constructor Summary
TopiaTransactionInterceptor()
           
 
Method Summary
protected abstract  org.nuiton.topia.TopiaContext beginTransaction()
          Method to open a new transaction.
 Set<String> getExcludeMethods()
           
 void init()
           
 String intercept(com.opensymphony.xwork2.ActionInvocation invocation)
           
protected  boolean isCommitNeeded(Object action, com.opensymphony.xwork2.ActionInvocation invocation)
           
 void setExcludeMethods(String excludeMethods)
           
 
Methods inherited from class com.opensymphony.xwork2.interceptor.AbstractInterceptor
destroy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_EXCLUDE_METHODS

public static final String[] DEFAULT_EXCLUDE_METHODS

excludeMethods

protected Set<String> excludeMethods
names of methods to forbid access while using proxy.

Constructor Detail

TopiaTransactionInterceptor

public TopiaTransactionInterceptor()
Method Detail

getExcludeMethods

public Set<String> getExcludeMethods()

setExcludeMethods

public void setExcludeMethods(String excludeMethods)

beginTransaction

protected abstract org.nuiton.topia.TopiaContext beginTransaction()
                                                           throws org.nuiton.topia.TopiaException
Method to open a new transaction.

Returns:
the new freshly opened transaction
Throws:
org.nuiton.topia.TopiaException - if any problem while opening a new transaction

init

public void init()
Specified by:
init in interface com.opensymphony.xwork2.interceptor.Interceptor
Overrides:
init in class com.opensymphony.xwork2.interceptor.AbstractInterceptor

intercept

public String intercept(com.opensymphony.xwork2.ActionInvocation invocation)
                 throws Exception
Specified by:
intercept in interface com.opensymphony.xwork2.interceptor.Interceptor
Specified by:
intercept in class com.opensymphony.xwork2.interceptor.AbstractInterceptor
Throws:
Exception

isCommitNeeded

protected boolean isCommitNeeded(Object action,
                                 com.opensymphony.xwork2.ActionInvocation invocation)
                          throws NoSuchMethodException
Throws:
NoSuchMethodException


Copyright © 2010-2011 CodeLutin. All Rights Reserved.