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 com.versant.core.metadata.ClassMetaData;
014: import com.versant.core.metadata.FetchGroup;
015: import com.versant.core.metadata.FieldMetaData;
016: import com.versant.core.metadata.ModelMetaData;
017: import com.versant.core.server.OIDGraph;
018:
019: import javax.jdo.spi.PersistenceCapable;
020: import java.io.ObjectInput;
021: import java.io.ObjectOutput;
022: import java.io.IOException;
023: import java.util.*;
024:
025: import com.versant.core.common.*;
026: import com.versant.core.util.IntArray;
027: import com.versant.core.util.OIDObjectOutput;
028: import com.versant.core.util.OIDObjectInput;
029:
030: /**
031: * This is a wrapper of the state instance to be used by the mem query classes.
032: */
033: public final class QueryStateWrapper extends State {
034:
035: private final PCStateMan pcStateMan;
036: private final PMProxy pm;
037: private ClassMetaData cmd;
038:
039: public QueryStateWrapper() {
040: pcStateMan = null;
041: pm = null;
042: }
043:
044: public boolean isCacheble() {
045: return false;
046: }
047:
048: public boolean isFieldNullorZero(int stateFieldNo) {
049: return false; //To change body of implemented methods use File | Settings | File Templates.
050: }
051:
052: public QueryStateWrapper(PCStateMan pcStateMan, PMProxy pm) {
053: this .pcStateMan = pcStateMan;
054: this .pm = pm;
055: }
056:
057: /**
058: * Return the internal value for the field.
059: */
060: public Object getInternalObjectField(int field) {
061: return pcStateMan.getObjectField(null,
062: cmd.stateFields[field].managedFieldNo, null);
063: }
064:
065: public Collection getInternalStateCollection(int field) {
066: Collection col = (Collection) getInternalObjectField(field);
067: int size = col == null ? 0 : col.size();
068: List results = new ArrayList(size);
069: if (size == 0) {
070: return results;
071: }
072: for (Iterator iterator = col.iterator(); iterator.hasNext();) {
073: PersistenceCapable pc = (PersistenceCapable) iterator
074: .next();
075: results.add(pm.getInternalSM(pc).queryStateWrapper);
076: }
077: return results;
078: }
079:
080: public boolean containsValidAppIdFields() {
081: return false;
082: }
083:
084: public void unmanageSCOFields() {
085: }
086:
087: public boolean checkKeyFields(OID oid) {
088: return true;
089: }
090:
091: public boolean containsKey(int field, Object key) {
092: FieldMetaData fmd = getCMD().stateFields[field];
093: if (fmd.keyTypeMetaData != null) {
094: Map map = ((Map) getInternalObjectField(field));
095: Set keys = map.keySet();
096: for (Iterator iterator = keys.iterator(); iterator
097: .hasNext();) {
098: PersistenceCapable capable = (PersistenceCapable) iterator
099: .next();
100: if (pm.getInternalOID(capable).equals(key)) {
101: return true;
102: }
103: }
104: } else {
105: return (((Map) getInternalObjectField(field))
106: .containsKey(key));
107: }
108: return false;
109: }
110:
111: public void setCmd(ClassMetaData cmd) {
112: this .cmd = cmd;
113: }
114:
115: private ClassMetaData getCMD() {
116: return cmd;
117: }
118:
119: public Collection getInternalOIDCollection(int field) {
120: Collection col = (Collection) getInternalObjectField(field);
121: int size = col == null ? 0 : col.size();
122: List results = new ArrayList(size);
123: if (size == 0) {
124: return results;
125: }
126: for (Iterator iterator = col.iterator(); iterator.hasNext();) {
127: PersistenceCapable pc = (PersistenceCapable) iterator
128: .next();
129: results.add(pm.getInternalSM(pc).oid);
130: }
131: return results;
132: }
133:
134: public Collection getInternalOIDValueCollectionForMap(int field) {
135: Collection col = ((Map) getInternalObjectField(field)).values();
136: int size = col == null ? 0 : col.size();
137: List results = new ArrayList(size);
138: if (size == 0) {
139: return results;
140: }
141: for (Iterator iterator = col.iterator(); iterator.hasNext();) {
142: PersistenceCapable pc = (PersistenceCapable) iterator
143: .next();
144: results.add(pm.getInternalSM(pc).oid);
145: }
146: return results;
147: }
148:
149: public Collection getInternalValueCollectionForMap(int field) {
150: Map m = (Map) getInternalObjectField(field);
151: return m.values();
152: }
153:
154: public OID getOID(int field) {
155: Object obj = getInternalObjectField(field);
156: if (obj instanceof PersistenceCapable) {
157: try {
158: obj = pm.getInternalOID((PersistenceCapable) obj);
159: } catch (Exception e) {
160: //ignore
161: obj = null;
162: }
163: }
164: return (OID) obj;
165: }
166:
167: public QueryStateWrapper getState(int field) {
168: QueryStateWrapper state = pm
169: .getInternalSM((PersistenceCapable) getInternalObjectField(field)).queryStateWrapper;
170: return state;
171: }
172:
173: public boolean getBooleanField(int field) {
174: return pcStateMan.getBooleanField(null,
175: cmd.stateFields[field].managedFieldNo, false);
176: }
177:
178: public char getCharField(int field) {
179: return pcStateMan.getCharField(null,
180: cmd.stateFields[field].managedFieldNo, (char) 0);
181: }
182:
183: public byte getByteField(int field) {
184: return pcStateMan.getByteField(null,
185: cmd.stateFields[field].managedFieldNo, (byte) 0);
186: }
187:
188: public short getShortField(int field) {
189: return pcStateMan.getShortField(null,
190: cmd.stateFields[field].managedFieldNo, (short) 0);
191: }
192:
193: public int getIntField(int field) {
194: return pcStateMan.getIntField(null,
195: cmd.stateFields[field].managedFieldNo, 0);
196: }
197:
198: public long getLongField(int field) {
199: return pcStateMan.getLongField(null,
200: cmd.stateFields[field].managedFieldNo, 0);
201: }
202:
203: public long getLongFieldInternal(int field) {
204: return getLongField(field);
205: }
206:
207: public float getFloatField(int field) {
208: return pcStateMan.getFloatField(null,
209: cmd.stateFields[field].managedFieldNo, 0);
210: }
211:
212: public double getDoubleField(int field) {
213: return pcStateMan.getDoubleField(null,
214: cmd.stateFields[field].managedFieldNo, 0);
215: }
216:
217: public String getStringField(int field) {
218: return pcStateMan.getStringField(null,
219: cmd.stateFields[field].managedFieldNo, null);
220: }
221:
222: public void writeExternal(ObjectOutput out) {
223: throw createBadMethodException();
224: }
225:
226: private RuntimeException createBadMethodException() {
227: return BindingSupportImpl.getInstance().internal(
228: "Should not be called");
229: }
230:
231: public void readExternal(ObjectInput in) {
232: throw createBadMethodException();
233: }
234:
235: public boolean isHollow() {
236: throw createBadMethodException();
237: }
238:
239: public State newInstance() {
240: throw createBadMethodException();
241: }
242:
243: public int getClassIndex() {
244: throw createBadMethodException();
245: }
246:
247: public ClassMetaData getClassMetaData(ModelMetaData jmd) {
248: throw createBadMethodException();
249: }
250:
251: public boolean isDirty() {
252: throw createBadMethodException();
253: }
254:
255: public boolean isDirty(int fieldNo) {
256: throw createBadMethodException();
257: }
258:
259: public void makeDirtyAbs(int fieldNo) {
260: throw createBadMethodException();
261: }
262:
263: public void clearDirtyFields() {
264: throw createBadMethodException();
265: }
266:
267: public void updateFrom(State state) {
268: throw createBadMethodException();
269: }
270:
271: public void updateNonFilled(State state) {
272: throw createBadMethodException();
273: }
274:
275: public int[] updateChanged(State state) {
276: throw createBadMethodException();
277: }
278:
279: public void clearNonAutoSetFields() {
280: throw createBadMethodException();
281: }
282:
283: public void retrieve(VersantPersistenceManagerImp sm) {
284: throw createBadMethodException();
285: }
286:
287: public void clearNonFilled(State state) {
288: throw createBadMethodException();
289: }
290:
291: public void clearCollectionFields() {
292: throw createBadMethodException();
293: }
294:
295: public void clearSCOFields() {
296: throw createBadMethodException();
297: }
298:
299: public void clearTransactionNonPersistentFields() {
300: throw createBadMethodException();
301: }
302:
303: public boolean fillToStoreState(State stateToStore,
304: PersistenceContext sm, VersantStateManager pcStateMan) {
305: throw createBadMethodException();
306: }
307:
308: public State getCopy() {
309: throw createBadMethodException();
310: }
311:
312: public void copyFieldsForOptimisticLocking(State state,
313: VersantPersistenceManagerImp sm) {
314: throw createBadMethodException();
315: }
316:
317: public void copyOptimisticLockingField(State state) {
318: throw createBadMethodException();
319: }
320:
321: public int replaceSCOFields(PersistenceCapable owner,
322: VersantPersistenceManagerImp sm, int[] absFieldNos) {
323: throw createBadMethodException();
324: }
325:
326: public void addRefs(VersantPersistenceManagerImp sm,
327: PCStateMan pcStateMan) {
328: throw createBadMethodException();
329: }
330:
331: public void clear() {
332: throw createBadMethodException();
333: }
334:
335: public void makeClean() {
336: throw createBadMethodException();
337: }
338:
339: public void setClassMetaData(ClassMetaData cmd) {
340: throw createBadMethodException();
341: }
342:
343: public ClassMetaData getClassMetaData() {
344: throw createBadMethodException();
345: }
346:
347: public boolean containsField(int stateFieldNo) {
348: throw createBadMethodException();
349: }
350:
351: public boolean containsFieldAbs(int absFieldNo) {
352: throw createBadMethodException();
353: }
354:
355: public boolean containFields(int[] stateFieldNos) {
356: throw createBadMethodException();
357: }
358:
359: public boolean containFieldsAbs(int[] absFieldNos) {
360: throw createBadMethodException();
361: }
362:
363: public boolean isEmpty() {
364: throw createBadMethodException();
365: }
366:
367: public boolean containsFetchGroup(FetchGroup fetchGroup) {
368: throw createBadMethodException();
369: }
370:
371: public int getFieldNos(int[] buf) {
372: throw createBadMethodException();
373: }
374:
375: public int getPass1FieldNos(int[] buf) {
376: throw createBadMethodException();
377: }
378:
379: public int getPass2FieldNos(int[] buf) {
380: throw createBadMethodException();
381: }
382:
383: public boolean containsPass1Fields() {
384: throw createBadMethodException();
385: }
386:
387: public boolean containsPass2Fields() {
388: throw createBadMethodException();
389: }
390:
391: public int compareToPass1(State state) {
392: throw createBadMethodException();
393: }
394:
395: public boolean hasSameFields(State state) {
396: throw createBadMethodException();
397: }
398:
399: public boolean hasSameNullFields(State state, State mask) {
400: throw createBadMethodException();
401: }
402:
403: public boolean isNull(int stateFieldNo) {
404: throw createBadMethodException();
405: }
406:
407: public boolean containsApplicationIdentityFields() {
408: throw createBadMethodException();
409: }
410:
411: public void clearApplicationIdentityFields() {
412: throw createBadMethodException();
413: }
414:
415: public void copyFields(OID oid) {
416: throw createBadMethodException();
417: }
418:
419: public boolean replaceNewObjectOIDs(int[] fieldNos,
420: int fieldNosLength) {
421: throw createBadMethodException();
422: }
423:
424: public void findDirectEdges(OIDGraph graph, IntArray edges) {
425: throw createBadMethodException();
426: }
427:
428: public void updateAutoSetFieldsCreated(Date now) {
429: throw createBadMethodException();
430: }
431:
432: public void updateAutoSetFieldsModified(Date now, State oldState) {
433: throw createBadMethodException();
434: }
435:
436: public void copyKeyFields(OID oid) {
437: throw createBadMethodException();
438: }
439:
440: public void copyKeyFieldsUpdate(OID oid) {
441: throw createBadMethodException();
442: }
443:
444: public boolean getBooleanFieldAbs(int absFieldNo) {
445: throw createBadMethodException();
446: }
447:
448: public char getCharFieldAbs(int field) {
449: throw createBadMethodException();
450: }
451:
452: public byte getByteFieldAbs(int field) {
453: throw createBadMethodException();
454: }
455:
456: public short getShortFieldAbs(int field) {
457: throw createBadMethodException();
458: }
459:
460: public int getIntFieldAbs(int field) {
461: throw createBadMethodException();
462: }
463:
464: public long getLongFieldAbs(int field) {
465: throw createBadMethodException();
466: }
467:
468: public float getFloatFieldAbs(int field) {
469: throw createBadMethodException();
470: }
471:
472: public double getDoubleFieldAbs(int field) {
473: throw createBadMethodException();
474: }
475:
476: public String getStringFieldAbs(int field) {
477: throw createBadMethodException();
478: }
479:
480: public Object getObjectField(int field,
481: PersistenceCapable owningPC, PersistenceContext sm, OID oid) {
482: throw createBadMethodException();
483: }
484:
485: public Object getObjectFieldAbs(int field,
486: PersistenceCapable owningPC, PersistenceContext sm, OID oid) {
487: throw createBadMethodException();
488: }
489:
490: public void setBooleanField(int field, boolean newValue) {
491: throw createBadMethodException();
492: }
493:
494: public void setBooleanFieldAbs(int field, boolean newValue) {
495: throw createBadMethodException();
496: }
497:
498: public void setCharField(int field, char newValue) {
499: throw createBadMethodException();
500: }
501:
502: public void setCharFieldAbs(int field, char newValue) {
503: throw createBadMethodException();
504: }
505:
506: public void setByteField(int field, byte newValue) {
507: throw createBadMethodException();
508: }
509:
510: public void setByteFieldAbs(int field, byte newValue) {
511: throw createBadMethodException();
512: }
513:
514: public void setShortField(int field, short newValue) {
515: throw createBadMethodException();
516: }
517:
518: public void setShortFieldAbs(int field, short newValue) {
519: throw createBadMethodException();
520: }
521:
522: public void setIntField(int field, int newValue) {
523: throw createBadMethodException();
524: }
525:
526: public void setIntFieldAbs(int field, int newValue) {
527: throw createBadMethodException();
528: }
529:
530: public void setLongField(int field, long newValue) {
531: throw createBadMethodException();
532: }
533:
534: public void setLongFieldAbs(int field, long newValue) {
535: throw createBadMethodException();
536: }
537:
538: public void setFloatField(int field, float newValue) {
539: throw createBadMethodException();
540: }
541:
542: public void setFloatFieldAbs(int field, float newValue) {
543: throw createBadMethodException();
544: }
545:
546: public void setDoubleField(int field, double newValue) {
547: throw createBadMethodException();
548: }
549:
550: public void setDoubleFieldAbs(int field, double newValue) {
551: throw createBadMethodException();
552: }
553:
554: public void setStringField(int field, String newValue) {
555: throw createBadMethodException();
556: }
557:
558: public void setStringFieldAbs(int field, String newValue) {
559: throw createBadMethodException();
560: }
561:
562: public void setObjectField(int field, Object newValue) {
563: throw createBadMethodException();
564: }
565:
566: public void setObjectFieldAbs(int field, Object newValue) {
567: throw createBadMethodException();
568: }
569:
570: public void setObjectFieldUnresolved(int field, Object newValue) {
571: throw createBadMethodException();
572: }
573:
574: public void setObjectFieldUnresolvedAbs(int field, Object newValue) {
575: throw createBadMethodException();
576: }
577:
578: public Object getInternalObjectFieldAbs(int field) {
579: throw createBadMethodException();
580: }
581:
582: public void setInternalBooleanField(int field, boolean newValue) {
583: throw createBadMethodException();
584: }
585:
586: public void setInternalBooleanFieldAbs(int field, boolean newValue) {
587: throw createBadMethodException();
588: }
589:
590: public void setInternalCharField(int field, char newValue) {
591: throw createBadMethodException();
592: }
593:
594: public void setInternalCharFieldAbs(int field, char newValue) {
595: throw createBadMethodException();
596: }
597:
598: public void setInternalByteField(int field, byte newValue) {
599: throw createBadMethodException();
600: }
601:
602: public void setInternalByteFieldAbs(int field, byte newValue) {
603: throw createBadMethodException();
604: }
605:
606: public void setInternalShortField(int field, short newValue) {
607: throw createBadMethodException();
608: }
609:
610: public void setInternalShortFieldAbs(int field, short newValue) {
611: throw createBadMethodException();
612: }
613:
614: public void setInternalIntField(int field, int newValue) {
615: throw createBadMethodException();
616: }
617:
618: public void setInternalIntFieldAbs(int field, int newValue) {
619: throw createBadMethodException();
620: }
621:
622: public void setInternalLongField(int field, long newValue) {
623: throw createBadMethodException();
624: }
625:
626: public void setInternalLongFieldAbs(int field, long newValue) {
627: throw createBadMethodException();
628: }
629:
630: public void setInternalFloatField(int field, float newValue) {
631: throw createBadMethodException();
632: }
633:
634: public void setInternalFloatFieldAbs(int field, float newValue) {
635: throw createBadMethodException();
636: }
637:
638: public void setInternalDoubleField(int field, double newValue) {
639: throw createBadMethodException();
640: }
641:
642: public void setInternalDoubleFieldAbs(int field, double newValue) {
643: throw createBadMethodException();
644: }
645:
646: public void setInternalStringField(int field, String newValue) {
647: throw createBadMethodException();
648: }
649:
650: public void setInternalStringFieldAbs(int field, String newValue) {
651: throw createBadMethodException();
652: }
653:
654: public void setInternalObjectField(int field, Object newValue) {
655: throw createBadMethodException();
656: }
657:
658: public void setInternalObjectFieldAbs(int field, Object newValue) {
659: throw createBadMethodException();
660: }
661:
662: public String getVersion() {
663: return Debug.VERSION;
664: }
665:
666: /**
667: * Is this state field nummber resolved for the Client
668: */
669: public boolean isResolvedForClient(int stateFieldNo) {
670: throw createBadMethodException();
671: }
672:
673: public Object getOptimisticLockingValue() {
674: throw createBadMethodException();
675: }
676:
677: public void setFilled(int field) {
678: throw createBadMethodException();
679: }
680:
681: public void fillForRead(State dest, VersantPersistenceManagerImp sm) {
682: throw createBadMethodException();
683: }
684:
685: public void clearFilledFlags() {
686: throw createBadMethodException();
687: }
688:
689: public int getPass1FieldRefFieldNosWithNewOids(int[] stateFieldNoBuf) {
690: throw createBadMethodException();
691: }
692:
693: public void deleteSecondaryFields(ArrayList arraylist) {
694: throw createBadMethodException();
695: }
696:
697: public void addOneToManyInverseFieldsForL2Evict(
698: VersantPersistenceManagerImp pm) {
699: throw createBadMethodException();
700: }
701:
702: public void writeExternal(OIDObjectOutput os) throws IOException {
703: throw createBadMethodException();
704: }
705:
706: public void readExternal(OIDObjectInput is) throws IOException,
707: ClassNotFoundException {
708: throw createBadMethodException();
709: }
710: }
|