01: /*
02: * Copyright 2004-2006 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.compass.core.transaction;
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.compass.core.CompassException;
28:
29: /**
30: * Adapter for a JTA UserTransaction handle, taking a JTA TransactionManager
31: * reference and creating a JTA UserTransaction handle for it.
32: * <p/>
33: * The JTA UserTransaction interface is an exact subset of the JTA
34: * TransactionManager interface. Unfortunately, it does not serve as
35: * super-interface of TransactionManager, though, which requires an
36: * adapter such as this class to be used when intending to talk to
37: * a TransactionManager handle through the UserTransaction interface.
38: *
39: * @author Wayne Robinson
40: * @author kimchy
41: */
42: public class UserTransactionAdapter implements UserTransaction {
43:
44: private final TransactionManager transactionManager;
45:
46: /**
47: * Create a new UserTransactionAdapter.
48: *
49: * @param transactionManager the JTA TransactionManager
50: */
51: public UserTransactionAdapter(TransactionManager transactionManager)
52: throws CompassException {
53: if (transactionManager == null) {
54: throw new TransactionException(
55: "TransactionManager is required");
56: }
57: this .transactionManager = transactionManager;
58: }
59:
60: /**
61: * Return the JTA TransactionManager that this adapter delegates to.
62: */
63: public TransactionManager getTransactionManager() {
64: return 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: this .transactionManager.commit();
75: }
76:
77: public int getStatus() throws SystemException {
78: return this .transactionManager.getStatus();
79: }
80:
81: public void rollback() throws IllegalStateException,
82: SecurityException, SystemException {
83: this .transactionManager.rollback();
84: }
85:
86: public void setRollbackOnly() throws IllegalStateException,
87: SystemException {
88: this .transactionManager.setRollbackOnly();
89: }
90:
91: public void setTransactionTimeout(int timeout)
92: throws SystemException {
93: this.transactionManager.setTransactionTimeout(timeout);
94: }
95:
96: }
|