User: osh
Date: 01/02/09 10:56:14
Modified: src/main/org/jboss/ejb MethodInvocation.java
Log:
Changed tx export/propagation/import in preparation to JTA independence.
Revision Changes Path
1.10 +130 -35 jboss/src/main/org/jboss/ejb/MethodInvocation.java
Index: MethodInvocation.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/MethodInvocation.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- MethodInvocation.java 2000/12/07 15:44:11 1.9
+++ MethodInvocation.java 2001/02/09 18:56:14 1.10
@@ -14,9 +14,14 @@
import java.lang.reflect.Method;
import java.util.Map;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
import java.security.Principal;
import javax.transaction.Transaction;
+import org.jboss.tm.TransactionPropagationContextImporter;
+
import org.jboss.logging.Logger;
/**
@@ -27,58 +32,110 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>.
- * @version $Revision: 1.9 $
+ * @version $Revision: 1.10 $
*/
public class MethodInvocation
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
+
Object id;
Object[] args;
- Transaction tx;
- Principal identity;
- Object credential;
+ Principal identity;
+ Object credential;
- Method m;
- EnterpriseContext ctx;
+ Method m;
+ EnterpriseContext ctx;
+
// Static --------------------------------------------------------
+ private static TransactionPropagationContextImporter tpcImporter;
+
+
// Constructors --------------------------------------------------
+
+ /**
+ * Create a new instance.
+ *
+ * @param id
+ * The id of target EJB of this method invocation.
+ * @param m
+ * The method to invoke. This method is declared in the remote or
+ * home interface of the bean.
+ * @param args
+ * The arguments for this invocation.
+ * @param tpc
+ * The transaction propagation context of this invocation.
+ * @param identity
+ * The security identity to use in this invocation.
+ * @param credential
+ * The security credentials to use in this invocation.
+ */
public MethodInvocation(Object id, Method m, Object[] args, Transaction tx,
- Principal identity, Object credential )
+ Principal identity, Object credential)
{
- this.id = id;
- this.m = m;
- this.args = args;
- this.tx = tx;
- this.identity = identity;
- this.credential = credential;
+ this.id = id;
+ this.m = m;
+ this.args = args;
+ this.tpc = null;
+ this.tx = tx;
+ this.identity = identity;
+ this.credential = credential;
}
+
+ /**
+ * Create a new instance.
+ *
+ * @param id
+ * The id of target EJB of this method invocation.
+ * @param m
+ * The method to invoke. This method is declared in the remote or
+ * home interface of the bean.
+ * @param args
+ * The arguments for this invocation.
+ * @param identity
+ * The security identity to use in this invocation.
+ * @param credential
+ * The security credentials to use in this invocation.
+ * @param tpc
+ * The transaction propagation context of this invocation.
+ */
+ public MethodInvocation(Object id, Method m, Object[] args,
+ Principal identity, Object credential, Object tpc)
+ {
+ this.id = id;
+ this.m = m;
+ this.args = args;
+ this.tpc = tpc;
+ this.tx = null;
+ this.identity = identity;
+ this.credential = credential;
+ }
+
// Public --------------------------------------------------------
+
public Object getId() { return id; }
public Method getMethod()
{
- return m;
+ return m;
}
public Object[] getArguments()
{
return args;
}
-
- /*
- * setTransaction()
- *
- * This method sets the transaction associated with the method
- * Note that this doesn't mean that the transaction is associated
- * with the thread. In fact this is the only place it exists until
- * the TxInterceptor logic. Notably it might be the case that the
- * tx associated here is different than the one on the target instance.
- */
+
+ /**
+ * This method sets the transaction associated with the method.
+ * Note that this doesn't mean that the transaction is associated
+ * with the thread. In fact this is the only place it exists until
+ * the TxInterceptor logic. Notably it might be the case that the
+ * tx associated here is different than the one on the target instance.
+ */
public void setTransaction(Transaction tx)
{
@@ -87,9 +144,36 @@
this.tx = tx;
}
-
+
+ /**
+ * Return the transaction associated with the method.
+ *
+ * If no transaction is associated with this method but we have
+ * a transaction propagation context, import the TPC into the
+ * transaction manager, and associate the resulting transaction
+ * with this method before returning it.
+ */
public Transaction getTransaction()
{
+ if (tx == null) {
+ // See if we have a transaction propagation context
+ if (tpc != null) {
+ // import the propagation context
+ if (tpcImporter == null) {
+ try {
+ tpcImporter = (TransactionPropagationContextImporter)new
InitialContext().lookup("java:/TransactionPropagationContextImporter");
+ } catch (NamingException ex) {
+ // No importer: Log exception, and return null.
+ Logger.exception(ex);
+ return null;
+ }
+ }
+ tx = tpcImporter.importTransactionPropagationContext(tpc);
+//DEBUG Logger.debug("Imported transaction " + tx +
+//DEBUG " on Method invocation " + hashCode() +
+//DEBUG " " + m.getName());
+ }
+ }
return tx;
}
@@ -113,22 +197,23 @@
return credential;
}
- /*
- * setEnterpriseContext()
- *
- * Once a context is associated to a Method Invocation the MI can pass it all
the relevant information
- * We set Transaction and Principal
- */
+ /**
+ * Set the enterprise context of this invocation.
+ *
+ * Once a context is associated to a Method Invocation,
+ * the MI can pass it all the relevant information.
+ * We set Transaction and Principal.
+ */
public void setEnterpriseContext(EnterpriseContext ctx)
{
this.ctx = ctx;
-
+
//Set the transaction
// MF FIXME: wrong decision. Setting the context is just an assocation of
the
// the Method invocation to the instance. Decisions on the transaction
association
// should be done elsewhere (new interceptor)
//ctx.setTransaction(tx);
-
+
// Set the principal
// MF FIXME: a warning really. The association of the context variables
(tx, principal)
// to the enterprise Context should not be done here but by the final
interceptor in the
@@ -148,7 +233,17 @@
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
+
+ /**
+ * The transaction propagation context of this invocation.
+ */
+ private Object tpc;
+
+ /**
+ * The transaction of this invocation.
+ */
+ private Transaction tx;
+
+ // Inner classes -------------------------------------------------
}