openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwsut...@apache.org
Subject svn commit: r550898 - in /openjpa/trunk/openjpa-kernel: pom.xml src/main/java/org/apache/openjpa/ee/AutomaticManagedRuntime.java src/main/java/org/apache/openjpa/ee/RegistryManagedRuntime.java
Date Tue, 26 Jun 2007 18:22:06 GMT
Author: kwsutter
Date: Tue Jun 26 11:22:06 2007
New Revision: 550898

URL: http://svn.apache.org/viewvc?view=rev&rev=550898
Log:
OPENJPA-61.  Marc's patch tests out okay with WebSphere.  I made a couple of minor cosmetic
changes to the
patch.  We need to get this into the stream for additional testing and verification by other
application servers.
So, let's go for it...

Added:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/RegistryManagedRuntime.java
Modified:
    openjpa/trunk/openjpa-kernel/pom.xml
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/AutomaticManagedRuntime.java

Modified: openjpa/trunk/openjpa-kernel/pom.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/pom.xml?view=diff&rev=550898&r1=550897&r2=550898
==============================================================================
--- openjpa/trunk/openjpa-kernel/pom.xml (original)
+++ openjpa/trunk/openjpa-kernel/pom.xml Tue Jun 26 11:22:06 2007
@@ -73,8 +73,8 @@
         </dependency>
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
-            <artifactId>geronimo-jta_1.0.1B_spec</artifactId>
-            <version>1.0.1</version>
+            <artifactId>geronimo-jta_1.1_spec</artifactId>
+            <version>1.1</version>
             <scope>compile</scope>
         </dependency>
         <dependency>

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/AutomaticManagedRuntime.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/AutomaticManagedRuntime.java?view=diff&rev=550898&r1=550897&r2=550898
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/AutomaticManagedRuntime.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/AutomaticManagedRuntime.java
Tue Jun 26 11:22:06 2007
@@ -66,6 +66,8 @@
         "com.inprise.visitransact.jta.TransactionManagerImpl."
             + "getTransactionManagerImpl", // borland
     };
+
+    private static final ManagedRuntime REGISTRY;
     private static final WLSManagedRuntime WLS;
     private static final SunOneManagedRuntime SUNONE;
     private static final WASManagedRuntime WAS;
