KickJava   Java API By Example, From Geeks To Geeks.

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


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.metadata.ClassMetaData;
15 import com.versant.core.metadata.FetchGroup;
16 import com.versant.core.metadata.FieldMetaData;
17 import com.versant.core.metadata.ModelMetaData;
18 import com.versant.core.server.OIDGraph;
19
20 import javax.jdo.spi.PersistenceCapable;
21 import java.io.ObjectInput JavaDoc;
22 import java.io.ObjectOutput JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.*;
25
26 import com.versant.core.common.*;
27 import com.versant.core.util.IntArray;
28 import com.versant.core.util.OIDObjectOutput;
29 import com.versant.core.util.OIDObjectInput;
30
31 /**
32  * This is a wrapper of the state instance to be used by the mem query classes.
33  */

34 public final class QueryStateWrapper extends State {
35
36     private final PCStateMan pcStateMan;
37     private final PMProxy pm;
38     private ClassMetaData cmd;
39
40     public QueryStateWrapper() {
41         pcStateMan = null;
42         pm = null;
43     }
44
45     public boolean isCacheble() {
46         return false;
47     }
48
49     public boolean isFieldNullorZero(int stateFieldNo) {
50         return false; //To change body of implemented methods use File | Settings | File Templates.
51
}
52
53     public QueryStateWrapper(PCStateMan pcStateMan, PMProxy pm) {
54         this.pcStateMan = pcStateMan;
55         this.pm = pm;
56     }
57
58     /**
59      * Return the internal value for the field.
60      */

61     public Object JavaDoc getInternalObjectField(int field) {
62         return pcStateMan.getObjectField(null,
63                 cmd.stateFields[field].managedFieldNo, null);
64     }
65
66     public Collection getInternalStateCollection(int field) {
67         Collection col = (Collection)getInternalObjectField(field);
68         int size = col == null ? 0 : col.size();
69         List results = new ArrayList(size);
70         if (size == 0) {
71             return results;
72         }
73         for (Iterator iterator = col.iterator(); iterator.hasNext();) {
74             PersistenceCapable pc = (PersistenceCapable)iterator.next();
75             results.add(pm.getInternalSM(pc).queryStateWrapper);
76         }
77         return results;
78     }
79
80     public boolean containsValidAppIdFields() {
81         return false;
82     }
83
84     public void unmanageSCOFields() {
85     }
86
87     public boolean checkKeyFields(OID oid) {
88         return true;
89     }
90
91     public boolean containsKey(int field, Object JavaDoc key) {
92         FieldMetaData fmd = getCMD().stateFields[field];
93         if (fmd.keyTypeMetaData != null) {
94             Map map = ((Map)getInternalObjectField(field));
95             Set keys = map.keySet();
96             for (Iterator iterator = keys.iterator(); iterator.hasNext();) {
97                 PersistenceCapable capable = (PersistenceCapable)iterator.next();
98                 if (pm.getInternalOID(capable).equals(key)) {
99                     return true;
100                 }
101             }
102         } else {
103             return (((Map)getInternalObjectField(field)).containsKey(key));
104         }
105         return false;
106     }
107
108     public void setCmd(ClassMetaData cmd) {
109         this.cmd = cmd;
110     }
111
112     private ClassMetaData getCMD() {
113         return cmd;
114     }
115
116     public Collection getInternalOIDCollection(int field) {
117         Collection col = (Collection)getInternalObjectField(field);
118         int size = col == null ? 0 : col.size();
119         List results = new ArrayList(size);
120         if (size == 0) {
121             return results;
122         }
123         for (Iterator iterator = col.iterator(); iterator.hasNext();) {
124             PersistenceCapable pc = (PersistenceCapable)iterator.next();
125             results.add(pm.getInternalSM(pc).oid);
126         }
127         return results;
128     }
129
130     public Collection getInternalOIDValueCollectionForMap(int field) {
131         Collection col = ((Map)getInternalObjectField(field)).values();
132         int size = col == null ? 0 : col.size();
133         List results = new ArrayList(size);
134         if (size == 0) {
135             return results;
136         }
137         for (Iterator iterator = col.iterator(); iterator.hasNext();) {
138             PersistenceCapable pc = (PersistenceCapable)iterator.next();
139             results.add(pm.getInternalSM(pc).oid);
140         }
141         return results;
142     }
143
144     public Collection getInternalValueCollectionForMap(int field) {
145         Map m = (Map)getInternalObjectField(field);
146         return m.values();
147     }
148
149     public OID getOID(int field) {
150         Object JavaDoc obj = getInternalObjectField(field);
151         if (obj instanceof PersistenceCapable) {
152             try {
153                 obj = pm.getInternalOID((PersistenceCapable)obj);
154             } catch (Exception JavaDoc e) {
155                 //ignore
156
obj = null;
157             }
158         }
159         return (OID)obj;
160     }
161
162     public QueryStateWrapper getState(int field) {
163         QueryStateWrapper state = pm.getInternalSM(
164                 (PersistenceCapable)getInternalObjectField(field)).queryStateWrapper;
165         return state;
166     }
167
168     public boolean getBooleanField(int field) {
169         return pcStateMan.getBooleanField(null,
170                 cmd.stateFields[field].managedFieldNo, false);
171     }
172
173     public char getCharField(int field) {
174         return pcStateMan.getCharField(null,
175                 cmd.stateFields[field].managedFieldNo, (char)0);
176     }
177
178     public byte getByteField(int field) {
179         return pcStateMan.getByteField(null,
180                 cmd.stateFields[field].managedFieldNo, (byte)0);
181     }
182
183     public short getShortField(int field) {
184         return pcStateMan.getShortField(null,
185                 cmd.stateFields[field].managedFieldNo, (short)0);
186     }
187
188     public int getIntField(int field) {
189         return pcStateMan.getIntField(null,
190                 cmd.stateFields[field].managedFieldNo, 0);
191     }
192
193     public long getLongField(int field) {
194         return pcStateMan.getLongField(null,
195                 cmd.stateFields[field].managedFieldNo, 0);
196     }
197
198     public long getLongFieldInternal(int field) {
199         return getLongField(field);
200     }
201
202     public float getFloatField(int field) {
203         return pcStateMan.getFloatField(null,
204                 cmd.stateFields[field].managedFieldNo, 0);
205     }
206
207     public double getDoubleField(int field) {
208         return pcStateMan.getDoubleField(null,
209                 cmd.stateFields[field].managedFieldNo, 0);
210     }
211
212     public String JavaDoc getStringField(int field) {
213         return pcStateMan.getStringField(null,
214                 cmd.stateFields[field].managedFieldNo, null);
215     }
216
217     public void writeExternal(ObjectOutput JavaDoc out) {
218         throw createBadMethodException();
219     }
220
221     private RuntimeException JavaDoc createBadMethodException() {
222         return BindingSupportImpl.getInstance().internal(
223                 "Should not be called");
224     }
225
226     public void readExternal(ObjectInput JavaDoc in) {
227         throw createBadMethodException();
228     }
229
230     public boolean isHollow() {
231         throw createBadMethodException();
232     }
233
234     public State newInstance() {
235         throw createBadMethodException();
236     }
237
238     public int getClassIndex() {
239         throw createBadMethodException();
240     }
241
242     public ClassMetaData getClassMetaData(ModelMetaData jmd) {
243         throw createBadMethodException();
244     }
245
246     public boolean isDirty() {
247         throw createBadMethodException();
248     }
249
250     public boolean isDirty(int fieldNo) {
251         throw createBadMethodException();
252     }
253
254     public void makeDirtyAbs(int fieldNo) {
255         throw createBadMethodException();
256     }
257
258     public void clearDirtyFields() {
259         throw createBadMethodException();
260     }
261
262     public void updateFrom(State state) {
263         throw createBadMethodException();
264     }
265
266     public void updateNonFilled(State state) {
267         throw createBadMethodException();
268     }
269
270     public int[] updateChanged(State state) {
271         throw createBadMethodException();
272     }
273
274     public void clearNonAutoSetFields() {
275         throw createBadMethodException();
276     }
277
278     public void retrieve(VersantPersistenceManagerImp sm) {
279         throw createBadMethodException();
280     }
281
282     public void clearNonFilled(State state) {
283         throw createBadMethodException();
284     }
285
286     public void clearCollectionFields() {
287         throw createBadMethodException();
288     }
289
290     public void clearSCOFields() {
291         throw createBadMethodException();
292     }
293
294     public void clearTransactionNonPersistentFields() {
295         throw createBadMethodException();
296     }
297
298     public boolean fillToStoreState(State stateToStore, PersistenceContext sm,
299             VersantStateManager pcStateMan) {
300         throw createBadMethodException();
301     }
302
303     public State getCopy() {
304         throw createBadMethodException();
305     }
306
307     public void copyFieldsForOptimisticLocking(State state,
308             VersantPersistenceManagerImp sm) {
309         throw createBadMethodException();
310     }
311
312     public void copyOptimisticLockingField(State state) {
313         throw createBadMethodException();
314     }
315
316     public int replaceSCOFields(PersistenceCapable owner,
317             VersantPersistenceManagerImp sm, int[] absFieldNos) {
318         throw createBadMethodException();
319     }
320
321     public void addRefs(VersantPersistenceManagerImp sm, PCStateMan pcStateMan) {
322         throw createBadMethodException();
323     }
324
325     public void clear() {
326         throw createBadMethodException();
327     }
328
329     public void makeClean() {
330         throw createBadMethodException();
331     }
332
333     public void setClassMetaData(ClassMetaData cmd) {
334         throw createBadMethodException();
335     }
336
337     public ClassMetaData getClassMetaData() {
338         throw createBadMethodException();
339     }
340
341     public boolean containsField(int stateFieldNo) {
342         throw createBadMethodException();
343     }
344
345     public boolean containsFieldAbs(int absFieldNo) {
346         throw createBadMethodException();
347     }
348
349     public boolean containFields(int[] stateFieldNos) {
350         throw createBadMethodException();
351     }
352
353     public boolean containFieldsAbs(int[] absFieldNos) {
354         throw createBadMethodException();
355     }
356
357     public boolean isEmpty() {
358         throw createBadMethodException();
359     }
360
361     public boolean containsFetchGroup(FetchGroup fetchGroup) {
362         throw createBadMethodException();
363     }
364
365     public int getFieldNos(int[] buf) {
366         throw createBadMethodException();
367     }
368
369     public int getPass1FieldNos(int[] buf) {
370         throw createBadMethodException();
371     }
372
373     public int getPass2FieldNos(int[] buf) {
374         throw createBadMethodException();
375     }
376
377     public boolean containsPass1Fields() {
378         throw createBadMethodException();
379     }
380
381     public boolean containsPass2Fields() {
382         throw createBadMethodException();
383     }
384
385     public int compareToPass1(State state) {
386         throw createBadMethodException();
387     }
388
389     public boolean hasSameFields(State state) {
390         throw createBadMethodException();
391     }
392
393     public boolean hasSameNullFields(State state, State mask) {
394         throw createBadMethodException();
395     }
396
397     public boolean isNull(int stateFieldNo) {
398         throw createBadMethodException();
399     }
400
401     public boolean containsApplicationIdentityFields() {
402         throw createBadMethodException();
403     }
404
405     public void clearApplicationIdentityFields() {
406         throw createBadMethodException();
407     }
408
409     public void copyFields(OID oid) {
410         throw createBadMethodException();
411     }
412
413     public boolean replaceNewObjectOIDs(int[] fieldNos, int fieldNosLength) {
414         throw createBadMethodException();
415     }
416
417     public void findDirectEdges(OIDGraph graph,
418             IntArray edges) {
419         throw createBadMethodException();
420     }
421
422     public void updateAutoSetFieldsCreated(Date now) {
423         throw createBadMethodException();
424     }
425
426     public void updateAutoSetFieldsModified(Date now, State oldState) {
427         throw createBadMethodException();
428     }
429
430     public void copyKeyFields(OID oid) {
431         throw createBadMethodException();
432     }
433
434     public void copyKeyFieldsUpdate(OID oid) {
435         throw createBadMethodException();
436     }
437
438     public boolean getBooleanFieldAbs(int absFieldNo) {
439         throw createBadMethodException();
440     }
441
442     public char getCharFieldAbs(int field) {
443         throw createBadMethodException();
444     }
445
446     public byte getByteFieldAbs(int field) {
447         throw createBadMethodException();
448     }
449
450     public short getShortFieldAbs(int field) {
451         throw createBadMethodException();
452     }
453
454     public int getIntFieldAbs(int field) {
455         throw createBadMethodException();
456     }
457
458     public long getLongFieldAbs(int field) {
459         throw createBadMethodException();
460     }
461
462     public float getFloatFieldAbs(int field) {
463         throw createBadMethodException();
464     }
465
466     public double getDoubleFieldAbs(int field) {
467         throw createBadMethodException();
468     }
469
470     public String JavaDoc getStringFieldAbs(int field) {
471         throw createBadMethodException();
472     }
473
474     public Object JavaDoc getObjectField(int field, PersistenceCapable owningPC,
475             PersistenceContext sm, OID oid) {
476         throw createBadMethodException();
477     }
478
479     public Object JavaDoc getObjectFieldAbs(int field, PersistenceCapable owningPC,
480             PersistenceContext sm, OID oid) {
481         throw createBadMethodException();
482     }
483
484     public void setBooleanField(int field, boolean newValue) {
485         throw createBadMethodException();
486     }
487
488     public void setBooleanFieldAbs(int field, boolean newValue) {
489         throw createBadMethodException();
490     }
491
492     public void setCharField(int field, char newValue) {
493         throw createBadMethodException();
494     }
495
496     public void setCharFieldAbs(int field, char newValue) {
497         throw createBadMethodException();
498     }
499
500     public void setByteField(int field, byte newValue) {
501         throw createBadMethodException();
502     }
503
504     public void setByteFieldAbs(int field, byte newValue) {
505         throw createBadMethodException();
506     }
507
508     public void setShortField(int field, short newValue) {
509         throw createBadMethodException();
510     }
511
512     public void setShortFieldAbs(int field, short newValue) {
513         throw createBadMethodException();
514     }
515
516     public void setIntField(int field, int newValue) {
517         throw createBadMethodException();
518     }
519
520     public void setIntFieldAbs(int field, int newValue) {
521         throw createBadMethodException();
522     }
523
524     public void setLongField(int field, long newValue) {
525         throw createBadMethodException();
526     }
527
528     public void setLongFieldAbs(int field, long newValue) {
529         throw createBadMethodException();
530     }
531
532     public void setFloatField(int field, float newValue) {
533         throw createBadMethodException();
534     }
535
536     public void setFloatFieldAbs(int field, float newValue) {
537         throw createBadMethodException();
538     }
539
540     public void setDoubleField(int field, double newValue) {
541         throw createBadMethodException();
542     }
543
544     public void setDoubleFieldAbs(int field, double newValue) {
545         throw createBadMethodException();
546     }
547
548     public void setStringField(int field, String JavaDoc newValue) {
549         throw createBadMethodException();
550     }
551
552     public void setStringFieldAbs(int field, String JavaDoc newValue) {
553         throw createBadMethodException();
554     }
555
556     public void setObjectField(int field, Object JavaDoc newValue) {
557         throw createBadMethodException();
558     }
559
560     public void setObjectFieldAbs(int field, Object JavaDoc newValue) {
561         throw createBadMethodException();
562     }
563
564     public void setObjectFieldUnresolved(int field, Object JavaDoc newValue) {
565         throw createBadMethodException();
566     }
567
568     public void setObjectFieldUnresolvedAbs(int field, Object JavaDoc newValue) {
569         throw createBadMethodException();
570     }
571
572     public Object JavaDoc getInternalObjectFieldAbs(int field) {
573         throw createBadMethodException();
574     }
575
576     public void setInternalBooleanField(int field, boolean newValue) {
577         throw createBadMethodException();
578     }
579
580     public void setInternalBooleanFieldAbs(int field, boolean newValue) {
581         throw createBadMethodException();
582     }
583
584     public void setInternalCharField(int field, char newValue) {
585         throw createBadMethodException();
586     }
587
588     public void setInternalCharFieldAbs(int field, char newValue) {
589         throw createBadMethodException();
590     }
591
592     public void setInternalByteField(int field, byte newValue) {
593         throw createBadMethodException();
594     }
595
596     public void setInternalByteFieldAbs(int field, byte newValue) {
597         throw createBadMethodException();
598     }
599
600     public void setInternalShortField(int field, short newValue) {
601         throw createBadMethodException();
602     }
603
604     public void setInternalShortFieldAbs(int field, short newValue) {
605         throw createBadMethodException();
606     }
607
608     public void setInternalIntField(int field, int newValue) {
609         throw createBadMethodException();
610     }
611
612     public void setInternalIntFieldAbs(int field, int newValue) {
613         throw createBadMethodException();
614     }
615
616     public void setInternalLongField(int field, long newValue) {
617         throw createBadMethodException();
618     }
619
620     public void setInternalLongFieldAbs(int field, long newValue) {
621         throw createBadMethodException();
622     }
623
624     public void setInternalFloatField(int field, float newValue) {
625         throw createBadMethodException();
626     }
627
628     public void setInternalFloatFieldAbs(int field, float newValue) {
629         throw createBadMethodException();
630     }
631
632     public void setInternalDoubleField(int field, double newValue) {
633         throw createBadMethodException();
634     }
635
636     public void setInternalDoubleFieldAbs(int field, double newValue) {
637         throw createBadMethodException();
638     }
639
640     public void setInternalStringField(int field, String JavaDoc newValue) {
641         throw createBadMethodException();
642     }
643
644     public void setInternalStringFieldAbs(int field, String JavaDoc newValue) {
645         throw createBadMethodException();
646     }
647
648     public void setInternalObjectField(int field, Object JavaDoc newValue) {
649         throw createBadMethodException();
650     }
651
652     public void setInternalObjectFieldAbs(int field, Object JavaDoc newValue) {
653         throw createBadMethodException();
654     }
655
656     public String JavaDoc getVersion() {
657         return Debug.VERSION;
658     }
659
660     /**
661      * Is this state field nummber resolved for the Client
662      */

663     public boolean isResolvedForClient(int stateFieldNo) {
664         throw createBadMethodException();
665     }
666
667     public Object JavaDoc getOptimisticLockingValue() {
668         throw createBadMethodException();
669     }
670
671     public void setFilled(int field) {
672         throw createBadMethodException();
673     }
674
675     public void fillForRead(State dest,
676             VersantPersistenceManagerImp sm) {
677         throw createBadMethodException();
678     }
679
680     public void clearFilledFlags() {
681         throw createBadMethodException();
682     }
683
684     public int getPass1FieldRefFieldNosWithNewOids(int[] stateFieldNoBuf) {
685         throw createBadMethodException();
686     }
687
688     public void deleteSecondaryFields(ArrayList arraylist) {
689         throw createBadMethodException();
690     }
691
692     public void addOneToManyInverseFieldsForL2Evict(
693             VersantPersistenceManagerImp pm) {
694         throw createBadMethodException();
695     }
696
697     public void writeExternal(OIDObjectOutput os) throws IOException JavaDoc {
698         throw createBadMethodException();
699     }
700
701     public void readExternal(OIDObjectInput is) throws IOException JavaDoc,
702             ClassNotFoundException JavaDoc {
703         throw createBadMethodException();
704     }
705 }
706
Popular Tags