01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.NotSupportedException;
22: import javax.transaction.RollbackException;
23: import javax.transaction.SystemException;
24: import javax.transaction.TransactionManager;
25: import javax.transaction.UserTransaction;
26:
27: import org.springframework.util.Assert;
28:
29: /**
30: * Adapter for a JTA UserTransaction handle, taking a JTA
31: * {@link javax.transaction.TransactionManager} reference and creating
32: * a JTA {@link javax.transaction.UserTransaction} handle for it.
33: *
34: * <p>The JTA UserTransaction interface is an exact subset of the JTA
35: * TransactionManager interface. Unfortunately, it does not serve as
36: * super-interface of TransactionManager, though, which requires an
37: * adapter such as this class to be used when intending to talk to
38: * a TransactionManager handle through the UserTransaction interface.
39: *
40: * <p>Used internally by Spring's {@link JtaTransactionManager} for certain
41: * scenarios. Not intended for direct use in application code.
42: *
43: * @author Juergen Hoeller
44: * @since 1.1.5
45: */
46: public class UserTransactionAdapter implements UserTransaction {
47:
48: private final TransactionManager transactionManager;
49:
50: /**
51: * Create a new UserTransactionAdapter for the given TransactionManager.
52: * @param transactionManager the JTA TransactionManager to wrap
53: */
54: public UserTransactionAdapter(TransactionManager transactionManager) {
55: Assert.notNull(transactionManager,
56: "TransactionManager must not be null");
57: this .transactionManager = transactionManager;
58: }
59:
60: /**
61: * Return the JTA TransactionManager that this adapter delegates to.
62: */
63: public final TransactionManager getTransactionManager() {
64: return this .transactionManager;
65: }
66:
67: public void begin() throws NotSupportedException, SystemException {
68: this .transactionManager.begin();
69: }
70:
71: public void commit() throws RollbackException,
72: HeuristicMixedException, HeuristicRollbackException,
73: SecurityException, IllegalStateException, SystemException {
74:
75: this .transactionManager.commit();
76: }
77:
78: public int getStatus() throws SystemException {
79: return this .transactionManager.getStatus();
80: }
81:
82: public void rollback() throws IllegalStateException,
83: SecurityException, SystemException {
84: this .transactionManager.rollback();
85: }
86:
87: public void setRollbackOnly() throws IllegalStateException,
88: SystemException {
89: this .transactionManager.setRollbackOnly();
90: }
91:
92: public void setTransactionTimeout(int timeout)
93: throws SystemException {
94: this.transactionManager.setTransactionTimeout(timeout);
95: }
96:
97: }
|