KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > search > transaction > SimpleTransactionManager


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.search.transaction;
18
19 import javax.transaction.HeuristicMixedException JavaDoc;
20 import javax.transaction.HeuristicRollbackException JavaDoc;
21 import javax.transaction.InvalidTransactionException JavaDoc;
22 import javax.transaction.NotSupportedException JavaDoc;
23 import javax.transaction.RollbackException JavaDoc;
24 import javax.transaction.SystemException JavaDoc;
25 import javax.transaction.Transaction JavaDoc;
26 import javax.transaction.TransactionManager JavaDoc;
27
28 public class SimpleTransactionManager implements TransactionManager JavaDoc
29 {
30     private static SimpleTransactionManager manager = new SimpleTransactionManager();
31
32     private int timeout;
33
34     private SimpleTransactionManager()
35     {
36         super();
37     }
38
39     public static SimpleTransactionManager getInstance()
40     {
41         return manager;
42     }
43
44     public void begin() throws NotSupportedException JavaDoc, SystemException JavaDoc
45     {
46         SimpleTransaction.begin();
47
48     }
49
50     public void commit() throws RollbackException JavaDoc, HeuristicMixedException JavaDoc, HeuristicRollbackException JavaDoc,
51             SecurityException JavaDoc, IllegalStateException JavaDoc, SystemException JavaDoc
52     {
53         SimpleTransaction transaction = getTransactionChecked();
54         transaction.commit();
55     }
56
57     public int getStatus() throws SystemException JavaDoc
58     {
59         SimpleTransaction transaction = getTransactionChecked();
60         return transaction.getStatus();
61     }
62
63     public SimpleTransaction getTransaction() throws SystemException JavaDoc
64     {
65         return SimpleTransaction.getTransaction();
66     }
67
68     private SimpleTransaction getTransactionChecked() throws SystemException JavaDoc, IllegalStateException JavaDoc
69     {
70         SimpleTransaction tx = SimpleTransaction.getTransaction();
71         if (tx == null)
72         {
73             throw new IllegalStateException JavaDoc("The thread is not bound to a transaction.");
74         }
75         return tx;
76     }
77
78     public void resume(Transaction JavaDoc tx) throws InvalidTransactionException JavaDoc, IllegalStateException JavaDoc, SystemException JavaDoc
79     {
80         if (!(tx instanceof SimpleTransaction))
81         {
82             throw new IllegalStateException JavaDoc("Transaction must be a SimpleTransaction to resume");
83         }
84         SimpleTransaction.resume((SimpleTransaction) tx);
85     }
86
87     public void rollback() throws IllegalStateException JavaDoc, SecurityException JavaDoc, SystemException JavaDoc
88     {
89         SimpleTransaction transaction = getTransactionChecked();
90         transaction.rollback();
91     }
92
93     public void setRollbackOnly() throws IllegalStateException JavaDoc, SystemException JavaDoc
94     {
95         SimpleTransaction transaction = getTransactionChecked();
96         transaction.setRollbackOnly();
97     }
98
99     public void setTransactionTimeout(int timeout) throws SystemException JavaDoc
100     {
101         this.timeout = timeout;
102     }
103
104     public SimpleTransaction suspend() throws SystemException JavaDoc
105     {
106         return SimpleTransaction.suspend();
107     }
108
109 }
110
Popular Tags