Index: openjpa-kernel/src/main/java/org/apache/openjpa/ee/AutomaticManagedRuntime.java
===================================================================
--- openjpa-kernel/src/main/java/org/apache/openjpa/ee/AutomaticManagedRuntime.java (revision 531269)
+++ openjpa-kernel/src/main/java/org/apache/openjpa/ee/AutomaticManagedRuntime.java (working copy)
@@ -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();
Index: openjpa-kernel/src/main/java/org/apache/openjpa/ee/RegistryManagedRuntime.java
===================================================================
--- openjpa-kernel/src/main/java/org/apache/openjpa/ee/RegistryManagedRuntime.java (revision 0)
+++ openjpa-kernel/src/main/java/org/apache/openjpa/ee/RegistryManagedRuntime.java (revision 0)
@@ -0,0 +1,176 @@
+/*
+ * 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.*; // ### FIXME
+import javax.transaction.xa.*; // ### FIXME
+
+/**
+ * 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 0.9.8
+ */
+public class RegistryManagedRuntime
+ implements ManagedRuntime {
+
+ private String _registryName =
+ "java:comp/TransactionSynchronizationRegistry";
+ private TransactionSynchronizationRegistry _registry = null;
+ 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();
+ }
+ }
+}
+
Property changes on: openjpa-kernel/src/main/java/org/apache/openjpa/ee/RegistryManagedRuntime.java
___________________________________________________________________
Name: svn:eol-style
+ native
Index: openjpa-kernel/pom.xml
===================================================================
--- openjpa-kernel/pom.xml (revision 531269)
+++ openjpa-kernel/pom.xml (working copy)
@@ -53,8 +53,8 @@
org.apache.geronimo.specs
- geronimo-jta_1.0.1B_spec
- 1.0.1
+ geronimo-jta_1.1_spec
+ 1.0
compile