Skip to content

Commit 4e7752c

Browse files
committed
JCA listener containers delegate to wrapped Transaction handle (for Geronimo compatibility; SPR-6991)
1 parent c13e5f9 commit 4e7752c

6 files changed

Lines changed: 121 additions & 34 deletions

File tree

org.springframework.transaction/src/main/java/org/springframework/transaction/jta/JtaTransactionManager.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,7 +55,7 @@
5555
/**
5656
* {@link org.springframework.transaction.PlatformTransactionManager} implementation
5757
* for JTA, delegating to a backend JTA provider. This is typically used to delegate
58-
* to a J2EE server's transaction coordinator, but may also be configured with a
58+
* to a Java EE server's transaction coordinator, but may also be configured with a
5959
* local JTA provider which is embedded within the application.
6060
*
6161
* <p>This transaction manager is appropriate for handling distributed transactions,
@@ -66,8 +66,8 @@
6666
* HibernateTransactionManager is appropriate, for example.
6767
*
6868
* <p><b>For typical JTA transactions (REQUIRED, SUPPORTS, MANDATORY, NEVER), a plain
69-
* JtaTransactionManager definition is all you need, portable across all J2EE servers.</b>
70-
* This corresponds to the functionality of the JTA UserTransaction, for which J2EE
69+
* JtaTransactionManager definition is all you need, portable across all Java EE servers.</b>
70+
* This corresponds to the functionality of the JTA UserTransaction, for which Java EE
7171
* specifies a standard JNDI name ("java:comp/UserTransaction"). There is no need to
7272
* configure a server-specific TransactionManager lookup for this kind of JTA usage.
7373
*
@@ -76,20 +76,20 @@
7676
* autodetected by JtaTransactionManager, provided that the "autodetectTransactionManager"
7777
* flag is set to "true" (which it is by default).
7878
*
79-
* <p>Note: Support for the JTA TransactionManager interface is not required by J2EE.
80-
* Almost all J2EE servers expose it, but do so as extension to J2EE. There might be some
79+
* <p>Note: Support for the JTA TransactionManager interface is not required by Java EE.
80+
* Almost all Java EE servers expose it, but do so as extension to EE. There might be some
8181
* issues with compatibility, despite the TransactionManager interface being part of JTA.
8282
* As a consequence, Spring provides various vendor-specific PlatformTransactionManagers,
8383
* which are recommended to be used if appropriate: {@link WebLogicJtaTransactionManager},
8484
* {@link WebSphereUowTransactionManager} and {@link OC4JJtaTransactionManager}.
85-
* For all other J2EE servers, the standard JtaTransactionManager is sufficient.
85+
* For all other Java EE servers, the standard JtaTransactionManager is sufficient.
8686
*
8787
* <p>This pure JtaTransactionManager class supports timeouts but not per-transaction
8888
* isolation levels. Custom subclasses may override the {@link #doJtaBegin} method for
8989
* specific JTA extensions in order to provide this functionality; Spring includes
9090
* corresponding {@link WebLogicJtaTransactionManager} and {@link OC4JJtaTransactionManager}
9191
* classes, for BEA's WebLogic Server and Oracle's OC4J, respectively. Such adapters
92-
* for specific J2EE transaction coordinators may also expose transaction names for
92+
* for specific Java EE transaction coordinators may also expose transaction names for
9393
* monitoring; with standard JTA, transaction names will simply be ignored.
9494
*
9595
* <p><b>Consider using Spring's <code>tx:jta-transaction-manager</code> configuration
@@ -102,7 +102,7 @@
102102
* it for registering Spring-managed synchronizations when participating in an existing
103103
* JTA transaction (e.g. controlled by EJB CMT). If no TransactionSynchronizationRegistry
104104
* is available (or the JTA 1.1 API isn't available), then such synchronizations
105-
* will be registered via the (non-J2EE) JTA TransactionManager handle.
105+
* will be registered via the (non-EE) JTA TransactionManager handle.
106106
*
107107
* <p>This class is serializable. However, active synchronizations do not survive serialization.
108108
*
@@ -121,7 +121,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager
121121
implements TransactionFactory, InitializingBean, Serializable {
122122

123123
/**
124-
* Default JNDI location for the JTA UserTransaction. Many J2EE servers
124+
* Default JNDI location for the JTA UserTransaction. Many Java EE servers
125125
* also provide support for the JTA TransactionManager interface there.
126126
* @see #setUserTransactionName
127127
* @see #setAutodetectTransactionManager
@@ -271,7 +271,7 @@ public Properties getJndiEnvironment() {
271271

272272
/**
273273
* Set the JTA UserTransaction to use as direct reference.
274-
* <p>Typically just used for local JTA setups; in a J2EE environment,
274+
* <p>Typically just used for local JTA setups; in a Java EE environment,
275275
* the UserTransaction will always be fetched from JNDI.
276276
* @see #setUserTransactionName
277277
* @see #setAutodetectUserTransaction
@@ -289,8 +289,8 @@ public UserTransaction getUserTransaction() {
289289

290290
/**
291291
* Set the JNDI name of the JTA UserTransaction.
292-
* <p>Note that the UserTransaction will be autodetected at the J2EE default
293-
* location "java:comp/UserTransaction" if not specified explicitly.
292+
* <p>Note that the UserTransaction will be autodetected at the Java EE
293+
* default location "java:comp/UserTransaction" if not specified explicitly.
294294
* @see #DEFAULT_USER_TRANSACTION_NAME
295295
* @see #setUserTransaction
296296
* @see #setAutodetectUserTransaction
@@ -301,7 +301,7 @@ public void setUserTransactionName(String userTransactionName) {
301301

302302
/**
303303
* Set whether to autodetect the JTA UserTransaction at its default
304-
* JNDI location "java:comp/UserTransaction", as specified by J2EE.
304+
* JNDI location "java:comp/UserTransaction", as specified by Java EE.
305305
* Will proceed without UserTransaction if none found.
306306
* <p>Default is "true", autodetecting the UserTransaction unless
307307
* it has been specified explicitly. Turn this flag off to allow for
@@ -1169,7 +1169,7 @@ public Transaction createTransaction(String name, int timeout) throws NotSupport
11691169
tm.setTransactionTimeout(timeout);
11701170
}
11711171
tm.begin();
1172-
return tm.getTransaction();
1172+
return new ManagedTransactionAdapter(tm);
11731173
}
11741174

11751175
public boolean supportsResourceAdapterManagedTransactions() {
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright 2002-2010 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.transaction.jta;
18+
19+
import javax.transaction.HeuristicMixedException;
20+
import javax.transaction.HeuristicRollbackException;
21+
import javax.transaction.RollbackException;
22+
import javax.transaction.Synchronization;
23+
import javax.transaction.SystemException;
24+
import javax.transaction.Transaction;
25+
import javax.transaction.TransactionManager;
26+
import javax.transaction.xa.XAResource;
27+
28+
import org.springframework.util.Assert;
29+
30+
/**
31+
* Adapter for a managed JTA Transaction handle, taking a JTA
32+
* {@link javax.transaction.TransactionManager} reference and creating
33+
* a JTA {@link javax.transaction.Transaction} handle for it.
34+
*
35+
* @author Juergen Hoeller
36+
* @since 3.0.2
37+
*/
38+
public class ManagedTransactionAdapter implements Transaction {
39+
40+
private final TransactionManager transactionManager;
41+
42+
43+
/**
44+
* Create a new ManagedTransactionAdapter for the given TransactionManager.
45+
* @param transactionManager the JTA TransactionManager to wrap
46+
*/
47+
public ManagedTransactionAdapter(TransactionManager transactionManager) throws SystemException {
48+
Assert.notNull(transactionManager, "TransactionManager must not be null");
49+
this.transactionManager = transactionManager;
50+
}
51+
52+
/**
53+
* Return the JTA TransactionManager that this adapter delegates to.
54+
*/
55+
public final TransactionManager getTransactionManager() {
56+
return this.transactionManager;
57+
}
58+
59+
60+
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
61+
SecurityException, SystemException {
62+
this.transactionManager.commit();
63+
}
64+
65+
public void rollback() throws SystemException {
66+
this.transactionManager.rollback();
67+
}
68+
69+
public void setRollbackOnly() throws SystemException {
70+
this.transactionManager.setRollbackOnly();
71+
}
72+
73+
public int getStatus() throws SystemException {
74+
return this.transactionManager.getStatus();
75+
}
76+
77+
public boolean enlistResource(XAResource xaRes) throws RollbackException, SystemException {
78+
return this.transactionManager.getTransaction().enlistResource(xaRes);
79+
}
80+
81+
public boolean delistResource(XAResource xaRes, int flag) throws SystemException {
82+
return this.transactionManager.getTransaction().delistResource(xaRes, flag);
83+
}
84+
85+
public void registerSynchronization(Synchronization sync) throws RollbackException, SystemException {
86+
this.transactionManager.getTransaction().registerSynchronization(sync);
87+
}
88+
89+
}

