KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > CollectionTest


1 package org.apache.ojb.broker;
2
3 import java.io.Serializable JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import java.util.Arrays JavaDoc;
6 import java.util.Collection JavaDoc;
7 import java.util.Iterator JavaDoc;
8 import java.util.List JavaDoc;
9
10 import org.apache.commons.lang.builder.ToStringBuilder;
11 import org.apache.commons.lang.builder.ToStringStyle;
12 import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
13 import org.apache.ojb.broker.query.Criteria;
14 import org.apache.ojb.broker.query.Query;
15 import org.apache.ojb.broker.query.QueryByCriteria;
16 import org.apache.ojb.broker.query.QueryFactory;
17 import org.apache.ojb.broker.util.ObjectModification;
18 import org.apache.ojb.broker.util.collections.RemovalAwareCollection;
19 import org.apache.ojb.junit.PBTestCase;
20
21 /**
22  * Test case for collection handling.
23  *
24  * Main class Gatherer have five collections of type CollectibleBase,
25  * CollectibleB, CollectibleC, CollectibleD, CollectibleDD
26  *
27  * Class hierarchy:
28  * [CollectibleBaseIF <--] CollectibleBase <-- CollectibleB <-- CollectibleC <-- CollectibleCC
29  * | |
30  * CollectibleD <-- CollectibleDD CollectibleCCC
31  *
32  * in repository interface CollectibleBaseIF was declared with five
33  * extents (CollectibleBase, CollectibleB, CollectibleC, CollectibleD, CollectibleDD)
34  *
35  * CollectibleBase
36  * auto-retrieve, auto-update, auto-delete all true
37  * proxy false
38  *
39  * CollectibleB
40  * auto-retrieve, auto-update set true, auto-delete false
41  * proxy true
42  *
43  * CollectibleC
44  * auto-retrieve, auto-update, auto-delete set true,
45  * proxy true
46  * CollectibleC has a reference back to the Gatherer object
47  * (auto-retrieve, auto-update, auto-delete set false to avoid circular
48  * object creation)
49  *
50  * CollectibleCC
51  * auto-retrieve true, auto-update true, auto-delete set true,
52  * proxy false
53  *
54  * CollectibleCCC
55  * auto-retrieve false, auto-update true, auto-delete set true,
56  * proxy false
57  *
58  * CollectibleD
59  * auto-retrieve, auto-update, auto-delete all true
60  * proxy false
61  *
62  * CollectibleDD
63  * auto-retrieve, auto-update, auto-delete all true
64  * proxy true
65  *
66  * TODO: Need some refactoring and more structured tests of different auto_xyz/proxy settings
67  *
68  * @author <a HREF="mailto:armin@codeAuLait.de">Armin Waibel</a>
69  * @version $Id: CollectionTest.java,v 1.11.2.7 2005/12/29 22:18:21 arminw Exp $
70  */

