Author: shane.bryzak(a)jboss.com
Date: 2008-11-11 07:26:23 -0500 (Tue, 11 Nov 2008)
New Revision: 9552
Modified:
trunk/src/main/org/jboss/seam/transaction/TransactionInterceptor.java
Log:
JBSEAM-3519
Modified: trunk/src/main/org/jboss/seam/transaction/TransactionInterceptor.java
===================================================================
--- trunk/src/main/org/jboss/seam/transaction/TransactionInterceptor.java 2008-11-11
09:41:43 UTC (rev 9551)
+++ trunk/src/main/org/jboss/seam/transaction/TransactionInterceptor.java 2008-11-11
12:26:23 UTC (rev 9552)
@@ -4,7 +4,10 @@
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+import org.jboss.seam.annotations.TransactionPropagationType;
import org.jboss.seam.annotations.Transactional;
import org.jboss.seam.annotations.intercept.AroundInvoke;
import org.jboss.seam.annotations.intercept.Interceptor;
@@ -19,15 +22,67 @@
* Implements transaction propagation rules for Seam JavaBean components.
*
* @author Gavin King
- *
+ * @author Shane Bryzak
*/
-@Interceptor(stateless=true,
+@Interceptor(stateless=false,
around={RollbackInterceptor.class, BusinessProcessInterceptor.class,
ConversationInterceptor.class, BijectionInterceptor.class})
public class TransactionInterceptor extends AbstractInterceptor
{
private static final long serialVersionUID = -4364203056333738988L;
+ private class TransactionMetadata
+ {
+ private boolean annotationPresent;
+ TransactionPropagationType propType;
+
+ public TransactionMetadata(AnnotatedElement element)
+ {
+ annotationPresent = element.isAnnotationPresent(Transactional.class);
+
+ if (annotationPresent)
+ {
+ propType = element.getAnnotation(Transactional.class).value();
+ }
+ }
+
+ public boolean isAnnotationPresent()
+ {
+ return annotationPresent;
+ }
+
+ public boolean isNewTransactionRequired(boolean transactionActive)
+ {
+ return propType != null &&
propType.isNewTransactionRequired(transactionActive);
+ }
+ }
+
+ private TransactionMetadata lookupTransactionMetadata(AnnotatedElement element)
+ {
+ TransactionMetadata metadata = transactionMetadata.get(element);
+
+ if (metadata == null)
+ {
+ metadata = loadMetadata(element);
+ }
+
+ return metadata;
+ }
+
+ private synchronized TransactionMetadata loadMetadata(AnnotatedElement element)
+ {
+ if (!transactionMetadata.containsKey(element))
+ {
+ TransactionMetadata metadata = new TransactionMetadata(element);
+ transactionMetadata.put(element, metadata);
+ return metadata;
+ }
+
+ return transactionMetadata.get(element);
+ }
+
+ private Map<AnnotatedElement,TransactionMetadata> transactionMetadata = new
HashMap<AnnotatedElement, TransactionMetadata>();
+
@AroundInvoke
public Object aroundInvoke(final InvocationContext invocation) throws Exception
{
@@ -48,21 +103,18 @@
private boolean isNewTransactionRequired(Method method, Class beanClass, boolean
transactionActive)
{
- return isTransactionAnnotationPresent(method) ?
- isNewTransactionRequired(method, transactionActive) :
- isTransactionAnnotationPresent(beanClass) &&
isNewTransactionRequired(beanClass, transactionActive);
+ TransactionMetadata metadata = lookupTransactionMetadata(method);
+ if (metadata.isNewTransactionRequired(transactionActive))
+ {
+ return true;
+ }
+ else
+ {
+ metadata = lookupTransactionMetadata(beanClass);
+ return metadata.isNewTransactionRequired(transactionActive);
+ }
}
- private boolean isTransactionAnnotationPresent(AnnotatedElement element)
- {
- return element.isAnnotationPresent(Transactional.class);
- }
-
- private boolean isNewTransactionRequired(AnnotatedElement element, boolean
transactionActive)
- {
- return
element.getAnnotation(Transactional.class).value().isNewTransactionRequired(transactionActive);
- }
-
}.workInTransaction();
}
Show replies by date