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

commit eef64ccd69c48ba8c7193509f6f621c6315bc74e
Author: Mark Struberg <strub...@apache.org>
AuthorDate: Wed Dec 2 12:12:13 2020 +0100

    OPENJPA-2843 remove ibm specific dependencies
    
    We now hav a single interface which I've implemented clean-room from the 
bytecode.
    This class will NOT get packaged into the jar but will be excluded.
---
 openjpa-kernel/pom.xml                             | 18 +++-------
 .../src/main/java/com/ibm/wsspi/uow/UOWAction.java | 30 ++++++++++++++++
 .../openjpa/ee/WASRegistryManagedRuntime.java      | 40 +++++++++++++++-------
 3 files changed, 62 insertions(+), 26 deletions(-)

diff --git a/openjpa-kernel/pom.xml b/openjpa-kernel/pom.xml
index d0d2793..9168694 100644
--- a/openjpa-kernel/pom.xml
+++ b/openjpa-kernel/pom.xml
@@ -57,12 +57,6 @@
             <artifactId>commons-pool2</artifactId>
         </dependency>
         <dependency>
-            <groupId>com.ibm.websphere</groupId>
-            <artifactId>uow_api</artifactId>
-            <version>6</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.ant</groupId>
             <artifactId>ant</artifactId>
             <scope>provided</scope>
@@ -144,6 +138,11 @@
                             <goal>jar</goal>
                         </goals>
                         <configuration>
+                            <excludes>
+                                <!-- do not include com/ibm UOW classes in the 
jar! -->
+                                <exclude>com</exclude>
+                                <exclude>com/**/*</exclude>
+                            </excludes>
                             <archive>
                                 <manifest>
                                    
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
@@ -166,11 +165,4 @@
         </plugins>
     </build>
 
-    <repositories>
-        <repository>
-            <id>seasar-repo</id>
-            <name>seasar repository</name>
-            <url>https://www.seasar.org/maven/maven2</url>
-        </repository>
-    </repositories>
 </project>
diff --git a/openjpa-kernel/src/main/java/com/ibm/wsspi/uow/UOWAction.java 
b/openjpa-kernel/src/main/java/com/ibm/wsspi/uow/UOWAction.java
new file mode 100644
index 0000000..d2c1951
--- /dev/null
+++ b/openjpa-kernel/src/main/java/com/ibm/wsspi/uow/UOWAction.java
@@ -0,0 +1,30 @@
+/*
+ * 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 com.ibm.wsspi.uow;
+
+/**
+ * This is a clean room re-implementation of the IBM UOWAction API from the 
existing bytecode API.
+ * This will not be shipped in any distribution but excluded from the packaged 
JAR file.
+ * It purely exists for compiling against it.
+ *
+ * @author <a href="mailto:strub...@yahoo.de";>Mark Struberg</a>
+ */
+public interface UOWAction {
+    void run() throws Exception;
+}
diff --git 
a/openjpa-kernel/src/main/java/org/apache/openjpa/ee/WASRegistryManagedRuntime.java
 
b/openjpa-kernel/src/main/java/org/apache/openjpa/ee/WASRegistryManagedRuntime.java
index da23e76..81fad51 100644
--- 
a/openjpa-kernel/src/main/java/org/apache/openjpa/ee/WASRegistryManagedRuntime.java
+++ 
b/openjpa-kernel/src/main/java/org/apache/openjpa/ee/WASRegistryManagedRuntime.java
@@ -18,11 +18,9 @@
  */
 package org.apache.openjpa.ee;
 
-import com.ibm.websphere.uow.UOWSynchronizationRegistry;
 import com.ibm.wsspi.uow.UOWAction;
-import com.ibm.wsspi.uow.UOWActionException;
-import com.ibm.wsspi.uow.UOWException;
-import com.ibm.wsspi.uow.UOWManagerFactory;
+
+import java.lang.reflect.Method;
 
 /**
  * WASRegistryManagedRuntime provides WebSphere specific extensions to
@@ -30,6 +28,26 @@ import com.ibm.wsspi.uow.UOWManagerFactory;
  * the WebSphere UOWManager interface to submit non transactional work.
  */
 public class WASRegistryManagedRuntime extends RegistryManagedRuntime {
+
+    // value taken from com.ibm.websphere.uow.UOWSynchronizationRegistry
+    private static final int WEBSPHERE_UOW_TYPE_LOCAL_TRANSACTION = 0;
+
+    private final Method getUOWManager;
+    private final Method runUnderUOW;
+
+    public WASRegistryManagedRuntime() {
+        try {
+            Class classUOWManagerFactory = 
Class.forName("com.ibm.wsspi.uow.UOWManagerFactory");
+            getUOWManager = classUOWManagerFactory.getMethod("getUOWManager");
+
+            Class classUOWManager = 
Class.forName("com.ibm.wsspi.uow.UOWManager");
+            runUnderUOW = classUOWManager.getMethod("runUnderUOW");
+        }
+        catch (Exception e) {
+            throw new RuntimeException("Problem while creating 
WASManagedRuntime", e);
+        }
+    }
+
     /**
      * <P>
      * RegistryManagedRuntime cannot suspend transactions, but WebSphere
@@ -40,16 +58,12 @@ public class WASRegistryManagedRuntime extends 
RegistryManagedRuntime {
     public void doNonTransactionalWork(Runnable runnable)
             throws RuntimeException, UnsupportedOperationException {
         try {
-            UOWManagerFactory.getUOWManager().runUnderUOW(
-                UOWSynchronizationRegistry.UOW_TYPE_LOCAL_TRANSACTION, false,
-                new DelegatingUOWAction(runnable));
-        }
-        catch(UOWActionException e ) {
-            RuntimeException re = new RuntimeException(e.getMessage());
-            re.initCause(e);
-            throw re;
+            Object uowManager = getUOWManager.invoke(null);
+
+            runUnderUOW.invoke(uowManager, 
WEBSPHERE_UOW_TYPE_LOCAL_TRANSACTION, false, new DelegatingUOWAction(runnable));
+
         }
-        catch(UOWException e ) {
+        catch(Exception e ) {
             RuntimeException re = new RuntimeException(e.getMessage());
             re.initCause(e);
             throw re;

Reply via email to