71 public class CollectionTest extends PBTestCase
72 {
73     static final int NONE = ObjectReferenceDescriptor.CASCADE_NONE;
74     static final int LINK = ObjectReferenceDescriptor.CASCADE_LINK;
75     static final int OBJECT = ObjectReferenceDescriptor.CASCADE_OBJECT;
76
77     public static void main(String JavaDoc[] args)
78     {
79         String JavaDoc[] arr = {CollectionTest.class.getName()};
80         junit.textui.TestRunner.main(arr);
81     }
82
83     /**
84      * test for OJB-82
85      */

86     public void testUsingExtentWhichIsNotInheritedFromBaseClass() throws Exception JavaDoc
87     {
88         // TODO: fix this bug
89
if(ojbSkipKnownIssueProblem("Test for OJB-82 will be fixed in next version")) return;
90
91         String JavaDoc prefix = "testUsingExtentWhichIsNotInheritedFromBaseClass_" + System.currentTimeMillis();
92
93         ojbChangeReferenceSetting(BookShelf.class, "items", true, OBJECT, OBJECT, false);
94         ojbChangeReferenceSetting(DVD.class, "shelf", true, NONE, NONE, false);
95         ojbChangeReferenceSetting(Book.class, "shelf", true, NONE, NONE, false);
96         ojbChangeReferenceSetting(Candie.class, "shelf", true, NONE, NONE, false);
97
98         BookShelf bookShelf = new BookShelf(prefix);
99         BookShelfItem dvd = new DVD(prefix+ "_dvd", bookShelf);
100         BookShelfItem book = new Book(prefix + "_book", bookShelf);
101         Candie candie = new Candie(prefix + "_book", bookShelf);
102         List JavaDoc items = new ArrayList JavaDoc();
103         items.add(dvd);
104         items.add(book);
105         items.add(candie);
106         bookShelf.setItems(items);
107
108         broker.beginTransaction();
109         broker.store(bookShelf);
110         broker.commitTransaction();
111
112         broker.clearCache();
113         BookShelf loadedCopy = (BookShelf) broker.getObjectByIdentity(
114                 broker.serviceIdentity().buildIdentity(BookShelf.class, bookShelf.getPk()));
115         assertNotNull(loadedCopy);
116         assertNotNull(loadedCopy.getItems());
117         assertEquals(3, loadedCopy.getItems().size());
118
119         broker.beginTransaction();
120         broker.clearCache();
121         Criteria criteria = new Criteria();
122         criteria.addLike("name", prefix + "%");
123         Query q = new QueryByCriteria(BookShelfItem.class, criteria);
124         Collection JavaDoc result = broker.getCollectionByQuery(q);
125         assertNotNull(result);
126         assertEquals(3, result.size());
127     }
128
129     public void testMoveProxyCollectionFromOneToAnother() throws Exception JavaDoc
130     {
131         String JavaDoc prefix = "testMoveProxyCollectionFromOneToAnother_" + System.currentTimeMillis();
132
133         ojbChangeReferenceSetting(BookShelf.class, "items", true, OBJECT, OBJECT, true);
134         ojbChangeReferenceSetting(DVD.class, "shelf", true, NONE, NONE, true);
135         ojbChangeReferenceSetting(Book.class, "shelf", true, NONE, NONE, true);
136
137         BookShelf bookShelf = new BookShelf(prefix);
138         BookShelf bookShelfSecond = new BookShelf(prefix+"_second");
139         BookShelfItem ev1 = new DVD(prefix+ "_dvd", bookShelf);
140         BookShelfItem ev2 = new Book(prefix + "_book", bookShelf);
141         bookShelf.addItem(ev1);
142         bookShelf.addItem(ev2);
143
144         broker.beginTransaction();
145         broker.store(bookShelfSecond);
146         broker.store(bookShelf);
147         broker.commitTransaction();
148
149         broker.clearCache();
150         BookShelf loadedCopy = (BookShelf) broker.getObjectByIdentity(
151                 broker.serviceIdentity().buildIdentity(BookShelf.class, bookShelf.getPk()));
152         assertNotNull(loadedCopy);
153         assertNotNull(loadedCopy.getItems());
154         assertEquals(2, loadedCopy.getItems().size());
155
156         broker.beginTransaction();
157         /*
158         now we move the unmaterialzed proxy collection from one to another object,
159         it's important to first store the bookshelf object with the nullified items
160         and then the bookshelf with moved item collection proxy - otherwise the PB-api
161         doesn't recognize the changes
162         */

163         bookShelfSecond.setItems(bookShelf.getItems());
164         bookShelf.setItems(null);
165         broker.store(bookShelf, ObjectModification.UPDATE);
166         broker.store(bookShelfSecond, ObjectModification.UPDATE);
167         broker.commitTransaction();
168         broker.clearCache();
169
170         loadedCopy = (BookShelf) broker.getObjectByIdentity(
171                 broker.serviceIdentity().buildIdentity(BookShelf.class, bookShelf.getPk()));
172         assertNotNull(loadedCopy);
173         assertNotNull(loadedCopy.getItems());
174         assertEquals(0, loadedCopy.getItems().size());
175
176         BookShelf loadedCopySecond = (BookShelf) broker.getObjectByIdentity(
177                 broker.serviceIdentity().buildIdentity(BookShelf.class, bookShelfSecond.getPk()));
178         assertNotNull(loadedCopySecond);
179         assertNotNull(loadedCopySecond.getItems());
180         assertEquals(2, loadedCopySecond.getItems().size());
181
182         broker.clearCache();
183         Criteria criteria = new Criteria();
184         criteria.addLike("name", prefix + "%");
185         Query q = new QueryByCriteria(BookShelfItem.class, criteria);
186         Collection JavaDoc items = broker.getCollectionByQuery(q);
187         assertNotNull(items);
188         assertEquals(2, items.size());
189         // we are using collection proxies, so we have to use the interface
190
BookShelfItem item = (BookShelfItem) items.iterator().next();
191         assertNotNull(item.getShelf());
192         BookShelfIF bs = item.getShelf();
193         assertEquals(bookShelfSecond.getPk(), bs.getPk());
194     }
195
196     public void testReadProxyCollection() throws Exception JavaDoc
197     {
198         String JavaDoc name = "testReadProxyCollection_"+System.currentTimeMillis();
199         Gatherer gat = new Gatherer(null, name);
200         CollectibleB[] cols = prepareCollectibleB(name);
201
202         gat.setCollectiblesB(Arrays.asList(cols));
203         broker.beginTransaction();
204         broker.store(gat);
205         broker.commitTransaction();
206
207         broker.clearCache();
208         Criteria crit = new Criteria();
209         crit.addLike("name", name);
210         Query q = QueryFactory.newQuery(Gatherer.class, crit);
211         Gatherer newGat = (Gatherer)broker.getObjectByQuery(q);
212
213         Iterator JavaDoc it = newGat.getCollectiblesB().iterator();
214         int i = 0;
215         while(it.hasNext())
216         {
217             CollectibleB colB = (CollectibleB) it.next();
218             assertTrue(colB.getName().indexOf(name) > -1);
219             i++;
220         }
221         assertEquals(4, i);
222     }
223
224     public void testStoreReadOfUserDefinedCollectionClass()
225     {
226         String JavaDoc name = "testStoreReadOfUserDefinedCollectionClass_"+System.currentTimeMillis();
227         Gatherer gat = new Gatherer(null, name);
228
229         CollectibleBase[] collBase = prepareCollectibleBase(name);
230         CollectionClassDummy dummyList = new CollectionClassDummy();
231         for (int i = 0; i < collBase.length; i++)
232         {
233             CollectibleBase collectibleBase = collBase[i];
234             dummyList.ojbAdd(collectibleBase);
235         }
236         gat.setCollectionDummy(dummyList);
237
238         broker.beginTransaction();
239         broker.store(gat);
240         broker.commitTransaction();
241
242         Identity oid = broker.serviceIdentity().buildIdentity(gat);
243         broker.clearCache();
244         Gatherer new_gat = (Gatherer) broker.getObjectByIdentity(oid);
245         assertNotNull(new_gat);
246         assertNotNull(new_gat.getCollectionDummy());
247         assertEquals(collBase.length, new_gat.getCollectionDummy().size());
248
249     }
250
251     public void testStoreReadOfUserDefinedCollectionClass_2()
252     {
253         String JavaDoc name = "testStoreReadOfUserDefinedCollectionClass_2_"+System.currentTimeMillis();
254         Gatherer gat = new Gatherer(null, name);
255
256         CollectibleBase[] collBase = prepareCollectibleBase(name);
257         CollectionClassDummy dummyList = new CollectionClassDummy();
258         for (int i = 0; i < collBase.length; i++)
259         {
260             CollectibleBase collectibleBase = collBase[i];
261             dummyList.ojbAdd(collectibleBase);
262         }
263         gat.setCollectionDummy(dummyList);
264
265         broker.beginTransaction();
266         broker.store(gat);
267         broker.commitTransaction();
268
269         broker.clearCache();
270         Criteria crit = new Criteria();
271         crit.addEqualTo("name", name);
272         Query q = QueryFactory.newQuery(Gatherer.class, crit);
273         Collection JavaDoc result = broker.getCollectionByQuery(q);
274         assertNotNull(result);
275         assertEquals(1, result.size());
276         Gatherer new_gat = (Gatherer) result.iterator().next();
277         assertNotNull(new_gat);
278         assertNotNull(new_gat.getCollectionDummy());
279         assertEquals(collBase.length, new_gat.getCollectionDummy().size());
280
281     }
282
283     /**
284      * generate main object with collections and store
285      * main object to make all persistent
286      */

287     public void testStoreDeleteSimpleCollections()
288     {
289         long timestamp = System.currentTimeMillis();
290         String JavaDoc colPrefix = "col_" + timestamp;
291         String JavaDoc name = timestamp + "_testStoreDeleteSimpleCollections";
292
293         // create gatherer with collections
294
Gatherer gatherer = new Gatherer(null, name);
295         gatherer.setCollectiblesBase(Arrays.asList(prepareCollectibleBase(colPrefix)));
296         gatherer.setCollectiblesB(Arrays.asList(prepareCollectibleB(colPrefix)));
297
298         broker.beginTransaction();
299         broker.store(gatherer);
300         broker.commitTransaction();
301         assertEquals("CollectibleBase objects", 3, gatherer.getCollectiblesBase().size());
302         assertEquals(gatherer.getGatId(), ((CollectibleBaseIF) gatherer.getCollectiblesBase().get(0)).getGathererId());
303         assertEquals("CollectibleB objects", 4, gatherer.getCollectiblesB().size());
304         assertEquals(gatherer.getGatId(), ((CollectibleBIF) gatherer.getCollectiblesB().get(0)).getGathererId());
305
306         Identity oid = broker.serviceIdentity().buildIdentity(gatherer);
307         broker.clearCache();
308         Gatherer new_gatherer = (Gatherer) broker.getObjectByIdentity(oid);
309
310         assertNotNull(new_gatherer);
311         assertNotNull(new_gatherer.getCollectiblesBase());
312         assertNotNull(new_gatherer.getCollectiblesB());
313         assertEquals("CollectibleBase objects", 3, new_gatherer.getCollectiblesBase().size());
314         assertEquals("CollectibleB objects", 4, new_gatherer.getCollectiblesB().size());
315         assertEquals(new_gatherer.getGatId(), ((CollectibleBaseIF) new_gatherer.getCollectiblesBase().get(0)).getGathererId());
316         assertEquals(new_gatherer.getGatId(), ((CollectibleBIF) new_gatherer.getCollectiblesB().get(0)).getGathererId());
317
318         broker.clearCache();
319
320         Criteria criteria = new Criteria();
321         criteria.addLike("name", colPrefix + "_colBase*");
322         Query q = new QueryByCriteria(CollectibleBase.class, criteria);
323         Collection JavaDoc result = broker.getCollectionByQuery(q);
324         assertNotNull(result);
325         assertEquals("Wrong number of queried objects", 3, result.size());
326
327         criteria = new Criteria();
328         criteria.addLike("name", colPrefix + "_colB*");
329         q = new QueryByCriteria(CollectibleB.class, criteria);
330         result = broker.getCollectionByQuery(q);
331         assertNotNull(result);
332         assertEquals("Wrong number of queried objects", 4, result.size());
333
334         criteria = new Criteria();
335         criteria.addLike("name", colPrefix + "*");
336         q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
337         result = broker.getCollectionByQuery(q);
338         assertNotNull(result);
339         assertEquals("Wrong number of queried objects", 7, result.size());
340
341
342         // now we delete the main object
343
// and see what's going on with the dependend objects
344
broker.beginTransaction();
345         // auto-delete false set for CollectiblesB
346
List JavaDoc manuallyList = new_gatherer.getCollectiblesB();
347         for (Iterator JavaDoc iterator = manuallyList.iterator(); iterator.hasNext();)
348         {
349             broker.delete(iterator.next());
350         }
351         broker.delete(new_gatherer);
352         broker.commitTransaction();
353
354         broker.clearCache();
355         new_gatherer = (Gatherer) broker.getObjectByIdentity(oid);
356
357         assertNull(new_gatherer);
358
359         criteria = new Criteria();
360         criteria.addLike("name", colPrefix + "_colBase*");
361         q = new QueryByCriteria(CollectibleBase.class, criteria);
362         result = broker.getCollectionByQuery(q);
363         assertNotNull(result);
364         // auto-delete is set true
365
assertEquals("Wrong number of queried objects", 0, result.size());
366
367         criteria = new Criteria();
368         criteria.addLike("name", colPrefix + "_colB*");
369         q = new QueryByCriteria(CollectibleB.class, criteria);
370         result = broker.getCollectionByQuery(q);
371         assertNotNull(result);
372         // auto-delete is set false, but we removed manually
373
assertEquals("Wrong number of queried objects", 0, result.size());
374
375         criteria = new Criteria();
376         criteria.addLike("name", colPrefix + "*");
377         q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
378         result = broker.getCollectionByQuery(q);
379         assertNotNull(result);
380         // since we delete all childs
381
assertEquals("Wrong number of queried objects", 0, result.size());
382     }
383
384     /**
385      * generate main object with collections and store
386      * main object to make all persistent
387      */

388     public void testDeleteCollection()
389     {
390         long timestamp = System.currentTimeMillis();
391         String JavaDoc colPrefix = "col_" + timestamp;
392         String JavaDoc name = timestamp + "_testDeleteCollectionDoRemoveCollectionObjectBeforeDelete";
393
394         // create gatherer with collections
395
Gatherer gatherer = new Gatherer(null, name);
396         gatherer.setCollectiblesBase(Arrays.asList(prepareCollectibleBase(colPrefix)));
397         gatherer.setCollectiblesB(Arrays.asList(prepareCollectibleB(colPrefix)));
398         gatherer.setCollectiblesCC(Arrays.asList(prepareCollectibleCC(colPrefix)));
399
400         broker.beginTransaction();
401         broker.store(gatherer);
402         broker.commitTransaction();
403         assertEquals("CollectibleBase objects", 3, gatherer.getCollectiblesBase().size());
404         assertEquals(gatherer.getGatId(), ((CollectibleBaseIF) gatherer.getCollectiblesBase().get(0)).getGathererId());
405         assertEquals("CollectibleB objects", 4, gatherer.getCollectiblesB().size());
406         assertEquals(gatherer.getGatId(), ((CollectibleBIF) gatherer.getCollectiblesB().get(0)).getGathererId());
407
408         Identity oid = broker.serviceIdentity().buildIdentity(gatherer);
409         broker.clearCache();
410         Gatherer new_gatherer = (Gatherer) broker.getObjectByIdentity(oid);
411
412         assertNotNull(new_gatherer);
413         assertNotNull(new_gatherer.getCollectiblesBase());
414         assertNotNull(new_gatherer.getCollectiblesB());
415         assertEquals("CollectibleBase objects", 3, new_gatherer.getCollectiblesBase().size());
416         assertEquals("CollectibleB objects", 4, new_gatherer.getCollectiblesB().size());
417         assertEquals(new_gatherer.getGatId(), ((CollectibleBaseIF) new_gatherer.getCollectiblesBase().get(0)).getGathererId());
418         assertEquals(new_gatherer.getGatId(), ((CollectibleBIF) new_gatherer.getCollectiblesB().get(0)).getGathererId());
419
420         broker.clearCache();
421
422         Criteria criteria = new Criteria();
423         criteria.addLike("name", colPrefix + "_colBase*");
424         Query q = new QueryByCriteria(CollectibleBase.class, criteria);
425         Collection JavaDoc result = broker.getCollectionByQuery(q);
426         assertNotNull(result);
427         assertEquals("Wrong number of queried objects", 3, result.size());
428
429         criteria = new Criteria();
430         criteria.addLike("name", colPrefix + "_colB*");
431         q = new QueryByCriteria(CollectibleB.class, criteria);
432         result = broker.getCollectionByQuery(q);
433         assertNotNull(result);
434         assertEquals("Wrong number of queried objects", 4, result.size());
435
436         criteria = new Criteria();
437         criteria.addLike("name", colPrefix + "*");
438         q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
439         result = broker.getCollectionByQuery(q);
440         assertNotNull(result);
441         assertEquals("Wrong number of queried objects", 7, result.size());
442
443         broker.beginTransaction();
444         // now get all CollectibleB
445
List JavaDoc colBList = new_gatherer.getCollectiblesB();
446         for (Iterator JavaDoc iterator = colBList.iterator(); iterator.hasNext();)
447         {
448             broker.delete(iterator.next());
449         }
450         broker.delete(new_gatherer);
451         broker.commitTransaction();
452
453         broker.clearCache();
454         new_gatherer = (Gatherer) broker.getObjectByIdentity(oid);
455
456         assertNull(new_gatherer);
457
458         criteria = new Criteria();
459         criteria.addLike("name", colPrefix + "_colBase*");
460         q = new QueryByCriteria(CollectibleBase.class, criteria);
461         result = broker.getCollectionByQuery(q);
462         assertNotNull(result);
463         // auto-delete is set true
464
assertEquals("Wrong number of queried objects", 0, result.size());
465
466         criteria = new Criteria();
467         criteria.addLike("name", colPrefix + "_colB*");
468         q = new QueryByCriteria(CollectibleB.class, criteria);
469         result = broker.getCollectionByQuery(q);
470         assertNotNull(result);
471         // auto-delete is set false
472
assertEquals("Wrong number of queried objects", 0, result.size());
473
474         criteria = new Criteria();
475         criteria.addLike("name", colPrefix + "*");
476         q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
477         result = broker.getCollectionByQuery(q);
478         assertNotNull(result);
479         assertEquals("Wrong number of queried objects", 0, result.size());
480     }
481
482     /**
483      * generate main object with collections and store
484      * main object to make all persistent
485      */

486     public void testDeleteMainObjectWithOneToNRelation()
487     {
488         long timestamp = System.currentTimeMillis();
489         String JavaDoc colPrefix = "col_" + timestamp;
490         String JavaDoc name = timestamp + "_testDeleteMainObjectWithOneToNRelation";
491
492         // create gatherer with collections
493
Gatherer gatherer = new Gatherer(null, name);
494         List JavaDoc colsList = Arrays.asList(prepareCollectibleC2(colPrefix));
495         gatherer.setCollectiblesC2(colsList);
496         for (Iterator JavaDoc iterator = colsList.iterator(); iterator.hasNext();)
497         {
498             ((CollectibleC2) iterator.next()).setGatherer(gatherer);
499         }
500
501
502         broker.beginTransaction();
503         broker.store(gatherer);
504         broker.commitTransaction();
505
506         assertNotNull(gatherer.getCollectiblesC2());
507         assertEquals(5, gatherer.getCollectiblesC2().size());
508         assertEquals(gatherer.getGatId(), ((CollectibleC2) gatherer.getCollectiblesC2().get(0)).getGathererId());
509
510         broker.clearCache();
511         Identity oid = broker.serviceIdentity().buildIdentity(gatherer);
512         gatherer = (Gatherer) broker.getObjectByIdentity(oid);
513         assertNotNull(gatherer);
514         // auto-retierve is set false
515
assertNull(gatherer.getCollectiblesC2());
516
517         Criteria criteria = new Criteria();
518         criteria.addLike("name", colPrefix + "*");
519         Query q = new QueryByCriteria(CollectibleC2.class, criteria);
520         Collection JavaDoc result = broker.getCollectionByQuery(q);
521         assertNotNull(result);
522         assertEquals("Wrong number of queried objects", 5, result.size());
523
524         broker.beginTransaction();
525         // auto-retieve is false, so get references manually
526
broker.retrieveAllReferences(gatherer);
527         assertNotNull(gatherer.getCollectiblesC2());
528         List JavaDoc colList = gatherer.getCollectiblesC2();
529         for (Iterator JavaDoc iterator = colList.iterator(); iterator.hasNext();)
530         {
531             // delete all references first
532
broker.delete(iterator.next());
533         }
534         broker.delete(gatherer);
535         broker.commitTransaction();
536
537         criteria = new Criteria();
538         criteria.addLike("name", colPrefix + "*");
539         q = new QueryByCriteria(CollectibleC2.class, criteria);
540         result = broker.getCollectionByQuery(q);
541         assertNotNull(result);
542         assertEquals("Wrong number of queried objects", 0, result.size());
543     }
544
545     /**
546      * generate main object with collections and store
547      * main object to make all persistent
548      * using ojbConcreteClass feature to map different
549      * objects to same table
550      */

551     public void testStoreDeleteSimpleCollections_2()
552     {
553         long timestamp = System.currentTimeMillis();
554         String JavaDoc colPrefix = "col_" + timestamp;
555         String JavaDoc name = timestamp + "_testStoreDeleteSimpleCollections";
556
557         // create gatherer with collections
558
Gatherer gatherer = new Gatherer(null, name);
559         gatherer.setCollectiblesD(Arrays.asList(prepareCollectibleD(colPrefix)));
560         gatherer.setCollectiblesDD(Arrays.asList(prepareCollectibleDD(colPrefix)));
561
562         broker.beginTransaction();
563         broker.store(gatherer);
564         broker.commitTransaction();
565         assertEquals("CollectibleD objects", 2, gatherer.getCollectiblesD().size());
566         assertEquals(gatherer.getGatId(), ((CollectibleDIF) gatherer.getCollectiblesD().get(0)).getGathererId());
567         assertEquals("CollectibleDD objects", 3, gatherer.getCollectiblesDD().size());
568         assertEquals(gatherer.getGatId(), ((CollectibleDDIF) gatherer.getCollectiblesDD().get(0)).getGathererId());
569
570         Identity oid = broker.serviceIdentity().buildIdentity(gatherer);
571         broker.clearCache();
572         Gatherer new_gatherer = (Gatherer) broker.getObjectByIdentity(oid);
573
574         assertNotNull(new_gatherer);
575         assertNotNull(new_gatherer.getCollectiblesD());
576         assertNotNull(new_gatherer.getCollectiblesDD());
577         assertEquals("CollectibleD objects", 2, new_gatherer.getCollectiblesD().size());
578         assertEquals("CollectibleDD objects", 3, new_gatherer.getCollectiblesDD().size());
579         assertEquals(new_gatherer.getGatId(), ((CollectibleDIF) new_gatherer.getCollectiblesD().get(0)).getGathererId());
580         assertEquals(new_gatherer.getGatId(), ((CollectibleDDIF) new_gatherer.getCollectiblesDD().get(0)).getGathererId());
581
582         broker.clearCache();
583
584         Criteria criteria = new Criteria();
585         criteria.addLike("name", colPrefix + "_colD*");
586         criteria.addLike("name", colPrefix + "*");
587         Query q = new QueryByCriteria(CollectibleD.class, criteria);
588         Collection JavaDoc result = broker.getCollectionByQuery(q);
589         assertNotNull(result);
590         assertEquals("Wrong number of queried objects", 2, result.size());
591
592         criteria = new Criteria();
593         criteria.addLike("name", colPrefix + "_colDD*");
594         q = new QueryByCriteria(CollectibleDD.class, criteria);
595         result = broker.getCollectionByQuery(q);
596         assertNotNull(result);
597         assertEquals("Wrong number of queried objects", 3, result.size());
598
599         // now test objConcreteClass feature
600
// should only return CollectibleD class instances
601
criteria = new Criteria();
602         criteria.addLike("name", colPrefix + "*");
603         q = new QueryByCriteria(CollectibleD.class, criteria);
604         result = broker.getCollectionByQuery(q);
605         assertNotNull(result);
606         assertEquals("Wrong number of queried objects", 2, result.size());
607         // now test objConcreteClass feature
608
criteria = new Criteria();
609         criteria.addLike("name", colPrefix + "*");
610         q = new QueryByCriteria(CollectibleDD.class, criteria);
611         result = broker.getCollectionByQuery(q);
612         assertNotNull(result);
613         assertEquals("Wrong number of queried objects", 3, result.size());
614
615         criteria = new Criteria();
616         criteria.addLike("name", colPrefix + "*");
617         q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
618         result = broker.getCollectionByQuery(q);
619         assertNotNull(result);
620         assertEquals("Wrong number of queried objects", 5, result.size());
621
622         // now we delete the main object
623
// and see what's going on with the dependend objects
624
broker.beginTransaction();
625         broker.delete(new_gatherer);
626         broker.commitTransaction();
627
628         broker.clearCache();
629         new_gatherer = (Gatherer) broker.getObjectByIdentity(oid);
630
631         assertNull(new_gatherer);
632
633         criteria = new Criteria();
634         criteria.addLike("name", colPrefix + "_colD*");
635         q = new QueryByCriteria(CollectibleD.class, criteria);
636         result = broker.getCollectionByQuery(q);
637         assertNotNull(result);
638         // auto-delete is set true
639
assertEquals("Wrong number of queried objects", 0, result.size());
640
641         criteria = new Criteria();
642         criteria.addLike("name", colPrefix + "_colDD*");
643         q = new QueryByCriteria(CollectibleDD.class, criteria);
644         result = broker.getCollectionByQuery(q);
645         assertNotNull(result);
646         // auto-delete is set true
647
assertEquals("Wrong number of queried objects", 0, result.size());
648
649         criteria = new Criteria();
650         criteria.addLike("name", colPrefix + "*");
651         q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
652         result = broker.getCollectionByQuery(q);
653         assertNotNull(result);
654         assertEquals("Wrong number of queried objects", 0, result.size());
655     }
656
657     public void testStoreSimpleCollections()
658     {
659         long timestamp = System.currentTimeMillis();
660         String JavaDoc colPrefix = "col_" + timestamp;
661         String JavaDoc name = timestamp + "_testStoreSimpleCollections";
662
663         // create gatherer with collections
664
Gatherer gatherer = new Gatherer(null, name);
665
666         broker.beginTransaction();
667         broker.store(gatherer);
668         gatherer.setCollectiblesBase(Arrays.asList(prepareCollectibleBase(colPrefix)));
669         gatherer.setCollectiblesB(Arrays.asList(prepareCollectibleB(colPrefix)));
670         broker.store(gatherer);
671         broker.commitTransaction();
672
673         Identity oid = broker.serviceIdentity().buildIdentity(gatherer);
674         broker.clearCache();
675         Gatherer new_gatherer = (Gatherer) broker.getObjectByIdentity(oid);
676
677         assertNotNull(new_gatherer);
678         assertNotNull(new_gatherer.getCollectiblesBase());
679         assertNotNull(new_gatherer.getCollectiblesB());
680         assertEquals("CollectibleBase objects", 3, new_gatherer.getCollectiblesBase().size());
681         assertEquals("CollectibleB objects", 4, new_gatherer.getCollectiblesB().size());
682         Integer JavaDoc gatId = ((CollectibleBaseIF) new_gatherer.getCollectiblesBase().get(0)).getGathererId();
683         assertNotNull(gatId);
684         assertEquals(new_gatherer.gatId, gatId);
685         broker.clearCache();
686
687         Criteria criteria = new Criteria();
688         criteria.addLike("name", colPrefix + "_colBase*");
689         Query q = new QueryByCriteria(CollectibleBase.class, criteria);
690         Collection JavaDoc result = broker.getCollectionByQuery(q);
691         assertNotNull(result);
692         assertEquals("Wrong number of queried objects", 3, result.size());
693
694         criteria = new Criteria();
695         criteria.addLike("name", colPrefix + "_colB*");
696         q = new QueryByCriteria(CollectibleB.class, criteria);
697         result = broker.getCollectionByQuery(q);
698         assertNotNull(result);
699         assertEquals("Wrong number of queried objects", 4, result.size());
700
701         criteria = new Criteria();
702         criteria.addLike("name", colPrefix + "*");
703         q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
704         result = broker.getCollectionByQuery(q);
705         assertNotNull(result);
706         assertEquals("Wrong number of queried objects", 7, result.size());
707     }
708
709     /**
710      * Add new reference objects to an existing collection reference (1:n)
711      * of a main object.
712      */

713     public void testAddNewObjectsToExistingCollection()
714     {
715         long timestamp = System.currentTimeMillis();
716         String JavaDoc colPrefix = "testAddNewObjectsToExistingCollection_" + timestamp;
717         String JavaDoc name = "testAddNewObjectsToExistingCollection_"+timestamp;
718
719         // create gatherer with collections
720
Gatherer gatherer = new Gatherer(null, name);
721
722         broker.beginTransaction();
723         gatherer.setCollectiblesBase(Arrays.asList(prepareCollectibleBase(colPrefix)));
724         broker.store(gatherer);
725         broker.commitTransaction();
726
727         Identity oid = broker.serviceIdentity().buildIdentity(gatherer);
728         broker.clearCache();
729         Gatherer new_gatherer = (Gatherer) broker.getObjectByIdentity(oid);
730
731         assertNotNull(new_gatherer);
732         assertNotNull(new_gatherer.getCollectiblesBase());
733         assertEquals("CollectibleBase objects", 3, new_gatherer.getCollectiblesBase().size());
734         Integer JavaDoc gatId = ((CollectibleBaseIF) new_gatherer.getCollectiblesBase().get(0)).getGathererId();
735         assertNotNull(gatId);
736         assertEquals(new_gatherer.gatId, gatId);
737         broker.clearCache();
738
739         // additional check, read reference objects by query
740
Criteria criteria = new Criteria();
741         criteria.addLike("name", colPrefix+"*");
742         Query q = new QueryByCriteria(CollectibleBase.class, criteria);
743         Collection JavaDoc result = broker.getCollectionByQuery(q);
744         assertNotNull(result);
745         assertEquals("Wrong number of queried objects", 3, result.size());
746
747         List JavaDoc newEntries = Arrays.asList(prepareCollectibleBase(colPrefix));
748         new_gatherer.getCollectiblesBase().addAll(newEntries);
749         broker.beginTransaction();
750         broker.store(new_gatherer);
751         broker.commitTransaction();
752         broker.clearCache();
753
754         new_gatherer = (Gatherer) broker.getObjectByIdentity(oid);
755         assertNotNull(new_gatherer);
756         assertNotNull(new_gatherer.getCollectiblesBase());
757         assertEquals("CollectibleBase objects", 6, new_gatherer.getCollectiblesBase().size());
758         gatId = ((CollectibleBaseIF) new_gatherer.getCollectiblesBase().get(5)).getGathererId();
759         assertNotNull(gatId);
760         assertEquals(new_gatherer.gatId, gatId);
761     }
762
763     /**
764      * generate main object with collections and store
765      * main object to make all persistent.
766      * same like {@link #testStoreSimpleCollections} but now the
767      * collection objects have a reference back to main object.
768      *
769      * Curious but this test does not pass
770      */

771     public void testStoreCollectionObjectsWithBackReference()
772     {
773         long timestamp = System.currentTimeMillis();
774         String JavaDoc colPrefix = "col_" + timestamp;
775         String JavaDoc name = timestamp + "_testStoreCollectionObjectsWithBackReference";
776
777         // create gatherer with collections
778
Gatherer gatherer = new Gatherer(null, name);
779         List JavaDoc collsCList = Arrays.asList(prepareCollectibleC(colPrefix));
780         gatherer.setCollectiblesC(collsCList);
781         for (Iterator JavaDoc iterator = collsCList.iterator(); iterator.hasNext();)
782         {
783             ((CollectibleC) iterator.next()).setGatherer(gatherer);
784         }
785
786         broker.beginTransaction();
787         broker.store(gatherer);
788         broker.commitTransaction();
789         assertEquals("CollectibleC objects", 5, gatherer.getCollectiblesC().size());
790         assertNotNull(gatherer.getCollectiblesC());
791         assertTrue(gatherer.getCollectiblesC().size() > 0);
792         assertEquals(gatherer.getGatId(), ((CollectibleCIF) gatherer.getCollectiblesC().get(0)).getGathererId());
793
794         Identity oid = broker.serviceIdentity().buildIdentity(gatherer);
795         broker.clearCache();
796         Gatherer new_gatherer = (Gatherer) broker.getObjectByIdentity(oid);
797
798         assertNotNull(new_gatherer);
799         assertNotNull(new_gatherer.getCollectiblesC());
800         assertEquals("CollectibleC objects", 5, gatherer.getCollectiblesC().size());
801         assertEquals(gatherer.getGatId(), ((CollectibleCIF) gatherer.getCollectiblesC().get(0)).getGathererId());
802
803         broker.clearCache();
804
805         Criteria criteria = new Criteria();
806         criteria.addLike("name", colPrefix + "_colC*");
807         Query q = new QueryByCriteria(CollectibleC.class, criteria);
808         Collection JavaDoc result = broker.getCollectionByQuery(q);
809         assertNotNull(result);
810         assertEquals("Wrong number of queried objects", 5, result.size());
811
812         criteria = new Criteria();
813         criteria.addLike("name", colPrefix + "*");
814         q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
815         result = broker.getCollectionByQuery(q);
816         assertNotNull(result);
817         assertEquals("Wrong number of queried objects", 5, result.size());
818     }
819
820     public void testOneBookShelfQueryByCollection() throws Exception JavaDoc
821     {
822         String JavaDoc prefix = "testOneBookShelfQueryByCollection_" + System.currentTimeMillis();
823
824         BookShelf bookShelf = new BookShelf(prefix);
825         BookShelfItem ev1 = new DVD(bookShelf);
826         bookShelf.addItem(ev1);
827         BookShelfItem ev2 = new Book(bookShelf);
828         bookShelf.addItem(ev2);
829
830         broker.beginTransaction();
831         broker.store(bookShelf);
832         broker.store(ev1);
833         broker.store(ev2);
834         broker.commitTransaction();
835         assertTrue(bookShelf.getPk() != null);
836
837         broker.clearCache();
838         BookShelf loadedCopy = (BookShelf) broker.getObjectByIdentity(
839                 broker.serviceIdentity().buildIdentity(BookShelf.class, bookShelf.getPk()));
840         assertNotNull(loadedCopy);
841         assertNotNull(loadedCopy.getItems());
842         assertEquals(2, loadedCopy.getItems().size());
843
844         broker.clearCache();
845         Criteria criteria = new Criteria();
846         criteria.addLike("name", prefix);
847         Query q = new QueryByCriteria(BookShelf.class, criteria);
848         Collection JavaDoc books = broker.getCollectionByQuery(q);
849         assertNotNull(books);
850         assertEquals(1, books.size());
851         // we are using collection proxies, so we have to use the interface
852
BookShelfIF bookShelfIF = (BookShelfIF) books.iterator().next();
853         assertNotNull(bookShelfIF.getItems());
854         assertEquals("wrong number of items found", 2, bookShelfIF.getItems().size());
855     }
856
857     public void testOneBookShelfQueryByIterator() throws Exception JavaDoc
858     {
859         String JavaDoc prefix = "testOneBookShelfQueryByIterator_" + System.currentTimeMillis();
860
861         BookShelf bookShelf = new BookShelf(prefix);
862         BookShelfItem ev1 = new DVD(bookShelf);
863         bookShelf.addItem(ev1);
864         BookShelfItem ev2 = new Book(bookShelf);
865         bookShelf.addItem(ev2);
866
867         broker.beginTransaction();
868         broker.store(bookShelf);
869         broker.store(ev1);
870         broker.store(ev2);
871         broker.commitTransaction();
872
873         assertTrue(bookShelf.getPk() != null);
874
875         broker.clearCache();
876         BookShelf loadedCopy = (BookShelf) broker.getObjectByIdentity(
877                 broker.serviceIdentity().buildIdentity(BookShelf.class, bookShelf.getPk()));
878         assertNotNull(loadedCopy);
879         assertNotNull(loadedCopy.getItems());
880         assertEquals(2, loadedCopy.getItems().size());
881
882         broker.clearCache();
883         Criteria criteria = new Criteria();
884         criteria.addLike("name", prefix);
885         Query q = new QueryByCriteria(BookShelf.class, criteria);
886         Iterator JavaDoc books = broker.getIteratorByQuery(q);
887         assertTrue(books.hasNext());
888         loadedCopy = (BookShelf) books.next();
889         assertNotNull(loadedCopy.getItems());
890         assertEquals("wrong number of items found", 2, loadedCopy.getItems().size());
891     }
892
893
894     /**
895      * Test RemovalAwareCollection remove() and clear()
896      */

897     public void testRemovalAwareCollection()
898     {
899         String JavaDoc prefix = "testRemovalAwareCollection_" + System.currentTimeMillis();
900
901         Identity gathererId;
902         Gatherer loadedCopy;
903         Gatherer gatherer = new Gatherer(null, "Gatherer_" + prefix);
904         List JavaDoc coll = new ArrayList JavaDoc();
905         coll.add(new CollectibleBase("Base_1_" + prefix));
906         coll.add(new CollectibleBase("Base_2_" + prefix));
907         coll.add(new CollectibleBase("Base_3_" + prefix));
908         gatherer.setCollectiblesBase(coll);
909
910         broker.beginTransaction();
911         broker.store(gatherer);
912         broker.commitTransaction();
913         assertTrue(gatherer.getGatId() != null);
914         gathererId = broker.serviceIdentity().buildIdentity(gatherer);
915
916         broker.clearCache();
917         loadedCopy = (Gatherer) broker.getObjectByIdentity(gathererId);
918         assertNotNull(loadedCopy);
919         assertNotNull(loadedCopy.getCollectiblesBase());
920         assertTrue(loadedCopy.getCollectiblesBase() instanceof RemovalAwareCollection);
921         assertEquals(3, loadedCopy.getCollectiblesBase().size());
922
923         //
924
// Remove a single element
925
//
926
broker.beginTransaction();
927         loadedCopy.getCollectiblesBase().remove(2);
928         broker.store(loadedCopy);
929         broker.commitTransaction();
930
931         broker.clearCache();
932         loadedCopy = (Gatherer) broker.getObjectByIdentity(gathererId);
933         assertNotNull(loadedCopy);
934         assertNotNull(loadedCopy.getCollectiblesBase());
935         assertTrue(loadedCopy.getCollectiblesBase() instanceof RemovalAwareCollection);
936         assertEquals(2, loadedCopy.getCollectiblesBase().size());
937
938         //
939
// Remove all elements
940
//
941
broker.beginTransaction();
942         loadedCopy.getCollectiblesBase().clear();
943         broker.store(loadedCopy);
944         broker.commitTransaction();
945
946         broker.clearCache();
947         loadedCopy = (Gatherer) broker.getObjectByIdentity(gathererId);
948         assertNotNull(loadedCopy);
949         assertNotNull(loadedCopy.getCollectiblesBase());
950         assertTrue(loadedCopy.getCollectiblesBase() instanceof RemovalAwareCollection);
951         assertEquals(0, loadedCopy.getCollectiblesBase().size());
952     }
953
954     /**
955      * Test RemovalAwareCollection remove() of non persistent obj
956      */

957     public void testRemovalAwareCollection2()
958     {
959         String JavaDoc prefix = "testRemovalAwareCollection2_" + System.currentTimeMillis();
960
961         Identity gathererId;
962         Gatherer loadedCopy;
963         Gatherer gatherer = new Gatherer(null, "Gatherer_" + prefix);
964         List JavaDoc coll = new ArrayList JavaDoc();
965         coll.add(new CollectibleBase("Base_1_" + prefix));
966         coll.add(new CollectibleBase("Base_2_" + prefix));
967         gatherer.setCollectiblesBase(coll);
968
969         broker.beginTransaction();
970         broker.store(gatherer);
971         broker.commitTransaction();
972         assertTrue(gatherer.getGatId() != null);
973         gathererId = broker.serviceIdentity().buildIdentity(gatherer);
974
975         broker.clearCache();
976         loadedCopy = (Gatherer) broker.getObjectByIdentity(gathererId);
977         assertNotNull(loadedCopy);
978         assertNotNull(loadedCopy.getCollectiblesBase());
979         assertTrue(loadedCopy.getCollectiblesBase() instanceof RemovalAwareCollection);
980         assertEquals(2, loadedCopy.getCollectiblesBase().size());
981
982         // add and remove non persistent obj
983
loadedCopy.getCollectiblesBase().add(new CollectibleBase("Base_3_" + prefix));
984         assertEquals(3, loadedCopy.getCollectiblesBase().size());
985         loadedCopy.getCollectiblesBase().remove(2);
986
987         broker.beginTransaction();
988         broker.store(loadedCopy);
989         broker.commitTransaction();
990     }
991
992     /**
993      * Test RemovalAwareCollection remove() and clear()
994      */

995     public void testRemovalAwareCollectionProxy()
996     {
997         String JavaDoc prefix = "testRemovalAwareCollectionProxy_" + System.currentTimeMillis();
998
999         Identity pgId;
1000        ProductGroup loadedCopy;
1001        InterfaceArticle article;
1002        ProductGroup pg = new ProductGroup(null, "PG_" + prefix, null);
1003        article = new Article();
1004        article.setArticleName("Art_1_" + prefix);
1005        pg.add(article);
1006        article = new Article();
1007        article.setArticleName("Art_2_" + prefix);
1008        pg.add(article);
1009        article = new Article();
1010        article.setArticleName("Art_3_" + prefix);
1011        pg.add(article);
1012
1013        broker.beginTransaction();
1014        broker.store(pg);
1015        broker.commitTransaction();
1016        assertTrue(pg.getGroupId() != null);
1017        pgId = broker.serviceIdentity().buildIdentity(pg);
1018
1019        broker.clearCache();
1020        loadedCopy = (ProductGroup) broker.getObjectByIdentity(pgId);
1021        assertNotNull(loadedCopy);
1022        assertNotNull(loadedCopy.getAllArticlesInGroup());
1023        assertTrue(loadedCopy.getAllArticlesInGroup() instanceof RemovalAwareCollection);
1024        assertEquals(3, loadedCopy.getAllArticlesInGroup().size());
1025
1026        //
1027
// Remove a single element
1028
//
1029
broker.beginTransaction();
1030        loadedCopy.getAllArticlesInGroup().remove(2);
1031        broker.store(loadedCopy);
1032        broker.commitTransaction();
1033
1034        broker.clearCache();
1035        loadedCopy = (ProductGroup) broker.getObjectByIdentity(pgId);
1036        assertNotNull(loadedCopy);
1037        assertNotNull(loadedCopy.getAllArticlesInGroup());
1038        assertTrue(loadedCopy.getAllArticlesInGroup() instanceof RemovalAwareCollection);
1039        assertEquals(2, loadedCopy.getAllArticlesInGroup().size());
1040
1041        //
1042
// Remove all elements
1043
//
1044
broker.beginTransaction();
1045        loadedCopy.getAllArticlesInGroup().clear();
1046        broker.store(loadedCopy);
1047        broker.commitTransaction();
1048
1049        broker.clearCache();
1050        loadedCopy = (ProductGroup) broker.getObjectByIdentity(pgId);
1051        assertNotNull(loadedCopy);
1052        assertNotNull(loadedCopy.getAllArticlesInGroup());
1053        assertTrue(loadedCopy.getAllArticlesInGroup() instanceof RemovalAwareCollection);
1054        assertEquals(0, loadedCopy.getAllArticlesInGroup().size());
1055    }
1056
1057    //************************************************************
1058
// helper methods
1059
//************************************************************
1060

1061    private CollectibleBase[] prepareCollectibleBase(String JavaDoc namePrefix)
1062    {
1063        return new CollectibleBase[]{
1064            new CollectibleBase(namePrefix + "_colBase_1"),
1065            new CollectibleBase(namePrefix + "_colBase_2"),
1066            new CollectibleBase(namePrefix + "_colBase_3")
1067        };
1068    }
1069
1070    private CollectibleB[] prepareCollectibleB(String JavaDoc namePrefix)
1071    {
1072        return new CollectibleB[]{
1073            new CollectibleB(namePrefix + "_colB_1"),
1074            new CollectibleB(namePrefix + "_colB_2"),
1075            new CollectibleB(namePrefix + "_colB_3"),
1076            new CollectibleB(namePrefix + "_colB_4")
1077        };
1078    }
1079
1080    private CollectibleC[] prepareCollectibleC(String JavaDoc namePrefix)
1081    {
1082        return new CollectibleC[]{
1083            new CollectibleC(namePrefix + "_colC_1", "ext1"),
1084            new CollectibleC(namePrefix + "_colC_2", "ext2"),
1085            new CollectibleC(namePrefix + "_colC_3", "ext3"),
1086            new CollectibleC(namePrefix + "_colC_4", "ext4"),
1087            new CollectibleC(namePrefix + "_colC_5", "ext5")
1088        };
1089    }
1090
1091    private CollectibleCC[] prepareCollectibleCC(String JavaDoc namePrefix)
1092    {
1093        return new CollectibleCC[]{
1094            new CollectibleCC(namePrefix + "_colCC_1", "ext1"),
1095            new CollectibleCC(namePrefix + "_colCC_2", "ext2"),
1096            new CollectibleCC(namePrefix + "_colCC_3", "ext3"),
1097            new CollectibleCC(namePrefix + "_colCC_4", "ext4"),
1098            new CollectibleCC(namePrefix + "_colCC_5", "ext5")
1099        };
1100    }
1101
1102    private CollectibleC2[] prepareCollectibleC2(String JavaDoc namePrefix)
1103    {
1104        return new CollectibleC2[]{
1105            new CollectibleC2(namePrefix + "_colC2_1", "ext1"),
1106            new CollectibleC2(namePrefix + "_colC2_2", "ext2"),
1107            new CollectibleC2(namePrefix + "_colC2_3", "ext3"),
1108            new CollectibleC2(namePrefix + "_colC2_4", "ext4"),
1109            new CollectibleC2(namePrefix + "_colC2_5", "ext5")
1110        };
1111    }
1112
1113    private CollectibleD[] prepareCollectibleD(String JavaDoc namePrefix)
1114    {
1115        return new CollectibleD[]{
1116            new CollectibleD(namePrefix + "_colD_1"),
1117            new CollectibleD(namePrefix + "_colD_2"),
1118        };
1119    }
1120
1121    private CollectibleDD[] prepareCollectibleDD(String JavaDoc namePrefix)
1122    {
1123        return new CollectibleDD[]{
1124            new CollectibleDD(namePrefix + "_colDD_1"),
1125            new CollectibleDD(namePrefix + "_colDD_2"),
1126            new CollectibleDD(namePrefix + "_colDD_3")
1127        };
1128    }
1129
1130
1131    //*********************************************************************
1132
// inner classes - persistent object
1133
//*********************************************************************
1134

1135    public static class CollectionClassDummy implements ManageableCollection
1136    {
1137        ArrayList JavaDoc list = new ArrayList JavaDoc();
1138
1139        public void ojbAdd(Object JavaDoc anObject)
1140        {
1141            list.add(anObject);
1142        }
1143
1144        public void ojbAddAll(ManageableCollection otherCollection)
1145        {
1146            Iterator JavaDoc it = otherCollection.ojbIterator();
1147            while (it.hasNext())
1148            {
1149                list.add(it.next());
1150            }
1151        }
1152
1153        public Iterator JavaDoc ojbIterator()
1154        {
1155            return list.iterator();
1156        }
1157
1158        public void afterStore(PersistenceBroker broker) throws PersistenceBrokerException
1159        {
1160            //noop
1161
}
1162
1163        public int size()
1164        {
1165            return list.size();
1166        }
1167    }
1168
1169
1170    public static class Gatherer implements Serializable JavaDoc
1171    {
1172        private Integer JavaDoc gatId;
1173        private String JavaDoc name;
1174        private List JavaDoc collectiblesBase;
1175        private List JavaDoc collectiblesB;
1176        private List JavaDoc collectiblesC;
1177        private List JavaDoc collectiblesCC;
1178        private List JavaDoc collectiblesC2;
1179        private List JavaDoc collectiblesD;
1180        private List JavaDoc collectiblesDD;
1181        private CollectionClassDummy collectionDummy;
1182
1183        public Gatherer()
1184        {
1185        }
1186
1187        public Gatherer(Integer JavaDoc gatId, String JavaDoc name)
1188        {
1189            this.gatId = gatId;
1190            this.name = name;
1191        }
1192
1193        public Integer JavaDoc getGatId()
1194        {
1195            return gatId;
1196        }
1197
1198        public void setGatId(Integer JavaDoc gatId)
1199        {
1200            this.gatId = gatId;
1201        }
1202
1203        public String JavaDoc getName()
1204        {
1205            return name;
1206        }
1207
1208        public void setName(String JavaDoc name)
1209        {
1210            this.name = name;
1211        }
1212
1213        public CollectionClassDummy getCollectionDummy()
1214        {
1215            return collectionDummy;
1216        }
1217
1218        public void setCollectionDummy(CollectionClassDummy collectionDummy)
1219        {
1220            this.collectionDummy = collectionDummy;
1221        }
1222
1223        public List JavaDoc getCollectiblesBase()
1224        {
1225            return collectiblesBase;
1226        }
1227
1228        public void setCollectiblesBase(List JavaDoc collectiblesBase)
1229        {
1230            this.collectiblesBase = collectiblesBase;
1231        }
1232
1233        public List JavaDoc getCollectiblesB()
1234        {
1235            return collectiblesB;
1236        }
1237
1238        public void setCollectiblesB(List JavaDoc collectiblesB)
1239        {
1240            this.collectiblesB = collectiblesB;
1241        }
1242
1243        public List JavaDoc getCollectiblesC()
1244        {
1245            return collectiblesC;
1246        }
1247
1248        public void setCollectiblesC(List JavaDoc collectiblesC)
1249        {
1250            this.collectiblesC = collectiblesC;
1251        }
1252
1253        public List JavaDoc getCollectiblesCC()
1254        {
1255            return collectiblesCC;
1256        }
1257
1258        public void setCollectiblesCC(List JavaDoc collectiblesCC)
1259        {
1260            this.collectiblesCC = collectiblesCC;
1261        }
1262
1263        public List JavaDoc getCollectiblesC2()
1264        {
1265            return collectiblesC2;
1266        }
1267
1268        public void setCollectiblesC2(List JavaDoc collectiblesC2)
1269        {
1270            this.collectiblesC2 = collectiblesC2;
1271        }
1272
1273        public List JavaDoc getCollectiblesD()
1274        {
1275            return collectiblesD;
1276        }
1277
1278        public void setCollectiblesD(List JavaDoc collectiblesD)
1279        {
1280            this.collectiblesD = collectiblesD;
1281        }
1282
1283        public List JavaDoc getCollectiblesDD()
1284        {
1285            return collectiblesDD;
1286        }
1287
1288        public void setCollectiblesDD(List JavaDoc collectiblesDD)
1289        {
1290            this.collectiblesDD = collectiblesDD;
1291        }
1292
1293        public String JavaDoc toString()
1294        {
1295            ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
1296            buf.append("gatId", gatId);
1297            buf.append("name", name);
1298            buf.append("collectiblesBase", collectiblesBase);
1299            buf.append("collectiblesB", collectiblesB);
1300            buf.append("collectiblesC", collectiblesC);
1301            buf.append("collectiblesD", collectiblesD);
1302            buf.append("collectiblesDD", collectiblesDD);
1303            return buf.toString();
1304        }
1305    }
1306
1307    public static interface CollectibleBaseIF extends Serializable JavaDoc
1308    {
1309        Integer JavaDoc getColId();
1310
1311        void setColId(Integer JavaDoc colId);
1312
1313        String JavaDoc getName();
1314
1315        void setName(String JavaDoc name);
1316
1317        Integer JavaDoc getGathererId();
1318
1319        void setGathererId(Integer JavaDoc colId);
1320
1321        Gatherer getGatherer();
1322
1323        void setGatherer(Gatherer gatherer);
1324    }
1325
1326    public static class CollectibleBase implements CollectibleBaseIF
1327    {
1328        private Integer JavaDoc colId;
1329        private String JavaDoc name;
1330        private Integer JavaDoc gathererId;
1331        private Gatherer gatherer;
1332        // protected String ojbConcreteClass;
1333

1334        public CollectibleBase()
1335        {
1336            // ojbConcreteClass = CollectibleBase.class.getName();
1337
}
1338
1339        public CollectibleBase(String JavaDoc name)
1340        {
1341            // ojbConcreteClass = CollectibleBase.class.getName();
1342
this.name = name;
1343        }
1344
1345        public String JavaDoc toString()
1346        {
1347            ToStringBuilder buf = new ToStringBuilder(this);
1348            buf.append("colId", colId);
1349            buf.append("name", name);
1350            buf.append("gathererId", gathererId);
1351// buf.append("ojbConcreteClass", ojbConcreteClass);
1352
return buf.toString();
1353        }
1354
1355        public Gatherer getGatherer()
1356        {
1357            return gatherer;
1358        }
1359
1360        public void setGatherer(Gatherer gatherer)
1361        {
1362            this.gatherer = gatherer;
1363        }
1364
1365        public Integer JavaDoc getGathererId()
1366        {
1367            return gathererId;
1368        }
1369
1370        public void setGathererId(Integer JavaDoc gathererId)
1371        {
1372            this.gathererId = gathererId;
1373        }
1374
1375        public Integer JavaDoc getColId()
1376        {
1377            return colId;
1378        }
1379
1380        public void setColId(Integer JavaDoc colId)
1381        {
1382            this.colId = colId;
1383        }
1384
1385        public String JavaDoc getName()
1386        {
1387            return name;
1388        }
1389
1390        public void setName(String JavaDoc name)
1391        {
1392            this.name = name;
1393        }
1394    }
1395
1396    public static interface CollectibleBIF extends CollectibleBaseIF
1397    {
1398
1399    }
1400
1401    public static class CollectibleB extends CollectibleBase implements CollectibleBIF
1402    {
1403        public CollectibleB()
1404        {
1405// ojbConcreteClass = CollectibleB.class.getName();
1406
}
1407
1408        public CollectibleB(String JavaDoc name)
1409        {
1410            super(name);
1411// ojbConcreteClass = CollectibleB.class.getName();
1412
}
1413    }
1414
1415    public static interface CollectibleCIF extends CollectibleBIF
1416    {
1417        String JavaDoc getExtentName();
1418
1419        void setExtentName(String JavaDoc extentName);
1420    }
1421
1422    public static class CollectibleC extends CollectibleB implements CollectibleCIF
1423    {
1424        private String JavaDoc extentName;
1425
1426        public CollectibleC()
1427        {
1428// ojbConcreteClass = CollectibleC.class.getName();
1429
}
1430
1431        public CollectibleC(String JavaDoc name)
1432        {
1433            super(name);
1434// ojbConcreteClass = CollectibleC.class.getName();
1435
}
1436
1437        public CollectibleC(String JavaDoc name, String JavaDoc extentName)
1438        {
1439            super(name);
1440// ojbConcreteClass = CollectibleC.class.getName();
1441
this.extentName = extentName;
1442        }
1443
1444        public String JavaDoc getExtentName()
1445        {
1446            return extentName;
1447        }
1448
1449        public void setExtentName(String JavaDoc extentName)
1450        {
1451            this.extentName = extentName;
1452        }
1453    }
1454
1455    public static class CollectibleCC extends CollectibleC
1456    {
1457        public CollectibleCC()
1458        {
1459        }
1460
1461        public CollectibleCC(String JavaDoc name)
1462        {
1463            super(name);
1464        }
1465
1466        public CollectibleCC(String JavaDoc name, String JavaDoc extentName)
1467        {
1468            super(name, extentName);
1469        }
1470    }
1471
1472    public static class CollectibleC2 extends CollectibleC
1473    {
1474        public CollectibleC2()
1475        {
1476        }
1477
1478        public CollectibleC2(String JavaDoc name)
1479        {
1480            super(name);
1481        }
1482
1483        public CollectibleC2(String JavaDoc name, String JavaDoc extentName)
1484        {
1485            super(name, extentName);
1486        }
1487    }
1488
1489    public static interface CollectibleDIF extends CollectibleBaseIF
1490    {
1491
1492    }
1493
1494    public static class CollectibleD extends CollectibleBase implements CollectibleDIF
1495    {
1496        protected String JavaDoc ojbConcreteClass;
1497
1498        public CollectibleD()
1499        {
1500            ojbConcreteClass = CollectibleD.class.getName();
1501        }
1502
1503        public CollectibleD(String JavaDoc name)
1504        {
1505            super(name);
1506            ojbConcreteClass = CollectibleD.class.getName();
1507        }
1508
1509        public String JavaDoc getOjbConcreteClass()
1510        {
1511            return ojbConcreteClass;
1512        }
1513
1514        public void setOjbConcreteClass(String JavaDoc ojbConcreteClass)
1515        {
1516            this.ojbConcreteClass = ojbConcreteClass;
1517        }
1518    }
1519
1520    public static interface CollectibleDDIF extends CollectibleBaseIF
1521    {
1522
1523    }
1524
1525    public static class CollectibleDD extends CollectibleBase implements CollectibleDDIF
1526    {
1527        protected String JavaDoc ojbConcreteClass;
1528
1529        public CollectibleDD()
1530        {
1531            ojbConcreteClass = CollectibleDD.class.getName();
1532        }
1533
1534        public CollectibleDD(String JavaDoc name)
1535        {
1536            super(name);
1537            ojbConcreteClass = CollectibleDD.class.getName();
1538        }
1539
1540        public String JavaDoc getOjbConcreteClass()
1541        {
1542            return ojbConcreteClass;
1543        }
1544
1545        public void setOjbConcreteClass(String JavaDoc ojbConcreteClass)
1546        {
1547            this.ojbConcreteClass = ojbConcreteClass;
1548        }
1549    }
1550
1551    public static interface BookShelfIF
1552    {
1553        public void addItem(BookShelfItem event);
1554        public List JavaDoc getItems();
1555        public Integer JavaDoc getPk();
1556        public void setPk(Integer JavaDoc pk);
1557        public String JavaDoc getName();
1558        public void setName(String JavaDoc name);
1559    }
1560
1561
1562    public static class BookShelf implements BookShelfIF
1563    {
1564        private Integer JavaDoc pk;
1565        private String JavaDoc name;
1566        private List JavaDoc items;
1567
1568        public BookShelf()
1569        {
1570        }
1571
1572        public BookShelf(String JavaDoc name)
1573        {
1574            this.name = name;
1575        }
1576
1577        public void addItem(BookShelfItem event)
1578        {
1579            if (items == null)
1580                items = new ArrayList JavaDoc();
1581
1582            items.add(event);
1583        }
1584
1585        public void setItems(List JavaDoc items)
1586        {
1587            this.items = items;
1588        }
1589
1590        public List JavaDoc getItems()
1591        {
1592            return items;
1593        }
1594
1595        public Integer JavaDoc getPk()
1596        {
1597            return pk;
1598        }
1599
1600        public void setPk(Integer JavaDoc pk)
1601        {
1602            this.pk = pk;
1603        }
1604
1605        public String JavaDoc getName()
1606        {
1607            return name;
1608        }
1609
1610        public void setName(String JavaDoc name)
1611        {
1612            this.name = name;
1613        }
1614    }
1615
1616    public static abstract class BookShelfItem
1617    {
1618        private Integer JavaDoc pk;
1619        private String JavaDoc name;
1620        private BookShelfIF shelf;
1621
1622        public BookShelfItem()
1623        {
1624        }
1625
1626        public BookShelfItem(BookShelfIF shelf)
1627        {
1628            this.shelf = shelf;
1629        }
1630
1631        protected BookShelfItem(String JavaDoc name, BookShelfIF shelf)
1632        {
1633            this.name = name;
1634            this.shelf = shelf;
1635        }
1636
1637        public Integer JavaDoc getPk()
1638        {
1639            return pk;
1640        }
1641
1642        public void setPk(Integer JavaDoc pk)
1643        {
1644            this.pk = pk;
1645        }
1646
1647        public String JavaDoc getName()
1648        {
1649            return name;
1650        }
1651
1652        public void setName(String JavaDoc name)
1653        {
1654            this.name = name;
1655        }
1656
1657        public BookShelfIF getShelf()
1658        {
1659            return shelf;
1660        }
1661
1662        public void setShelf(BookShelf shelf)
1663        {
1664            this.shelf = shelf;
1665        }
1666    }
1667
1668    public static class DVD extends BookShelfItem
1669    {
1670        public DVD()
1671        {
1672        }
1673
1674        public DVD(BookShelf shelf)
1675        {
1676            super(shelf);
1677        }
1678
1679        public DVD(String JavaDoc name, BookShelfIF shelf)
1680        {
1681            super(name, shelf);
1682        }
1683    }
1684
1685    public static class Book extends BookShelfItem
1686    {
1687        public Book()
1688        {
1689        }
1690
1691        public Book(BookShelfIF shelf)
1692        {
1693            super(shelf);
1694        }
1695
1696        public Book(String JavaDoc name, BookShelfIF shelf)
1697        {
1698            super(name, shelf);
1699        }
1700    }
1701
1702     public static class Candie
1703    {
1704        private Integer JavaDoc pk;
1705        private String JavaDoc name;
1706        private String JavaDoc ingredients;
1707        private BookShelfIF shelf;
1708
1709        public Candie()
1710        {
1711        }
1712
1713        public Candie(BookShelfIF shelf)
1714        {
1715            this.shelf = shelf;
1716        }
1717
1718        protected Candie(String JavaDoc name, BookShelfIF shelf)
1719        {
1720            this.name = name;
1721            this.shelf = shelf;
1722        }
1723
1724        public Integer JavaDoc getPk()
1725        {
1726            return pk;
1727        }
1728
1729        public void setPk(Integer JavaDoc pk)
1730        {
1731            this.pk = pk;
1732        }
1733
1734        public String JavaDoc getName()
1735        {
1736            return name;
1737        }
1738
1739        public void setName(String JavaDoc name)
1740        {
1741            this.name = name;
1742        }
1743
1744        public String JavaDoc getIngredients()
1745        {
1746            return ingredients;
1747        }
1748
1749        public void setIngredients(String JavaDoc ingredients)
1750        {
1751            this.ingredients = ingredients;
1752        }
1753
1754        public BookShelfIF getShelf()
1755        {
1756            return shelf;
1757        }
1758
1759        public void setShelf(BookShelf shelf)
1760        {
1761            this.shelf = shelf;
1762        }
1763    }
1764}
1765
Popular Tags