KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > dyade > aaa > util > NullTransaction


1 /*
2  * Copyright (C) 2001 - 2004 ScalAgent Distributed Technologies
3  * Copyright (C) 1996 - 2000 BULL
4  * Copyright (C) 1996 - 2000 INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): Dyade
22  * Contributor(s): ScalAgent Distributed Technologies
23  */

24 package fr.dyade.aaa.util;
25
26 import java.io.*;
27
28 public class NullTransaction implements Transaction, NullTransactionMBean {
29   // State of the transaction monitor.
30
private int phase = INIT;
31
32   private final void setPhase(int newPhase) {
33     phase = newPhase;
34   }
35
36   /**
37    *
38    */

39   public int getPhase() {
40     return phase;
41   }
42
43   public String JavaDoc getPhaseInfo() {
44     return PhaseInfo[phase];
45   }
46
47   public NullTransaction() {}
48
49   /**
50    * Tests if the Transaction component is persistent.
51    *
52    * @return false.
53    */

54   public boolean isPersistent() {
55     return false;
56   }
57
58   public void init(String JavaDoc path) throws IOException {
59     phase = INIT;
60
61     /* The Transaction subsystem is ready */
62     setPhase(FREE);
63   }
64
65   public File getDir() {
66     return null;
67   }
68
69   /**
70    * Returns the path of persistence directory.
71    *
72    * @return null.
73    */

74   public String JavaDoc getPersistenceDir() {
75     return null;
76   }
77
78   public synchronized void begin() throws IOException {
79     while (phase != FREE) {
80       try {
81     wait();
82       } catch (InterruptedException JavaDoc exc) {
83       }
84     }
85     // Change the transaction state.
86
setPhase(RUN);
87   }
88
89   public String JavaDoc[] getList(String JavaDoc prefix) {
90     return new String JavaDoc[0];
91   }
92
93   public void save(Serializable obj, String JavaDoc name) throws IOException {}
94   
95   public void saveByteArray(byte[] buf, String JavaDoc name) throws IOException {}
96
97   public Object JavaDoc load(String JavaDoc name) throws IOException, ClassNotFoundException JavaDoc {
98     return null;
99   }
100   
101   public byte[] loadByteArray(String JavaDoc name) throws IOException, ClassNotFoundException JavaDoc {
102     return null;
103   }
104
105   public void delete(String JavaDoc name) {}
106
107   public void save(Serializable obj, String JavaDoc dirName, String JavaDoc name) throws IOException {}
108   
109   public void saveByteArray(byte[] buf, String JavaDoc dirName, String JavaDoc name) throws IOException {}
110
111   public Object JavaDoc load(String JavaDoc dirName, String JavaDoc name) throws IOException, ClassNotFoundException JavaDoc {
112     return null;
113   }
114   
115   public byte[] loadByteArray(String JavaDoc dirName, String JavaDoc name) throws IOException {
116     return null;
117   }
118
119   public void delete(String JavaDoc dirName, String JavaDoc name) {}
120
121   public void commit() throws IOException {
122     if (phase != RUN)
123       throw new IllegalStateException JavaDoc("Can not commit.");
124
125     setPhase(COMMIT);
126   }
127
128   public void rollback() throws IOException {
129     if (phase != RUN)
130       throw new IllegalStateException JavaDoc("Can not rollback.");
131
132     setPhase(ROLLBACK);
133   }
134
135   public synchronized void release() throws IOException {
136     if ((phase != RUN) && (phase != COMMIT) && (phase != ROLLBACK))
137       throw new IllegalStateException JavaDoc("Can not release transaction.");
138
139     // Change the transaction state.
140
setPhase(FREE);
141     // wake-up an eventually user's thread in begin
142
notify();
143   }
144
145   public synchronized final void stop() {
146     while (phase != FREE) {
147       // Wait for the transaction subsystem to be free
148
try {
149         wait();
150       } catch (InterruptedException JavaDoc exc) {
151       }
152     }
153     // Change the transaction state.
154
setPhase(FREE);
155   }
156
157
158   public synchronized final void close() {
159     if (phase == INIT) return;
160
161     while (phase != FREE) {
162       // Wait for the transaction subsystem to be free
163
try {
164         wait();
165       } catch (InterruptedException JavaDoc exc) {
166       }
167     }
168     // Change the transaction state.
169
setPhase(INIT);
170   }
171 }
172
Popular Tags