KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > mim > lib > BasicSpeedoAccessor


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
4  * Copyright (C) 2001-2004 France Telecom R&D
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 of the License, or (at your option) 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 USA
19  *
20  *
21  *
22  * Contact: speedo@objectweb.org
23  *
24  * Authors: S.Chassande-Barrioz.
25  *
26  */

27 package org.objectweb.speedo.mim.lib;
28
29 import org.objectweb.speedo.mim.api.LifeCycle;
30 import org.objectweb.speedo.mim.api.DetachedLifeCycle;
31 import org.objectweb.speedo.mim.api.SpeedoAccessor;
32 import org.objectweb.speedo.mim.api.SpeedoProxy;
33 import org.objectweb.perseus.cache.api.CacheEntry;
34 import org.objectweb.perseus.persistence.api.State;
35
36 import javax.jdo.JDOUserException;
37
38 /**
39  * This class is the basic implementation of the SpeedoAccessor interface. It
40  * is used at the top of the XXXFields class inheritance.
41  *
42  * @author S.Chassande-Barrioz
43  */

44 public abstract class BasicSpeedoAccessor implements SpeedoAccessor {
45
46     /**
47      * This version is allocated:
48      * - before attach
49      * - before detach
50      * - before commit
51      */

52     
53     protected byte jdoStatus = LifeCycle.initState();
54
55     public byte detachedStatus = DetachedLifeCycle.initState();
56     
57     protected boolean isToMerge = false;
58     
59     public SpeedoProxy proxy = null;
60
61     public boolean hasBeenFlush = false;
62
63     public BasicSpeedoAccessor() {
64     }
65
66     public BasicSpeedoAccessor(SpeedoProxy _proxy) {
67         this.proxy = _proxy;
68     }
69
70     // IMPLEMENTATION OF THE State INTERFACE //
71
//---------------------------------------//
72

73     public CacheEntry getCacheEntry() {
74         return proxy;
75     }
76
77     
78     // IMPLEMENTATION OF THE PAccessor INTERFACE //
79
//-------------------------------------------//
80

81     public Object JavaDoc getMemoryInstance() {
82         return this;
83     }
84
85
86     // IMPLEMENTATION OF THE SpeedoAccessor INTERFACE //
87
//------------------------------------------------//
88

89     /**
90      * Changes the status of this object
91      *
92      * @see org.objectweb.speedo.mim.api.LifeCycle
93      * @param action the action that may change the status
94      */

95     public void jdoChangeStatus(byte action) {
96         byte neo = LifeCycle.nextStatePersistenceCapable(jdoStatus, action);
97         if (neo == LifeCycle.ERROR) {
98             throw new JDOUserException("Operation "
99                     + LifeCycle.actionToString(action)
100                     + " not allowed with the status "
101                     + LifeCycle.statusToString(jdoStatus));
102         }
103         jdoStatus = neo;
104     }
105
106     /**
107      * Gets the current status of this object
108      *
109      * @see org.objectweb.speedo.mim.api.LifeCycle
110      * @return the current state in the life cycle
111      */

112     public byte jdoGetStatus() {
113         return jdoStatus;
114     }
115
116     /**
117      * Forces the new value of the status
118      *
119      * @see org.objectweb.speedo.mim.api.LifeCycle
120      * @param newValue the new status of this object
121      */

122     public void jdoSetStatus(byte newValue) {
123         jdoStatus = newValue;
124     }
125
126     public byte getDetachedStatus() {
127         return detachedStatus;
128     }
129     
130     public void setDetachedStatus(byte newValue) {
131         detachedStatus = newValue;
132     }
133     
134     /**
135      * @return The SpeedoProxy attached to this state representation.
136      */

137     public SpeedoProxy getSpeedoProxy() {
138         return proxy;
139     }
140
141     /**
142      * It assignes the SpeedoProxy attached to this state representation.
143      */

144     public void setSpeedoProxy(SpeedoProxy sp) {
145         proxy = sp;
146     }
147
148     public void prepareWrite() {
149         // do nothing
150
}
151
152     public void workingSetClosed() {
153         // do nothing
154
}
155
156     public boolean hasBeenFlush() {
157         return hasBeenFlush;
158     }
159
160     public void setFlushed(boolean val) {
161         hasBeenFlush = val;
162     }
163
164     public void changeVersion() {
165         //do nothing
166
}
167
168     public boolean checkVersion(SpeedoAccessor sa) {
169         return true;
170     }
171     
172     public long getVersion() {
173         return 0;
174     }
175     
176     public boolean isToMerge() {
177         return this.isToMerge;
178     }
179     public void makeToMerge(Object JavaDoc thinLock) {
180         this.isToMerge = true;
181
182     }
183     public State merge(State oldState) {
184         this.isToMerge = false;
185         return oldState;
186     }
187     
188     public Object JavaDoc getUserKey(int cacheId) {
189         return null;
190     }
191     
192     public void indexFieldModified(int cacheId, boolean rebind) {
193     }
194 }
195
Popular Tags