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.common.OID;
014:
015: import javax.jdo.PersistenceManager;
016: import javax.jdo.spi.PersistenceCapable;
017: import javax.jdo.spi.StateManager;
018: import java.lang.reflect.Array;
019: import java.util.Collection;
020: import java.util.Iterator;
021: import java.util.Map;
022:
023: import com.versant.core.common.BindingSupportImpl;
024: import com.versant.core.common.OID;
025:
026: /**
027: *
028: */
029: public class AttachNavStateManager implements VersantStateManager {
030:
031: private VersantPersistenceManagerImp pm;
032: private AttachStateContainer asc;
033:
034: public AttachNavStateManager(VersantPersistenceManagerImp pm) {
035: this .pm = pm;
036: }
037:
038: public AttachNavStateManager(AttachStateContainer asc) {
039: this .asc = asc;
040: }
041:
042: public OID getOID() {
043: return null; //To change body of implemented methods use File | Settings | File Templates.
044: }
045:
046: public PersistenceCapable getPersistenceCapable() {
047: return null; //To change body of implemented methods use File | Settings | File Templates.
048: }
049:
050: public byte replacingFlags(PersistenceCapable persistenceCapable) {
051: return 0;
052: }
053:
054: public StateManager replacingStateManager(
055: PersistenceCapable persistenceCapable,
056: StateManager stateManager) {
057: return stateManager;
058: }
059:
060: public boolean isDirty(PersistenceCapable persistenceCapable) {
061: return ((VersantDetachable) persistenceCapable)
062: .versantIsDirty();
063: }
064:
065: public boolean isTransactional(PersistenceCapable persistenceCapable) {
066: return false;
067: }
068:
069: public boolean isPersistent(PersistenceCapable persistenceCapable) {
070: return false;
071: }
072:
073: public boolean isNew(PersistenceCapable persistenceCapable) {
074: return getPcOID(persistenceCapable).isNew();
075: }
076:
077: public boolean isDeleted(PersistenceCapable persistenceCapable) {
078: return false;
079: }
080:
081: public PersistenceManager getPersistenceManager(
082: PersistenceCapable persistenceCapable) {
083: return null;
084: }
085:
086: public void makeDirty(PersistenceCapable persistenceCapable,
087: String s) {
088: ((VersantDetachable) persistenceCapable).versantMakeDirty(s);
089: }
090:
091: public Object getObjectId(PersistenceCapable persistenceCapable) {
092: return getPcOID(persistenceCapable);
093: }
094:
095: public Object getTransactionalObjectId(
096: PersistenceCapable persistenceCapable) {
097: return null;
098: }
099:
100: public boolean isLoaded(PersistenceCapable persistenceCapable, int i) {
101: return ((VersantDetachable) persistenceCapable)
102: .versantIsLoaded(i);
103: }
104:
105: public void preSerialize(PersistenceCapable persistenceCapable) {
106:
107: }
108:
109: public boolean getBooleanField(
110: PersistenceCapable persistenceCapable, int i, boolean b) {
111: if (!isLoaded(persistenceCapable, i)) {
112: throw BindingSupportImpl.getInstance().fieldDetached();
113: }
114: return b;
115: }
116:
117: public char getCharField(PersistenceCapable persistenceCapable,
118: int i, char c) {
119: if (!isLoaded(persistenceCapable, i)) {
120: throw BindingSupportImpl.getInstance().fieldDetached();
121: }
122: return c;
123: }
124:
125: public byte getByteField(PersistenceCapable persistenceCapable,
126: int i, byte b) {
127: if (!isLoaded(persistenceCapable, i)) {
128: throw BindingSupportImpl.getInstance().fieldDetached();
129: }
130: return b;
131: }
132:
133: public short getShortField(PersistenceCapable persistenceCapable,
134: int i, short i1) {
135: if (!isLoaded(persistenceCapable, i)) {
136: throw BindingSupportImpl.getInstance().fieldDetached();
137: }
138: return i1;
139: }
140:
141: public int getIntField(PersistenceCapable persistenceCapable,
142: int i, int i1) {
143: if (!isLoaded(persistenceCapable, i)) {
144: throw BindingSupportImpl.getInstance().fieldDetached();
145: }
146: return i1;
147: }
148:
149: public long getLongField(PersistenceCapable persistenceCapable,
150: int i, long l) {
151: if (!isLoaded(persistenceCapable, i)) {
152: throw BindingSupportImpl.getInstance().fieldDetached();
153: }
154: return l;
155: }
156:
157: public float getFloatField(PersistenceCapable persistenceCapable,
158: int i, float v) {
159: if (!isLoaded(persistenceCapable, i)) {
160: throw BindingSupportImpl.getInstance().fieldDetached();
161: }
162: return v;
163: }
164:
165: public double getDoubleField(PersistenceCapable persistenceCapable,
166: int i, double v) {
167: if (!isLoaded(persistenceCapable, i)) {
168: throw BindingSupportImpl.getInstance().fieldDetached();
169: }
170: return v;
171: }
172:
173: public String getStringField(PersistenceCapable persistenceCapable,
174: int i, String s) {
175: if (!isLoaded(persistenceCapable, i)) {
176: throw BindingSupportImpl.getInstance().fieldDetached();
177: }
178: return s;
179: }
180:
181: public Object getObjectField(PersistenceCapable persistenceCapable,
182: int i, Object o) {
183: if (!isLoaded(persistenceCapable, i)) {
184: throw BindingSupportImpl.getInstance().fieldDetached();
185: }
186: return o;
187: }
188:
189: public void setBooleanField(PersistenceCapable persistenceCapable,
190: int i, boolean b, boolean b1) {
191: }
192:
193: public void setCharField(PersistenceCapable persistenceCapable,
194: int i, char c, char c1) {
195: }
196:
197: public void setByteField(PersistenceCapable persistenceCapable,
198: int i, byte b, byte b1) {
199: }
200:
201: public void setShortField(PersistenceCapable persistenceCapable,
202: int i, short i1, short i2) {
203: }
204:
205: public void setIntField(PersistenceCapable persistenceCapable,
206: int i, int i1, int i2) {
207: }
208:
209: public void setLongField(PersistenceCapable persistenceCapable,
210: int i, long l, long l1) {
211: }
212:
213: public void setFloatField(PersistenceCapable persistenceCapable,
214: int i, float v, float v1) {
215: }
216:
217: public void setDoubleField(PersistenceCapable persistenceCapable,
218: int i, double v, double v1) {
219: }
220:
221: public void setStringField(PersistenceCapable persistenceCapable,
222: int i, String s, String s1) {
223: }
224:
225: public void setObjectField(PersistenceCapable persistenceCapable,
226: int i, Object o, Object o1) {
227: }
228:
229: public void providedBooleanField(
230: PersistenceCapable persistenceCapable, int i, boolean b) {
231: }
232:
233: public void providedCharField(
234: PersistenceCapable persistenceCapable, int i, char c) {
235: }
236:
237: public void providedByteField(
238: PersistenceCapable persistenceCapable, int i, byte b) {
239: }
240:
241: public void providedShortField(
242: PersistenceCapable persistenceCapable, int i, short i1) {
243: }
244:
245: public void providedIntField(PersistenceCapable persistenceCapable,
246: int i, int i1) {
247: }
248:
249: public void providedLongField(
250: PersistenceCapable persistenceCapable, int i, long l) {
251: }
252:
253: public void providedFloatField(
254: PersistenceCapable persistenceCapable, int i, float v) {
255: }
256:
257: public void providedDoubleField(
258: PersistenceCapable persistenceCapable, int i, double v) {
259: }
260:
261: public void providedStringField(
262: PersistenceCapable persistenceCapable, int i, String s) {
263: }
264:
265: public void providedObjectField(
266: PersistenceCapable persistenceCapable, int i, Object o) {
267: addObject(o);
268: }
269:
270: private void addObject(Object o) {
271: if (o == null)
272: return;
273: //todo this needs to change
274: if (o.getClass().isArray()) {
275: Class type = o.getClass().getComponentType();
276: if (type != null && !type.isPrimitive()) {
277: int length = Array.getLength(o);
278: for (int x = 0; x < length; x++) {
279: addObject(Array.get(o, x));
280: }
281: }
282: } else if (o instanceof Collection) {
283: Collection col = (Collection) o;
284: for (Iterator it = col.iterator(); it.hasNext();) {
285: addObject((Object) it.next());
286: }
287: } else if (o instanceof Map) {
288: Map map = (Map) o;
289: for (Iterator it = map.keySet().iterator(); it.hasNext();) {
290: addObject(it.next());
291: }
292: for (Iterator it = map.values().iterator(); it.hasNext();) {
293: addObject(it.next());
294: }
295: } else if (o instanceof VersantDetachable) {
296: asc.addVersantDetachable((VersantDetachable) o);
297: }
298: }
299:
300: public boolean replacingBooleanField(
301: PersistenceCapable persistenceCapable, int i) {
302: return false;
303: }
304:
305: public char replacingCharField(
306: PersistenceCapable persistenceCapable, int i) {
307: return 0;
308: }
309:
310: public byte replacingByteField(
311: PersistenceCapable persistenceCapable, int i) {
312: return 0;
313: }
314:
315: public short replacingShortField(
316: PersistenceCapable persistenceCapable, int i) {
317: return 0;
318: }
319:
320: public int replacingIntField(PersistenceCapable persistenceCapable,
321: int i) {
322: return 0;
323: }
324:
325: public long replacingLongField(
326: PersistenceCapable persistenceCapable, int i) {
327: return 0;
328: }
329:
330: public float replacingFloatField(
331: PersistenceCapable persistenceCapable, int i) {
332: return 0;
333: }
334:
335: public double replacingDoubleField(
336: PersistenceCapable persistenceCapable, int i) {
337: return 0;
338: }
339:
340: public String replacingStringField(
341: PersistenceCapable persistenceCapable, int i) {
342: return null;
343: }
344:
345: public Object replacingObjectField(
346: PersistenceCapable persistenceCapable, int i) {
347: return null;
348: }
349:
350: public void makeDirty(PersistenceCapable pc, int managedFieldNo) {
351: ((VersantDetachable) pc).versantMakeDirty(managedFieldNo);
352: }
353:
354: private OID getPcOID(PersistenceCapable persistenceCapable) {
355: return pm.extractOID(((VersantDetachable) persistenceCapable)
356: .versantGetOID());
357: }
358:
359: public void fillNewAppPKField(int fieldNo) {
360: }
361:
362: }
|