Skip to main content
summaryrefslogtreecommitdiffstats
blob: cc3286206c97050fd66a0d4f3921e527a6817611 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
/**
 * <copyright>
 *
 * Copyright (c) 2005, 2006 Springsite BV (The Netherlands) and others
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Martin Taal
 * </copyright>
 *
 * $Id: EListWrapper.java,v 1.7 2006/11/29 07:07:27 mtaal Exp $
 */

package org.eclipse.emf.teneo.jpox.elist;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.spi.PersistenceCapable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
import org.eclipse.emf.ecore.util.DelegatingEcoreEList;
import org.eclipse.emf.teneo.EContainerRepairControl;
import org.eclipse.emf.teneo.jpox.JpoxStoreException;
import org.eclipse.emf.teneo.jpox.JpoxUtil;
import org.eclipse.emf.teneo.jpox.mapping.AnyTypeEObject;
import org.eclipse.emf.teneo.jpox.mapping.AnyTypeObject;
import org.eclipse.emf.teneo.jpox.resource.JPOXResource;
import org.eclipse.emf.teneo.mapping.elist.PersistableEList;
import org.eclipse.emf.teneo.resource.StoreResource;
import org.eclipse.emf.teneo.util.AssertUtil;
import org.eclipse.emf.teneo.util.StoreUtil;
import org.jpox.AbstractPersistenceManager;
import org.jpox.StateManager;
import org.jpox.sco.SCO;
import org.jpox.sco.SCOList;
import org.jpox.sco.exceptions.QueryUnownedSCOException;
import org.jpox.state.FetchPlanState;
import org.jpox.store.expression.QueryExpression;
import org.jpox.store.query.Queryable;
import org.jpox.store.query.ResultObjectFactory;

/**
 * This class works as a wrapper around the EList as it is used in the EMF objects. The class extends PersistableEList,
 * the delegate of this elist is a normal arraylist. In addition this class has a reference to a jpox arraylist which
 * represents the underlying datastore. The jpox arraylist can not be used as the delegate because certain type of store
 * objects (AnyObject_ are replaced by their contained value at load time, this indirection can not be accomplished when
 * the jpox arraylist is the delegate.
 * 
 * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
 * @version $Revision: 1.7 $ $Date: 2006/11/29 07:07:27 $
 */

public class EListWrapper extends PersistableEList implements SCO, Queryable, SCOList {
	/** The logger */
	private static Log log = LogFactory.getLog(EListWrapper.class);

	/** The statemanager used to get to all the jdo information */
	private StateManager stateManager = null;

	/** The field for which this EList operates */
	private String elistFieldName = null;

	/** The jdo delegate representing the datastore */
	protected JPOXArrayList jdoDelegate = null;

	/** Is set to true if this is a containment list */
	private final boolean containmentList;

	/** Is true if this list contains EObjectListElements */
	private final boolean isEObjectList;

	/** Is true if this list contains unidentified Objects */
	private final boolean isObjectList;

	/**
	 * Constructor, using the StateManager of the "owner" and the field name.
	 * 
	 * @param ownerSM
	 *            The owner StateManager
	 * @param fieldName
	 *            The name of the field of the SCO.
	 */
	public EListWrapper(StateManager ownerSM, String fieldName) {
		this(ownerSM, fieldName, new ArrayList());
	}

	/**
	 * Constructor, using the StateManager of the "owner" and the field name.
	 * 
	 * @param ownerSM
	 *            The owner StateManager
	 * @param fieldName
	 *            The name of the field of the SCO.
	 */
	public EListWrapper(StateManager ownerSM, String fieldName, List list) {
		super((InternalEObject) ownerSM.getObject(), StoreUtil.getEStructuralFeature((InternalEObject) ownerSM
				.getObject(), fieldName), new ArrayList(list));

		AssertUtil.assertTrue("The delegate may not be an elistwrapper", !(getDelegate() instanceof EListWrapper));

		stateManager = ownerSM;

		containmentList = getEStructuralFeature() instanceof EAttribute
				|| ((EReference) getEStructuralFeature()).isContainment();
		jdoDelegate = new JPOXArrayList(ownerSM, fieldName);
		elistFieldName = fieldName;

		final Class elementType = getEStructuralFeature().getEType().getInstanceClass();
		isEObjectList = elementType == EObject.class; // AnyTypeEObject.class;
		isObjectList = elementType == Object.class; // AnyTypeEObject.class;

		if (jdoDelegate.isLoaded()) {
			load();
		}
	}

