KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > VersantDetachedStateManager


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo;
13
14 import javax.jdo.PersistenceManager;
15 import javax.jdo.spi.PersistenceCapable;
16 import javax.jdo.spi.StateManager;
17 import java.io.Serializable JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.HashSet JavaDoc;
20
21 import com.versant.core.common.BindingSupportImpl;
22 import com.versant.core.common.OID;
23
24 /**
25  * State manager shared by a graph of detached instances.
26  */

27 public class VersantDetachedStateManager implements VersantStateManager,
28         Serializable JavaDoc {
29
30     private transient boolean booleanField;
31     private transient char charField;
32     private transient byte byteField;
33     private transient short shortField;
34     private transient int intField;
35     private transient long longField;
36     private transient float floatField;
37     private transient double doubleField;
38     private transient String JavaDoc stringField;
39     private transient Object JavaDoc objectField;
40     private HashSet JavaDoc deleted = new HashSet JavaDoc();
41
42     public byte replacingFlags(PersistenceCapable pc) {
43         return 0;
44     }
45
46     public StateManager replacingStateManager(PersistenceCapable pc,
47             StateManager sm) {
48         return sm;
49     }
50
51     public boolean isDirty(PersistenceCapable pc) {
52         return ((VersantDetachable)pc).versantIsDirty();
53     }
54
55     public boolean isTransactional(PersistenceCapable pc) {
56         return false;
57     }
58
59     public boolean isPersistent(PersistenceCapable pc) {
60         return false;
61     }
62
63     public boolean isNew(PersistenceCapable pc) {
64         return false;
65     }
66
67     public boolean isDeleted(PersistenceCapable pc) {
68         return deleted.contains(((VersantDetachable)pc).versantGetOID());
69     }
70
71     public PersistenceManager getPersistenceManager(PersistenceCapable pc) {
72         return null;
73     }
74
75     public void makeDirty(PersistenceCapable pc, String JavaDoc s) {
76         ((VersantDetachable)pc).versantMakeDirty(s);
77     }
78
79     public Object JavaDoc getObjectId(PersistenceCapable pc) {
80         return ((VersantDetachable)pc).versantGetOID();
81     }
82
83     public Object JavaDoc getTransactionalObjectId(PersistenceCapable pc) {
84         return null;
85     }
86
87     public boolean isLoaded(PersistenceCapable pc, int field) {
88         return ((VersantDetachable)pc).versantIsLoaded(field);
89     }
90
91     public void preSerialize(PersistenceCapable pc) {
92     }
93
94     public boolean getBooleanField(PersistenceCapable pc, int field,
95             boolean currentValue) {
96         if (!isLoaded(pc, field)) {
97             throw BindingSupportImpl.getInstance().fieldDetached();
98         }
99         return currentValue;
100     }
101
102     public char getCharField(PersistenceCapable pc, int field,
103             char currentValue) {
104         if (!isLoaded(pc, field)) {
105             throw BindingSupportImpl.getInstance().fieldDetached();
106         }
107         return currentValue;
108     }
109
110     public byte getByteField(PersistenceCapable pc, int field,
111             byte currentValue) {
112         if (!isLoaded(pc, field)) {
113             throw BindingSupportImpl.getInstance().fieldDetached();
114         }
115         return currentValue;
116     }
117
118     public short getShortField(PersistenceCapable pc, int field,
119             short currentValue) {
120         if (!isLoaded(pc, field)) {
121             throw BindingSupportImpl.getInstance().fieldDetached();
122         }
123         return currentValue;
124     }
125
126     public int getIntField(PersistenceCapable pc, int field,
127             int currentValue) {
128         if (!isLoaded(pc, field)) {
129             throw BindingSupportImpl.getInstance().fieldDetached();
130         }
131         return currentValue;
132     }
133
134     public long getLongField(PersistenceCapable pc, int field,
135             long currentValue) {
136         if (!isLoaded(pc, field)) {
137             throw BindingSupportImpl.getInstance().fieldDetached();
138         }
139         return currentValue;
140     }
141
142     public float getFloatField(PersistenceCapable pc, int field,
143             float currentValue) {
144         if (!isLoaded(pc, field)) {
145             throw BindingSupportImpl.getInstance().fieldDetached();
146         }
147         return currentValue;
148     }
149
150     public double getDoubleField(PersistenceCapable pc, int field,
151             double currentValue) {
152         if (!isLoaded(pc, field)) {
153             throw BindingSupportImpl.getInstance().fieldDetached();
154         }
155         return currentValue;
156     }
157
158     public String JavaDoc getStringField(PersistenceCapable pc, int field,
159             String JavaDoc currentValue) {
160         if (!isLoaded(pc, field)) {
161             throw BindingSupportImpl.getInstance().fieldDetached();
162         }
163         return currentValue;
164     }
165
166     public Object JavaDoc getObjectField(PersistenceCapable pc, int field,
167             Object JavaDoc currentValue) {
168         if (!isLoaded(pc, field)) {
169             throw BindingSupportImpl.getInstance().fieldDetached();
170         }
171         return currentValue;
172     }
173
174     public void setBooleanField(PersistenceCapable pc, int field,
175             boolean currentValue, boolean newValue) {
176         booleanField = newValue;
177         ((VersantDetachable)pc).versantMakeDirty(field);
178         pc.jdoReplaceField(field);
179     }
180
181     public void setCharField(PersistenceCapable pc, int field,
182             char currentValue, char newValue) {
183         charField = newValue;
184         ((VersantDetachable)pc).versantMakeDirty(field);
185         pc.jdoReplaceField(field);
186     }
187
188     public void setByteField(PersistenceCapable pc, int field,
189             byte currentValue, byte newValue) {
190         byteField = newValue;
191         ((VersantDetachable)pc).versantMakeDirty(field);
192         pc.jdoReplaceField(field);
193     }
194
195     public void setShortField(PersistenceCapable pc, int field,
196             short currentValue, short newValue) {
197         shortField = newValue;
198         ((VersantDetachable)pc).versantMakeDirty(field);
199         pc.jdoReplaceField(field);
200     }
201
202     public void setIntField(PersistenceCapable pc, int field,
203             int currentValue, int newValue) {
204         intField = newValue;
205         ((VersantDetachable)pc).versantMakeDirty(field);
206         pc.jdoReplaceField(field);
207     }
208
209     public void setLongField(PersistenceCapable pc, int field,
210             long currentValue, long newValue) {
211         longField = newValue;
212         ((VersantDetachable)pc).versantMakeDirty(field);
213         pc.jdoReplaceField(field);
214     }
215
216     public void setFloatField(PersistenceCapable pc, int field,
217             float currentValue, float newValue) {
218         floatField = newValue;
219         ((VersantDetachable)pc).versantMakeDirty(field);
220         pc.jdoReplaceField(field);
221     }
222
223     public void setDoubleField(PersistenceCapable pc, int field,
224             double currentValue, double newValue) {
225         doubleField = newValue;
226         ((VersantDetachable)pc).versantMakeDirty(field);
227         pc.jdoReplaceField(field);
228     }
229
230     public void setStringField(PersistenceCapable pc, int field,
231             String JavaDoc currentValue, String JavaDoc newValue) {
232         stringField = newValue;
233         ((VersantDetachable)pc).versantMakeDirty(field);
234         pc.jdoReplaceField(field);
235     }
236
237     public void setObjectField(PersistenceCapable pc, int field,
238             Object JavaDoc currentValue, Object JavaDoc newValue) {
239         objectField = newValue;
240         ((VersantDetachable)pc).versantMakeDirty(field);
241         pc.jdoReplaceField(field);
242     }
243
244     public void providedBooleanField(PersistenceCapable pc,
245             int field, boolean currentValue) {
246     }
247
248     public void providedCharField(PersistenceCapable pc, int field,
249             char currentValue) {
250     }
251
252     public void providedByteField(PersistenceCapable pc, int field,
253             byte currentValue) {
254     }
255
256     public void providedShortField(PersistenceCapable pc,
257             int field, short currentValue) {
258     }
259
260     public void providedIntField(PersistenceCapable pc, int field,
261             int currentValue) {
262     }
263
264     public void providedLongField(PersistenceCapable pc, int field,
265             long currentValue) {
266     }
267
268     public void providedFloatField(PersistenceCapable pc,
269             int field, float currentValue) {
270     }
271
272     public void providedDoubleField(PersistenceCapable pc,
273             int field, double currentValue) {
274     }
275
276     public void providedStringField(PersistenceCapable pc,
277             int field, String JavaDoc currentValue) {
278     }
279
280     public void providedObjectField(PersistenceCapable pc,
281             int field, Object JavaDoc currentValue) {
282     }
283
284     public boolean replacingBooleanField(final PersistenceCapable pc,
285             final int field) {
286         ((VersantDetachable)pc).versantSetLoaded(field);
287         return booleanField;
288     }
289
290     public char replacingCharField(final PersistenceCapable pc,
291             final int field) {
292         ((VersantDetachable)pc).versantSetLoaded(field);
293         return charField;
294     }
295
296     public byte replacingByteField(final PersistenceCapable pc,
297             final int field) {
298         ((VersantDetachable)pc).versantSetLoaded(field);
299         return byteField;
300     }
301
302     public short replacingShortField(final PersistenceCapable pc,
303             final int field) {
304         ((VersantDetachable)pc).versantSetLoaded(field);
305         return shortField;
306     }
307
308     public int replacingIntField(final PersistenceCapable pc,
309             final int field) {
310         ((VersantDetachable)pc).versantSetLoaded(field);
311         return intField;
312     }
313
314     public float replacingFloatField(final PersistenceCapable pc,
315             final int field) {
316         ((VersantDetachable)pc).versantSetLoaded(field);
317         return floatField;
318     }
319
320     public double replacingDoubleField(final PersistenceCapable pc,
321             final int field) {
322         ((VersantDetachable)pc).versantSetLoaded(field);
323         return doubleField;
324     }
325
326     public long replacingLongField(final PersistenceCapable pc,
327             final int field) {
328         ((VersantDetachable)pc).versantSetLoaded(field);
329         return longField;
330     }
331
332     public String JavaDoc replacingStringField(final PersistenceCapable pc,
333             final int field) {
334         ((VersantDetachable)pc).versantSetLoaded(field);
335         return stringField;
336     }
337
338     public Object JavaDoc replacingObjectField(final PersistenceCapable pc,
339             final int field) {
340         ((VersantDetachable)pc).versantSetLoaded(field);
341         return objectField;
342     }
343
344     public void makeDirty(PersistenceCapable pc,
345             int managedFieldNo) {
346         ((VersantDetachable)pc).versantMakeDirty(managedFieldNo);
347     }
348
349     public void fillNewAppPKField(int fieldNo) {}
350
351     public void versantAddDeleted(Object JavaDoc oid) {
352         deleted.add(oid);
353     }
354
355     public Collection JavaDoc versantGetDeleted() {
356         return deleted;
357     }
358
359     public PersistenceCapable getPersistenceCapable() {
360         return null;
361     }
362
363     public OID getOID() {
364         return null;
365     }
366
367
368
369 }
370
Popular Tags