1 /**
2 *
3 * Copyright 2003-2004 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.geronimo.transaction;
19
20 import java.io.Serializable;
21 import javax.transaction.HeuristicMixedException;
22 import javax.transaction.HeuristicRollbackException;
23 import javax.transaction.NotSupportedException;
24 import javax.transaction.RollbackException;
25 import javax.transaction.SystemException;
26 import javax.transaction.TransactionManager;
27 import javax.transaction.UserTransaction;
28
29 public final class GeronimoUserTransaction implements UserTransaction, Serializable {
30 private static final long serialVersionUID = -7524804683512228998L;
31 private transient TransactionManager transactionManager;
32
33 public GeronimoUserTransaction(TransactionManager transactionManager) {
34 this.transactionManager = transactionManager;
35 }
36
37 boolean isActive() {
38 return transactionManager != null;
39 }
40
41 public void setTransactionManager(TransactionManager transactionManager) {
42 if (this.transactionManager == null) {
43 this.transactionManager = transactionManager;
44 } else if (this.transactionManager != transactionManager) {
45 throw new IllegalStateException("This user transaction is already associated with another transaction manager");
46 }
47 }
48
49
50 public int getStatus() throws SystemException {
51 return transactionManager.getStatus();
52 }
53
54 public void setRollbackOnly() throws IllegalStateException, SystemException {
55 transactionManager.setRollbackOnly();
56 }
57
58 public void setTransactionTimeout(int seconds) throws SystemException {
59 if (seconds < 0) {
60 throw new SystemException("transaction timeout must be positive or 0, not " + seconds);
61 }
62 transactionManager.setTransactionTimeout(seconds);
63 }
64
65 public void begin() throws NotSupportedException, SystemException {
66 transactionManager.begin();
67 }
68
69 public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException {
70 transactionManager.commit();
71 }
72
73 public void rollback() throws IllegalStateException, SecurityException, SystemException {
74 transactionManager.rollback();
75 }
76 }