openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r468504 - in /incubator/openjpa/trunk/openjpa-kernel: ./ src/main/java/org/apache/openjpa/ee/ src/main/java/org/apache/openjpa/util/ src/test/java/org/apache/openjpa/ee/ src/test/java/org/apache/openjpa/util/
Date Fri, 27 Oct 2006 19:17:33 GMT
Author: awhite
Date: Fri Oct 27 12:17:32 2006
New Revision: 468504

URL: http://svn.apache.org/viewvc?view=rev&rev=468504
Log:
Move build logic for adding an interface to WASManagedRuntime's inner class to
WASManagedRuntime itself.  Move caching in WASManagedRuntime to 
endConfiguration() callback to avoid threading issues.


Added:
    incubator/openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/ee/
    incubator/openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/ee/TestWASManagedRuntime.java
Removed:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/WASTransformer.java
    incubator/openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/
Modified:
    incubator/openjpa/trunk/openjpa-kernel/pom.xml
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/AutomaticManagedRuntime.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/WASManagedRuntime.java

Modified: incubator/openjpa/trunk/openjpa-kernel/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/pom.xml?view=diff&rev=468504&r1=468503&r2=468504
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/pom.xml (original)
+++ incubator/openjpa/trunk/openjpa-kernel/pom.xml Fri Oct 27 12:17:32 2006
@@ -109,7 +109,7 @@
 						<configuration>
 							<tasks>
 								<java
-									classname="org.apache.openjpa.util.WASTransformer" classpathref="maven.runtime.classpath"
/>
+									classname="org.apache.openjpa.ee.WASManagedRuntime" classpathref="maven.runtime.classpath"
/>
 							</tasks>
 						</configuration>
 						<goals>

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/AutomaticManagedRuntime.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/AutomaticManagedRuntime.java?view=diff&rev=468504&r1=468503&r2=468504
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/AutomaticManagedRuntime.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/AutomaticManagedRuntime.java
Fri Oct 27 12:17:32 2006
@@ -63,9 +63,9 @@
         "com.inprise.visitransact.jta.TransactionManagerImpl."
             + "getTransactionManagerImpl", // borland
     };
-    private static final ManagedRuntime WLS;
-    private static final ManagedRuntime SUNONE;
-    private static final ManagedRuntime WAS;
+    private static final WLSManagedRuntime WLS;
+    private static final SunOneManagedRuntime SUNONE;
+    private static final WASManagedRuntime WAS;
 
     private static Localizer _loc = Localizer.forPackage
         (AutomaticManagedRuntime.class);
@@ -76,24 +76,22 @@
             mr = new WLSManagedRuntime();
         } catch (Throwable t) {
         }
-        WLS = mr;
+        WLS = (WLSManagedRuntime) mr;
 
         mr = null;
         try {
             mr = new SunOneManagedRuntime();
         } catch (Throwable t) {
         }
-        SUNONE = mr;
+        SUNONE = (SunOneManagedRuntime) mr;
 
         mr = null;
         try {
             mr = new WASManagedRuntime();
         }
         catch(Throwable t) {
-
         }
-        WAS= mr;
-
+        WAS= (WASManagedRuntime) mr;
     }
 
     private Configuration _conf = null;
