db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/schema ojbtest-schema.xml
Date Wed, 12 Mar 2003 09:29:01 GMT
arminw      2003/03/12 01:29:01

  Modified:    src/test/org/apache/ojb repository_junit.xml
               src/test/org/apache/ojb/odmg AllTests.java
               src/schema ojbtest-schema.xml
  Added:       src/test/org/apache/ojb/odmg CollectionsTest.java
  Removed:     src/test/org/apache/ojb/odmg OdmgCollectionsTest.java
  Log:
  add new test, checking collection handling
  with ODMG, remove empty test case
  
  Revision  Changes    Path
  1.52      +189 -0    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.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- repository_junit.xml	8 Mar 2003 11:37:49 -0000	1.51
  +++ repository_junit.xml	12 Mar 2003 09:29:00 -0000	1.52
  @@ -3410,5 +3410,194 @@
           />
       </class-descriptor>
   
  +<!-- ************************************************* -->
  +<!--      ODMG collection tests                        -->
  +<!-- ************************************************* -->
  +
  +    <!--
  +        private Integer gatId;
  +        private String name;
  +        private Collection collectiblesA;
  +        private Collection collectiblesB;
  +    -->
  +    <class-descriptor
  +        class="org.apache.ojb.odmg.CollectionsTest$Gatherer"
  +        table="COLLECTION_GATHERER">
  +
  +        <field-descriptor
  +         name="gatId"
  +         column="GAT_ID"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +         name="name"
  +         column="NAME"
  +         jdbc-type="VARCHAR"
  +        />
  +
  +        <collection-descriptor
  +            name="collectiblesA"
  +            element-class-ref="org.apache.ojb.odmg.CollectionsTest$CollectibleA"
  +            proxy="false"
  +            auto-retrieve="true"
  +            auto-update="false"
  +            auto-delete="false"
  +        >
  +            <orderby name="colId" sort="DESC"/>
  +            <inverse-foreignkey field-ref="gathererId"/>
  +        </collection-descriptor>
  +
  +        <collection-descriptor
  +            name="collectiblesB"
  +            element-class-ref="org.apache.ojb.odmg.CollectionsTest$CollectibleB"
  +            proxy="true"
  +            auto-retrieve="true"
  +            auto-update="false"
  +            auto-delete="false"
  +        >
  +            <orderby name="colId" sort="DESC"/>
  +            <inverse-foreignkey field-ref="gathererId"/>
  +        </collection-descriptor>
  +
  +        <collection-descriptor
  +            name="collectiblesC"
  +            element-class-ref="org.apache.ojb.odmg.CollectionsTest$CollectibleC"
  +            proxy="true"
  +            auto-retrieve="true"
  +            auto-update="false"
  +            auto-delete="false"
  +        >
  +            <orderby name="colId" sort="DESC"/>
  +            <inverse-foreignkey field-ref="gathererId"/>
  +        </collection-descriptor>
  +    </class-descriptor>
  +
  +    <class-descriptor class="org.apache.ojb.odmg.CollectionsTest$CollectibleAIF">
  +      <extent-class class-ref="org.apache.ojb.odmg.CollectionsTest$CollectibleA" />
  +   </class-descriptor>
  +
  +    <!--
  +        private Integer colId;
  +        private String name;
  +        private Integer gathererId;
  +        private Gatherer gatherer;
  +        private String extentName;
  +    -->
  +    <class-descriptor
  +        class="org.apache.ojb.odmg.CollectionsTest$CollectibleA"
  +        table="COLLECTION_COLLECTIBLE_A">
  +
  +        <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="gathererId"
  +         column="GAT_ID"
  +         jdbc-type="INTEGER"
  +        />
  +
  +        <!-- reference-descriptor
  +            name="gatherer"
  +            class-ref="org.apache.ojb.odmg.CollectionsTest$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.odmg.CollectionsTest$CollectibleB"
  +        table="COLLECTION_COLLECTIBLE_BC">
  +
  +        <extent-class class-ref="org.apache.ojb.odmg.CollectionsTest$CollectibleC" />
  +
  +        <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="gathererId"
  +         column="GAT_ID"
  +         jdbc-type="INTEGER"
  +        />
  +
  +        <!-- reference-descriptor
  +            name="gatherer"
  +            class-ref="org.apache.ojb.odmg.CollectionsTest$Gatherer"
  +            proxy="false"
  +            auto-retrieve="true"
  +            auto-update="false"
  +            auto-delete="false">
  +                <foreignkey field-ref="gathererId"/>
  +        </reference-descriptor -->
  +    </class-descriptor>
  +
  +    <class-descriptor
  +        class="org.apache.ojb.odmg.CollectionsTest$CollectibleC"
  +        table="COLLECTION_COLLECTIBLE_BC">
  +
  +        <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="gathererId"
  +         column="GAT_ID"
  +         jdbc-type="INTEGER"
  +        />
  +
  +        <field-descriptor
  +         name="extentName"
  +         column="EXTENT_NAME"
  +         jdbc-type="VARCHAR"
  +        />
  +
  +        <!-- reference-descriptor
  +            name="gatherer"
  +            class-ref="org.apache.ojb.odmg.CollectionsTest$Gatherer"
  +            proxy="false"
  +            auto-retrieve="true"
  +            auto-update="false"
  +            auto-delete="false">
  +                <foreignkey field-ref="gathererId"/>
  +        </reference-descriptor -->
  +    </class-descriptor>
  +
   
   <!-- Mapping of classes used in junit tests and tutorials ends here -->
  
  
  
  1.13      +1 -1      db-ojb/src/test/org/apache/ojb/odmg/AllTests.java
  
  Index: AllTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/AllTests.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- AllTests.java	3 Mar 2003 19:30:35 -0000	1.12
  +++ AllTests.java	12 Mar 2003 09:29:01 -0000	1.13
  @@ -54,7 +54,7 @@
           suite.addTest(new TestSuite(OQLOrOnForeignKeyTest.class));
           suite.addTest(new TestSuite(FieldConversion_4.class));
           suite.addTest(new TestSuite(BatchModeTest.class));
  -		//suite.addTest(new TestSuite(OdmgCollectionsTest.class));
  +        suite.addTest(new TestSuite(CollectionsTest.class));
   		suite.addTest(new TestSuite(PersonWithArrayTest.class));
           return suite;
       }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/odmg/CollectionsTest.java
  
  Index: CollectionsTest.java
  ===================================================================
  package org.apache.ojb.odmg;
  
  import junit.framework.TestCase;
  import org.apache.ojb.broker.TestHelper;
  import org.odmg.Database;
  import org.odmg.Implementation;
  import org.odmg.Transaction;
  import org.odmg.OQLQuery;
  
  import java.util.Collection;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Vector;
  import java.util.List;
  
  /**
   * Test case handles with collections.
   *
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: CollectionsTest.java,v 1.1 2003/03/12 09:29:01 arminw Exp $
   */
  public class CollectionsTest extends TestCase
  {
      private Implementation odmg;
      private Database db;
  
      public CollectionsTest(String s)
      {
          super(s);
      }
  
      public static void main(String[] args)
      {
          String[] arr = {CollectionsTest.class.getName()};
          junit.textui.TestRunner.main(arr);
      }
  
      public void setUp() throws Exception
      {
          super.setUp();
  
          odmg = OJB.getInstance();
          db = odmg.newDatabase();
          db.open(TestHelper.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);
      }
  
      protected void tearDown() throws Exception
      {
          super.tearDown();
          try
          {
              db.close();
              odmg = null;
          }
          catch (Exception e)
          {
              // ignore
          }
      }
  
      public void testStoreFetchDelete() throws Exception
      {
          String prefix = "testInsertDelete"+System.currentTimeMillis();
          String queryStr = "select gatherer from "+Gatherer.class.getName()+" where gatId=$1";
  
          // prepare test case
          Gatherer gat = new Gatherer(null, prefix+"_Gatherer");
          CollectibleA[] cols = prepareCollectibleA(prefix);
          List colList = Arrays.asList(cols);
          // set List of CollectibleA objects
          gat.setCollectiblesA(colList);
          Transaction tx = odmg.newTransaction();
          tx.begin();
          db.makePersistent(gat);
          tx.commit();
  
          // check if gatherer was stored
          tx.begin();
          OQLQuery query = odmg.newOQLQuery();
          query.create(queryStr);
          Integer gatId = gat.getGatId();
          assertNotNull(gatId);
          query.bind(gatId);
          Collection result = (Collection) query.execute();
          tx.commit();
          assertEquals("Wrong number of objects found", 1, result.size());
          Gatherer fetchedGat = (Gatherer) result.iterator().next();
  
          // check if gatherer contains list of CollectibleA
          tx.begin();
          List colsA = fetchedGat.getCollectiblesA();
          assertEquals("Wrong number of CollectiblesA", 3, colsA.size());
  
          // delete one of the CollectibleA
          db.deletePersistent(colsA.get(0));
          tx.commit();
  
          // check if the CollectibleA was really deleted from DB
          tx.begin();
          query = odmg.newOQLQuery();
          query.create("select allCollectibleA from "+CollectibleA.class.getName()+
                  " where name like $1");
          query.bind(prefix+"%");
          result = (Collection) query.execute();
          assertEquals("Wrong number of objects found", 2, result.size());
          tx.commit();
  
          // check if the gatherer now contains a CollectibleA list
          // reduced by the deleted
          tx.begin();
  // when clear cache test will be passed
  //        ((HasBroker)tx).getBroker().clearCache();
          query = odmg.newOQLQuery();
          query.create(queryStr);
          query.bind(gatId);
          result = (Collection) query.execute();
          assertEquals("Wrong number of objects found", 1, result.size());
          fetchedGat = (Gatherer) result.iterator().next();
          colsA = fetchedGat.getCollectiblesA();
          assertEquals("Wrong number of CollectiblesA found in Gatherer", 2, colsA.size());
          tx.commit();
      }
  
      private CollectibleA[] prepareCollectibleA(String namePrefix)
      {
          CollectibleA[] colA = new CollectibleA[]{
              new CollectibleA(namePrefix + " colA_1"),
              new CollectibleA(namePrefix + " colA_2"),
              new CollectibleA(namePrefix + " colA_3")
          };
          return colA;
      }
  
      private CollectibleB[] prepareCollectibleB(String namePrefix)
      {
          CollectibleB[] colB = new CollectibleB[]{
              new CollectibleB(namePrefix + " colB_1"),
              new CollectibleB(namePrefix + " colB_2"),
              new CollectibleB(namePrefix + " colB_3")
          };
          return colB;
      }
  
      private CollectibleB[] prepareCollectibleC(String namePrefix)
      {
          CollectibleC[] colC = new CollectibleC[]{
              new CollectibleC(null, namePrefix + " colB_1", null, "ext1"),
              new CollectibleC(null, namePrefix + " colB_2", null, "ext2"),
              new CollectibleC(null, namePrefix + " colB_3", null, "ext3")
          };
          return colC;
      }
  
  
      //****************************************************************************
      // inner classes
      //****************************************************************************
      public static class Gatherer
      {
          private Integer gatId;
          private String name;
          private List collectiblesA = new Vector();
          private List collectiblesB = new Vector();
          private List collectiblesC = new Vector();
  
          public Gatherer()
          {
          }
  
          public void addCollectibleA(CollectibleA colA)
          {
              if(collectiblesA == null) collectiblesA = new Vector();
              collectiblesA.add(colA);
          }
  
          public Gatherer(Integer gatId, String name)
          {
              this.gatId = gatId;
              this.name = name;
          }
  
          public Integer getGatId()
          {
              return gatId;
          }
  
          public void setGatId(Integer gatId)
          {
              this.gatId = gatId;
          }
  
          public String getName()
          {
              return name;
          }
  
          public void setName(String name)
          {
              this.name = name;
          }
  
          public List getCollectiblesA()
          {
              return collectiblesA;
          }
  
          public void setCollectiblesA(List collectiblesA)
          {
              this.collectiblesA = collectiblesA;
          }
  
          public List getCollectiblesB()
          {
              return collectiblesB;
          }
  
          public void setCollectiblesB(List collectiblesB)
          {
              this.collectiblesB = collectiblesB;
          }
  
          public List getCollectiblesC()
          {
              return collectiblesC;
          }
  
          public void setCollectiblesC(List collectiblesC)
          {
              this.collectiblesC = collectiblesC;
          }
      }
  
      public static interface CollectibleBIF
      {
          Integer getColId();
  
          void setColId(Integer colId);
  
          String getName();
  
          void setName(String name);
  
          Integer getGathererId();
  
          void setGathererId(Integer colId);
  
          Gatherer getGatherer();
  
          void setGatherer(Gatherer gatherer);
      }
  
      public static class CollectibleB implements CollectibleBIF
      {
          private Integer colId;
          private String name;
          private Integer gathererId;
          private Gatherer gatherer;
  
          public CollectibleB()
          {
          }
  
          public CollectibleB(String name)
          {
              this.name = name;
          }
  
          public CollectibleB(String name, Integer gathererId)
          {
              this.name = name;
              this.gathererId = gathererId;
          }
  
          public CollectibleB(Integer colId, String name, Integer gathererId)
          {
              this.colId = colId;
              this.name = name;
              this.gathererId = gathererId;
          }
  
          public Gatherer getGatherer()
          {
              return gatherer;
          }
  
          public void setGatherer(Gatherer gatherer)
          {
              this.gatherer = gatherer;
          }
  
          public Integer getGathererId()
          {
              return gathererId;
          }
  
          public void setGathererId(Integer gathererId)
          {
              this.gathererId = gathererId;
          }
  
          public Integer getColId()
          {
              return colId;
          }
  
          public void setColId(Integer colId)
          {
              this.colId = colId;
          }
  
          public String getName()
          {
              return name;
          }
  
          public void setName(String name)
          {
              this.name = name;
          }
      }
  
      public static interface CollectibleAIF
      {
          Integer getColId();
  
          void setColId(Integer colId);
  
          String getName();
  
          void setName(String name);
  
          Integer getGathererId();
  
          void setGathererId(Integer colId);
  
          Gatherer getGatherer();
  
          void setGatherer(Gatherer gatherer);
      }
  
      public static class CollectibleA implements CollectibleAIF
      {
          private Integer colId;
          private String name;
          private Integer gathererId;
          private Gatherer gatherer;
  
          public CollectibleA()
          {
          }
  
          public CollectibleA(Integer colId, String name, Integer gathererId)
          {
              this.colId = colId;
              this.name = name;
              this.gathererId = gathererId;
          }
  
          public CollectibleA(String name, Integer gathererId)
          {
              this.name = name;
              this.gathererId = gathererId;
          }
  
          public CollectibleA(String name)
          {
              this.name = name;
          }
  
          public Gatherer getGatherer()
          {
              return gatherer;
          }
  
          public void setGatherer(Gatherer gatherer)
          {
              this.gatherer = gatherer;
          }
  
          public Integer getGathererId()
          {
              return gathererId;
          }
  
          public void setGathererId(Integer gathererId)
          {
              this.gathererId = gathererId;
          }
  
          public Integer getColId()
          {
              return colId;
          }
  
          public void setColId(Integer colId)
          {
              this.colId = colId;
          }
  
          public String getName()
          {
              return name;
          }
  
          public void setName(String name)
          {
              this.name = name;
          }
      }
  
      public static interface CollectibleCIF extends CollectibleBIF
      {
          String getExtentName();
  
          void setExtentName(String extentName);
      }
  
      public static class CollectibleC extends CollectibleB implements CollectibleCIF
      {
          private String extentName;
  
          public CollectibleC()
          {
              this.extentName = extentName;
          }
  
          public CollectibleC(Integer colId, String name, Integer gathererId, String extentName)
          {
              super(colId, name, gathererId);
              this.extentName = extentName;
          }
  
          public String getExtentName()
          {
              return extentName;
          }
  
          public void setExtentName(String extentName)
          {
              this.extentName = extentName;
          }
      }
  }
  
  
  
  1.28      +34 -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.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- ojbtest-schema.xml	8 Mar 2003 11:37:50 -0000	1.27
  +++ ojbtest-schema.xml	12 Mar 2003 09:29:01 -0000	1.28
  @@ -588,7 +588,7 @@
       </table>
   
       <!-- =================================================== -->
  -    <!-- Refernece test table                                -->
  +    <!-- Reference test tables                               -->
       <!-- =================================================== -->
       <table name="REF_REPOSITORY">
           <column name="REP_ID" required="true" primaryKey="true" type="INTEGER"/>
  @@ -603,5 +603,38 @@
           <column name="NAME" type="VARCHAR" size="100"/>
           <column name="REF_NAME_A" type="VARCHAR" size="100"/>
           <column name="REF_NAME_B" type="VARCHAR" size="100"/>
  +    </table>
  +
  +    <!-- =================================================== -->
  +    <!-- ODMG collection test tables                         -->
  +    <!-- =================================================== -->
  +    <!--
  +        private Integer gatId;
  +        private String name;
  +        private Collection collectiblesA;
  +        private Collection collectiblesB;
  +
  +        private Integer colId;
  +        private String name;
  +        private Integer gathererId;
  +        private Gatherer gatherer;
  +        private String extentName;
  +    -->
  +    <table name="COLLECTION_GATHERER">
  +        <column name="GAT_ID" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="NAME" type="VARCHAR" size="150"/>
  +    </table>
  +
  +    <table name="COLLECTION_COLLECTIBLE_A">
  +        <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_BC">
  +        <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>
   </database>
  
  
  

Mime
View raw message