KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > odmg > CollectionsTest


1 package org.apache.ojb.odmg;
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 import java.util.Vector JavaDoc;
10
11 import org.apache.ojb.broker.PersistenceBroker;
12 import org.apache.ojb.broker.PersistenceBrokerFactory;
13 import org.apache.ojb.broker.metadata.CollectionDescriptor;
14 import org.apache.ojb.broker.query.Criteria;
15 import org.apache.ojb.broker.query.Query;
16 import org.apache.ojb.broker.query.QueryFactory;
17 import org.apache.ojb.junit.ODMGTestCase;
18 import org.apache.commons.lang.builder.ToStringBuilder;
19 import org.apache.commons.lang.builder.ToStringStyle;
20 import org.odmg.OQLQuery;
21 import org.odmg.Transaction;
22
23 /**
24  * Test case handles with collections.
25  *
26  * @author <a HREF="mailto:armin@codeAuLait.de">Armin Waibel</a>
27  * @version $Id: CollectionsTest.java,v 1.13.2.12 2005/11/25 14:35:30 arminw Exp $
28  */

29 public class CollectionsTest extends ODMGTestCase
30 {
31     public CollectionsTest(String JavaDoc s)
32     {
33         super(s);
34     }
35
36     public static void main(String JavaDoc[] args)
37     {
38         String JavaDoc[] arr = {CollectionsTest.class.getName()};
39         junit.textui.TestRunner.main(arr);
40     }
41
42     public void setUp() throws Exception JavaDoc
43     {
44         super.setUp();
45     }
46
47     protected void tearDown() throws Exception JavaDoc
48     {
49         super.tearDown();
50     }
51
52
53     public void testStoreDeleteCascadeDelete() throws Exception JavaDoc
54     {
55         String JavaDoc prefix = "testStoreDeleteCascadeDelete_" + System.currentTimeMillis();
56         String JavaDoc queryStr = "select gatherer from " + Gatherer.class.getName() + " where gatId=$1";
57
58         ojbChangeReferenceSetting(Gatherer.class, "collectiblesA", true,
59                 CollectionDescriptor.CASCADE_NONE, CollectionDescriptor.CASCADE_OBJECT, false);
60
61         // prepare test case
62
Gatherer gat = new Gatherer(null, prefix + "_Gatherer");
63         CollectibleA[] cols = prepareCollectibleA(gat, prefix);
64         List JavaDoc colList = Arrays.asList(cols);
65         // set List of CollectiblesA objects
66
gat.setCollectiblesA(colList);
67         TransactionExt tx = (TransactionExt)odmg.newTransaction();
68         tx.begin();
69         database.makePersistent(gat);
70         tx.commit();
71
72         // check if gatherer was stored
73
tx.begin();
74         tx.getBroker().clearCache();
75         OQLQuery query = odmg.newOQLQuery();
76         query.create(queryStr);
77         Integer JavaDoc gatId = gat.getGatId();
78         assertNotNull(gatId);
79         query.bind(gatId);
80         Collection JavaDoc result = (Collection JavaDoc) query.execute();
81         tx.commit();
82         assertEquals("Wrong number of objects found", 1, result.size());
83         Gatherer fetchedGat = (Gatherer) result.iterator().next();
84
85         List JavaDoc colsA = fetchedGat.getCollectiblesA();
86         assertEquals("Wrong number of CollectiblesA", 3, colsA.size());
87         // check if gatherer contains list of CollectibleBase
88
tx.begin();
89         //*************************************
90
database.deletePersistent(fetchedGat);
91         //*************************************
92
tx.commit();
93
94         // check if the CollectibleBase was really deleted from DB
95
tx.begin();
96         query = odmg.newOQLQuery();
97         query.create("select allCollectibleA from " + CollectibleA.class.getName() +
98                 " where name like $1");
99         query.bind(prefix + "%");
100         result = (Collection JavaDoc) query.execute();
101         assertEquals("Wrong number of objects found", 0, result.size());
102         tx.commit();
103
104         // check if the gatherer now contains a CollectibleBase list
105
// reduced by the deleted
106
tx.begin();
107         query = odmg.newOQLQuery();
108         query.create(queryStr);
109         query.bind(gatId);
110         result = (Collection JavaDoc) query.execute();
111         assertEquals("Wrong number of objects found", 0, result.size());
112         tx.commit();
113     }
114
115     public void testStoreCollectionElementWithoutBackReference() throws Exception JavaDoc
116     {
117         // String queryColl = "select colls from " + CollectibleC.class.getName() + " where name=$1";
118
String JavaDoc queryGat = "select gatherer from " + Gatherer.class.getName() + " where gatId=$1";
119         String JavaDoc prefix = "testStoreCollectionElementWithoutBackReference_" + System.currentTimeMillis();
120
121         // prepare test case
122
Gatherer gat = new Gatherer(null, prefix + "_Gatherer");
123         TransactionExt tx = (TransactionExt)odmg.newTransaction();
124         tx.begin();
125         database.makePersistent(gat);
126         tx.commit();
127         // check if gatherer was stored
128
tx.begin();
129         tx.getBroker().clearCache();
130         assertNotNull(gat.getGatId());
131         OQLQuery query = odmg.newOQLQuery();
132         query.create(queryGat);
133         query.bind(gat.getGatId());
134         Collection JavaDoc result = (Collection JavaDoc) query.execute();
135         tx.commit();
136         assertEquals("Wrong number of objects found", 1, result.size());
137         gat = (Gatherer) result.iterator().next();
138         assertNotNull(gat);
139         //**********************************************
140
CollectibleC child = new CollectibleC(prefix, null, "a new CollectibleC");
141         tx.begin();
142         tx.lock(gat, Transaction.WRITE);
143         tx.lock(child, Transaction.WRITE);
144         List JavaDoc childs = new ArrayList JavaDoc();
145         childs.add(child);
146         gat.setCollectiblesC(childs);
147         tx.commit();
148         //**********************************************
149
// check if gatherer was stored
150
tx.begin();
151         tx.getBroker().clearCache();
152         assertNotNull(gat.getGatId());
153         query = odmg.newOQLQuery();
154         query.create(queryGat);
155         query.bind(gat.getGatId());
156         result = (Collection JavaDoc) query.execute();
157         tx.commit();
158         assertEquals("Wrong number of objects found", 1, result.size());
159         gat = (Gatherer) result.iterator().next();
160         assertNotNull(gat);
161         assertNotNull(gat.getCollectiblesC());
162         assertEquals(1, gat.getCollectiblesC().size());
163     }
164
165     /**
166      * Create an main object Gatherer with a collection of objects CollectiblesC.
167      * CollectiblesC hasn't a reference back to the main object. After creation we
168      * remove an collection element.
169      */

170     public void testRemoveCollectionElementWithoutBackReference() throws Exception JavaDoc
171     {
172         // String queryColl = "select colls from " + CollectibleC.class.getName() + " where name=$1";
173
String JavaDoc queryGat = "select gatherer from " + Gatherer.class.getName() + " where gatId=$1";
174         String JavaDoc prefix = "testDeleteCollectionElementWithoutBackReference_" + System.currentTimeMillis();
175
176         // prepare test case
177
Gatherer gat = new Gatherer(null, prefix + "_Gatherer");
178         // we don't set the gatId in CollectiblesC, because we don't have one
179
// Set List of CollectiblesC objects
180
gat.setCollectiblesC(Arrays.asList(prepareCollectibleC(null, prefix)));
181         TransactionExt tx = (TransactionExt)odmg.newTransaction();
182         tx.begin();
183         database.makePersistent(gat);
184         tx.commit();
185
186         // check if gatherer was stored
187
tx.begin();
188         tx.getBroker().clearCache();
189         assertNotNull(gat.getGatId());
190
191         OQLQuery query = odmg.newOQLQuery();
192         query.create(queryGat);
193         query.bind(gat.getGatId());
194
195         Collection JavaDoc result = (Collection JavaDoc) query.execute();
196         tx.commit();
197         assertEquals("Wrong number of objects found", 1, result.size());
198         Gatherer fetchedGat = (Gatherer) result.iterator().next();
199         assertNotNull(fetchedGat);
200
201         // check if gatherer contains list of CollectibleBase
202
List JavaDoc colC = fetchedGat.getCollectiblesC();
203         assertEquals("Wrong number of CollectiblesC", 3, colC.size());
204
205         tx.begin();
206         //*************************************
207
tx.lock(fetchedGat, Transaction.WRITE);
208         // Remove collection object
209
Object JavaDoc toDelete = fetchedGat.getCollectiblesC().remove(0);
210         // explicit persistent delete call needed
211
database.deletePersistent(toDelete);
212         // alternative use TransactionExt#autoDeleteRemovedCollectionReferences
213
//*************************************
214
tx.commit();
215
216         // check if the Collectibles were really deleted from DB
217
tx.begin();
218         tx.getBroker().clearCache();
219
220         query = odmg.newOQLQuery();
221         query.create("select colls from " + CollectibleC.class.getName() +
222                 " where name like $1");
223         query.bind(prefix + "%");
224         result = (Collection JavaDoc) query.execute();
225
226         assertEquals("Wrong number of objects found", 2, result.size());
227         tx.commit();
228
229         // check if the gatherer now contains a CollectibleBase list
230
// increased by the added
231
tx.begin();
232         tx.getBroker().clearCache();
233         query = odmg.newOQLQuery();
234         query.create(queryGat);
235         query.bind(gat.getGatId());
236         result = (Collection JavaDoc) query.execute();
237         assertEquals("Wrong number of objects found", 1, result.size());
238         fetchedGat = (Gatherer) result.iterator().next();
239         colC = fetchedGat.getCollectiblesC();
240         assertEquals("Wrong number of CollectiblesA found in Gatherer", 2, colC.size());
241         tx.commit();
242         assertNotNull(colC.get(0));
243     }
244
245     public void testStoreFetchDeleteCollectionWithBackReference() throws Exception JavaDoc
246     {
247         String JavaDoc prefix = "testStoreFetchDeleteCollectionWithBackReference_" + System.currentTimeMillis();
248         String JavaDoc queryStr = "select gatherer from " + Gatherer.class.getName() + " where gatId=$1";
249
250         // prepare test case
251
Gatherer gat = new Gatherer(null, prefix + "_Gatherer");
252         CollectibleA[] cols = prepareCollectibleA(gat, prefix);
253         List JavaDoc colList = Arrays.asList(cols);
254         // set List of CollectiblesA objects
255
gat.setCollectiblesA(colList);
256         TransactionExt tx = (TransactionExt)odmg.newTransaction();
257         tx.begin();
258         database.makePersistent(gat);
259         tx.commit();
260
261         // check if gatherer was stored
262
tx.begin();
263         tx.getBroker().clearCache();
264         OQLQuery query = odmg.newOQLQuery();
265         query.create(queryStr);
266         Integer JavaDoc gatId = gat.getGatId();
267         assertNotNull(gatId);
268         query.bind(gatId);
269         Collection JavaDoc result = (Collection JavaDoc) query.execute();
270         tx.commit();
271         assertEquals("Wrong number of objects found", 1, result.size());
272         Gatherer fetchedGat = (Gatherer) result.iterator().next();
273
274         List JavaDoc colsA = fetchedGat.getCollectiblesA();
275         assertEquals("Wrong number of CollectiblesA", 3, colsA.size());
276         // check if gatherer contains list of CollectibleBase
277
tx.begin();
278         //*************************************
279
// delete one of the CollectibleBase
280
// we have to set the new reduced list in the
281
// gatherer object
282
List JavaDoc newCols = new ArrayList JavaDoc();
283         newCols.add(colsA.get(1));
284         newCols.add(colsA.get(2));
285         fetchedGat.setCollectiblesA(newCols);
286         tx.lock(fetchedGat, Transaction.WRITE);
287         // todo: do we need to delete removed reference explicit?
288
database.deletePersistent(colsA.get(0));
289         //*************************************
290
tx.commit();
291
292         // check if the CollectibleBase was really deleted from DB
293
tx.begin();
294         query = odmg.newOQLQuery();
295         query.create("select allCollectibleA from " + CollectibleA.class.getName() +
296                 " where name like $1");
297         query.bind(prefix + "%");
298         result = (Collection JavaDoc) query.execute();
299         assertEquals("Wrong number of objects found", 2, result.size());
300         tx.commit();
301
302         // check if the gatherer now contains a CollectibleBase list
303
// reduced by the deleted
304
tx.begin();
305         query = odmg.newOQLQuery();
306         query.create(queryStr);
307         query.bind(gatId);
308         result = (Collection JavaDoc) query.execute();
309         assertEquals("Wrong number of objects found", 1, result.size());
310         fetchedGat = (Gatherer) result.iterator().next();
311         colsA = fetchedGat.getCollectiblesA();
312         assertEquals("Wrong number of CollectiblesA found in Gatherer", 2, colsA.size());
313         tx.commit();
314
315         colsA.get(0);
316     }
317
318     public void testWithBackReference_1() throws Exception JavaDoc
319     {
320         String JavaDoc prefix = "testWithBackReference_1_" + System.currentTimeMillis();
321         String JavaDoc queryStr = "select gatherer from " + Gatherer.class.getName() + " where gatId=$1";
322
323         TransactionExt tx = (TransactionExt) odmg.newTransaction();
324         tx.begin();
325         // prepare test case
326
Gatherer gat = new Gatherer(null, prefix + "_Gatherer");
327         CollectibleA[] colsA = prepareCollectibleA(gat, prefix);
328         CollectibleB[] colsB = prepareCollectibleB(gat, prefix);
329         List JavaDoc colListA = Arrays.asList(colsA);
330         List JavaDoc colListB = Arrays.asList(colsB);
331         // set List of CollectibleBase objects
332
gat.setCollectiblesA(colListA);
333         gat.setCollectiblesB(colListB);
334
335         database.makePersistent(gat);
336         tx.commit();
337
338         // check if gatherer was stored
339
tx.begin();
340         tx.getBroker().clearCache();
341         OQLQuery query = odmg.newOQLQuery();
342         query.create(queryStr);
343         Integer JavaDoc gatId = gat.getGatId();
344         assertNotNull(gatId);
345         query.bind(gatId);
346         Collection JavaDoc result = (Collection JavaDoc) query.execute();
347
348         assertEquals("Wrong number of objects found", 1, result.size());
349         Gatherer fetchedGat = (Gatherer) result.iterator().next();
350         //*************************************
351
tx.lock(fetchedGat, Transaction.WRITE);
352         assertNotNull(fetchedGat.getCollectiblesA());
353         assertNotNull(fetchedGat.getCollectiblesB());
354         assertEquals(3, fetchedGat.getCollectiblesA().size());
355         assertEquals(3, fetchedGat.getCollectiblesB().size());
356         assertEquals(0, fetchedGat.getCollectiblesC().size());
357         assertNotNull(fetchedGat.getCollectiblesA().get(0));
358         assertNotNull(fetchedGat.getCollectiblesB().get(0));
359
360         fetchedGat.getCollectiblesA().remove(0);
361         fetchedGat.getCollectiblesB().remove(0);
362         //*************************************
363
//System.out.println("===> commit");
364
tx.commit();
365
366         tx.begin();
367         tx.getBroker().clearCache();
368         query = odmg.newOQLQuery();
369         query.create(queryStr);
370         gatId = gat.getGatId();
371         assertNotNull(gatId);
372         query.bind(gatId);
373         result = (Collection JavaDoc) query.execute();
374         tx.commit();
375         assertEquals("Wrong number of objects found", 1, result.size());
376         fetchedGat = (Gatherer) result.iterator().next();
377
378         assertNotNull(fetchedGat.getCollectiblesA());
379         assertNotNull(fetchedGat.getCollectiblesB());
380         assertEquals(2, fetchedGat.getCollectiblesA().size());
381         assertEquals(2, fetchedGat.getCollectiblesB().size());
382         assertNotNull(fetchedGat.getCollectiblesA().get(0));
383         assertNotNull(fetchedGat.getCollectiblesB().get(0));
384     }
385
386     /**
387      * This test shows an issue with circular references in conjunction with
388      * lazy loading and a non-global-shared cache.
389      */

390     public void testWithBackReference_2() throws Exception JavaDoc
391     {
392         if(ojbSkipKnownIssueProblem("Issue using proxies with circular references and a non-global-shared cache")) return;
393
394         /*
395         Say we have an object with circular reference (A has a 1:1 reference to B
396         and B has a 1:n collection reference to A)
397         A1 -1:1-> B1 -1:n-> [A1,A4]
398         and the 1:n is a collection proxy.
399
400         Now user lookup A1 and get A1@11->B1@12-->[proxy@]. He wants to
401         remove the A4 object in the 1:n reference in B@12. Because B has an
402         proxy collection, the proxy materialize on
403         B.getA's().remove(1) ==> remove A4
404         call.
405         While materialization of the collection proxy OJB lookup again an A1 instance.
406         When the previous materialzed A1@11 instance isn't in the session
407         cache (e.g. A1 was used in a previous session), OJB lookup the real cache.
408         If the real cache is "empty" or works with copies of persistent objects (TLCache)
409         new instance for A1 ==> A1@22 and a new B1@44 will be materialized.
410
411         Thus we have after the remove of A4 with materialized proxy:
412         A1@11 --> B1@12 -->proxy@[A1@22[-->B1@44]-->A1@22]] !!!!
413         Needless to say this will cause problems on update.
414
415         The workaround for the odmg-api is shown in test #testWithBackReference_2,
416         if the materialization of the proxy object is done within a running tx and
417         the changed object is locked again after materialization of the proxy (to replace
418         the new created object instance with the old one).
419         */

420
421         String JavaDoc prefix = "testWithBackReference_2_" + System.currentTimeMillis();
422         String JavaDoc queryStr = "select gatherer from " + Gatherer.class.getName() + " where gatId=$1";
423
424         TransactionExt tx = (TransactionExt) odmg.newTransaction();
425         tx.begin();
426         // prepare test case
427
Gatherer gat = new Gatherer(null, prefix + "_Gatherer");
428         CollectibleA[] colsA = prepareCollectibleA(gat, prefix);
429         CollectibleB[] colsB = prepareCollectibleB(gat, prefix);
430         List JavaDoc colListA = Arrays.asList(colsA);
431         List JavaDoc colListB = Arrays.asList(colsB);
432         // set List of CollectibleBase objects
433
gat.setCollectiblesA(colListA);
434         gat.setCollectiblesB(colListB);
435
436         database.makePersistent(gat);
437         tx.commit();
438 //System.out.println("===> commit");
439
//System.out.println();
440
//System.out.println();
441

442         // check if gatherer was stored
443
tx.begin();
444         tx.getBroker().clearCache();
445         OQLQuery query = odmg.newOQLQuery();
446         query.create(queryStr);
447         Integer JavaDoc gatId = gat.getGatId();
448         assertNotNull(gatId);
449         query.bind(gatId);
450         Collection JavaDoc result = (Collection JavaDoc) query.execute();
451         tx.commit();
452
453         assertEquals("Wrong number of objects found", 1, result.size());
454         Gatherer fetchedGat = (Gatherer) result.iterator().next();
455         assertNotNull(fetchedGat.getCollectiblesA());
456         assertNotNull(fetchedGat.getCollectiblesB());
457         assertEquals(3, fetchedGat.getCollectiblesA().size());
458         assertEquals(3, fetchedGat.getCollectiblesB().size());
459         assertEquals(0, fetchedGat.getCollectiblesC().size());
460         assertNotNull(fetchedGat.getCollectiblesA().get(0));
461         assertNotNull(fetchedGat.getCollectiblesB().get(0));
462 //System.out.println("A: " + fetchedGat.getCollectiblesA());
463
//System.out.println("B: " + fetchedGat.getCollectiblesB());
464
// for(int i = 0; i < fetchedGat.getCollectiblesB().size(); i++)
465
// {
466
// System.out.println(" b="+fetchedGat.getCollectiblesB().get(i));
467
// }
468
//System.out.println();
469
//System.out.println();
470
//System.out.println("## New tx begin");
471
tx.begin();
472         tx.getBroker().clearCache();
473         //*************************************
474
tx.lock(fetchedGat, Transaction.WRITE);
475         // we want automatic delete of removed collection objects
476
//tx.autoDeleteRemovedCollectionReferences(true);
477
// alternative do explicit call Database#deletePersistent for removed objects
478
fetchedGat.getCollectiblesA().remove(0);
479         fetchedGat.getCollectiblesB().remove(0);
480 tx.getBroker().serviceObjectCache().cache(tx.getBroker().serviceIdentity().buildIdentity(fetchedGat), fetchedGat);
481 //System.out.println("remove: " + tx.getBroker().serviceIdentity().buildIdentity(fetchedGat.getCollectiblesA().remove(0)));
482
//System.out.println("remove: " + tx.getBroker().serviceIdentity().buildIdentity(fetchedGat.getCollectiblesB().remove(0)));
483
//System.out.println("A: " + fetchedGat.getCollectiblesA());
484
//System.out.println("B: " + fetchedGat.getCollectiblesB());
485
//System.out.println("===> commit after remove");
486
//System.out.println("===> commit after remove");
487
//*************************************
488
tx.commit();
489 //System.out.println("after commit <==");
490
//System.out.println("after commit <==");
491
//System.out.println("");System.out.println();
492

493         tx.begin();
494         tx.getBroker().clearCache();
495         query = odmg.newOQLQuery();
496         query.create(queryStr);
497         gatId = gat.getGatId();
498         assertNotNull(gatId);
499         query.bind(gatId);
500         result = (Collection JavaDoc) query.execute();
501         tx.commit();
502         assertEquals("Wrong number of objects found", 1, result.size());
503         fetchedGat = (Gatherer) result.iterator().next();
504
505         assertNotNull(fetchedGat.getCollectiblesA());
506         assertNotNull(fetchedGat.getCollectiblesB());
507         assertEquals(2, fetchedGat.getCollectiblesA().size());
508         assertEquals(2, fetchedGat.getCollectiblesB().size());
509         assertNotNull(fetchedGat.getCollectiblesA().get(0));
510         assertNotNull(fetchedGat.getCollectiblesB().get(0));
511     }
512
513     public void testUpdateCollectionWithBackReference() throws Exception JavaDoc
514     {
515         String JavaDoc name = "testUpdateCollectionWithBackReference" + System.currentTimeMillis();
516         String JavaDoc queryStr = "select colls from " + CollectibleA.class.getName() + " where name=$1";
517
518         // prepare test case
519
Gatherer gat_1 = new Gatherer(null, "Gatherer_" + name);
520         CollectibleA coll_1 = new CollectibleA(name);
521         Gatherer gat_2 = new Gatherer(null, "Gatherer_" + name);
522         CollectibleA coll_2 = new CollectibleA(name);
523
524         coll_1.setGatherer(gat_1);
525         ArrayList JavaDoc alist = new ArrayList JavaDoc();
526         alist.add(coll_1);
527         gat_1.setCollectiblesA(alist);
528
529         coll_2.setGatherer(gat_2);
530         ArrayList JavaDoc blist = new ArrayList JavaDoc();
531         blist.add(coll_2);
532         gat_2.setCollectiblesA(blist);
533
534         TransactionExt tx = (TransactionExt) odmg.newTransaction();
535         tx.begin();
536         database.makePersistent(coll_1);
537         database.makePersistent(coll_2);
538         tx.commit();
539
540         tx.begin();
541         tx.getBroker().clearCache();
542         OQLQuery query = odmg.newOQLQuery();
543         query.create(queryStr);
544         query.bind(name);
545         Collection JavaDoc result = (Collection JavaDoc) query.execute();
546         assertNotNull(result);
547         assertEquals(2, result.size());
548
549         for (Iterator JavaDoc iterator = result.iterator(); iterator.hasNext();)
550         {
551             CollectibleA collectible = (CollectibleA) iterator.next();
552             Gatherer gat = collectible.getGatherer();
553             assertNotNull(gat);
554             assertEquals("Gatherer_"+name, gat.getName());
555             tx.lock(collectible, Transaction.WRITE);
556             collectible.getGatherer().setName("New_"+name);
557         }
558         tx.commit();
559
560         tx.begin();
561         tx.getBroker().clearCache();
562         query = odmg.newOQLQuery();
563         query.create(queryStr);
564         query.bind(name);
565         result = (Collection JavaDoc) query.execute();
566         assertNotNull(result);
567         assertEquals(2, result.size());
568
569         // we don't want that Gatherer does some cascade delete
570
tx.setCascadingDelete(Gatherer.class, false);
571         for (Iterator JavaDoc iterator = result.iterator(); iterator.hasNext();)
572         {
573             CollectibleA collectible = (CollectibleA) iterator.next();
574             Gatherer gat = collectible.getGatherer();
575             assertNotNull(gat);
576             assertEquals("New_"+name, gat.getName());
577             tx.lock(collectible, Transaction.WRITE);
578             collectible.setGatherer(null);
579             gat.getCollectiblesA().remove(collectible);
580         }
581         tx.commit();
582
583         tx.begin();
584         tx.getBroker().clearCache();
585         query = odmg.newOQLQuery();
586         query.create(queryStr);
587         query.bind(name);
588         result = (Collection JavaDoc) query.execute();
589         assertNotNull(result);
590         assertEquals(2, result.size());
591
592         for (Iterator JavaDoc iterator = result.iterator(); iterator.hasNext();)
593         {
594             CollectibleA collectible = (CollectibleA) iterator.next();
595             Gatherer gat = collectible.getGatherer();
596             assertNull(gat);
597         }
598         tx.commit();
599     }
600
601     /**
602      * Create object with 3 objects in associated collection.
603      * We change one object of the collection
604      */

605     public void testUpdateCollection() throws Exception JavaDoc
606     {
607         String JavaDoc prefix = "testUpdateCollection" + System.currentTimeMillis();
608         String JavaDoc queryStr = "select gatherer from " + Gatherer.class.getName() + " where gatId=$1";
609         String JavaDoc modifiedName = "modified_name_" + System.currentTimeMillis();
610         String JavaDoc queryMod = "select coll from " + CollectibleA.class.getName() + " where name like $1";
611
612         // prepare test case
613
Gatherer gat = new Gatherer(null, prefix + "_Gatherer");
614         // set List of CollectiblesA objects
615
gat.setCollectiblesA(Arrays.asList(prepareCollectibleA(gat, prefix + "_1_")));
616         TransactionExt tx = (TransactionExt)odmg.newTransaction();
617         tx.begin();
618         database.makePersistent(gat);
619         tx.commit();
620
621         tx.begin();
622         tx.getBroker().clearCache();
623         // check if gatherer was stored
624
OQLQuery query = odmg.newOQLQuery();
625         query.create(queryStr);
626         assertNotNull(gat.getGatId());
627         query.bind(gat.getGatId());
628         Collection JavaDoc result = (Collection JavaDoc) query.execute();
629         tx.commit();
630         assertEquals("Wrong number of objects found", 1, result.size());
631         Gatherer fetchedGat = (Gatherer) result.iterator().next();
632
633         tx.begin();
634         tx.lock(fetchedGat, Transaction.WRITE);
635         List JavaDoc collsA = fetchedGat.getCollectiblesA();
636         assertEquals(3, collsA.size());
637         // now we change an object of the collection
638
((CollectibleA)collsA.get(0)).setName(modifiedName);
639         tx.commit();
640
641         tx.begin();
642         tx.getBroker().clearCache();
643         // now check if the modification was stored
644
query = odmg.newOQLQuery();
645         query.create(queryMod);
646         query.bind(modifiedName);
647         result = (Collection JavaDoc) query.execute();
648         tx.commit();
649         assertEquals("Wrong number of objects found", 1, result.size());
650         CollectibleA collA = (CollectibleA) result.iterator().next();
651         assertNotNull(collA);
652         assertEquals(modifiedName, collA.getName());
653     }
654
655     /**
656      * we create two objects with one object in collection:
657      * gat1{collC1} and gat2{collC2}
658      * then we exchange the collections
659      * gat1{collC2} and gat2{collC1}
660      * and commit. So the size of the collection
661      * hold by the main object doesn't change
662      */

663     public void testUpdateWhenExchangeObjectsInCollection() throws Exception JavaDoc
664     {
665         final String JavaDoc prefix = "testUpdateWhenExchangeObjectsInCollection" + System.currentTimeMillis();
666         final String JavaDoc queryStr = "select gatherer from " + Gatherer.class.getName() +
667                                 " where gatId=$1 or gatId=$2 order by gatId asc";
668
669         // prepare test case
670
final String JavaDoc gat1Name = prefix + "_Gatherer";
671         final String JavaDoc gat2Name = prefix + "_Gatherer2";
672         Gatherer gat = new Gatherer(null, gat1Name);
673         Gatherer gat2 = new Gatherer(null, gat2Name);
674         // set List of CollectiblesC objects
675
CollectibleC collC_1 = new CollectibleC(prefix + "NO_1", null, "nothing1");
676         CollectibleC collC_2 = new CollectibleC(prefix + "NO_2", null, "nothing2");
677         gat.setCollectiblesC(Arrays.asList(new CollectibleC[]{collC_1}));
678         gat2.setCollectiblesC(Arrays.asList(new CollectibleC[]{collC_2}));
679         TransactionExt tx = (TransactionExt)odmg.newTransaction();
680         tx.begin();
681         database.makePersistent(gat);
682         database.makePersistent(gat2);
683         tx.commit();
684
685         // query and check the result
686
tx.begin();
687         tx.getBroker().clearCache();
688         OQLQuery query = odmg.newOQLQuery();
689         query.create(queryStr);
690         assertNotNull(gat.getGatId());
691         query.bind(gat.getGatId());
692         query.bind(gat2.getGatId());
693         Collection JavaDoc result = (Collection JavaDoc) query.execute();
694         tx.commit();
695         assertEquals("Wrong number of objects found", 2, result.size());
696         Iterator JavaDoc it = result.iterator();
697         Gatherer fetchedGat = (Gatherer) it.next();
698         Gatherer fetchedGat2 = (Gatherer) it.next();
699         assertNotNull(fetchedGat);
700         assertNotNull(fetchedGat2);
701         assertEquals("Wrong gatherer returned: fetchedGat should be first Gatherer",
702                 gat1Name, fetchedGat.getName());
703         assertEquals("Wrong gatherer returned: fetchedGat2 should be second Gatherer",
704                 gat2Name, fetchedGat2.getName());
705         assertNotNull(fetchedGat.collectiblesC);
706         assertNotNull(fetchedGat2.collectiblesC);
707         assertEquals(1, fetchedGat.getCollectiblesC().size());
708         assertEquals(1, fetchedGat2.getCollectiblesC().size());
709
710         collC_1 = (CollectibleC) fetchedGat.getCollectiblesC().get(0);
711         collC_2 = (CollectibleC) fetchedGat2.getCollectiblesC().get(0);
712         assertEquals(prefix + "NO_1", collC_1.getName());
713         assertEquals(prefix + "NO_2", collC_2.getName());
714
715         //*****************************************************
716
List JavaDoc list1 = fetchedGat.getCollectiblesC();
717         List JavaDoc list2 = fetchedGat2.getCollectiblesC();
718         // now exchange the lists
719
tx.begin();
720         tx.lock(fetchedGat, Transaction.WRITE);
721         tx.lock(fetchedGat2, Transaction.WRITE);
722         fetchedGat.setCollectiblesC(list2);
723         fetchedGat2.setCollectiblesC(list1);
724         // System.out.println("#####===> start commit");
725
tx.commit();
726         //*****************************************************
727
// System.out.println("#####===> end commit");
728

729         // now we do same procedure to query and check
730
tx.begin();
731         tx.getBroker().clearCache();
732         query = odmg.newOQLQuery();
733         query.create(queryStr);
734         assertNotNull(gat.getGatId());
735         query.bind(gat.getGatId());
736         query.bind(gat2.getGatId());
737         result = (Collection JavaDoc) query.execute();
738         tx.commit();
739         assertEquals("Wrong number of objects found", 2, result.size());
740         it = result.iterator();
741         fetchedGat = (Gatherer) it.next();
742         fetchedGat2 = (Gatherer) it.next();
743         assertNotNull(fetchedGat);
744         assertNotNull(fetchedGat2);
745         assertNotNull(fetchedGat.getCollectiblesC());
746         assertNotNull(fetchedGat2.getCollectiblesC());
747         assertEquals(1, fetchedGat.getCollectiblesC().size());
748         assertEquals(1, fetchedGat2.getCollectiblesC().size());
749
750         collC_1 = (CollectibleC) fetchedGat.getCollectiblesC().get(0);
751         collC_2 = (CollectibleC) fetchedGat2.getCollectiblesC().get(0);
752         // we exchange the lists, thus we expect exchanged names
753
assertEquals(prefix + "NO_2", collC_1.getName());
754         assertEquals(prefix + "NO_1", collC_2.getName());
755     }
756
757     /**
758      * Create an main object Gatherer with a collection of objects CollectiblesC.
759      * CollectiblesC hasn't a reference back to the main object, thus we don't have to set
760      * the main object in the collection objects. Further we can't set the object id of the
761      * main object, because we don't know it at creation time.
762      * Then we remove one object of the collection
763      */

764     public void testRemoveCollectionElementWithoutBackReference_2() throws Exception JavaDoc
765     {
766         // String queryColl = "select colls from " + CollectibleC.class.getName() + " where name=$1";
767
String JavaDoc queryGat = "select gatherer from " + Gatherer.class.getName() + " where gatId=$1";
768         String JavaDoc prefix = "testRemoveCollectionObjectWithoutBackReference_2_" + System.currentTimeMillis();
769
770         // prepare test case
771
Gatherer gat = new Gatherer(null, prefix + "_Gatherer");
772         // we don't set the gatId in CollectiblesC, because we don't have one
773
// Set List of CollectiblesC objects
774
gat.setCollectiblesC(Arrays.asList(prepareCollectibleC(null, prefix)));
775         TransactionExt tx = (TransactionExt)odmg.newTransaction();
776         tx.begin();
777         database.makePersistent(gat);
778         tx.commit();
779
780         // check if gatherer was stored
781
tx.begin();
782         tx.getBroker().clearCache();
783         assertNotNull(gat.getGatId());
784
785         OQLQuery query = odmg.newOQLQuery();
786         query.create(queryGat);
787         query.bind(gat.getGatId());
788
789         Collection JavaDoc result = (Collection JavaDoc) query.execute();
790         tx.commit();
791         assertEquals("Wrong number of objects found", 1, result.size());
792         Gatherer fetchedGat = (Gatherer) result.iterator().next();
793         assertNotNull(fetchedGat);
794
795         List JavaDoc colC = fetchedGat.getCollectiblesC();
796         assertEquals("Wrong number of CollectiblesC", 3, colC.size());
797         // check if gatherer contains list of CollectibleBase
798
tx.begin();
799         //**********************************************************
800
// we replace the collection of main object with a new collection
801
// reduced by one element
802
List JavaDoc newCols = new ArrayList JavaDoc(colC);
803         Object JavaDoc toDelete = newCols.remove(2);
804         // lock object before do changes
805
tx.lock(fetchedGat, Transaction.WRITE);
806         fetchedGat.setCollectiblesC(newCols);
807         // todo: we need to delete removed object explicit?
808
database.deletePersistent(toDelete);
809         //**********************************************************
810
tx.commit();
811
812         // check if the Collectibles were really deleted from DB
813
tx.begin();
814         tx.getBroker().clearCache();
815
816         query = odmg.newOQLQuery();
817         query.create("select colls from " + CollectibleC.class.getName() +
818                 " where name like $1");
819         query.bind(prefix + "%");
820         result = (Collection JavaDoc) query.execute();
821         assertEquals("Wrong number of objects found", 2, result.size());
822         tx.commit();
823
824         // check if the gatherer now contains a CollectibleBase list
825
// reduced by the deleted
826
tx.begin();
827         query = odmg.newOQLQuery();
828         query.create(queryGat);
829         query.bind(gat.getGatId());
830         result = (Collection JavaDoc) query.execute();
831         assertEquals("Wrong number of objects found", 1, result.size());
832         fetchedGat = (Gatherer) result.iterator().next();
833         colC = fetchedGat.getCollectiblesC();
834         assertEquals("Wrong number of CollectiblesA found in Gatherer", 2, colC.size());
835         tx.commit();
836
837         colC.get(0);
838     }
839
840     /**
841      * Create an main object Gatherer with a collection of objects CollectiblesC.
842      * CollectiblesC hasn't a reference back to the main object, thus we don't have to set
843      * the main object in the collection objects. Further we can't set the object id of the
844      * main object, because we don't know it at creation time.
845      * Then we ADD a new object to the collection
846      */

847     public void testAddCollectionElementWithoutBackReference() throws Exception JavaDoc
848     {
849         // String queryColl = "select colls from " + CollectibleC.class.getName() + " where name=$1";
850
String JavaDoc queryGat = "select gatherer from " + Gatherer.class.getName() + " where gatId=$1";
851         String JavaDoc prefix = "testAddCollectionElementWithoutBackReference_" + System.currentTimeMillis();
852
853         // prepare test case
854
Gatherer gat = new Gatherer(null, prefix + "_Gatherer");
855         // we don't set the gatId in CollectiblesC, because we don't have one
856
// Set List of CollectiblesC objects
857
gat.setCollectiblesC(Arrays.asList(prepareCollectibleC(null, prefix)));
858         TransactionExt tx = (TransactionExt)odmg.newTransaction();
859         tx.begin();
860         database.makePersistent(gat);
861         tx.commit();
862
863         // check if gatherer was stored
864
tx.begin();
865         tx.getBroker().clearCache();
866         assertNotNull(gat.getGatId());
867
868         OQLQuery query = odmg.newOQLQuery();
869         query.create(queryGat);
870         query.bind(gat.getGatId());
871
872         Collection JavaDoc result = (Collection JavaDoc) query.execute();
873         tx.commit();
874         assertEquals("Wrong number of objects found", 1, result.size());
875         Gatherer fetchedGat = (Gatherer) result.iterator().next();
876         assertNotNull(fetchedGat);
877
878         // check if gatherer contains list of CollectibleBase
879
List JavaDoc colC = fetchedGat.getCollectiblesC();
880         assertEquals("Wrong number of CollectiblesC", 3, colC.size());
881
882         tx.begin();
883         //*************************************
884
tx.lock(fetchedGat, Transaction.WRITE);
885         // Now add a new collection object
886
CollectibleC newC = new CollectibleC(prefix, null, "### new added ###");
887         fetchedGat.getCollectiblesC().add(newC);
888         newC.setGathererId(fetchedGat.getGatId());
889         tx.lock(newC, Transaction.WRITE);
890         //*************************************
891
tx.commit();
892
893         // check if the Collectibles were really deleted from DB
894
tx.begin();
895         tx.getBroker().clearCache();
896
897         query = odmg.newOQLQuery();
898         query.create("select colls from " + CollectibleC.class.getName() +
899                 " where name like $1");
900         query.bind(prefix + "%");
901         result = (Collection JavaDoc) query.execute();
902         assertEquals("Wrong number of objects found", 4, result.size());
903         tx.commit();
904
905         // check if the gatherer now contains a CollectibleBase list
906
// increased by the added
907
tx.begin();
908         tx.getBroker().clearCache();
909         query = odmg.newOQLQuery();
910         query.create(queryGat);
911         query.bind(gat.getGatId());
912         result = (Collection JavaDoc) query.execute();
913         assertEquals("Wrong number of objects found", 1, result.size());
914         fetchedGat = (Gatherer) result.iterator().next();
915         colC = fetchedGat.getCollectiblesC();
916         assertEquals("Wrong number of CollectiblesA found in Gatherer", 4, colC.size());
917         tx.commit();
918
919         colC.get(0);
920     }
921
922     /**
923      * Create an main object Gatherer with a collection of objects CollectiblesC
924      * (CollectiblesC has a reference back to the main object).
925      * Then we ADD a new object to the collection
926      */

927     public void testAddCollectionElementWithBackReference() throws Exception JavaDoc
928     {
929         String JavaDoc queryGat = "select gatherer from " + Gatherer.class.getName() + " where gatId=$1";
930         String JavaDoc prefix = "testAddCollectionElementWithBackReference_" + System.currentTimeMillis();
931
932         /*
933         prepare test case
934         If the back reference was not set, the test doesn't pass
935         */

936         Gatherer gat = new Gatherer(null, prefix + "_Gatherer");
937         // Set List of CollectiblesB objects
938
gat.setCollectiblesB(Arrays.asList(prepareCollectibleB(gat, prefix)));
939
940         TransactionExt tx = (TransactionExt)odmg.newTransaction();
941         tx.begin();
942         database.makePersistent(gat);
943         tx.commit();
944
945         // check if gatherer was stored
946
tx.begin();
947         tx.getBroker().clearCache();
948         assertNotNull(gat.getGatId());
949
950         OQLQuery query = odmg.newOQLQuery();
951         query.create(queryGat);
952         query.bind(gat.getGatId());
953
954         Collection JavaDoc result = (Collection JavaDoc) query.execute();
955         tx.commit();
956         assertEquals("Wrong number of objects found", 1, result.size());
957         Gatherer fetchedGat = (Gatherer) result.iterator().next();
958         assertNotNull(fetchedGat);
959
960
961         tx.begin();
962         // check if gatherer contains list of CollectibleBase
963
List JavaDoc colB = fetchedGat.getCollectiblesB();
964         assertEquals("Wrong number of CollectiblesB", 3, colB.size());
965
966         //*************************************
967
tx.lock(fetchedGat, Transaction.WRITE);
968         // Now add a new collection object
969
CollectibleB newB = new CollectibleB(prefix);
970         newB.setGatherer(fetchedGat);
971         fetchedGat.getCollectiblesB().add(newB);
972         // lock the new object
973
tx.lock(newB, Transaction.WRITE);
974         //*************************************
975

976         tx.commit();
977
978         // check
979
tx.begin();
980         tx.getBroker().clearCache();
981
982         query = odmg.newOQLQuery();
983         query.create("select colls from " + CollectibleB.class.getName() +
984                 " where name like $1");
985         query.bind(prefix + "%");
986         result = (Collection JavaDoc) query.execute();
987         assertEquals("Wrong number of objects found", 4, result.size());
988         tx.commit();
989
990         // check if the gatherer now contains a CollectibleBase list
991
// increased by the added
992
tx.begin();
993         tx.getBroker().clearCache();
994         query = odmg.newOQLQuery();
995         query.create(queryGat);
996         query.bind(gat.getGatId());
997         result = (Collection JavaDoc) query.execute();
998         assertEquals("Wrong number of objects found", 1, result.size());
999         fetchedGat = (Gatherer) result.iterator().next();
1000        colB = fetchedGat.getCollectiblesB();
1001        assertEquals("Wrong number of CollectiblesA found in Gatherer", 4, colB.size());
1002        tx.commit();
1003
1004        colB.get(0);
1005    }
1006
1007/*
1008    User test case from user-list:
1009> A contains a collection of B. B has a reference back to its parent A.
1010> Calling A.addB(B) sets B's reference to A.
1011>
1012> Create new A.
1013> Create new B.
1014> Add B to A.
1015> Make A persistent.
1016> A and B successfully persisted to the database.
1017> Clear the OJB cache
1018> Retrieve A (using PB)
1019> Start Tx (ODMG)
1020> Lock A for writing (ODMG)
1021> Create a new B2.
1022> Add B2 to A.
1023> Commit Tx.
1024> Clear Cache.
1025> Retrieve A (using PB)
1026> Assert(A count Bs == 2) FAIL. B2 was never persisted.
1027>
1028> ODMG's Persistence by reachability should have persisted B2, should it not?
1029> I thought that using DList might fix this.
1030     */

1031    public void testAddCollectionElementCrossAPI() throws Exception JavaDoc
1032    {
1033        String JavaDoc name = "testAddCollectionElementCrossAPI_"+System.currentTimeMillis();
1034        // prepare test case
1035
Gatherer gat = new Gatherer(null, name);
1036        CollectibleB B = new CollectibleB(name);
1037        B.setGatherer(gat);
1038        ArrayList JavaDoc cols = new ArrayList JavaDoc();
1039        cols.add(B);
1040        gat.setCollectiblesB(cols);
1041
1042        TransactionExt tx = (TransactionExt) odmg.newTransaction();
1043        tx.begin();
1044        database.makePersistent(gat);
1045        tx.commit();
1046
1047        // now cross ODMG with PB api
1048
Gatherer fetchedGatherer = null;
1049        PersistenceBroker pb = null;
1050        try
1051        {
1052            pb = PersistenceBrokerFactory.defaultPersistenceBroker();
1053            pb.clearCache();
1054            Criteria crit = new Criteria();
1055            crit.addLike("name", name);
1056            Query q = QueryFactory.newQuery(Gatherer.class, crit);
1057            fetchedGatherer = (Gatherer) pb.getObjectByQuery(q);
1058        }
1059        finally
1060        {
1061            if(pb != null) pb.close();
1062        }
1063
1064        // check queried result
1065
assertNotNull(fetchedGatherer);
1066        assertEquals(gat.getGatId(), fetchedGatherer.getGatId());
1067        assertNotNull(fetchedGatherer.getCollectiblesB());
1068        assertEquals(1, fetchedGatherer.getCollectiblesB().size());
1069        CollectibleB fetched_B = (CollectibleB) fetchedGatherer.getCollectiblesB().iterator().next();
1070        assertNotNull(fetched_B);
1071
1072        // Now work with queried result
1073
tx.begin();
1074        tx.getBroker().clearCache();
1075        //*************************************
1076
tx.lock(fetchedGatherer, Transaction.WRITE);
1077        CollectibleB newB = new CollectibleB(name);
1078        newB.setGatherer(fetchedGatherer);
1079        fetchedGatherer.getCollectiblesB().add(newB);
1080        tx.lock(newB, Transaction.WRITE);
1081        //*************************************
1082
assertEquals(2, fetchedGatherer.getCollectiblesB().size());
1083        tx.commit();
1084
1085        // now cross again ODMG with PB api
1086
fetchedGatherer = null;
1087        pb = null;
1088        try
1089        {
1090            pb = PersistenceBrokerFactory.defaultPersistenceBroker();
1091            pb.clearCache();
1092            Criteria crit = new Criteria();
1093            crit.addLike("name", name);
1094            Query q = QueryFactory.newQuery(Gatherer.class, crit);
1095            fetchedGatherer = (Gatherer) pb.getObjectByQuery(q);
1096        }
1097        finally
1098        {
1099            if(pb != null) pb.close();
1100        }
1101
1102        // check queried result
1103
assertNotNull(fetchedGatherer);
1104        assertEquals(gat.getGatId(), fetchedGatherer.getGatId());
1105        assertNotNull(fetchedGatherer.getCollectiblesB());
1106        assertEquals(2, fetchedGatherer.getCollectiblesB().size());
1107        CollectibleB fetched_B_1 = (CollectibleB) fetchedGatherer.getCollectiblesB().iterator().next();
1108        CollectibleB fetched_B_2 = (CollectibleB) fetchedGatherer.getCollectiblesB().iterator().next();
1109        assertNotNull(fetched_B_1);
1110        assertNotNull(fetched_B_2);
1111    }
1112
1113
1114
1115    //**********************************************************
1116
// helper methods
1117
//**********************************************************
1118

1119    private CollectibleA[] prepareCollectibleA(Gatherer gat, String JavaDoc namePrefix)
1120    {
1121        CollectibleA[] colA = new CollectibleA[]{
1122            new CollectibleA(namePrefix + " colA_1"),
1123            new CollectibleA(namePrefix + " colA_2"),
1124            new CollectibleA(namePrefix + " colA_3")
1125        };
1126        for (int i = 0; i < colA.length; i++)
1127        {
1128            CollectibleA collectibleA = colA[i];
1129            collectibleA.setGatherer(gat);
1130        }
1131        return colA;
1132    }
1133
1134    private CollectibleB[] prepareCollectibleB(Gatherer gat, String JavaDoc namePrefix)
1135    {
1136        CollectibleB[] colB = new CollectibleB[]{
1137            new CollectibleB(namePrefix + " colB_1"),
1138            new CollectibleB(namePrefix + " colB_2"),
1139            new CollectibleB(namePrefix + " colB_3")
1140        };
1141        for (int i = 0; i < colB.length; i++)
1142        {
1143            CollectibleB collectibleB = colB[i];
1144            collectibleB.setGatherer(gat);
1145        }
1146        return colB;
1147    }
1148
1149    private CollectibleC[] prepareCollectibleC(Gatherer gat, String JavaDoc namePrefix)
1150    {
1151        CollectibleC[] colC = new CollectibleC[]{
1152            new CollectibleC(namePrefix + " colC_1", null, "ext1"),
1153            new CollectibleC(namePrefix + " colC_2", null, "ext2"),
1154            new CollectibleC(namePrefix + " colC_3", null, "ext3")
1155        };
1156        for (int i = 0; i < colC.length; i++)
1157        {
1158            CollectibleC collectibleC = colC[i];
1159            collectibleC.setGathererId(gat != null ? gat.gatId : null);
1160        }
1161        return colC;
1162    }
1163
1164
1165    //****************************************************************************
1166
// inner classes
1167
//****************************************************************************
1168
public static class Gatherer implements Serializable JavaDoc
1169    {
1170        private Integer JavaDoc gatId;
1171        private String JavaDoc name;
1172        private List JavaDoc collectiblesA = new Vector JavaDoc();
1173        private List JavaDoc collectiblesB = new Vector JavaDoc();
1174        private List JavaDoc collectiblesC = new Vector JavaDoc();
1175
1176        public Gatherer()
1177        {
1178        }
1179
1180        public String JavaDoc toString()
1181        {
1182            return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
1183                    .append("gatId", gatId)
1184                    .append("name", name)
1185                    .append("colA", collectiblesA)
1186                    .append("colB", collectiblesB)
1187                    .append("colc", collectiblesC)
1188                    .toString();
1189        }
1190
1191        public void addCollectibleA(CollectibleA colA)
1192        {
1193            if (collectiblesA == null) collectiblesA = new Vector JavaDoc();
1194            collectiblesA.add(colA);
1195        }
1196
1197        public Gatherer(Integer JavaDoc gatId, String JavaDoc name)
1198        {
1199            this.gatId = gatId;
1200            this.name = name;
1201        }
1202
1203        public Integer JavaDoc getGatId()
1204        {
1205            return gatId;
1206        }
1207
1208        public void setGatId(Integer JavaDoc gatId)
1209        {
1210            this.gatId = gatId;
1211        }
1212
1213        public String JavaDoc getName()
1214        {
1215            return name;
1216        }
1217
1218        public void setName(String JavaDoc name)
1219        {
1220            this.name = name;
1221        }
1222
1223        public List JavaDoc getCollectiblesA()
1224        {
1225            return collectiblesA;
1226        }
1227
1228        public void setCollectiblesA(List JavaDoc collectiblesA)
1229        {
1230            this.collectiblesA = collectiblesA;
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
1254    public static interface CollectibleBIF extends Serializable JavaDoc
1255    {
1256        Integer JavaDoc getColId();
1257        void setColId(Integer JavaDoc colId);
1258        String JavaDoc getName();
1259        void setName(String JavaDoc name);
1260        Integer JavaDoc getGathererId();
1261        void setGathererId(Integer JavaDoc colId);
1262        Gatherer getGatherer();
1263        void setGatherer(Gatherer gatherer);
1264    }
1265
1266    public static class CollectibleB implements CollectibleBIF
1267    {
1268        private Integer JavaDoc colId;
1269        private String JavaDoc name;
1270        private Integer JavaDoc gathererId;
1271        private Gatherer gatherer;
1272
1273        public CollectibleB()
1274        {
1275        }
1276
1277        public CollectibleB(String JavaDoc name)
1278        {
1279            this.name = name;
1280        }
1281
1282        public CollectibleB(String JavaDoc name, Integer JavaDoc gathererId)
1283        {
1284            this.name = name;
1285            this.gathererId = gathererId;
1286        }
1287
1288        public CollectibleB(Integer JavaDoc colId, String JavaDoc name, Integer JavaDoc gathererId)
1289        {
1290            this.colId = colId;
1291            this.name = name;
1292            this.gathererId = gathererId;
1293        }
1294
1295        public Gatherer getGatherer()
1296        {
1297            return gatherer;
1298        }
1299
1300        public void setGatherer(Gatherer gatherer)
1301        {
1302            this.gatherer = gatherer;
1303        }
1304
1305        public Integer JavaDoc getGathererId()
1306        {
1307            return gathererId;
1308        }
1309
1310        public void setGathererId(Integer JavaDoc gathererId)
1311        {
1312            this.gathererId = gathererId;
1313        }
1314
1315        public Integer JavaDoc getColId()
1316        {
1317            return colId;
1318        }
1319
1320        public void setColId(Integer JavaDoc colId)
1321        {
1322            this.colId = colId;
1323        }
1324
1325        public String JavaDoc getName()
1326        {
1327            return name;
1328        }
1329
1330        public void setName(String JavaDoc name)
1331        {
1332            this.name = name;
1333        }
1334    }
1335
1336    public static interface CollectibleAIF extends Serializable JavaDoc
1337    {
1338        Integer JavaDoc getColId();
1339
1340        void setColId(Integer JavaDoc colId);
1341
1342        String JavaDoc getName();
1343
1344        void setName(String JavaDoc name);
1345
1346        Integer JavaDoc getGathererId();
1347
1348        void setGathererId(Integer JavaDoc colId);
1349
1350        Gatherer getGatherer();
1351
1352        void setGatherer(Gatherer gatherer);
1353    }
1354
1355    public static class CollectibleA implements CollectibleAIF
1356    {
1357        private Integer JavaDoc colId;
1358        private String JavaDoc name;
1359        private Integer JavaDoc gathererId;
1360        private Gatherer gatherer;
1361
1362        public CollectibleA()
1363        {
1364        }
1365
1366        public CollectibleA(Integer JavaDoc colId, String JavaDoc name, Integer JavaDoc gathererId)
1367        {
1368            this.colId = colId;
1369            this.name = name;
1370            this.gathererId = gathererId;
1371        }
1372
1373        public CollectibleA(String JavaDoc name, Integer JavaDoc gathererId)
1374        {
1375            this.name = name;
1376            this.gathererId = gathererId;
1377        }
1378
1379        public CollectibleA(String JavaDoc name)
1380        {
1381            this.name = name;
1382        }
1383
1384        public Gatherer getGatherer()
1385        {
1386            return gatherer;
1387        }
1388
1389        public void setGatherer(Gatherer gatherer)
1390        {
1391            this.gatherer = gatherer;
1392        }
1393
1394        public Integer JavaDoc getGathererId()
1395        {
1396            return gathererId;
1397        }
1398
1399        public void setGathererId(Integer JavaDoc gathererId)
1400        {
1401            this.gathererId = gathererId;
1402        }
1403
1404        public Integer JavaDoc getColId()
1405        {
1406            return colId;
1407        }
1408
1409        public void setColId(Integer JavaDoc colId)
1410        {
1411            this.colId = colId;
1412        }
1413
1414        public String JavaDoc getName()
1415        {
1416            return name;
1417        }
1418
1419        public void setName(String JavaDoc name)
1420        {
1421            this.name = name;
1422        }
1423    }
1424
1425    public static interface CollectibleCIF extends Serializable JavaDoc
1426    {
1427        Integer JavaDoc getColId();
1428        void setColId(Integer JavaDoc colId);
1429        String JavaDoc getName();
1430        void setName(String JavaDoc name);
1431        Integer JavaDoc getGathererId();
1432        void setGathererId(Integer JavaDoc colId);
1433        Gatherer getGatherer();
1434        void setGatherer(Gatherer gatherer);
1435        String JavaDoc getExtentName();
1436        void setExtentName(String JavaDoc extentName);
1437    }
1438
1439    public static class CollectibleC
1440    {
1441        private Integer JavaDoc colId;
1442        private String JavaDoc name;
1443        private Integer JavaDoc gathererId;
1444        private String JavaDoc extentName;
1445
1446        public CollectibleC()
1447        {
1448        }
1449
1450        public CollectibleC(String JavaDoc name, Integer JavaDoc gathererId, String JavaDoc extentName)
1451        {
1452            this.name = name;
1453            this.gathererId = gathererId;
1454            this.extentName = extentName;
1455        }
1456
1457        public String JavaDoc getExtentName()
1458        {
1459            return extentName;
1460        }
1461
1462        public void setExtentName(String JavaDoc extentName)
1463        {
1464            this.extentName = extentName;
1465        }
1466
1467        public Integer JavaDoc getColId()
1468        {
1469            return colId;
1470        }
1471
1472        public void setColId(Integer JavaDoc colId)
1473        {
1474            this.colId = colId;
1475        }
1476
1477        public String JavaDoc getName()
1478        {
1479            return name;
1480        }
1481
1482        public void setName(String JavaDoc name)
1483        {
1484            this.name = name;
1485        }
1486
1487        public Integer JavaDoc getGathererId()
1488        {
1489            return gathererId;
1490        }
1491
1492        public void setGathererId(Integer JavaDoc gathererId)
1493        {
1494            this.gathererId = gathererId;
1495        }
1496    }
1497}
1498
Popular Tags