KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > entity > BeforeTxFlushModeInterceptor


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.ejb3.entity;
8
9 import org.jboss.aop.advice.Interceptor;
10 import org.jboss.aop.joinpoint.Invocation;
11
12 import javax.persistence.FlushModeType;
13 import javax.persistence.FlushModeType;
14
15 /**
16  * This interceptor must be called before the Tx interceptor to make sure tha the TxLocal is set properly
17  *
18  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
19  */

20 public class BeforeTxFlushModeInterceptor implements Interceptor
21 {
22
23    public String JavaDoc getName()
24    {
25       return BeforeTxFlushModeInterceptor.class.getName();
26    }
27
28
29    public Object JavaDoc invoke(Invocation invocation) throws Throwable JavaDoc
30    {
31
32       FlushModeType old = (FlushModeType)FlushModeInterceptor.flushMode.get();
33       try
34       {
35          return invocation.invokeNext();
36       }
37       finally
38       {
39          FlushModeInterceptor.flushMode.set(old);
40          if (FlushModeInterceptor.txFlushMode.getTransaction() != null) FlushModeInterceptor.txFlushMode.set(old);
41       }
42    }
43 }
44
Popular Tags