1 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 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 getName() 31 { 32 return FlushModeInterceptor.class.getName(); 33 } 34 35 36 protected static ThreadLocal flushMode = new ThreadLocal (); 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 invoke(Invocation invocation) throws Throwable 55 { 56 flushMode.set(mode); 57 if (txFlushMode.getTransaction() != null) txFlushMode.set(mode); 58 return invocation.invokeNext(); 59 } 60 } 61 | Popular Tags |