	/**
	 * Constructor, used for the clone method
	 * 
	 * @param ownerSM
	 *            The owner StateManager
	 * @param fieldName
	 *            The name of the field of the SCO.
	 */
	private EListWrapper(EListWrapper copyFrom) {
		super((InternalEObject) copyFrom.getEObject(), copyFrom.getEStructuralFeature(), new ArrayList());
		containmentList = copyFrom.containmentList;
		jdoDelegate = new JPOXArrayList(copyFrom.stateManager, copyFrom.elistFieldName);
		isEObjectList = copyFrom.isEObjectList;
		isObjectList = copyFrom.isObjectList;
		log.debug("Cloned elist: " + getLogString());
	}

	/** Nullify the delegate and stateManager before serializing */
	private void writeObject(java.io.ObjectOutputStream out) throws IOException {
		jdoDelegate = null;
		stateManager = null;
		additionalWriteObject();
		out.defaultWriteObject();
	}

	/** Replace normal EObject with AnyTypeImpl */
	private Object replaceForAnyType(Object obj) {
		if (isEObjectList)
			return replaceForAnyTypeEObject(obj);
		if (isObjectList)
			return replaceForAnyTypeObject(obj);

		return obj; // note that an exception can not be thrown because the
		// replace is always tried
	}

	/** Do your subclass thing for serialization */
	protected void additionalWriteObject() {
	}

	/** Replace normal EObject with AnyTypeImpl */
	private Object replaceForAnyTypeObject(Object obj) {
		assert (isObjectList);

		if (jdoDelegate == null)
			return obj; // do this at attach

		if (obj instanceof AnyTypeObject) {
			return (AnyTypeObject) obj;
		}

		return new AnyTypeObject(getPM(), obj);
	}

	/** Replace normal EObject with AnyTypeImpl */
	private Object replaceForAnyTypeEObject(Object obj) {
		assert (isEObjectList);

		assert (obj instanceof EObject);

		if (jdoDelegate == null) {
			return obj; // do this at attach
		}

		if (obj instanceof AnyTypeEObject) {
			return (AnyTypeEObject) obj;
		}

		return new AnyTypeEObject(getPM(), (EObject) obj);
	}

	// ----------------------- Implementation of JPOXElist methods
	// -------------------

	/**
	 * Method to detach the elements of this list.
	 */
	public void detach(FetchPlanState state) {
		if (jdoDelegate == null)
			return;
		if (!isLoaded())
			return;

		load();
		jdoDelegate.detach(state);

		final Object[] values = toArray();
		for (int i = 0; i < values.length; i++) {
			if (values[i] != null && values[i] instanceof PersistenceCapable) {
				stateManager.getPersistenceManager().detachInternal(values[i], state);
			}
		}
		stateManager = null;
		jdoDelegate = null;
	}

	/**
	 * Method to return a detached copy of the list.
	 */
	public Object detachCopy(FetchPlanState state) {
		final ArrayList detached = new ArrayList();
		final Object[] values = toArray();
		for (int i = 0; i < values.length; i++) {
			if (values[i] == null) {
				detached.add(null);
			} else {
				Object object = values[i];
				if (object instanceof PersistenceCapable) {
					detached.add(stateManager.getPersistenceManager().detachCopyInternal(object, state));
				} else {
					detached.add(object);
				}
			}
		}

		// create a delegating ecorelist, this ensures that all the feature characteristics
		// are supported
		final EStructuralFeature feature = getEStructuralFeature();
		final InternalEObject myOwner = (InternalEObject) getOwner();
		final EList elist = new DelegatingEcoreEList(myOwner) {
			protected List delegateList() {
				return detached;
			}

			public EStructuralFeature getEStructuralFeature() {
				return feature;
			}
		};

		return elist;
	}

	/** Detach self, means nullify all references to jdo */
	public void detachSelf() {
		// and detach ourselves also
		jdoDelegate = null;
		stateManager = null;
	}

