You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by st...@apache.org on 2023/05/15 07:17:42 UTC

[openjpa] branch master updated: OPENJPA-2910 WASManagedRuntime without Serp

This is an automated email from the ASF dual-hosted git repository.

struberg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openjpa.git


The following commit(s) were added to refs/heads/master by this push:
     new 2ab2746f7 OPENJPA-2910 WASManagedRuntime without Serp
2ab2746f7 is described below

commit 2ab2746f7793e65968309520bf2ec0fe36a430ff
Author: Mark Struberg <st...@apache.org>
AuthorDate: Mon May 15 09:16:07 2023 +0200

    OPENJPA-2910 WASManagedRuntime without Serp
    
    The required interfaces are now publicly available via OpenLiberty artifacts under EPL.
    We do not package them, so no NOTICE is required.
    
    I've also removed the test as it did only test that the com.ibm class
    is not on the classpath (which it now is for the test run as a provided artifact)
---
 openjpa-kernel/pom.xml                             | 18 ++++++-
 .../org/apache/openjpa/ee/WASManagedRuntime.java   | 56 +++------------------
 .../apache/openjpa/ee/TestWASManagedRuntime.java   | 58 ----------------------
 3 files changed, 23 insertions(+), 109 deletions(-)

diff --git a/openjpa-kernel/pom.xml b/openjpa-kernel/pom.xml
index 71b7fe094..b1eb29b08 100644
--- a/openjpa-kernel/pom.xml
+++ b/openjpa-kernel/pom.xml
@@ -71,6 +71,20 @@
             <artifactId>xbean-asm9-shaded</artifactId>
             <version>${xbean.version}</version>
         </dependency>
+
+        <dependency>
+            <!--
+                This is only used for implementing WASManagedRuntime
+                which implements the
+                com.ibm.websphere.jtaextensions.SynchronizationCallback
+                interface
+            -->
+            <groupId>io.openliberty.api</groupId>
+            <artifactId>io.openliberty.transaction</artifactId>
+            <version>1.1.74</version>
+            <scope>provided</scope>
+            <optional>true</optional>
+        </dependency>
     </dependencies>
 
     <build>
@@ -97,7 +111,7 @@
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-antrun-plugin</artifactId>
                 <executions>
-                    <execution>
+          <!--          <execution>
                         <id>add-was-interfaces</id>
                         <phase>process-classes</phase>
                         <configuration>
@@ -108,7 +122,7 @@
                         <goals>
                             <goal>run</goal>
                         </goals>
-                    </execution>
+                    </execution>-->
                     <execution>
                         <id>generate-standard-sco-proxies</id>
                         <phase>process-classes</phase>
diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/ee/WASManagedRuntime.java b/openjpa-kernel/src/main/java/org/apache/openjpa/ee/WASManagedRuntime.java
index 553217374..28259513f 100644
--- a/openjpa-kernel/src/main/java/org/apache/openjpa/ee/WASManagedRuntime.java
+++ b/openjpa-kernel/src/main/java/org/apache/openjpa/ee/WASManagedRuntime.java
@@ -18,12 +18,10 @@
  */
 package org.apache.openjpa.ee;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Method;
-
 import javax.naming.Context;
 import javax.naming.InitialContext;
+
+import com.ibm.websphere.jtaextensions.ExtendedJTATransaction;
 import jakarta.transaction.HeuristicMixedException;
 import jakarta.transaction.HeuristicRollbackException;
 import jakarta.transaction.InvalidTransactionException;
@@ -36,7 +34,6 @@ import jakarta.transaction.Transaction;
 import javax.transaction.xa.XAResource;
 
 import org.apache.openjpa.conf.OpenJPAConfiguration;
-import org.apache.openjpa.enhance.AsmAdaptor;
 import org.apache.openjpa.lib.conf.Configurable;
 import org.apache.openjpa.lib.conf.Configuration;
 import org.apache.openjpa.lib.log.Log;
@@ -44,8 +41,6 @@ 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
@@ -68,9 +63,7 @@ public class WASManagedRuntime extends AbstractManagedRuntime
     private static final Localizer _loc =
         Localizer.forPackage(WASManagedRuntime.class);
 
-    private Object _extendedTransaction = null;
-    private Method _getGlobalId = null;
-    private Method _registerSync = null;
+    private com.ibm.websphere.jtaextensions.ExtendedJTATransaction _extendedTransaction = null;
     private OpenJPAConfiguration _conf = null;
     private Log _log = null;
 