@@ -121,7 +119,9 @@
 
         if (WAS != null) {
             try {
-                ((Configurable)WAS).setConfiguration(_conf);
+                WAS.setConfiguration(_conf);
+                WAS.startConfiguration();
+                WAS.endConfiguration();
                 tm = WAS.getTransactionManager();
             } catch (Throwable t) {
                 errors.add(t);

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/WASManagedRuntime.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/WASManagedRuntime.java?view=diff&rev=468504&r1=468503&r2=468504
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/WASManagedRuntime.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/WASManagedRuntime.java
Fri Oct 27 12:17:32 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.openjpa.ee;
 
+import java.io.IOException;
 import java.lang.reflect.Method;
 
 import javax.naming.Context;
@@ -34,10 +35,11 @@
 import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.lib.conf.Configurable;
 import org.apache.openjpa.lib.conf.Configuration;
-import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.util.InvalidStateException;
 import org.apache.openjpa.util.NoTransactionException;
+import serp.bytecode.BCClass;
+import serp.bytecode.Project;
 
 /**
  * {@link ManagedRuntime} implementation that allows synchronization with a
@@ -59,60 +61,11 @@
     private static Localizer _loc =
         Localizer.forPackage(WASManagedRuntime.class);
 
-    protected Object _extendedTransaction = null;
-
-    protected Method _getGlobalId = null;
-
-    protected Method _getLocalId = null;
-
-    protected Method _registerSync = null;
-
-    OpenJPAConfiguration _conf = null;
-
-    Log _log = null;
-
-    /**
-     * Lookup the extendedTransaction object from JNDI.
-     *
-     * @throws NamingException
-     */
-    private void getExtendedTransaction() throws NamingException {
-
-        if (_extendedTransaction == null) {
-            Context ctx = new InitialContext();
-            try {
-                _extendedTransaction =
-                    ctx.lookup("java:comp/websphere/ExtendedJTATransaction");
-
-            } finally {
-                ctx.close();
-            }
-        }
-    }
-
-    /**
-     * Caches the WebSphere proprietary methods for ExtendedJTATransaction.
-     */
-    private void getWebSphereMethods() throws Exception {
-        ClassLoader loader =
-            _conf.getClassResolverInstance().getClassLoader(getClass(), null);
-
-        Class extendedJTATransaction =
-            Class.forName(
-                "com.ibm.websphere.jtaextensions.ExtendedJTATransaction", true,
-                loader);
-
-        _registerSync =
-            extendedJTATransaction.getMethod(
-                "registerSynchronizationCallbackForCurrentTran",
-                new Class[] { Class.forName(
-                    "com.ibm.websphere.jtaextensions.SynchronizationCallback",
-                    true, loader) });
-
-        _getGlobalId = extendedJTATransaction.getMethod("getGlobalId", null);
-
-        _getLocalId = extendedJTATransaction.getMethod("getLocalId", null);
-    }
+    private Object _extendedTransaction = null;
+    private Method _getGlobalId = null;
+    private Method _getLocalId = null;
+    private Method _registerSync = null;
+    private OpenJPAConfiguration _conf = null;
 
     /**
      * Gets an extendedJTATransaction from JNDI and creates a transaction
@@ -120,7 +73,6 @@
      */
     public javax.transaction.TransactionManager getTransactionManager()
         throws Exception {
-        getExtendedTransaction();
         return new WASTransaction();
     }
 
@@ -142,24 +94,14 @@
 
         public int getStatus() throws SystemException {
             int rval = Status.STATUS_UNKNOWN;
-
             try {
                 if (getId() != null) {
                     rval = Status.STATUS_ACTIVE;
                 } else {
-
-                    if (_log != null && _log.isErrorEnabled()) {
-                        _log.error(_loc.get("was-no-transaction"));
-                    }
-
                     throw new NoTransactionException(_loc
                         .get("was-no-transaction"));
                 }
             } catch (Exception e) {
-
-                if (_log != null && _log.isErrorEnabled()) {
-                    _log.error(_loc.get("was-no-transaction"), e);
-                }
                 throw new NoTransactionException(_loc.get("was-no-transaction"))
                     .setCause(e);
             }
@@ -183,27 +125,15 @@
          */
         public void registerSynchronization(Synchronization arg0)
             throws IllegalStateException, RollbackException, SystemException {
-
             if (_extendedTransaction != null) {
                 try {
-                    if (_registerSync == null) {
-                        getWebSphereMethods();
-                    }
                     _registerSync.invoke(_extendedTransaction,
                         new Object[] { new WASSynchronization(arg0) });
                 } catch (Exception e) {
-                    if (_log != null && _log.isErrorEnabled()) {
-                        _log.error(_loc.get("was-reflection-exception"), e);
-                    }
-
                     throw new InvalidStateException(_loc
                         .get("was-reflection-exception")).setCause(e);
                 }
             } else {
-                if (_log != null && _log.isErrorEnabled()) {
-                    _log.error(_loc.get("was-lookup-error"));
-                }
-
                 throw new InvalidStateException(_loc.get("was-lookup-error"));
             }
         }
@@ -220,9 +150,7 @@
          */
         private Object getId() throws Exception {
             Object rval;
-
             rval = getGlobalId();
-
             if (rval == null) {
                 rval = getLocalId();
             }
@@ -232,9 +160,6 @@
                  * If there's no globalId or localId we're running outside of a
                  * transaction and need to throw an error.
                  */
-                if (_log != null && _log.isErrorEnabled()) {
-                    _log.error(_loc.get("was-no-transaction"));
-                }
                 throw new NoTransactionException(_loc
                     .get("was-no-transaction"));
             }
@@ -249,23 +174,13 @@
          *         occurs. byte[] id if a global transaction is active.
          */
         private byte[] getGlobalId() {
-
             byte[] rval = null;
-
             try {
-                if(_getGlobalId == null) {
-                    getWebSphereMethods();
-                }
                 rval = (byte[]) _getGlobalId.invoke(_extendedTransaction, null);
             } catch (Exception e) {
-                if (_log != null && _log.isErrorEnabled()) {
-                    _log.error(_loc.get("was-reflection-exception"), e);
-                }
-
                 throw new InvalidStateException(_loc
                     .get("was-reflection-exception")).setCause(e);
             }
-
             return rval;
         }
 
@@ -278,16 +193,9 @@
          */
         private Integer getLocalId() {
             Integer rval;
-
             try {
-                if(_getLocalId == null)  {
-                    getWebSphereMethods();
-                }
                 rval = (Integer) _getLocalId.invoke(_extendedTransaction, null);
             } catch (Exception e) {
-                if (_log != null && _log.isErrorEnabled()) {
-                    _log.error(_loc.get("was-reflection-exception"), e);
-                }
                 throw new InvalidStateException(_loc
                     .get("was-reflection-exception")).setCause(e);
             }
@@ -402,6 +310,7 @@
      * @see org.apache.openjpa.util.WASTransformer
      */
     static class WASSynchronization {
+
         Synchronization _sync = null;
 
         WASSynchronization(Synchronization sync) {
@@ -440,14 +349,41 @@
      */
     public void setConfiguration(Configuration conf) {
         _conf = (OpenJPAConfiguration) conf;
-        _log = _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
     }
 
     /**
      * EndConfiguration stub.
      */
     public void endConfiguration() {
-        // Nothing to do
+        try {
+            Context ctx = new InitialContext();
+            try {
+                _extendedTransaction =
+                    ctx.lookup("java:comp/websphere/ExtendedJTATransaction");
+            } finally {
+                ctx.close();
+            }
+
+            ClassLoader loader = _conf.getClassResolverInstance()
+                .getClassLoader(getClass(), null);
+
+            Class extendedJTATransaction = Class.forName(
+                "com.ibm.websphere.jtaextensions.ExtendedJTATransaction", true,
+                loader);
+
+            _registerSync = extendedJTATransaction.getMethod(
+                "registerSynchronizationCallbackForCurrentTran",
+                new Class[] { Class.forName(
+                    "com.ibm.websphere.jtaextensions.SynchronizationCallback",
+                    true, loader) });
+            _getGlobalId = extendedJTATransaction.
+                getMethod("getGlobalId", null);
+            _getLocalId = extendedJTATransaction.
+                getMethod("getLocalId", null);
+        } catch (Exception e) {
+            throw new InvalidStateException(_loc
+                .get("was-reflection-exception"), e).setFatal(true);
+        }
     }
 
     /**
@@ -455,5 +391,25 @@
      */
     public void startConfiguration() {
         // Nothing to do
+    }
+
+    /**
+     * Class that will be modified
+     */
+    static final String CLASS =
+        "org.apache.openjpa.ee.WASManagedRuntime$WASSynchronization";
+
+    /**
+     * Interface which will be added
+     */
+    static final String INTERFACE =
+        "com.ibm.websphere.jtaextensions.SynchronizationCallback";
+
+    public static void main(String[] args) 
+        throws IOException {
+        Project project = new Project();
+        BCClass bcClass = project.loadClass(CLASS);
+        bcClass.declareInterface(INTERFACE);
+        bcClass.write();
     }
 }

Added: incubator/openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/ee/TestWASManagedRuntime.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/ee/TestWASManagedRuntime.java?view=auto&rev=468504
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/ee/TestWASManagedRuntime.java
(added)
+++ incubator/openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/ee/TestWASManagedRuntime.java
Fri Oct 27 12:17:32 2006
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.ee;
+
+import junit.framework.TestCase;
+
+import serp.util.Strings;
+
+/**
+ * Test class for build transformation performed by WASManagedRuntime.
+ *
+ */
+public class TestWASManagedRuntime extends TestCase {
+
+    /**
+     * This test will verify that the WASManagedRuntime$WASSynchronization
+     * class was properly modified by the maven build process (reference
+     * the top level pom.xml).  This testcase will not execute properly
+     * within Eclipse since the Eclipse target directory (probably) hasn't
+     * been modified via the maven build.
+     *
+     * @throws ClassNotFoundException
+     * @author Michael Dick
+     */
+    public void testInterfaceAdded() throws ClassNotFoundException {
+
+        String msg = null;
+
+        try {
+            Class.forName(WASManagedRuntime.CLASS);
+            fail("expected an exception to be thrown");
+        } catch (NoClassDefFoundError e) {
+            msg = e.getMessage();
+        }
+        String interfaceName = Strings.
+            getClassName(WASManagedRuntime.INTERFACE);
+        assertTrue("message should have contained "
+            + interfaceName + ", but was '" + msg + "'",
+            msg.contains(interfaceName));
+    }
+}



Mime
View raw message