KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > transaction > context > UnspecifiedTransactionContext


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.context;
19
20 import javax.transaction.Synchronization JavaDoc;
21 import javax.transaction.xa.XAResource JavaDoc;
22
23 /**
24  * @version $Rev: 155839 $ $Date: 2005-03-01 15:30:08 -0800 (Tue, 01 Mar 2005) $
25  */

26 class UnspecifiedTransactionContext extends AbstractTransactionContext {
27     private boolean active = true;
28     private boolean failed = false;
29
30     public UnspecifiedTransactionContext() {
31     }
32
33     public boolean isInheritable() {
34         return false;
35     }
36
37     public boolean isActive() {
38         return active;
39     }
40
41     public boolean enlistResource(XAResource JavaDoc xaResource){
42         throw new IllegalStateException JavaDoc("There is no transaction in progress.");
43     }
44
45     public boolean delistResource(XAResource JavaDoc xaResource, int flag) {
46         throw new IllegalStateException JavaDoc("There is no transaction in progress.");
47     }
48
49     public void registerSynchronization(Synchronization JavaDoc synchronization) {
50         throw new IllegalStateException JavaDoc("There is no transaction in progress.");
51     }
52
53     public boolean getRollbackOnly() {
54         return failed;
55     }
56
57     public void setRollbackOnly() {
58         this.failed = true;
59     }
60
61     public void suspend() {
62     }
63
64     public void resume() {
65     }
66
67     public boolean commit() {
68         complete();
69         return true;
70     }
71
72     public void rollback() {
73         setRollbackOnly();
74         complete();
75     }
76
77     private void complete() {
78         try {
79             if (!failed) {
80                 flushState();
81             }
82         } catch (Error JavaDoc e) {
83             throw e;
84         } catch (RuntimeException JavaDoc re) {
85             throw re;
86         } catch (Throwable JavaDoc e) {
87             log.error("Unable to flush state, continuing", e);
88         } finally {
89             active = false;
90             unassociateAll();
91         }
92     }
93 }
94
Popular Tags