@@ -75,7 +77,20 @@
 
     static {
         ManagedRuntime mr = null;
+
+        mr = null;
         try {
+            mr = (ManagedRuntime) Class.
+                forName("org.apache.openjpa.ee.RegistryManagedRuntime").
+                    newInstance();
+        } catch (Throwable t) {
+            // might be JTA version lower than 1.1, which doesn't have 
+            // TransactionSynchronizationRegistry
+        }
+        REGISTRY = mr;
+
+        mr = null;
+        try {
             mr = new WLSManagedRuntime();
         } catch (Throwable t) {
         }
@@ -108,6 +123,20 @@
         List errors = new LinkedList();
         TransactionManager tm = null;
 
+        // first try the registry, which is the official way to obtain
+        // transaction synchronication in JTA 1.1
+        if (REGISTRY != null) {
+            try {
+                tm = REGISTRY.getTransactionManager();
+            } catch (Throwable t) {
+                errors.add(t);
+            }
+            if (tm != null) {
+                _runtime = REGISTRY;
+                return tm;
+            }
+        }
+
         if (WLS != null) {
             try {
                 tm = WLS.getTransactionManager();

Added: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/RegistryManagedRuntime.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/RegistryManagedRuntime.java?view=auto&rev=550898
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/RegistryManagedRuntime.java
(added)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/RegistryManagedRuntime.java
Tue Jun 26 11:22:06 2007
@@ -0,0 +1,184 @@
+/*
+ * 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 javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.InvalidTransactionException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.transaction.TransactionSynchronizationRegistry;
+import javax.transaction.xa.XAResource;
+
+/**
+ * Implementation of the {@link ManagedRuntime} interface that uses 
+ * the {@link TransactionSynchronizationRegistry} interface (new in JTA 1.1)
+ * to create a {@link TransactionManager} facade for controlling transactions.
+ *
+ * @author Marc Prud'hommeaux
+ * @since 1.0.0
+ */
+public class RegistryManagedRuntime
+    implements ManagedRuntime {
+
+    private String _registryName =
+        "java:comp/TransactionSynchronizationRegistry";
+    private TransactionManager _tm = null;
+
+    /**
+     * Return the cached TransactionManager instance.
+     */
+    public TransactionManager getTransactionManager() throws Exception {
+        if (_tm == null) {
+            Context ctx = new InitialContext();
+            try {
+                _tm = new TransactionManagerRegistryFacade
+                    ((TransactionSynchronizationRegistry) ctx.
+                        lookup(_registryName));
+            } finally {
+                ctx.close();
+            }
+        }
+        return _tm;
+    }
+
+    public void setRollbackOnly(Throwable cause)
+        throws Exception {
+        // there is no generic support for setting the rollback cause
+        getTransactionManager().getTransaction().setRollbackOnly();
+    }
+
+    public Throwable getRollbackCause()
+        throws Exception {
+        // there is no generic support for setting the rollback cause
+        return null;
+    }
+
+    public void setRegistryName(String registryName) {
+        _registryName = registryName;
+    }
+
+    public String getRegistryName() {
+        return _registryName;
+    }
+
+    /** 
+     *  A {@link TransactionManager} and {@link Transaction} facade
+     *  that delegates the appropriate methods to the internally-held
+     *  {@link TransactionSynchronizationRegistry}. Since the
+     *  registry is not able to start or end transactions, all transaction
+     *  control methods will just throw a {@link SystemException}.
+     *  
+     *  @author  Marc Prud'hommeaux
+     */
+    public static class TransactionManagerRegistryFacade
+        implements TransactionManager, Transaction {
+        private final TransactionSynchronizationRegistry _registry;
+
+        public TransactionManagerRegistryFacade
+            (TransactionSynchronizationRegistry registry) {
+            _registry = registry;
+        }
+
+
+        public Transaction getTransaction()
+            throws SystemException {
+            return TransactionManagerRegistryFacade.this;
+        }
+
+
+        public void registerSynchronization(Synchronization sync)
+            throws RollbackException, IllegalStateException, SystemException {
+            _registry.registerInterposedSynchronization(sync);
+        }
+
+
+        public void setRollbackOnly()
+            throws IllegalStateException, SystemException {
+            _registry.setRollbackOnly();
+        }
+
+
+        public int getStatus()
+            throws SystemException {
+            return _registry.getTransactionStatus();
+        }
+
+        //////////////////////////////
+        // Unsupported methods follow
+        //////////////////////////////
+
+        public void begin()
+            throws NotSupportedException, SystemException {
+            throw new NotSupportedException();
+        }
+
+
+        public void commit()
+            throws RollbackException, HeuristicMixedException, SystemException,
+                HeuristicRollbackException, SecurityException,
+                IllegalStateException {
+            throw new SystemException();
+        }
+
+
+        public void resume(Transaction tobj)
+            throws InvalidTransactionException, IllegalStateException,
+                SystemException {
+            throw new SystemException();
+        }
+
+
+        public void rollback()
+            throws IllegalStateException, SecurityException, SystemException {
+            throw new SystemException();
+        }
+
+
+        public void setTransactionTimeout(int seconds)
+            throws SystemException {
+            throw new SystemException();
+        }
+
+
+        public Transaction suspend()
+            throws SystemException {
+            throw new SystemException();
+        }
+
+
+        public boolean delistResource(XAResource xaRes, int flag)
+            throws IllegalStateException, SystemException {
+            throw new SystemException();
+        }
+
+
+        public boolean enlistResource(XAResource xaRes)
+            throws RollbackException, IllegalStateException, SystemException {
+            throw new SystemException();
+        }
+    }
+}
+



Mime
View raw message