@@ -137,8 +130,7 @@ public class WASManagedRuntime extends AbstractManagedRuntime
             throws IllegalStateException, RollbackException, SystemException {
             if (_extendedTransaction != null) {
                 try {
-                    _registerSync.invoke(_extendedTransaction,
-                        new Object[] { new WASSynchronization(arg0) });
+                    _extendedTransaction.registerSynchronizationCallback(new WASSynchronization(arg0));
                 } catch (Exception e) {
                     throw new InvalidStateException(_loc
                         .get("was-reflection-exception")).setCause(e);
@@ -157,7 +149,7 @@ public class WASManagedRuntime extends AbstractManagedRuntime
          */
         private byte[] getGlobalId() {
             try {
-                return (byte[]) _getGlobalId.invoke(_extendedTransaction, null);
+                return _extendedTransaction.getGlobalId();
             } catch (Exception e) {
                 throw new InvalidStateException(_loc
                     .get("was-reflection-exception")).setCause(e);
@@ -284,9 +276,8 @@ public class WASManagedRuntime extends AbstractManagedRuntime
      * is instantiated, therefore this class should only be used when running in
      * WebSphere.
      *
-     * @see org.apache.openjpa.util.WASTransformer
      */
-    static class WASSynchronization {
+    static class WASSynchronization implements com.ibm.websphere.jtaextensions.SynchronizationCallback {
 
         Synchronization _sync = null;
 
@@ -338,22 +329,10 @@ public class WASManagedRuntime extends AbstractManagedRuntime
         try {
             Context ctx = new InitialContext();
             try {
-                _extendedTransaction =
-                    ctx.lookup("java:comp/websphere/ExtendedJTATransaction");
+                _extendedTransaction = (ExtendedJTATransaction) ctx.lookup("java:comp/websphere/ExtendedJTATransaction");
             } finally {
                 ctx.close();
             }
-
-            Class extendedJTATransaction = Class.forName(
-                    "com.ibm.websphere.jtaextensions.ExtendedJTATransaction");
-            Class synchronizationCallback = Class.forName(
-                    "com.ibm.websphere.jtaextensions.SynchronizationCallback");
-
-            _registerSync = extendedJTATransaction.getMethod(
-                    "registerSynchronizationCallbackForCurrentTran",
-                    new Class[] { synchronizationCallback });
-            _getGlobalId = extendedJTATransaction.
-                getMethod("getGlobalId", null);
         } catch (Exception e) {
             throw new InvalidStateException(_loc
                 .get("was-reflection-exception"), e).setFatal(true);
@@ -380,27 +359,6 @@ public class WASManagedRuntime extends AbstractManagedRuntime
     static final String INTERFACE =
         "com.ibm.websphere.jtaextensions.SynchronizationCallback";
 
-    public static void main(String[] args)
-        throws IOException {
-        Project project = new Project();
-
-        InputStream in = WASManagedRuntime.class.getClassLoader()
-            .getResourceAsStream(CLASS.replace('.', '/') + ".class");
-        BCClass bcClass = project.loadClass(in);
-
-        String [] interfaces = bcClass.getInterfaceNames();
-
-        if(interfaces != null) {
-            for (String anInterface : interfaces) {
-                if (anInterface.equals(INTERFACE)) {
-                    return;
-                }
-            }
-        }
-        bcClass.declareInterface(INTERFACE);
-        AsmAdaptor.write(bcClass);
-    }
-
     @Override
     public void setRollbackOnly(Throwable cause)
         throws Exception {
diff --git a/openjpa-kernel/src/test/java/org/apache/openjpa/ee/TestWASManagedRuntime.java b/openjpa-kernel/src/test/java/org/apache/openjpa/ee/TestWASManagedRuntime.java
deleted file mode 100644
index f1f37e325..000000000
--- a/openjpa-kernel/src/test/java/org/apache/openjpa/ee/TestWASManagedRuntime.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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 org.apache.openjpa.lib.util.ClassUtil;
-import org.junit.Test;
-
-
-import static org.junit.Assert.*;
-
-/**
- * Test class for build transformation performed by WASManagedRuntime.
- *
- */
-public class TestWASManagedRuntime {
-
-    /**
-     * 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
-     */
-    @Test
-    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 = ClassUtil.getClassName(WASManagedRuntime.INTERFACE);
-        assertTrue("message should have contained "
-            + interfaceName + ", but was '" + msg + "'",
-            msg.indexOf(interfaceName) != -1);
-    }
-}