[jbpm-commits] JBoss JBPM SVN: r1971 - jbpm3/branches/jpdl-3.2.3.CP/jpdl/jar/src/main/java/org/jbpm/persistence/jta.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Aug 21 19:36:05 EDT 2008


Author: alex.guizar at jboss.com
Date: 2008-08-21 19:36:05 -0400 (Thu, 21 Aug 2008)
New Revision: 1971

Modified:
   jbpm3/branches/jpdl-3.2.3.CP/jpdl/jar/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceService.java
   jbpm3/branches/jpdl-3.2.3.CP/jpdl/jar/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceServiceFactory.java
Log:
move UserTransaction lookup to persistence service factory: JBPM-1694

Modified: jbpm3/branches/jpdl-3.2.3.CP/jpdl/jar/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceService.java
===================================================================
--- jbpm3/branches/jpdl-3.2.3.CP/jpdl/jar/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceService.java	2008-08-21 23:24:03 UTC (rev 1970)
+++ jbpm3/branches/jpdl-3.2.3.CP/jpdl/jar/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceService.java	2008-08-21 23:36:05 UTC (rev 1971)
@@ -21,8 +21,6 @@
  */
 package org.jbpm.persistence.jta;
 
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import javax.transaction.SystemException;
 import javax.transaction.UserTransaction;
 
@@ -70,7 +68,7 @@
   void beginJtaTransaction() {
     try {
     	log.debug("start user JTA transaction");
-    	userTransaction = getUserTransaction();
+    	userTransaction = ((JtaDbPersistenceServiceFactory) persistenceServiceFactory).getUserTransaction();
       userTransaction.begin();
     } catch (Exception e) {
       throw new JbpmException("couldn't start JTA transaction", e);
@@ -95,27 +93,6 @@
     }
   }
 
-  UserTransaction getUserTransaction() {
-    String jndiName = persistenceServiceFactory.getConfiguration().getProperty("jta.UserTransaction");
-    if (jndiName == null) {
-      /*
-       * EJB 2.1 section 20.9 The container must make the UserTransaction interface available to the
-       * enterprise beans that are allowed to use this interface (only session and message-
-       * driven beans with bean-managed transaction demarcation are allowed to use this 
-       * interface) in JNDI under the name java:comp/UserTransaction.
-       * J2EE 1.4 section 4.2.1.1 The J2EE platform must provide an object implementing the
-       * UserTransaction interface to all web components. The platform must publish the 
-       * UserTransaction object in JNDI under the name java:comp/UserTransaction.
-       */
-      jndiName = "java:comp/UserTransaction";
-    }
-    try {
-      return (UserTransaction) new InitialContext().lookup(jndiName);
-    } catch (NamingException e) {
-      throw new JbpmException("couldn't lookup UserTransaction in JNDI with name "+jndiName, e);
-    }
-  }
-
   int getJtaTransactionStatus() {
     try {
       return userTransaction.getStatus();

Modified: jbpm3/branches/jpdl-3.2.3.CP/jpdl/jar/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceServiceFactory.java
===================================================================
--- jbpm3/branches/jpdl-3.2.3.CP/jpdl/jar/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceServiceFactory.java	2008-08-21 23:24:03 UTC (rev 1970)
+++ jbpm3/branches/jpdl-3.2.3.CP/jpdl/jar/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceServiceFactory.java	2008-08-21 23:36:05 UTC (rev 1971)
@@ -21,6 +21,11 @@
  */
 package org.jbpm.persistence.jta;
 
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.transaction.UserTransaction;
+
+import org.jbpm.JbpmException;
 import org.jbpm.persistence.db.DbPersistenceServiceFactory;
 import org.jbpm.svc.Service;
 
@@ -47,6 +52,8 @@
 
   private static final long serialVersionUID = 1L;
 
+  private UserTransaction userTransaction;
+
   public JtaDbPersistenceServiceFactory() {
     setCurrentSessionEnabled(true);
     setTransactionEnabled(false);
@@ -55,4 +62,28 @@
   public Service openService() {
     return new JtaDbPersistenceService(this);
   }
+
+  public UserTransaction getUserTransaction() {
+    if (userTransaction == null) {      
+      String jndiName = getConfiguration().getProperty("jta.UserTransaction");
+      if (jndiName == null) {
+        /*
+         * EJB 2.1 section 20.9 The container must make the UserTransaction interface available to the
+         * enterprise beans that are allowed to use this interface (only session and message-
+         * driven beans with bean-managed transaction demarcation are allowed to use this 
+         * interface) in JNDI under the name java:comp/UserTransaction.
+         * J2EE 1.4 section 4.2.1.1 The J2EE platform must provide an object implementing the
+         * UserTransaction interface to all web components. The platform must publish the 
+         * UserTransaction object in JNDI under the name java:comp/UserTransaction.
+         */
+        jndiName = "java:comp/UserTransaction";
+      }
+      try {
+        userTransaction = (UserTransaction) new InitialContext().lookup(jndiName);
+      } catch (NamingException e) {
+        throw new JbpmException("could not retrieve user transaction with name "+jndiName, e);
+      }
+    }
+    return userTransaction;
+  }
 }




More information about the jbpm-commits mailing list