org.springframework.transaction/src/main/java/org/springframework/transaction/jta/OC4JJtaTransactionManager.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@
1818

1919
import java.lang.reflect.InvocationTargetException;
2020
import java.lang.reflect.Method;
21-
2221
import javax.transaction.NotSupportedException;
2322
import javax.transaction.SystemException;
2423
import javax.transaction.Transaction;
@@ -241,7 +240,7 @@ else if (ex.getTargetException() instanceof RuntimeException) {
241240
catch (Exception ex) {
242241
throw new SystemException("Could not invoke OC4J's UserTransaction.begin(String) method: " + ex);
243242
}
244-
return getTransactionManager().getTransaction();
243+
return new ManagedTransactionAdapter(getTransactionManager());
245244
}
246245

247246
else {

org.springframework.transaction/src/main/java/org/springframework/transaction/jta/SimpleTransactionFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,7 +55,7 @@ public Transaction createTransaction(String name, int timeout) throws NotSupport
5555
this.transactionManager.setTransactionTimeout(timeout);
5656
}
5757
this.transactionManager.begin();
58-
return this.transactionManager.getTransaction();
58+
return new ManagedTransactionAdapter(this.transactionManager);
5959
}
6060

6161
public boolean supportsResourceAdapterManagedTransactions() {

org.springframework.transaction/src/main/java/org/springframework/transaction/jta/UserTransactionAdapter.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2007 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,31 +65,30 @@ public final TransactionManager getTransactionManager() {
6565
}
6666

6767

68+
public void setTransactionTimeout(int timeout) throws SystemException {
69+
this.transactionManager.setTransactionTimeout(timeout);
70+
}
71+
6872
public void begin() throws NotSupportedException, SystemException {
6973
this.transactionManager.begin();
7074
}
7175

7276
public void commit()
7377
throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
74-
SecurityException, IllegalStateException, SystemException {
75-
78+
SecurityException, SystemException {
7679
this.transactionManager.commit();
7780
}
7881

79-
public int getStatus() throws SystemException {
80-
return this.transactionManager.getStatus();
81-
}
82-
83-
public void rollback() throws IllegalStateException, SecurityException, SystemException {
82+
public void rollback() throws SecurityException, SystemException {
8483
this.transactionManager.rollback();
8584
}
8685

87-
public void setRollbackOnly() throws IllegalStateException, SystemException {
86+
public void setRollbackOnly() throws SystemException {
8887
this.transactionManager.setRollbackOnly();
8988
}
9089

91-
public void setTransactionTimeout(int timeout) throws SystemException {
92-
this.transactionManager.setTransactionTimeout(timeout);
90+
public int getStatus() throws SystemException {
91+
return this.transactionManager.getStatus();
9392
}
9493

9594
}

org.springframework.transaction/src/main/java/org/springframework/transaction/jta/WebLogicJtaTransactionManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@
3030
import org.springframework.transaction.TransactionSystemException;
3131

3232
/**
33-
* Special {@link JtaTransactionManager} variant for BEA WebLogic (8.1 and higher).
33+
* Special {@link JtaTransactionManager} variant for BEA WebLogic (9.0 and higher).
3434
* Supports the full power of Spring's transaction definitions on WebLogic's
3535
* transaction coordinator, <i>beyond standard JTA</i>: transaction names,
3636
* per-transaction isolation levels, and proper resuming of transactions in all cases.
@@ -325,7 +325,7 @@ else if (ex.getTargetException() instanceof RuntimeException) {
325325
catch (Exception ex) {
326326
throw new SystemException("Could not invoke WebLogic's UserTransaction.begin() method: " + ex);
327327
}
328-
return getTransactionManager().getTransaction();
328+
return new ManagedTransactionAdapter(getTransactionManager());
329329
}
330330

331331
else {

0 commit comments

Comments
 (0)