001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.jdo;
012:
013: import javax.jdo.PersistenceManager;
014: import javax.jdo.spi.PersistenceCapable;
015: import javax.jdo.spi.StateManager;
016: import java.io.Serializable;
017: import java.util.Collection;
018: import java.util.HashSet;
019:
020: import com.versant.core.common.BindingSupportImpl;
021: import com.versant.core.common.OID;
022:
023: /**
024: * State manager shared by a graph of detached instances.
025: */
026: public class VersantDetachedStateManager implements
027: VersantStateManager, Serializable {
028:
029: private transient boolean booleanField;
030: private transient char charField;
031: private transient byte byteField;
032: private transient short shortField;
033: private transient int intField;
034: private transient long longField;
035: private transient float floatField;
036: private transient double doubleField;
037: private transient String stringField;
038: private transient Object objectField;
039: private HashSet deleted = new HashSet();
040:
041: public byte replacingFlags(PersistenceCapable pc) {
042: return 0;
043: }
044:
045: public StateManager replacingStateManager(PersistenceCapable pc,
046: StateManager sm) {
047: return sm;
048: }
049:
050: public boolean isDirty(PersistenceCapable pc) {
051: return ((VersantDetachable) pc).versantIsDirty();
052: }
053:
054: public boolean isTransactional(PersistenceCapable pc) {
055: return false;
056: }
057:
058: public boolean isPersistent(PersistenceCapable pc) {
059: return false;
060: }
061:
062: public boolean isNew(PersistenceCapable pc) {
063: return false;
064: }
065:
066: public boolean isDeleted(PersistenceCapable pc) {
067: return deleted.contains(((VersantDetachable) pc)
068: .versantGetOID());
069: }
070:
071: public PersistenceManager getPersistenceManager(
072: PersistenceCapable pc) {
073: return null;
074: }
075:
076: public void makeDirty(PersistenceCapable pc, String s) {
077: ((VersantDetachable) pc).versantMakeDirty(s);
078: }
079:
080: public Object getObjectId(PersistenceCapable pc) {
081: return ((VersantDetachable) pc).versantGetOID();
082: }
083:
084: public Object getTransactionalObjectId(PersistenceCapable pc) {
085: return null;
086: }
087:
088: public boolean isLoaded(PersistenceCapable pc, int field) {
089: return ((VersantDetachable) pc).versantIsLoaded(field);
090: }
091:
092: public void preSerialize(PersistenceCapable pc) {
093: }
094:
095: public boolean getBooleanField(PersistenceCapable pc, int field,
096: boolean currentValue) {
097: if (!isLoaded(pc, field)) {
098: throw BindingSupportImpl.getInstance().fieldDetached();
099: }
100: return currentValue;
101: }
102:
103: public char getCharField(PersistenceCapable pc, int field,
104: char currentValue) {
105: if (!isLoaded(pc, field)) {
106: throw BindingSupportImpl.getInstance().fieldDetached();
107: }
108: return currentValue;
109: }
110:
111: public byte getByteField(PersistenceCapable pc, int field,
112: byte currentValue) {
113: if (!isLoaded(pc, field)) {
114: throw BindingSupportImpl.getInstance().fieldDetached();
115: }
116: return currentValue;
117: }
118:
119: public short getShortField(PersistenceCapable pc, int field,
120: short currentValue) {
121: if (!isLoaded(pc, field)) {
122: throw BindingSupportImpl.getInstance().fieldDetached();
123: }
124: return currentValue;
125: }
126:
127: public int getIntField(PersistenceCapable pc, int field,
128: int currentValue) {
129: if (!isLoaded(pc, field)) {
130: throw BindingSupportImpl.getInstance().fieldDetached();
131: }
132: return currentValue;
133: }
134:
135: public long getLongField(PersistenceCapable pc, int field,
136: long currentValue) {
137: if (!isLoaded(pc, field)) {
138: throw BindingSupportImpl.getInstance().fieldDetached();
139: }
140: return currentValue;
141: }
142:
143: public float getFloatField(PersistenceCapable pc, int field,
144: float currentValue) {
145: if (!isLoaded(pc, field)) {
146: throw BindingSupportImpl.getInstance().fieldDetached();
147: }
148: return currentValue;
149: }
150:
151: public double getDoubleField(PersistenceCapable pc, int field,
152: double currentValue) {
153: if (!isLoaded(pc, field)) {
154: throw BindingSupportImpl.getInstance().fieldDetached();
155: }
156: return currentValue;
157: }
158:
159: public String getStringField(PersistenceCapable pc, int field,
160: String currentValue) {
161: if (!isLoaded(pc, field)) {
162: throw BindingSupportImpl.getInstance().fieldDetached();
163: }
164: return currentValue;
165: }
166:
167: public Object getObjectField(PersistenceCapable pc, int field,
168: Object currentValue) {
169: if (!isLoaded(pc, field)) {
170: throw BindingSupportImpl.getInstance().fieldDetached();
171: }
172: return currentValue;
173: }
174:
175: public void setBooleanField(PersistenceCapable pc, int field,
176: boolean currentValue, boolean newValue) {
177: booleanField = newValue;
178: ((VersantDetachable) pc).versantMakeDirty(field);
179: pc.jdoReplaceField(field);
180: }
181:
182: public void setCharField(PersistenceCapable pc, int field,
183: char currentValue, char newValue) {
184: charField = newValue;
185: ((VersantDetachable) pc).versantMakeDirty(field);
186: pc.jdoReplaceField(field);
187: }
188:
189: public void setByteField(PersistenceCapable pc, int field,
190: byte currentValue, byte newValue) {
191: byteField = newValue;
192: ((VersantDetachable) pc).versantMakeDirty(field);
193: pc.jdoReplaceField(field);
194: }
195:
196: public void setShortField(PersistenceCapable pc, int field,
197: short currentValue, short newValue) {
198: shortField = newValue;
199: ((VersantDetachable) pc).versantMakeDirty(field);
200: pc.jdoReplaceField(field);
201: }
202:
203: public void setIntField(PersistenceCapable pc, int field,
204: int currentValue, int newValue) {
205: intField = newValue;
206: ((VersantDetachable) pc).versantMakeDirty(field);
207: pc.jdoReplaceField(field);
208: }
209:
210: public void setLongField(PersistenceCapable pc, int field,
211: long currentValue, long newValue) {
212: longField = newValue;
213: ((VersantDetachable) pc).versantMakeDirty(field);
214: pc.jdoReplaceField(field);
215: }
216:
217: public void setFloatField(PersistenceCapable pc, int field,
218: float currentValue, float newValue) {
219: floatField = newValue;
220: ((VersantDetachable) pc).versantMakeDirty(field);
221: pc.jdoReplaceField(field);
222: }
223:
224: public void setDoubleField(PersistenceCapable pc, int field,
225: double currentValue, double newValue) {
226: doubleField = newValue;
227: ((VersantDetachable) pc).versantMakeDirty(field);
228: pc.jdoReplaceField(field);
229: }
230:
231: public void setStringField(PersistenceCapable pc, int field,
232: String currentValue, String newValue) {
233: stringField = newValue;
234: ((VersantDetachable) pc).versantMakeDirty(field);
235: pc.jdoReplaceField(field);
236: }
237:
238: public void setObjectField(PersistenceCapable pc, int field,
239: Object currentValue, Object newValue) {
240: objectField = newValue;
241: ((VersantDetachable) pc).versantMakeDirty(field);
242: pc.jdoReplaceField(field);
243: }
244:
245: public void providedBooleanField(PersistenceCapable pc, int field,
246: boolean currentValue) {
247: }
248:
249: public void providedCharField(PersistenceCapable pc, int field,
250: char currentValue) {
251: }
252:
253: public void providedByteField(PersistenceCapable pc, int field,
254: byte currentValue) {
255: }
256:
257: public void providedShortField(PersistenceCapable pc, int field,
258: short currentValue) {
259: }
260:
261: public void providedIntField(PersistenceCapable pc, int field,
262: int currentValue) {
263: }
264:
265: public void providedLongField(PersistenceCapable pc, int field,
266: long currentValue) {
267: }
268:
269: public void providedFloatField(PersistenceCapable pc, int field,
270: float currentValue) {
271: }
272:
273: public void providedDoubleField(PersistenceCapable pc, int field,
274: double currentValue) {
275: }
276:
277: public void providedStringField(PersistenceCapable pc, int field,
278: String currentValue) {
279: }
280:
281: public void providedObjectField(PersistenceCapable pc, int field,
282: Object currentValue) {
283: }
284:
285: public boolean replacingBooleanField(final PersistenceCapable pc,
286: final int field) {
287: ((VersantDetachable) pc).versantSetLoaded(field);
288: return booleanField;
289: }
290:
291: public char replacingCharField(final PersistenceCapable pc,
292: final int field) {
293: ((VersantDetachable) pc).versantSetLoaded(field);
294: return charField;
295: }
296:
297: public byte replacingByteField(final PersistenceCapable pc,
298: final int field) {
299: ((VersantDetachable) pc).versantSetLoaded(field);
300: return byteField;
301: }
302:
303: public short replacingShortField(final PersistenceCapable pc,
304: final int field) {
305: ((VersantDetachable) pc).versantSetLoaded(field);
306: return shortField;
307: }
308:
309: public int replacingIntField(final PersistenceCapable pc,
310: final int field) {
311: ((VersantDetachable) pc).versantSetLoaded(field);
312: return intField;
313: }
314:
315: public float replacingFloatField(final PersistenceCapable pc,
316: final int field) {
317: ((VersantDetachable) pc).versantSetLoaded(field);
318: return floatField;
319: }
320:
321: public double replacingDoubleField(final PersistenceCapable pc,
322: final int field) {
323: ((VersantDetachable) pc).versantSetLoaded(field);
324: return doubleField;
325: }
326:
327: public long replacingLongField(final PersistenceCapable pc,
328: final int field) {
329: ((VersantDetachable) pc).versantSetLoaded(field);
330: return longField;
331: }
332:
333: public String replacingStringField(final PersistenceCapable pc,
334: final int field) {
335: ((VersantDetachable) pc).versantSetLoaded(field);
336: return stringField;
337: }
338:
339: public Object replacingObjectField(final PersistenceCapable pc,
340: final int field) {
341: ((VersantDetachable) pc).versantSetLoaded(field);
342: return objectField;
343: }
344:
345: public void makeDirty(PersistenceCapable pc, int managedFieldNo) {
346: ((VersantDetachable) pc).versantMakeDirty(managedFieldNo);
347: }
348:
349: public void fillNewAppPKField(int fieldNo) {
350: }
351:
352: public void versantAddDeleted(Object oid) {
353: deleted.add(oid);
354: }
355:
356: public Collection versantGetDeleted() {
357: return deleted;
358: }
359:
360: public PersistenceCapable getPersistenceCapable() {
361: return null;
362: }
363:
364: public OID getOID() {
365: return null;
366: }
367:
368: }
|