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.BindingSupportImpl;
014: import com.versant.core.metadata.FieldMetaData;
015: import com.versant.core.metadata.ClassMetaData;
016: import com.versant.core.metadata.ModelMetaData;
017:
018: import javax.jdo.spi.StateManager;
019: import javax.jdo.spi.PersistenceCapable;
020: import javax.jdo.spi.JDOImplHelper;
021: import javax.jdo.PersistenceManager;
022:
023: /**
024: */
025: public class EmbeddedStateManager implements StateManager {
026: public PCStateMan owner;
027: public PersistenceCapable pc;
028: public ClassMetaData cmd;
029: public ModelMetaData jmd;
030: public FieldMetaData owningFmd;
031: /**
032: * field to replace the flags of the pc instance.
033: */
034: private byte jdoFlags = PersistenceCapable.LOAD_REQUIRED;
035:
036: public EmbeddedStateManager(PCStateMan owner, ModelMetaData jmd,
037: JDOImplHelper jdoImplHelper, FieldMetaData fmd) {
038: Class cls = fmd.typeMetaData.cls;
039: owningFmd = fmd;
040: this .jmd = jmd;
041: this .owner = owner;
042: pc = jdoImplHelper.newInstance(cls, this );
043: cmd = jmd.getClassMetaData(cls);
044: }
045:
046: public EmbeddedStateManager(PCStateMan owner,
047: PersistenceCapable pc, ModelMetaData jmd, FieldMetaData fmd) {
048: this .owningFmd = fmd;
049: this .jmd = jmd;
050: this .owner = owner;
051: this .pc = pc;
052: cmd = jmd.getClassMetaData(pc.getClass());
053: }
054:
055: public void setLoadRequired() {
056: jdoFlags = PersistenceCapable.LOAD_REQUIRED;
057: pc.jdoReplaceFlags();
058: }
059:
060: public byte replacingFlags(PersistenceCapable pc) {
061: return jdoFlags;
062: }
063:
064: public StateManager replacingStateManager(PersistenceCapable pc,
065: StateManager sm) {
066: return sm;
067: }
068:
069: public boolean isDirty(PersistenceCapable pc) {
070: return owner.isDirty();
071: }
072:
073: public boolean isTransactional(PersistenceCapable pc) {
074: return owner.isTransactional(pc);
075: }
076:
077: public boolean isPersistent(PersistenceCapable pc) {
078: return owner.isPersistent(pc);
079: }
080:
081: public boolean isNew(PersistenceCapable pc) {
082: return owner.isNew(pc);
083: }
084:
085: public boolean isDeleted(PersistenceCapable pc) {
086: return owner.isDeleted(pc);
087: }
088:
089: public PersistenceManager getPersistenceManager(
090: PersistenceCapable pc) {
091: return owner.getPersistenceManager(pc);
092: }
093:
094: public void makeDirty(PersistenceCapable pc, String fieldName) {
095: owner.makeDirty(pc, fieldName);
096: }
097:
098: public Object getObjectId(PersistenceCapable pc) {
099: throwNotImplemented();
100: return null; //To change body of implemented methods use File | Settings | File Templates.
101: }
102:
103: public Object getTransactionalObjectId(PersistenceCapable pc) {
104: throwNotImplemented();
105: return null; //To change body of implemented methods use File | Settings | File Templates.
106: }
107:
108: public boolean isLoaded(PersistenceCapable pc, int field) {
109: return owner.isLoaded(pc, getFmd(field));
110: }
111:
112: public void preSerialize(PersistenceCapable pc) {
113: throwNotImplemented();
114: }
115:
116: public boolean getBooleanField(PersistenceCapable pc, int field,
117: boolean currentValue) {
118: return owner
119: .getBooleanFieldImp(pc, getFmd(field), currentValue);
120: }
121:
122: public char getCharField(PersistenceCapable pc, int field,
123: char currentValue) {
124: return owner.getCharFieldImp(pc, getFmd(field), currentValue);
125: }
126:
127: public byte getByteField(PersistenceCapable pc, int field,
128: byte currentValue) {
129: return owner.getByteFieldImp(pc, getFmd(field), currentValue);
130: }
131:
132: public short getShortField(PersistenceCapable pc, int field,
133: short currentValue) {
134: return owner.getShortFieldImp(pc, getFmd(field), currentValue);
135: }
136:
137: public int getIntField(PersistenceCapable pc, int field,
138: int currentValue) {
139: return owner.getIntFieldImp(pc, getFmd(field), currentValue);
140: }
141:
142: public long getLongField(PersistenceCapable pc, int field,
143: long currentValue) {
144: return owner.getLongFieldImp(pc, getFmd(field), currentValue);
145: }
146:
147: public float getFloatField(PersistenceCapable pc, int field,
148: float currentValue) {
149: return owner.getFloatFieldImp(pc, getFmd(field), currentValue);
150: }
151:
152: public double getDoubleField(PersistenceCapable pc, int field,
153: double currentValue) {
154: return owner.getDoubleFieldImp(pc, getFmd(field), currentValue);
155: }
156:
157: public String getStringField(PersistenceCapable pc, int field,
158: String currentValue) {
159: return owner.getStringFieldImp(pc, getFmd(field), currentValue);
160: }
161:
162: public Object getObjectField(PersistenceCapable pc, int field,
163: Object currentValue) {
164: return owner.getObjectFieldImp(pc, getFmd(field), currentValue);
165: }
166:
167: public void setBooleanField(PersistenceCapable pc, int field,
168: boolean currentValue, boolean newValue) {
169: owner.setBooleanFieldImp(this .pc, getFmd(field), currentValue,
170: newValue);
171: pc.jdoReplaceField(field);
172: }
173:
174: public void setCharField(PersistenceCapable pc, int field,
175: char currentValue, char newValue) {
176: owner.setCharFieldImp(this .pc, getFmd(field), currentValue,
177: newValue);
178: pc.jdoReplaceField(field);
179: }
180:
181: public void setByteField(PersistenceCapable pc, int field,
182: byte currentValue, byte newValue) {
183: owner.setByteFieldImp(this .pc, getFmd(field), currentValue,
184: newValue);
185: pc.jdoReplaceField(field);
186: }
187:
188: public void setShortField(PersistenceCapable pc, int field,
189: short currentValue, short newValue) {
190: owner.setShortFieldImp(this .pc, getFmd(field), currentValue,
191: newValue);
192: pc.jdoReplaceField(field);
193: }
194:
195: public void setIntField(PersistenceCapable pc, int field,
196: int currentValue, int newValue) {
197: owner.setIntFieldImp(this .pc, getFmd(field), currentValue,
198: newValue);
199: pc.jdoReplaceField(field);
200: }
201:
202: public void setLongField(PersistenceCapable pc, int field,
203: long currentValue, long newValue) {
204: owner.setLongFieldImp(this .pc, getFmd(field), currentValue,
205: newValue);
206: pc.jdoReplaceField(field);
207: }
208:
209: public void setFloatField(PersistenceCapable pc, int field,
210: float currentValue, float newValue) {
211: owner.setFloatFieldImp(this .pc, getFmd(field), currentValue,
212: newValue);
213: pc.jdoReplaceField(field);
214: }
215:
216: public void setDoubleField(PersistenceCapable pc, int field,
217: double currentValue, double newValue) {
218: owner.setDoubleFieldImp(this .pc, getFmd(field), currentValue,
219: newValue);
220: pc.jdoReplaceField(field);
221: }
222:
223: public void setStringField(PersistenceCapable pc, int field,
224: String currentValue, String newValue) {
225: owner.setStringFieldImp(this .pc, getFmd(field), currentValue,
226: newValue);
227: pc.jdoReplaceField(field);
228: }
229:
230: public void setObjectField(PersistenceCapable pc, int field,
231: Object currentValue, Object newValue) {
232: owner.setObjectFieldImp(this .pc, getFmd(field), currentValue,
233: newValue);
234: pc.jdoReplaceField(field);
235: }
236:
237: private FieldMetaData getFmd(int fieldNo) {
238: return owningFmd.managedEmbeddedFields[fieldNo];
239: // FieldMetaData rFmd = cmd.managedFields[fieldNo];
240: // FieldMetaData[] fmds = owningFmd.embeddedFmds;
241: // for (int i = 0; i < fmds.length; i++) {
242: // FieldMetaData fmd = fmds[i];
243: // if (fmd.origFmd == rFmd) {
244: // return fmd;
245: // }
246: // }
247: // throw BindingSupportImpl.getInstance().internal("Fmd not found");
248: }
249:
250: public void providedBooleanField(PersistenceCapable pc, int field,
251: boolean currentValue) {
252: owner.providedBooleanFieldImp(pc, getFmd(field), currentValue);
253: }
254:
255: public void providedCharField(PersistenceCapable pc, int field,
256: char currentValue) {
257: owner.providedCharFieldImp(pc, getFmd(field), currentValue);
258: }
259:
260: public void providedByteField(PersistenceCapable pc, int field,
261: byte currentValue) {
262: owner.providedByteFieldImp(pc, getFmd(field), currentValue);
263: }
264:
265: public void providedShortField(PersistenceCapable pc, int field,
266: short currentValue) {
267: owner.providedShortFieldImp(pc, getFmd(field), currentValue);
268: }
269:
270: public void providedIntField(PersistenceCapable pc, int field,
271: int currentValue) {
272: owner.providedIntFieldImp(pc, getFmd(field), currentValue);
273: }
274:
275: public void providedLongField(PersistenceCapable pc, int field,
276: long currentValue) {
277: owner.providedLongFieldImp(pc, getFmd(field), currentValue);
278: }
279:
280: public void providedFloatField(PersistenceCapable pc, int field,
281: float currentValue) {
282: owner.providedFloatFieldImp(pc, getFmd(field), currentValue);
283: }
284:
285: public void providedDoubleField(PersistenceCapable pc, int field,
286: double currentValue) {
287: owner.providedDoubleFieldImp(pc, getFmd(field), currentValue);
288: }
289:
290: public void providedStringField(PersistenceCapable pc, int field,
291: String currentValue) {
292: owner.providedStringFieldImp(pc, getFmd(field), currentValue);
293: }
294:
295: public void providedObjectField(PersistenceCapable pc, int field,
296: Object currentValue) {
297: owner.providedObjectFieldImp(pc, getFmd(field), currentValue);
298: }
299:
300: public boolean replacingBooleanField(PersistenceCapable pc,
301: int field) {
302: return owner.replacingBooleanFieldImp(pc, getFmd(field));
303: }
304:
305: public char replacingCharField(PersistenceCapable pc, int field) {
306: return owner.replacingCharFieldImp(pc, getFmd(field));
307: }
308:
309: public byte replacingByteField(PersistenceCapable pc, int field) {
310: return owner.replacingByteFieldImp(pc, getFmd(field));
311: }
312:
313: public short replacingShortField(PersistenceCapable pc, int field) {
314: return owner.replacingShortFieldImp(pc, getFmd(field));
315: }
316:
317: public int replacingIntField(PersistenceCapable pc, int field) {
318: return owner.replacingIntFieldImp(pc, getFmd(field));
319: }
320:
321: public long replacingLongField(PersistenceCapable pc, int field) {
322: return owner.replacingLongFieldImp(pc, getFmd(field));
323: }
324:
325: public float replacingFloatField(PersistenceCapable pc, int field) {
326: return owner.replacingFloatFieldImp(pc, getFmd(field));
327: }
328:
329: public double replacingDoubleField(PersistenceCapable pc, int field) {
330: return owner.replacingDoubleFieldImp(pc, getFmd(field));
331: }
332:
333: public String replacingStringField(PersistenceCapable pc, int field) {
334: return owner.replacingStringFieldImp(pc, getFmd(field));
335: }
336:
337: public Object replacingObjectField(PersistenceCapable pc, int field) {
338: return owner.replacingObjectFieldImp(pc, getFmd(field));
339: }
340:
341: private void throwNotImplemented() {
342: throw BindingSupportImpl.getInstance().invalidOperation(
343: "Not implememted");
344: }
345:
346: }
|