	/**
	 * Method to run reachability on this SCO.
	 * 
	 * @param reachables
	 *            List of StateManagers reachable so far
	 */
	public void runReachability(java.util.Set reachables) {
		Object[] values = toArray();
		for (int i = 0; i < values.length; i++) {
			if (values[i] != null && values[i] instanceof PersistenceCapable) {
				StateManager sm = stateManager.getPersistenceManager().findStateManager((PersistenceCapable) values[i]);
				if (sm != null) { // already detached
					sm.runReachability(reachables);
				}
			}
		}
	}

	/** Set method for SCO.set */
	public Object set(int arg0, Object arg1, boolean arg2) {
		return jdoDelegate.set(arg0, arg1, arg2);
	}

	// ----------------------- Implementation of SCO methods -------------------

	/** Is the owner detached */
	private boolean isOwnerDetached() {
		final PersistenceCapable pc = (PersistenceCapable) getEObject();
		return pc.jdoIsDetached();
	}

	/** Returns the persistence manager from the owner */
	private PersistenceManager getPM() {
		final PersistenceCapable pc = (PersistenceCapable) getEObject();
		if (!pc.jdoIsDetached())
			return pc.jdoGetPersistenceManager();
		throw new JpoxStoreException("This method may not be called if the elist is detached");
	}

	/** Clones this object */
	public Object clone() {
		return new EListWrapper(this);
	}

	/**
	 * Mutator for setting using an object.
	 * 
	 * @param o
	 *            The object to set from
	 */
	public void setValueFrom(Object o) {
		Collection c = (Collection) o;
		clear();
		delegate.addAll(c);
	}

	/**
	 * Accessor for the field name.
	 * 
	 * @return The field name
	 */
	public String getFieldName() {
		return elistFieldName;
	}

	/**
	 * Accessor for the owner object.
	 * 
	 * @return The owner object
	 */
	public Object getOwner() {
		return getEObject();
	}

	/**
	 * Method to unset the owner and field information.
	 */
	public synchronized void unsetOwner() {
		log.debug("Unsetting owner of elist " + getLogString());

		if (jdoDelegate != null) {
			// elistFieldName = null;
			jdoDelegate = null;
			stateManager = null;
		}
	}

	/**
	 * Utility to mark the object as dirty
	 */
	public void makeDirty() {
		if (jdoDelegate != null)
			jdoDelegate.makeDirty();
	}

