You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Don Brown (JIRA)" <ji...@apache.org> on 2006/06/10 05:17:22 UTC

[jira] Updated: (WW-1094) Spring Transaction Interceptor

     [ http://issues.apache.org/struts/browse/WW-1094?page=all ]

Don Brown updated WW-1094:
--------------------------

    Fix Version: Future
                     (was: 2.0.0)

> Spring Transaction Interceptor
> ------------------------------
>
>          Key: WW-1094
>          URL: http://issues.apache.org/struts/browse/WW-1094
>      Project: Struts Action 2
>         Type: New Feature

>   Components: Interceptors
>     Versions: WW 2.2
>     Reporter: Behrang Javaherian
>     Assignee: Rene Gielen
>      Fix For: Future

>
> This is a patch for an interceptor which call the action inside the transaction. I am not sure is there better way to do this webwork or not. We can define the transaction for each execute function inside the xml file. But there is too much boilerplate definition inside the xml file. This approach is simple and more straight forward for most of application.
> public interface Transactional {
>     PlatformTransactionManager getTransactionManager();
>     void setTransactionManager(PlatformTransactionManager transactionManager);
> }
> public class BaseAction extends ActionSupport implements Transactional {
>     private PlatformTransactionManager transactionManager;
>     public BaseAction() {
>         super();
>     }
>     public PlatformTransactionManager getTransactionManager() {
>         return transactionManager;
>     }
>     public void setTransactionManager(PlatformTransactionManager transactionManager) {
>         this.transactionManager = transactionManager;
>     }
> }
> public class TransactionInterceptor implements Interceptor {
>     public void destroy() {
>     }
>     public void init() {
>     }
>     public String intercept(ActionInvocation invocation) throws Exception {
>         final Object action = invocation.getAction();
>         String result;
>         if(action instanceof Transactional)  {
>             Transactional transactionalAction = (Transactional) action;
>             TransactionStatus transactionStatus = transactionalAction.getTransactionManager().getTransaction(null);
>             try {
>                 result = invocation.invoke();
>                 transactionalAction.getTransactionManager().commit(transactionStatus);
>                 return result;
>             } catch (Exception e) {
>                 transactionalAction.getTransactionManager().rollback(transactionStatus);
>                 throw e;
>             }
>         }
>         else {
>             return invocation.invoke();
>         }
>     }
> }
> define the springtransaction interceptor before any other interceptor in your interceptor stack. Of course if you need more complicated transaction behaviour you  should follow the spring documentation recipes. But this will work for most of the cases!
> Behrang Javaherian
> www.behrang.info
> Software Engineer
> Innovit-Birng Integrity to you product data
> www.innovit.com

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira