KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.jboss.tm.TransactionLocal;
12
13 import javax.persistence.FlushModeType;
14 import javax.persistence.FlushModeType;
15
16 /**
17  * comment
18  *
19  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
20  */

21 public class FlushModeInterceptor implements Interceptor
22 {
23    private FlushModeType mode;
24
25    public FlushModeInterceptor(FlushModeType mode)
26    {
27       this.mode = mode;
28    }
29
30    public String JavaDoc getName()
31    {
32       return FlushModeInterceptor.class.getName();
33    }
34
35
36    protected static ThreadLocal JavaDoc flushMode = new ThreadLocal JavaDoc();
37    protected static TransactionLocal txFlushMode = new TransactionLocal();
38
39    public static FlushModeType getFlushMode()
40    {
41       FlushModeType mode = (FlushModeType) flushMode.get();
42       if (mode == null) mode = FlushModeType.AUTO;
43       return mode;
44    }
45
46    public static FlushModeType getTxFlushMode()
47    {
48       FlushModeType mode = (FlushModeType) txFlushMode.get();
49       if (mode == null) mode = FlushModeType.AUTO;
50       return mode;
51    }
52
53
54    public Object JavaDoc invoke(Invocation invocation) throws Throwable JavaDoc
55    {
56       flushMode.set(mode);
57       if (txFlushMode.getTransaction() != null) txFlushMode.set(mode);
58       return invocation.invokeNext();
59    }
60 }
61
Popular Tags