	/**
	 * Method to make transient all elements of this list.
	 */
	public void makeTransient(FetchPlanState state) {
		final Object[] values = toArray();
		for (int i = 0; i < values.length; i++) {
			if (values[i] != null && values[i] instanceof PersistenceCapable) {
				stateManager.getPersistenceManager().findStateManager((PersistenceCapable) values[i]).makeTransient(
						state);
			}
		}
		stateManager = null;
		jdoDelegate = null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jpox.sco.SCO#setValueFrom(java.lang.Object, boolean)
	 */
	public void setValueFrom(Object arg0, boolean arg1) throws ClassCastException {
		final Collection c = (Collection) arg0;
		if (arg1) {
			clear();
			addAll(c);
		} else {
			getDelegate().clear();
			getDelegate().addAll(c);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jpox.sco.SCOCollection#getElementType()
	 */
	public Class getElementType() {
		return getEStructuralFeature().getEType().getInstanceClass();
	}

	/**
	 * Method to re-attach a detached collection. Goes through the existing elements in the store for this owner field
	 * and removes ones no longer present, and adds new elements. All elements in the (detached) value are attached.
	 * 
	 * @param value
	 *            The new (collection) value
	 * @param makeTransactional
	 *            Whether to make this transactional
	 */
	public void attachCopy(Object value) {
		// if not loaded then nothing changed so nothing to attach
		assert (value instanceof PersistableEList);
		if (!((PersistableEList) value).isLoaded())
			return;

		java.util.Collection c = (java.util.Collection) value;

		// force a load!
		load();

		// Attach all of the elements in the new list
		final ArrayList attachedElements = new ArrayList(c.size());
		final Iterator iter = c.iterator();
		while (iter.hasNext()) {
			final PersistenceCapable detachedElement = (PersistenceCapable) iter.next();
			attachedElements.add(((AbstractPersistenceManager) getPM()).attachCopy(detachedElement, false));
		}

		log.debug("Attaching " + attachedElements.size() + " objects to elist " + getLogString());
		// NOTE: needed to pass the jdodelegate because the update actions
		// should go directly to the
		// underlying datastore and not through this list. Tests showed that if
		// the updates where
		// done directly in this list that in case of bidirectional reatlions
		// elements which had
		// been moved from one list to another ended up with empty relations
		// because the remove
		// action in the updateListWithListElements cleared the one side of the
		// bidirectional case.
		JpoxUtil.updateListWithListElements(jdoDelegate, attachedElements);
	}

	/**
	 * Method to return a ResultObjectFactory for the SCO.
	 * 
	 * @param stmt
	 *            The QueryStatement
	 * @param ignoreCache
	 *            Whether to ignore the cache
	 * @param resultClass
	 *            Whether to create objects of a particular class
	 * @param useFetchPlan
	 *            whether to use the fetch plan to retrieve fields in the same query
	 * @return The ResultObjectFactory
	 */
    public synchronized ResultObjectFactory newResultObjectFactory(
            QueryExpression stmt, boolean ignoreCache, Class resultClass, boolean useFetchPlan) {
		if (jdoDelegate == null) {
			throw new QueryUnownedSCOException();
		}
		return jdoDelegate.newResultObjectFactory(stmt, ignoreCache, resultClass, useFetchPlan);
	}

	/**
	 * Method to update an embedded element in this collection.
	 * 
	 * @param element
	 *            The element
	 * @param fieldNumber
	 *            Number of field in the element
	 * @param value
	 *            New value for this field
	 */
	public void updateEmbeddedElement(Object element, int fieldNumber, Object value) {
		if (jdoDelegate != null) {
			jdoDelegate.updateEmbeddedElement(element, fieldNumber, value);
		}
	}

	// ------------------------ Query Statement methods ------------------------

	/**
	 * Method to generate a QueryStatement for the SCO.
	 * 
	 * @return The QueryStatement
	 */
	public synchronized QueryExpression newQueryStatement() {
		if (jdoDelegate == null) {
			throw new QueryUnownedSCOException();
		}
		return jdoDelegate.newQueryStatement();
	}

	/**
	 * Method to return a QueryStatement, using the specified candidate class.
	 * 
	 * @param candidate_class
	 *            The candidate class
	 * @return The QueryStatement
	 */
	public synchronized QueryExpression newQueryStatement(Class candidate_class) {
		if (jdoDelegate == null) {
			throw new QueryUnownedSCOException();
		}
		return jdoDelegate.newQueryStatement(candidate_class);
	}

	// ---------------------------------- EList methods including loading from
	// the store ------------------------

	/** Does the actual loading from the store in a synchronized manner */
	protected synchronized void doLoad() {
		AssertUtil.assertTrue("EList " + getLogString() + " is already loaded", !isLoaded());

		final Resource res = getEObject().eResource();
		final boolean setLoading = res != null && res instanceof JPOXResource && !((StoreResource) res).isLoading();
		if (setLoading) {
			((StoreResource) res).setIsLoading(true);
		}

		// note add directly to the delegate to prevent infinite looping and
		// notifications
		final List list = getDelegate();
		final Iterator iter = jdoDelegate.iterator();
		while (iter.hasNext()) {
			Object child = iter.next();

			// get the eobject if hidden behind an eobjectlistelement
			// bit ugly to reuse child var but okay
			if (child instanceof AnyTypeEObject) {
				child = ((AnyTypeEObject) child).getEObject();
			} else if (child instanceof AnyTypeObject) {
				child = ((AnyTypeObject) child).getObject();
			}
			list.add(child);
		}

		final Iterator it = getDelegate().iterator();
		while (it.hasNext()) {
			final Object child = it.next();
			if (containmentList) {
				EContainerRepairControl.repair(getEObject(), child, getEStructuralFeature());
			} else if (res != null && res instanceof ResourceImpl &&
					child instanceof EObject && ((EObject)child).eResource() == null) {
				// attach the new objects so that they are adapted when
				// required
				// true is passed although this is not containment, need to do that 
				// to get attached working correctly. TODO make nicer
				((StoreResource) res).addToContentOrAttach((InternalEObject) child, true);
			}
		}
		if (setLoading) {
			((JPOXResource) res).setIsLoading(false);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.emf.teneo.mapping.elist.PersistableEList#isPersistencyWrapped()
	 */
	public boolean isPersistencyWrapped() {
		return true;
	}

	/**
	 * Updates the backing store
	 * 
	 * @see org.eclipse.emf.common.util.DelegatingEList#didAdd(int, java.lang.Object)
	 */
	protected void didAdd(int index, Object newObject) {
		if (jdoDelegate != null)
			jdoDelegate.add(index, replaceForAnyType(newObject));
		super.didAdd(index, newObject);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.emf.common.util.DelegatingEList#didChange()
	 */
	protected void didChange() {
		if (jdoDelegate != null)
			jdoDelegate.makeDirty();
		super.didChange();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.emf.common.util.DelegatingEList#didClear(int, java.lang.Object[])
	 */
	protected void didClear(int size, Object[] oldObjects) {
		if (oldObjects == null)
			return;

		if (jdoDelegate != null)
			jdoDelegate.clear();

		// don't do super do clear because it calls didremveo again
		// super.didClear(size, oldObjects);

		if (containmentList) // check if this is now handled correctly by
		// jpox
		{
			if (!isOwnerDetached()) {
				// check which part of the list is persistencecapable!
				// only that part should be deleted
				final ArrayList pcList = new ArrayList();
				for (int i = 0; i < oldObjects.length; i++) {
					if (oldObjects[i] instanceof PersistenceCapable) {
						pcList.add(oldObjects[i]);
					}
				}

				getPM().deletePersistentAll(pcList);
			}
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.emf.common.util.DelegatingEList#didMove(int, java.lang.Object, int)
	 */
	protected void didMove(int index, Object movedObject, int oldIndex) {
		if (jdoDelegate != null) {
			// note that the object moved/removed from the jdo delegate can be
			// different from the
			// one stored in this list (because of handling anytype)
			Object obj = jdoDelegate.get(oldIndex);
			jdoDelegate.add(index, obj);
			/*
			 * no join table for !containment therefor the following is not required anymore if (!containmentList) // in
			 * case of containment no join table and the set statement will have solved it all { int delPos =
			 * oldPosition; if (newPosition < oldPosition) { delPos++; } listStore.remove(stateManager, delPos); }
			 */
		}
		super.didMove(index, movedObject, oldIndex);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.emf.common.util.DelegatingEList#didRemove(int, java.lang.Object)
	 */
	protected void didRemove(int index, Object oldObject) {
		// note that the object removed from the jdo delegate can be different
		// from the
		// one stored in this list (because of handling anytype), therefore
		// remove on the basis
		// index is chosen
		if (jdoDelegate != null) {
			Object obj = jdoDelegate.remove(index);

			if (containmentList && !isOwnerDetached() && obj instanceof PersistenceCapable && owner.eResource() == null) {
				// only remove if not working within a resource because the resource will handle the remove then
				PersistenceCapable pc = (PersistenceCapable) oldObject;
				if (pc.jdoIsPersistent() || pc.jdoIsTransactional()) {
					getPM().deletePersistent(oldObject);
				}
			}
		}
		super.didRemove(index, oldObject);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.emf.common.util.DelegatingEList#didSet(int, java.lang.Object, java.lang.Object)
	 */
	protected void didSet(int index, Object newObject, Object oldObject) {
		// not that the object removed from the jdo delegate can be different
		// from the
		// one stored in this list (because of handling anytype)
		if (jdoDelegate != null) {
			jdoDelegate.set(index, replaceForAnyType(newObject));

			if (containmentList && !isOwnerDetached() && oldObject instanceof PersistenceCapable) {
				PersistenceCapable pc = (PersistenceCapable) oldObject;
				if (pc.jdoIsPersistent() || pc.jdoIsTransactional()) {
					getPM().deletePersistent(oldObject);
				}
			}
		}

		super.didSet(index, newObject, oldObject);
	}

	/**
	 * Overridden to make public
	 */
	public void load() {
		// TODO Auto-generated method stub
		super.load();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jpox.sco.SCOContainer#loadFieldsInFetchPlan(org.jpox.state.FetchPlanState)
	 */
	public void loadFieldsInFetchPlan(FetchPlanState arg0) {
		if (!isLoaded())
			return;

		if (stateManager == null)
			return;
		Object[] values = toArray();
		for (int i = 0; i < values.length; i++) {
			if (values[i] != null && values[i] instanceof PersistenceCapable) {
				stateManager.getPersistenceManager().findStateManager((PersistenceCapable) values[i])
						.loadFieldsInFetchPlan(arg0);
			}
		}
	}
}

Back to the top