KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > transaction > GeronimoUserTransaction


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 JavaDoc;
21 import javax.transaction.HeuristicMixedException JavaDoc;
22 import javax.transaction.HeuristicRollbackException JavaDoc;
23 import javax.transaction.NotSupportedException JavaDoc;
24 import javax.transaction.RollbackException JavaDoc;
25 import javax.transaction.SystemException JavaDoc;
26 import javax.transaction.TransactionManager JavaDoc;
27 import javax.transaction.UserTransaction JavaDoc;
28
29 public final class GeronimoUserTransaction implements UserTransaction JavaDoc, Serializable JavaDoc {
30     private static final long serialVersionUID = -7524804683512228998L;
31     private transient TransactionManager JavaDoc transactionManager;
32
33     public GeronimoUserTransaction(TransactionManager JavaDoc transactionManager) {
34         this.transactionManager = transactionManager;
35     }
36
37     boolean isActive() {
38         return transactionManager != null;
39     }
40
41     public void setTransactionManager(TransactionManager JavaDoc transactionManager) {
42         if (this.transactionManager == null) {
43             this.transactionManager = transactionManager;
44         } else if (this.transactionManager != transactionManager) {
45             throw new IllegalStateException JavaDoc("This user transaction is already associated with another transaction manager");
46         }
47     }
48
49
50     public int getStatus() throws SystemException JavaDoc {
51         return transactionManager.getStatus();
52     }
53
54     public void setRollbackOnly() throws IllegalStateException JavaDoc, SystemException JavaDoc {
55         transactionManager.setRollbackOnly();
56     }
57
58     public void setTransactionTimeout(int seconds) throws SystemException JavaDoc {
59         if (seconds < 0) {
60             throw new SystemException JavaDoc("transaction timeout must be positive or 0, not " + seconds);
61         }
62         transactionManager.setTransactionTimeout(seconds);
63     }
64
65     public void begin() throws NotSupportedException JavaDoc, SystemException JavaDoc {
66         transactionManager.begin();
67     }
68
69     public void commit() throws HeuristicMixedException JavaDoc, HeuristicRollbackException JavaDoc, IllegalStateException JavaDoc, RollbackException JavaDoc, SecurityException JavaDoc, SystemException JavaDoc {
70         transactionManager.commit();
71     }
72
73     public void rollback() throws IllegalStateException JavaDoc, SecurityException JavaDoc, SystemException JavaDoc {
74         transactionManager.rollback();
75     }
76 }
77
Popular Tags