001: /**
002: * Speedo: an implementation of JDO compliant personality on top of JORM generic
003: * I/O sub-system.
004: * Copyright (C) 2001-2004 France Telecom R&D
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: *
021: *
022: * Contact: speedo@objectweb.org
023: *
024: * Authors: S.Chassande-Barrioz.
025: *
026: */package org.objectweb.speedo.mim.lib;
027:
028: import org.objectweb.speedo.mim.api.LifeCycle;
029: import org.objectweb.speedo.mim.api.DetachedLifeCycle;
030: import org.objectweb.speedo.mim.api.StateItf;
031: import org.objectweb.speedo.mim.api.PersistentObjectItf;
032: import org.objectweb.perseus.cache.api.CacheEntry;
033:
034: /**
035: * This class is the basic implementation of the StateItf interface. It
036: * is used at the top of the XXXFields class inheritance.
037: *
038: * @author S.Chassande-Barrioz
039: */
040: public abstract class AbstractStateImpl implements StateItf {
041:
042: /**
043: * This version is allocated:
044: * - before attach
045: * - before detach
046: * - before commit
047: */
048:
049: protected byte jdoStatus = LifeCycle.initState();
050:
051: public byte detachedStatus = DetachedLifeCycle.initState();
052:
053: protected boolean isToMerge = false;
054:
055: public PersistentObjectItf speedoPO = null;
056:
057: public boolean hasBeenFlush = false;
058:
059: public AbstractStateImpl() {
060: }
061:
062: public AbstractStateImpl(PersistentObjectItf thepo) {
063: this .speedoPO = thepo;
064: }
065:
066: // IMPLEMENTATION OF THE StateItf INTERFACE //
067: //---------------------------------------//
068:
069: public CacheEntry getCacheEntry() {
070: return speedoPO;
071: }
072:
073: public void setCacheEntry(CacheEntry ce) {
074: speedoPO = (PersistentObjectItf) ce;
075: }
076:
077: // IMPLEMENTATION OF THE PAccessor INTERFACE //
078: //-------------------------------------------//
079:
080: public Object getMemoryInstance() {
081: return speedoPO;
082: }
083:
084: // IMPLEMENTATION OF THE StateItf INTERFACE //
085: //------------------------------------------------//
086:
087: /**
088: * Changes the status of this object
089: *
090: * @see org.objectweb.speedo.mim.api.LifeCycle
091: * @param action the action that may change the status
092: */
093: public void speedoChangeStatus(byte action) {
094: byte neo = LifeCycle.nextStatePersistenceCapable(jdoStatus,
095: action);
096: if (neo == LifeCycle.ERROR) {
097: throw new RuntimeException("Operation "
098: + LifeCycle.actionToString(action)
099: + " not allowed with the status "
100: + LifeCycle.statusToString(jdoStatus));
101: }
102: jdoStatus = neo;
103: }
104:
105: /**
106: * Gets the current status of this object
107: *
108: * @see org.objectweb.speedo.mim.api.LifeCycle
109: * @return the current state in the life cycle
110: */
111: public byte speedoGetStatus() {
112: return jdoStatus;
113: }
114:
115: /**
116: * Forces the new value of the status
117: *
118: * @see org.objectweb.speedo.mim.api.LifeCycle
119: * @param newValue the new status of this object
120: */
121: public void speedoSetStatus(byte newValue) {
122: jdoStatus = newValue;
123: }
124:
125: public byte getDetachedStatus() {
126: return detachedStatus;
127: }
128:
129: public void setDetachedStatus(byte newValue) {
130: detachedStatus = newValue;
131: }
132:
133: /**
134: * @return The PersistentObjectItf attached to this state representation.
135: */
136: public PersistentObjectItf getSpeedoPO() {
137: return speedoPO;
138: }
139:
140: /**
141: * It assignes the PersistentObjectItf attached to this state representation.
142: */
143: public void setSpeedoPO(PersistentObjectItf sp) {
144: speedoPO = sp;
145: }
146:
147: public void prepareWrite() {
148: // do nothing
149: }
150:
151: public void workingSetClosed() {
152: // do nothing
153: }
154:
155: public boolean hasBeenFlush() {
156: return hasBeenFlush;
157: }
158:
159: public void setFlushed(boolean val) {
160: hasBeenFlush = val;
161: }
162:
163: public void speedoChangeVersion() {
164: //do nothing
165: }
166:
167: public boolean checkVersion(StateItf sa) {
168: return true;
169: }
170:
171: public long getVersion() {
172: return 0;
173: }
174:
175: public boolean isToMerge() {
176: return this .isToMerge;
177: }
178:
179: public void makeToMerge(Object thinLock) {
180: this .isToMerge = true;
181:
182: }
183:
184: public org.objectweb.perseus.persistence.api.State merge(
185: org.objectweb.perseus.persistence.api.State oldState) {
186: this .isToMerge = false;
187: return oldState;
188: }
189:
190: public Object getUserKey(int cacheId) {
191: return null;
192: }
193:
194: public void indexFieldModified(int cacheId, boolean rebind) {
195: }
196: }
|