KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.versant.core.common.OID;
15
16 import javax.jdo.PersistenceManager;
17 import javax.jdo.spi.PersistenceCapable;
18 import javax.jdo.spi.StateManager;
19 import java.lang.reflect.Array JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import com.versant.core.common.BindingSupportImpl;
25 import com.versant.core.common.OID;
26
27 /**
28  *
29  */

30 public class AttachNavStateManager implements VersantStateManager {
31
32     private VersantPersistenceManagerImp pm;
33     private AttachStateContainer asc;
34
35     public AttachNavStateManager(VersantPersistenceManagerImp pm) {
36         this.pm = pm;
37     }
38
39     public AttachNavStateManager(AttachStateContainer asc) {
40         this.asc = asc;
41     }
42
43     public OID getOID() {
44         return null; //To change body of implemented methods use File | Settings | File Templates.
45
}
46
47     public PersistenceCapable getPersistenceCapable() {
48         return null; //To change body of implemented methods use File | Settings | File Templates.
49
}
50
51     public byte replacingFlags(PersistenceCapable persistenceCapable) {
52         return 0;
53     }
54
55     public StateManager replacingStateManager(PersistenceCapable persistenceCapable, StateManager stateManager) {
56         return stateManager;
57     }
58
59     public boolean isDirty(PersistenceCapable persistenceCapable) {
60         return ((VersantDetachable) persistenceCapable).versantIsDirty();
61     }
62
63     public boolean isTransactional(PersistenceCapable persistenceCapable) {
64         return false;
65     }
66
67     public boolean isPersistent(PersistenceCapable persistenceCapable) {
68         return false;
69     }
70
71     public boolean isNew(PersistenceCapable persistenceCapable) {
72         return getPcOID(persistenceCapable).isNew();
73     }
74
75     public boolean isDeleted(PersistenceCapable persistenceCapable) {
76         return false;
77     }
78
79     public PersistenceManager getPersistenceManager(PersistenceCapable persistenceCapable) {
80         return null;
81     }
82
83     public void makeDirty(PersistenceCapable persistenceCapable, String JavaDoc s) {
84         ((VersantDetachable) persistenceCapable).versantMakeDirty(s);
85     }
86
87     public Object JavaDoc getObjectId(PersistenceCapable persistenceCapable) {
88         return getPcOID(persistenceCapable);
89     }
90
91     public Object JavaDoc getTransactionalObjectId(PersistenceCapable persistenceCapable) {
92         return null;
93     }
94
95     public boolean isLoaded(PersistenceCapable persistenceCapable, int i) {
96         return ((VersantDetachable) persistenceCapable).versantIsLoaded(i);
97     }
98
99     public void preSerialize(PersistenceCapable persistenceCapable) {
100
101     }
102
103     public boolean getBooleanField(PersistenceCapable persistenceCapable,
104                                    int i, boolean b) {
105         if (!isLoaded(persistenceCapable, i)) {
106             throw BindingSupportImpl.getInstance().fieldDetached();
107         }
108         return b;
109     }
110
111     public char getCharField(PersistenceCapable persistenceCapable, int i,
112                              char c) {
113         if (!isLoaded(persistenceCapable, i)) {
114             throw BindingSupportImpl.getInstance().fieldDetached();
115         }
116         return c;
117     }
118
119     public byte getByteField(PersistenceCapable persistenceCapable, int i,
120                              byte b) {
121         if (!isLoaded(persistenceCapable, i)) {
122             throw BindingSupportImpl.getInstance().fieldDetached();
123         }
124         return b;
125     }
126
127     public short getShortField(PersistenceCapable persistenceCapable, int i,
128                                short i1) {
129         if (!isLoaded(persistenceCapable, i)) {
130             throw BindingSupportImpl.getInstance().fieldDetached();
131         }
132         return i1;
133     }
134
135     public int getIntField(PersistenceCapable persistenceCapable, int i,
136                            int i1) {
137         if (!isLoaded(persistenceCapable, i)) {
138             throw BindingSupportImpl.getInstance().fieldDetached();
139         }
140         return i1;
141     }
142
143     public long getLongField(PersistenceCapable persistenceCapable, int i,
144                              long l) {
145         if (!isLoaded(persistenceCapable, i)) {
146             throw BindingSupportImpl.getInstance().fieldDetached();
147         }
148         return l;
149     }
150
151     public float getFloatField(PersistenceCapable persistenceCapable, int i,
152                                float v) {
153         if (!isLoaded(persistenceCapable, i)) {
154             throw BindingSupportImpl.getInstance().fieldDetached();
155         }
156         return v;
157     }
158
159     public double getDoubleField(PersistenceCapable persistenceCapable, int i,
160                                  double v) {
161         if (!isLoaded(persistenceCapable, i)) {
162             throw BindingSupportImpl.getInstance().fieldDetached();
163         }
164         return v;
165     }
166
167     public String JavaDoc getStringField(PersistenceCapable persistenceCapable, int i,
168                                  String JavaDoc s) {
169         if (!isLoaded(persistenceCapable, i)) {
170             throw BindingSupportImpl.getInstance().fieldDetached();
171         }
172         return s;
173     }
174
175     public Object JavaDoc getObjectField(PersistenceCapable persistenceCapable, int i,
176                                  Object JavaDoc o) {
177         if (!isLoaded(persistenceCapable, i)) {
178             throw BindingSupportImpl.getInstance().fieldDetached();
179         }
180         return o;
181     }
182
183     public void setBooleanField(PersistenceCapable persistenceCapable, int i,
184                                 boolean b, boolean b1) {
185     }
186
187     public void setCharField(PersistenceCapable persistenceCapable, int i,
188                              char c, char c1) {
189     }
190
191     public void setByteField(PersistenceCapable persistenceCapable, int i,
192                              byte b, byte b1) {
193     }
194
195     public void setShortField(PersistenceCapable persistenceCapable, int i,
196                               short i1, short i2) {
197     }
198
199     public void setIntField(PersistenceCapable persistenceCapable, int i,
200                             int i1, int i2) {
201     }
202
203     public void setLongField(PersistenceCapable persistenceCapable, int i,
204                              long l, long l1) {
205     }
206
207     public void setFloatField(PersistenceCapable persistenceCapable, int i,
208                               float v, float v1) {
209     }
210
211     public void setDoubleField(PersistenceCapable persistenceCapable, int i,
212                                double v, double v1) {
213     }
214
215     public void setStringField(PersistenceCapable persistenceCapable, int i,
216                                String JavaDoc s, String JavaDoc s1) {
217     }
218
219     public void setObjectField(PersistenceCapable persistenceCapable, int i,
220                                Object JavaDoc o, Object JavaDoc o1) {
221     }
222
223     public void providedBooleanField(PersistenceCapable persistenceCapable,
224                                      int i, boolean b) {
225     }
226
227     public void providedCharField(PersistenceCapable persistenceCapable, int i,
228                                   char c) {
229     }
230
231     public void providedByteField(PersistenceCapable persistenceCapable, int i,
232                                   byte b) {
233     }
234
235     public void providedShortField(PersistenceCapable persistenceCapable,
236                                    int i, short i1) {
237     }
238
239     public void providedIntField(PersistenceCapable persistenceCapable, int i,
240                                  int i1) {
241     }
242
243     public void providedLongField(PersistenceCapable persistenceCapable, int i,
244                                   long l) {
245     }
246
247     public void providedFloatField(PersistenceCapable persistenceCapable,
248                                    int i, float v) {
249     }
250
251     public void providedDoubleField(PersistenceCapable persistenceCapable,
252                                     int i, double v) {
253     }
254
255     public void providedStringField(PersistenceCapable persistenceCapable,
256                                     int i, String JavaDoc s) {
257     }
258
259     public void providedObjectField(PersistenceCapable persistenceCapable,
260                                     int i, Object JavaDoc o) {
261         addObject(o);
262     }
263
264     private void addObject(Object JavaDoc o) {
265         if (o == null) return;
266         //todo this needs to change
267
if (o.getClass().isArray()) {
268             Class JavaDoc type = o.getClass().getComponentType();
269             if (type != null && !type.isPrimitive()) {
270                 int length = Array.getLength(o);
271                 for (int x = 0; x < length; x++) {
272                     addObject(Array.get(o, x));
273                 }
274             }
275         } else if (o instanceof Collection JavaDoc) {
276             Collection JavaDoc col = (Collection JavaDoc) o;
277             for (Iterator JavaDoc it = col.iterator(); it.hasNext();) {
278                 addObject((Object JavaDoc) it.next());
279             }
280         } else if (o instanceof Map JavaDoc) {
281             Map JavaDoc map = (Map JavaDoc) o;
282             for (Iterator JavaDoc it = map.keySet().iterator(); it.hasNext();) {
283                 addObject(it.next());
284             }
285             for (Iterator JavaDoc it = map.values().iterator(); it.hasNext();) {
286                 addObject(it.next());
287             }
288         } else if (o instanceof VersantDetachable) {
289             asc.addVersantDetachable((VersantDetachable) o);
290         }
291     }
292
293     public boolean replacingBooleanField(PersistenceCapable persistenceCapable,
294                                          int i) {
295         return false;
296     }
297
298     public char replacingCharField(PersistenceCapable persistenceCapable,
299                                    int i) {
300         return 0;
301     }
302
303     public byte replacingByteField(PersistenceCapable persistenceCapable,
304                                    int i) {
305         return 0;
306     }
307
308     public short replacingShortField(PersistenceCapable persistenceCapable,
309                                      int i) {
310         return 0;
311     }
312
313     public int replacingIntField(PersistenceCapable persistenceCapable, int i) {
314         return 0;
315     }
316
317     public long replacingLongField(PersistenceCapable persistenceCapable,
318                                    int i) {
319         return 0;
320     }
321
322     public float replacingFloatField(PersistenceCapable persistenceCapable,
323                                      int i) {
324         return 0;
325     }
326
327     public double replacingDoubleField(PersistenceCapable persistenceCapable,
328                                        int i) {
329         return 0;
330     }
331
332     public String JavaDoc replacingStringField(PersistenceCapable persistenceCapable,
333                                        int i) {
334         return null;
335     }
336
337     public Object JavaDoc replacingObjectField(PersistenceCapable persistenceCapable,
338                                        int i) {
339         return null;
340     }
341
342     public void makeDirty(PersistenceCapable pc,
343                           int managedFieldNo) {
344         ((VersantDetachable) pc).versantMakeDirty(managedFieldNo);
345     }
346
347     private OID getPcOID(PersistenceCapable persistenceCapable) {
348         return pm.extractOID(((VersantDetachable) persistenceCapable).versantGetOID());
349     }
350
351     public void fillNewAppPKField(int fieldNo) { }
352
353
354 }
355
Popular Tags