You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2003/08/09 12:04:35 UTC
cvs commit: db-ojb/src/test/org/apache/ojb/broker CollectionTest.java
arminw 2003/08/09 03:04:35
Modified: src/test/org/apache/ojb repository_junit.xml
src/schema ojbtest-schema.xml
src/test/org/apache/ojb/broker CollectionTest.java
Log:
- add new tests, update tests
one test does not pass
Can anyone shed some light on this?
Revision Changes Path
1.83 +98 -25 db-ojb/src/test/org/apache/ojb/repository_junit.xml
Index: repository_junit.xml
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit.xml,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -r1.82 -r1.83
--- repository_junit.xml 25 Jul 2003 00:19:12 -0000 1.82
+++ repository_junit.xml 9 Aug 2003 10:04:34 -0000 1.83
@@ -4010,7 +4010,31 @@
proxy="true"
auto-retrieve="true"
auto-update="true"
- auto-delete="false"
+ auto-delete="true"
+ >
+ <orderby name="colId" sort="DESC"/>
+ <inverse-foreignkey field-ref="gathererId"/>
+ </collection-descriptor>
+
+ <collection-descriptor
+ name="collectiblesD"
+ element-class-ref="org.apache.ojb.broker.CollectionTest$CollectibleD"
+ proxy="false"
+ auto-retrieve="true"
+ auto-update="true"
+ auto-delete="true"
+ >
+ <orderby name="colId" sort="DESC"/>
+ <inverse-foreignkey field-ref="gathererId"/>
+ </collection-descriptor>
+
+ <collection-descriptor
+ name="collectiblesDD"
+ element-class-ref="org.apache.ojb.broker.CollectionTest$CollectibleDD"
+ proxy="true"
+ auto-retrieve="true"
+ auto-update="true"
+ auto-delete="true"
>
<orderby name="colId" sort="DESC"/>
<inverse-foreignkey field-ref="gathererId"/>
@@ -4026,8 +4050,8 @@
-->
<class-descriptor
class="org.apache.ojb.broker.CollectionTest$CollectibleBase"
- table="COLLECTION_COLLECTIBLE_A">
- <extent-class class-ref="org.apache.ojb.broker.CollectionTest$CollectibleB" />
+ table="COLLECTION_COLLECTIBLE_BASE">
+ <!-- extent-class class-ref="org.apache.ojb.broker.CollectionTest$CollectibleB" / -->
<field-descriptor
name="colId"
column="COL_ID"
@@ -4048,22 +4072,13 @@
jdbc-type="INTEGER"
/>
- <reference-descriptor
- name="gatherer"
- class-ref="org.apache.ojb.broker.CollectionTest$Gatherer"
- proxy="false"
- auto-retrieve="false"
- auto-update="false"
- auto-delete="false">
- <foreignkey field-ref="gathererId"/>
- </reference-descriptor>
</class-descriptor>
<class-descriptor
class="org.apache.ojb.broker.CollectionTest$CollectibleB"
- table="COLLECTION_COLLECTIBLE_BC">
+ table="COLLECTION_COLLECTIBLE_B">
- <extent-class class-ref="org.apache.ojb.broker.CollectionTest$CollectibleC" />
+ <!-- extent-class class-ref="org.apache.ojb.broker.CollectionTest$CollectibleC" / -->
<field-descriptor
name="colId"
@@ -4084,21 +4099,11 @@
column="GAT_ID"
jdbc-type="INTEGER"
/>
-
- <reference-descriptor
- name="gatherer"
- class-ref="org.apache.ojb.broker.CollectionTest$Gatherer"
- proxy="false"
- auto-retrieve="false"
- auto-update="false"
- auto-delete="false">
- <foreignkey field-ref="gathererId"/>
- </reference-descriptor>
</class-descriptor>
<class-descriptor
class="org.apache.ojb.broker.CollectionTest$CollectibleC"
- table="COLLECTION_COLLECTIBLE_BC">
+ table="COLLECTION_COLLECTIBLE_C">
<field-descriptor
name="colId"
@@ -4135,10 +4140,78 @@
auto-delete="false">
<foreignkey field-ref="gathererId"/>
</reference-descriptor>
+
+ </class-descriptor>
+
+ <class-descriptor
+ class="org.apache.ojb.broker.CollectionTest$CollectibleD"
+ table="COLLECTION_COLLECTIBLE_D">
+
+ <field-descriptor
+ name="colId"
+ column="COL_ID"
+ jdbc-type="INTEGER"
+ primarykey="true"
+ autoincrement="true"
+ />
+
+ <field-descriptor
+ name="name"
+ column="NAME"
+ jdbc-type="VARCHAR"
+ />
+
+ <field-descriptor
+ name="ojbConcreteClass"
+ column="OJB_CONCRETE_CLASS"
+ jdbc-type="VARCHAR"
+ />
+
+ <field-descriptor
+ name="gathererId"
+ column="GAT_ID"
+ jdbc-type="INTEGER"
+ />
+
+ </class-descriptor>
+
+ <class-descriptor
+ class="org.apache.ojb.broker.CollectionTest$CollectibleDD"
+ table="COLLECTION_COLLECTIBLE_D">
+
+ <field-descriptor
+ name="colId"
+ column="COL_ID"
+ jdbc-type="INTEGER"
+ primarykey="true"
+ autoincrement="true"
+ />
+
+ <field-descriptor
+ name="name"
+ column="NAME"
+ jdbc-type="VARCHAR"
+ />
+
+ <field-descriptor
+ name="ojbConcreteClass"
+ column="OJB_CONCRETE_CLASS"
+ jdbc-type="VARCHAR"
+ />
+
+ <field-descriptor
+ name="gathererId"
+ column="GAT_ID"
+ jdbc-type="INTEGER"
+ />
</class-descriptor>
<class-descriptor class="org.apache.ojb.broker.CollectionTest$CollectibleBaseIF">
<extent-class class-ref="org.apache.ojb.broker.CollectionTest$CollectibleBase" />
+ <extent-class class-ref="org.apache.ojb.broker.CollectionTest$CollectibleB" />
+ <extent-class class-ref="org.apache.ojb.broker.CollectionTest$CollectibleC" />
+ <extent-class class-ref="org.apache.ojb.broker.CollectionTest$CollectibleD" />
+ <extent-class class-ref="org.apache.ojb.broker.CollectionTest$CollectibleDD" />
</class-descriptor>
1.45 +20 -1 db-ojb/src/schema/ojbtest-schema.xml
Index: ojbtest-schema.xml
===================================================================
RCS file: /home/cvs/db-ojb/src/schema/ojbtest-schema.xml,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- ojbtest-schema.xml 25 Jul 2003 00:19:12 -0000 1.44
+++ ojbtest-schema.xml 9 Aug 2003 10:04:34 -0000 1.45
@@ -683,11 +683,30 @@
<column name="GAT_ID" type="INTEGER"/>
</table>
- <table name="COLLECTION_COLLECTIBLE_BC">
+ <table name="COLLECTION_COLLECTIBLE_BASE">
+ <column name="COL_ID" required="true" primaryKey="true" type="INTEGER"/>
+ <column name="NAME" type="VARCHAR" size="150"/>
+ <column name="GAT_ID" type="INTEGER"/>
+ </table>
+
+ <table name="COLLECTION_COLLECTIBLE_B">
+ <column name="COL_ID" required="true" primaryKey="true" type="INTEGER"/>
+ <column name="NAME" type="VARCHAR" size="150"/>
+ <column name="GAT_ID" type="INTEGER"/>
+ </table>
+
+ <table name="COLLECTION_COLLECTIBLE_C">
<column name="COL_ID" required="true" primaryKey="true" type="INTEGER"/>
<column name="NAME" type="VARCHAR" size="150"/>
<column name="GAT_ID" type="INTEGER"/>
<column name="EXTENT_NAME" type="VARCHAR" size="150"/>
+ </table>
+
+ <table name="COLLECTION_COLLECTIBLE_D">
+ <column name="COL_ID" required="true" primaryKey="true" type="INTEGER"/>
+ <column name="NAME" type="VARCHAR" size="150"/>
+ <column name="OJB_CONCRETE_CLASS" type="VARCHAR" size="150"/>
+ <column name="GAT_ID" type="INTEGER"/>
</table>
<!-- =================================================== -->
1.3 +446 -40 db-ojb/src/test/org/apache/ojb/broker/CollectionTest.java
Index: CollectionTest.java
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/CollectionTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CollectionTest.java 7 Jun 2003 10:13:28 -0000 1.2
+++ CollectionTest.java 9 Aug 2003 10:04:35 -0000 1.3
@@ -1,6 +1,8 @@
package org.apache.ojb.broker;
import junit.framework.TestCase;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.ojb.broker.query.Criteria;
import org.apache.ojb.broker.query.Query;
import org.apache.ojb.broker.query.QueryByCriteria;
@@ -9,9 +11,43 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import java.util.Vector;
/**
+ * Test case for collection handling.
+ *
+ * Main class Gatherer have five collections of type CollectibleBase,
+ * CollectibleB, CollectibleC, CollectibleD, CollectibleDD
+ *
+ * Class hierarchy:
+ * [CollectibleBaseIF <--] CollectibleBase <-- CollectibleB <-- CollectibleC
+ * |
+ * CollectibleD <-- CollectibleDD
+ *
+ * in repository interface CollectibleBaseIF was declared with five
+ * extents (CollectibleBase, CollectibleB, CollectibleC, CollectibleD, CollectibleDD)
+ *
+ * CollectibleBase
+ * auto-retrieve, auto-update, auto-delete all true
+ * proxy false
+ *
+ * CollectibleB
+ * auto-retrieve, auto-update set true, auto-delete false
+ * proxy true
+ *
+ * CollectibleC
+ * auto-retrieve, auto-update, auto-delete set true,
+ * proxy true
+ * CollectibleC has a reference back to the Gatherer object
+ * (auto-retrieve, auto-update, auto-delete set false to avoid circular
+ * object creation)
+ *
+ * CollectibleD
+ * auto-retrieve, auto-update, auto-delete all true
+ * proxy false
+ *
+ * CollectibleDD
+ * auto-retrieve, auto-update, auto-delete all true
+ * proxy true
*
* @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
* @version $Id$
@@ -42,21 +78,42 @@
}
}
- public void testCollectionCreation()
+ /**
+ * generate main object with collections and store
+ * main object to make all persistent
+ */
+ public void testStoreDeleteSimpleCollections()
{
long timestamp = System.currentTimeMillis();
String colPrefix = "col_" + timestamp;
- String name = timestamp + "_test gatherer";
+ String name = timestamp + "_testStoreDeleteSimpleCollections";
// create gatherer with collections
Gatherer gatherer = new Gatherer(null, name);
gatherer.setCollectiblesBase(Arrays.asList(prepareCollectibleBase(colPrefix)));
gatherer.setCollectiblesB(Arrays.asList(prepareCollectibleB(colPrefix)));
- gatherer.setCollectiblesC(Arrays.asList(prepareCollectibleC(colPrefix)));
broker.beginTransaction();
broker.store(gatherer);
broker.commitTransaction();
+ assertEquals("CollectibleBase objects", 3, gatherer.getCollectiblesBase().size());
+ assertEquals(gatherer.getGatId(), ((CollectibleBaseIF) gatherer.getCollectiblesBase().get(0)).getGathererId());
+ assertEquals("CollectibleB objects", 4, gatherer.getCollectiblesB().size());
+ assertEquals(gatherer.getGatId(), ((CollectibleBIF) gatherer.getCollectiblesB().get(0)).getGathererId());
+
+ Identity oid = new Identity(gatherer, broker);
+ broker.clearCache();
+ Gatherer new_gatherer = (Gatherer) broker.getObjectByIdentity(oid);
+
+ assertNotNull(new_gatherer);
+ assertNotNull(new_gatherer.getCollectiblesBase());
+ assertNotNull(new_gatherer.getCollectiblesB());
+ assertEquals("CollectibleBase objects", 3, new_gatherer.getCollectiblesBase().size());
+ assertEquals("CollectibleB objects", 4, new_gatherer.getCollectiblesB().size());
+ assertEquals(new_gatherer.getGatId(), ((CollectibleBaseIF) new_gatherer.getCollectiblesBase().get(0)).getGathererId());
+ assertEquals(new_gatherer.getGatId(), ((CollectibleBIF) new_gatherer.getCollectiblesB().get(0)).getGathererId());
+
+ broker.clearCache();
Criteria criteria = new Criteria();
criteria.addLike("name", colPrefix + "_colBase*");
@@ -73,10 +130,264 @@
assertEquals("Wrong number of queried objects", 4, result.size());
criteria = new Criteria();
- criteria.addLike("name", colPrefix + "_colC*");
- q = new QueryByCriteria(CollectibleC.class, criteria);
+ criteria.addLike("name", colPrefix + "*");
+ q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
+ result = (Collection) broker.getCollectionByQuery(q);
+ assertNotNull(result);
+ assertEquals("Wrong number of queried objects", 7, result.size());
+
+ // now we delete the main object
+ // and see what's going on with the dependend objects
+ broker.beginTransaction();
+ broker.delete(new_gatherer);
+ broker.commitTransaction();
+
+ broker.clearCache();
+ new_gatherer = (Gatherer) broker.getObjectByIdentity(oid);
+
+ assertNull(new_gatherer);
+
+ criteria = new Criteria();
+ criteria.addLike("name", colPrefix + "_colBase*");
+ q = new QueryByCriteria(CollectibleBase.class, criteria);
+ result = (Collection) broker.getCollectionByQuery(q);
+ assertNotNull(result);
+ // auto-delete is set true
+ assertEquals("Wrong number of queried objects", 0, result.size());
+
+ criteria = new Criteria();
+ criteria.addLike("name", colPrefix + "_colB*");
+ q = new QueryByCriteria(CollectibleB.class, criteria);
+ result = (Collection) broker.getCollectionByQuery(q);
+ assertNotNull(result);
+ // auto-delete is set false
+ assertEquals("Wrong number of queried objects", 4, result.size());
+
+ criteria = new Criteria();
+ criteria.addLike("name", colPrefix + "*");
+ q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
+ result = (Collection) broker.getCollectionByQuery(q);
+ assertNotNull(result);
+ assertEquals("Wrong number of queried objects", 4, result.size());
+ }
+
+ /**
+ * generate main object with collections and store
+ * main object to make all persistent
+ * using ojbConcreteClass feature to map different
+ * objects to same table
+ */
+ public void testStoreDeleteSimpleCollections_2()
+ {
+ long timestamp = System.currentTimeMillis();
+ String colPrefix = "col_" + timestamp;
+ String name = timestamp + "_testStoreDeleteSimpleCollections";
+
+ // create gatherer with collections
+ Gatherer gatherer = new Gatherer(null, name);
+ gatherer.setCollectiblesD(Arrays.asList(prepareCollectibleD(colPrefix)));
+ gatherer.setCollectiblesDD(Arrays.asList(prepareCollectibleDD(colPrefix)));
+
+ broker.beginTransaction();
+ broker.store(gatherer);
+ broker.commitTransaction();
+ assertEquals("CollectibleD objects", 2, gatherer.getCollectiblesD().size());
+ assertEquals(gatherer.getGatId(), ((CollectibleDIF) gatherer.getCollectiblesD().get(0)).getGathererId());
+ assertEquals("CollectibleDD objects", 3, gatherer.getCollectiblesDD().size());
+ assertEquals(gatherer.getGatId(), ((CollectibleDDIF) gatherer.getCollectiblesDD().get(0)).getGathererId());
+
+ Identity oid = new Identity(gatherer, broker);
+ broker.clearCache();
+ Gatherer new_gatherer = (Gatherer) broker.getObjectByIdentity(oid);
+
+ assertNotNull(new_gatherer);
+ assertNotNull(new_gatherer.getCollectiblesD());
+ assertNotNull(new_gatherer.getCollectiblesDD());
+ assertEquals("CollectibleD objects", 2, new_gatherer.getCollectiblesD().size());
+ assertEquals("CollectibleDD objects", 3, new_gatherer.getCollectiblesDD().size());
+ assertEquals(new_gatherer.getGatId(), ((CollectibleDIF) new_gatherer.getCollectiblesD().get(0)).getGathererId());
+ assertEquals(new_gatherer.getGatId(), ((CollectibleDDIF) new_gatherer.getCollectiblesDD().get(0)).getGathererId());
+
+ broker.clearCache();
+
+ Criteria criteria = new Criteria();
+ criteria.addLike("name", colPrefix + "_colD*");
+ criteria.addLike("name", colPrefix + "*");
+ Query q = new QueryByCriteria(CollectibleD.class, criteria);
+ Collection result = (Collection) broker.getCollectionByQuery(q);
+ assertNotNull(result);
+ assertEquals("Wrong number of queried objects", 2, result.size());
+
+ criteria = new Criteria();
+ criteria.addLike("name", colPrefix + "_colDD*");
+ q = new QueryByCriteria(CollectibleDD.class, criteria);
+ result = (Collection) broker.getCollectionByQuery(q);
+ assertNotNull(result);
+ assertEquals("Wrong number of queried objects", 3, result.size());
+
+ // now test objConcreteClass feature
+ // should only return CollectibleD class instances
+ criteria = new Criteria();
+ criteria.addLike("name", colPrefix + "*");
+ q = new QueryByCriteria(CollectibleD.class, criteria);
+ result = (Collection) broker.getCollectionByQuery(q);
+ assertNotNull(result);
+ assertEquals("Wrong number of queried objects", 2, result.size());
+ // now test objConcreteClass feature
+ criteria = new Criteria();
+ criteria.addLike("name", colPrefix + "*");
+ q = new QueryByCriteria(CollectibleDD.class, criteria);
+ result = (Collection) broker.getCollectionByQuery(q);
+ assertNotNull(result);
+ assertEquals("Wrong number of queried objects", 3, result.size());
+
+ criteria = new Criteria();
+ criteria.addLike("name", colPrefix + "*");
+ q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
+ result = (Collection) broker.getCollectionByQuery(q);
+ assertNotNull(result);
+ assertEquals("Wrong number of queried objects", 5, result.size());
+
+ // now we delete the main object
+ // and see what's going on with the dependend objects
+ broker.beginTransaction();
+ broker.delete(new_gatherer);
+ broker.commitTransaction();
+
+ broker.clearCache();
+ new_gatherer = (Gatherer) broker.getObjectByIdentity(oid);
+
+ assertNull(new_gatherer);
+
+ criteria = new Criteria();
+ criteria.addLike("name", colPrefix + "_colD*");
+ q = new QueryByCriteria(CollectibleD.class, criteria);
+ result = (Collection) broker.getCollectionByQuery(q);
+ assertNotNull(result);
+ // auto-delete is set true
+ assertEquals("Wrong number of queried objects", 0, result.size());
+
+ criteria = new Criteria();
+ criteria.addLike("name", colPrefix + "_colDD*");
+ q = new QueryByCriteria(CollectibleDD.class, criteria);
+ result = (Collection) broker.getCollectionByQuery(q);
+ assertNotNull(result);
+ // auto-delete is set true
+ assertEquals("Wrong number of queried objects", 0, result.size());
+
+ criteria = new Criteria();
+ criteria.addLike("name", colPrefix + "*");
+ q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
+ result = (Collection) broker.getCollectionByQuery(q);
+ assertNotNull(result);
+ assertEquals("Wrong number of queried objects", 0, result.size());
+ }
+
+ public void testStoreSimpleCollections()
+ {
+ long timestamp = System.currentTimeMillis();
+ String colPrefix = "col_" + timestamp;
+ String name = timestamp + "_testStoreSimpleCollections";
+
+ // create gatherer with collections
+ Gatherer gatherer = new Gatherer(null, name);
+
+ broker.beginTransaction();
+ broker.store(gatherer);
+ gatherer.setCollectiblesBase(Arrays.asList(prepareCollectibleBase(colPrefix)));
+ gatherer.setCollectiblesB(Arrays.asList(prepareCollectibleB(colPrefix)));
+ broker.store(gatherer);
+ broker.commitTransaction();
+
+ Identity oid = new Identity(gatherer, broker);
+ broker.clearCache();
+ Gatherer new_gatherer = (Gatherer) broker.getObjectByIdentity(oid);
+
+ assertNotNull(new_gatherer);
+ assertNotNull(new_gatherer.getCollectiblesBase());
+ assertNotNull(new_gatherer.getCollectiblesB());
+ assertEquals("CollectibleBase objects", 3, new_gatherer.getCollectiblesBase().size());
+ assertEquals("CollectibleB objects", 4, new_gatherer.getCollectiblesB().size());
+ Integer gatId = ((CollectibleBaseIF)new_gatherer.getCollectiblesBase().get(0)).getGathererId();
+ assertNotNull(gatId);
+ assertEquals(new_gatherer.gatId, gatId);
+ broker.clearCache();
+
+ Criteria criteria = new Criteria();
+ criteria.addLike("name", colPrefix + "_colBase*");
+ Query q = new QueryByCriteria(CollectibleBase.class, criteria);
+ Collection result = (Collection) broker.getCollectionByQuery(q);
+ assertNotNull(result);
+ assertEquals("Wrong number of queried objects", 3, result.size());
+
+ criteria = new Criteria();
+ criteria.addLike("name", colPrefix + "_colB*");
+ q = new QueryByCriteria(CollectibleB.class, criteria);
+ result = (Collection) broker.getCollectionByQuery(q);
+ assertNotNull(result);
+ assertEquals("Wrong number of queried objects", 4, result.size());
+
+ criteria = new Criteria();
+ criteria.addLike("name", colPrefix + "*");
+ q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
result = (Collection) broker.getCollectionByQuery(q);
assertNotNull(result);
+ assertEquals("Wrong number of queried objects", 7, result.size());
+ }
+
+ /**
+ * generate main object with collections and store
+ * main object to make all persistent.
+ * same like {@link #testStoreSimpleCollections} but now the
+ * collection objects have a reference back to main object.
+ *
+ * Curious but this test does not pass
+ */
+ public void testStoreCollectionObjectsWithBackReference()
+ {
+ long timestamp = System.currentTimeMillis();
+ String colPrefix = "col_" + timestamp;
+ String name = timestamp + "_testStoreCollectionObjectsWithBackReference";
+
+ // create gatherer with collections
+ Gatherer gatherer = new Gatherer(null, name);
+ gatherer.setCollectiblesC(Arrays.asList(prepareCollectibleC(colPrefix)));
+
+ broker.beginTransaction();
+ broker.store(gatherer);
+ broker.commitTransaction();
+ assertEquals("CollectibleC objects", 5, gatherer.getCollectiblesC().size());
+ /*
+ TODO: does not pass. the same test with an object that
+ doesn't have a reference back to main object (Gatherer)
+ pass without problems.
+ */
+ assertEquals(gatherer.getGatId(), ((CollectibleCIF) gatherer.getCollectiblesC().get(0)).getGathererId());
+
+ Identity oid = new Identity(gatherer, broker);
+ broker.clearCache();
+// System.out.println("## stored "+gatherer);
+ Gatherer new_gatherer = (Gatherer) broker.getObjectByIdentity(oid);
+// System.out.println("## after lookup "+new_gatherer);
+// System.out.println("## after "+new_gatherer.getCollectiblesC().size());
+
+ assertNotNull(new_gatherer);
+ assertNotNull(new_gatherer.getCollectiblesC());
+ /*
+ TODO: fix this. When dependend object has a reference to the main object,
+ the test fails. After store, all is ok. Seems something going wrong
+ on lookup.
+ */
+ assertEquals("CollectibleC objects", 5, gatherer.getCollectiblesC().size());
+ assertEquals(gatherer.getGatId(), ((CollectibleCIF) gatherer.getCollectiblesC().get(0)).getGathererId());
+
+ broker.clearCache();
+
+ Criteria criteria = new Criteria();
+ criteria.addLike("name", colPrefix + "_colC*");
+ Query q = new QueryByCriteria(CollectibleC.class, criteria);
+ Collection result = (Collection) broker.getCollectionByQuery(q);
+ assertNotNull(result);
assertEquals("Wrong number of queried objects", 5, result.size());
criteria = new Criteria();
@@ -84,7 +395,7 @@
q = new QueryByCriteria(CollectibleBaseIF.class, criteria);
result = (Collection) broker.getCollectionByQuery(q);
assertNotNull(result);
- assertEquals("Wrong number of queried objects", 12, result.size());
+ assertEquals("Wrong number of queried objects", 5, result.size());
}
private CollectibleBase[] prepareCollectibleBase(String namePrefix)
@@ -111,15 +422,34 @@
private CollectibleB[] prepareCollectibleC(String namePrefix)
{
CollectibleC[] colC = new CollectibleC[]{
- new CollectibleC(null, namePrefix + "_colC_1", null, "ext1"),
- new CollectibleC(null, namePrefix + "_colC_2", null, "ext2"),
- new CollectibleC(null, namePrefix + "_colC_3", null, "ext3"),
- new CollectibleC(null, namePrefix + "_colC_4", null, "ext4"),
- new CollectibleC(null, namePrefix + "_colC_5", null, "ext5")
+ new CollectibleC(namePrefix + "_colC_1", "ext1"),
+ new CollectibleC(namePrefix + "_colC_2", "ext2"),
+ new CollectibleC(namePrefix + "_colC_3", "ext3"),
+ new CollectibleC(namePrefix + "_colC_4", "ext4"),
+ new CollectibleC(namePrefix + "_colC_5", "ext5")
};
return colC;
}
+ private CollectibleD[] prepareCollectibleD(String namePrefix)
+ {
+ CollectibleD[] colD = new CollectibleD[]{
+ new CollectibleD(namePrefix + "_colD_1"),
+ new CollectibleD(namePrefix + "_colD_2"),
+ };
+ return colD;
+ }
+
+ private CollectibleDD[] prepareCollectibleDD(String namePrefix)
+ {
+ CollectibleDD[] colDD = new CollectibleDD[]{
+ new CollectibleDD(namePrefix + "_colDD_1"),
+ new CollectibleDD(namePrefix + "_colDD_2"),
+ new CollectibleDD(namePrefix + "_colDD_3")
+ };
+ return colDD;
+ }
+
//*********************************************************************
// inner class - persistent object
@@ -128,20 +458,16 @@
{
private Integer gatId;
private String name;
- private List collectiblesBase = new Vector();
- private List collectiblesB = new Vector();
- private List collectiblesC = new Vector();
+ private List collectiblesBase;
+ private List collectiblesB;
+ private List collectiblesC;
+ private List collectiblesD;
+ private List collectiblesDD;
public Gatherer()
{
}
- public void addCollectibleA(CollectibleBase colA)
- {
- if (collectiblesBase == null) collectiblesBase = new Vector();
- collectiblesBase.add(colA);
- }
-
public Gatherer(Integer gatId, String name)
{
this.gatId = gatId;
@@ -197,6 +523,39 @@
{
this.collectiblesC = collectiblesC;
}
+
+ public List getCollectiblesD()
+ {
+ return collectiblesD;
+ }
+
+ public void setCollectiblesD(List collectiblesD)
+ {
+ this.collectiblesD = collectiblesD;
+ }
+
+ public List getCollectiblesDD()
+ {
+ return collectiblesDD;
+ }
+
+ public void setCollectiblesDD(List collectiblesDD)
+ {
+ this.collectiblesDD = collectiblesDD;
+ }
+
+ public String toString()
+ {
+ ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
+ buf.append("gatId", gatId);
+ buf.append("name", name);
+ buf.append("collectiblesBase", collectiblesBase);
+ buf.append("collectiblesB", collectiblesB);
+ buf.append("collectiblesC", collectiblesC);
+ buf.append("collectiblesD", collectiblesD);
+ buf.append("collectiblesDD", collectiblesDD);
+ return buf.toString();
+ }
}
public static interface CollectibleBaseIF extends Serializable
@@ -224,27 +583,27 @@
private String name;
private Integer gathererId;
private Gatherer gatherer;
+ // protected String ojbConcreteClass;
public CollectibleBase()
{
+ // ojbConcreteClass = CollectibleBase.class.getName();
}
- public CollectibleBase(Integer colId, String name, Integer gathererId)
- {
- this.colId = colId;
- this.name = name;
- this.gathererId = gathererId;
- }
-
- public CollectibleBase(String name, Integer gathererId)
+ public CollectibleBase(String name)
{
+ // ojbConcreteClass = CollectibleBase.class.getName();
this.name = name;
- this.gathererId = gathererId;
}
- public CollectibleBase(String name)
+ public String toString()
{
- this.name = name;
+ ToStringBuilder buf = new ToStringBuilder(this);
+ buf.append("colId", colId);
+ buf.append("name", name);
+ buf.append("gathererId", gathererId);
+// buf.append("ojbConcreteClass", ojbConcreteClass);
+ return buf.toString();
}
public Gatherer getGatherer()
@@ -297,16 +656,13 @@
{
public CollectibleB()
{
+// ojbConcreteClass = CollectibleB.class.getName();
}
public CollectibleB(String name)
{
super(name);
- }
-
- public CollectibleB(Integer colId, String name, Integer gathererId)
- {
- super(colId, name, gathererId);
+// ojbConcreteClass = CollectibleB.class.getName();
}
}
@@ -323,11 +679,19 @@
public CollectibleC()
{
+// ojbConcreteClass = CollectibleC.class.getName();
}
- public CollectibleC(Integer colId, String name, Integer gathererId, String extentName)
+ public CollectibleC(String name)
{
- super(colId, name, gathererId);
+ super(name);
+// ojbConcreteClass = CollectibleC.class.getName();
+ }
+
+ public CollectibleC(String name, String extentName)
+ {
+ super(name);
+// ojbConcreteClass = CollectibleC.class.getName();
this.extentName = extentName;
}
@@ -339,6 +703,48 @@
public void setExtentName(String extentName)
{
this.extentName = extentName;
+ }
+ }
+
+ public static interface CollectibleDIF extends CollectibleBaseIF
+ {
+
+ }
+
+ public static class CollectibleD extends CollectibleBase implements CollectibleDIF
+ {
+ protected String ojbConcreteClass;
+
+ public CollectibleD()
+ {
+ ojbConcreteClass = CollectibleD.class.getName();
+ }
+
+ public CollectibleD(String name)
+ {
+ super(name);
+ ojbConcreteClass = CollectibleD.class.getName();
+ }
+ }
+
+ public static interface CollectibleDDIF extends CollectibleBaseIF
+ {
+
+ }
+
+ public static class CollectibleDD extends CollectibleBase implements CollectibleDDIF
+ {
+ protected String ojbConcreteClass;
+
+ public CollectibleDD()
+ {
+ ojbConcreteClass = CollectibleDD.class.getName();
+ }
+
+ public CollectibleDD(String name)
+ {
+ super(name);
+ ojbConcreteClass = CollectibleDD.class.getName();
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org