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/test/org/apache/ojb/broker AbstractExtentClassTest.java
Date Fri, 13 Jun 2003 10:11:54 GMT
arminw      2003/06/13 03:11:54

  Modified:    src/test/org/apache/ojb repository_junit.xml
               src/schema ojbtest-schema.xml
  Added:       src/test/org/apache/ojb/broker AbstractExtentClassTest.java
  Log:
  add new test case posted by
  Oliver Matz
  
  Revision  Changes    Path
  1.71      +78 -11    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.70
  retrieving revision 1.71
  diff -u -r1.70 -r1.71
  --- repository_junit.xml	10 Jun 2003 20:44:46 -0000	1.70
  +++ repository_junit.xml	13 Jun 2003 10:11:53 -0000	1.71
  @@ -4126,8 +4126,8 @@
   	     />
   
       </class-descriptor>
  -    
  -    
  +
  +
   <!-- mappings for anonymous field testclasses-->
    <class-descriptor
           class="org.apache.ojb.broker.E"
  @@ -4147,7 +4147,7 @@
               jdbc-type="INTEGER"
           />
   
  - </class-descriptor>    
  + </class-descriptor>
   
    <class-descriptor
           class="org.apache.ojb.broker.F"
  @@ -4165,7 +4165,7 @@
           	name="eID"
           	column="E_ID"
           	jdbc-type="INTEGER"
  -        	access="anonymous" 
  +        	access="anonymous"
           />
   
           <field-descriptor
  @@ -4173,17 +4173,84 @@
               column="SOMEVALUE"
               jdbc-type="INTEGER"
           />
  - 
  -        
  -  		<reference-descriptor name="super" 
  -  			class-ref="org.apache.ojb.broker.E" 
  -     		auto-retrieve="true" 
  -     		auto-update="true" 
  +
  +
  +  		<reference-descriptor name="super"
  +  			class-ref="org.apache.ojb.broker.E"
  +     		auto-retrieve="true"
  +     		auto-update="true"
        		auto-delete="true">
       		<foreignkey field-ref="eID" />
     		</reference-descriptor>
  +    </class-descriptor>
  +
  +
  +
  +    <!-- ************************************************* -->
  +    <!--      abstract collections test                    -->
  +    <!-- ************************************************* -->
  +    <class-descriptor
  +    class="org.apache.ojb.broker.AbstractExtentClassTest$AbstractX">
  +
  +        <extent-class class-ref="org.apache.ojb.broker.AbstractExtentClassTest$AbstractY"
/>
  +
  +        <field-descriptor
  +        name="containerId"
  +        column="CONTAINER_ID"
  +        jdbc-type="INTEGER"/>
  +    </class-descriptor>
   
  -    </class-descriptor>    
  +    <class-descriptor
  +    class="org.apache.ojb.broker.AbstractExtentClassTest$AbstractY">
   
  +        <extent-class class-ref="org.apache.ojb.broker.AbstractExtentClassTest$ConcreteZ"
/>
  +
  +        <field-descriptor
  +        name="containerId"
  +        column="CONTAINER_ID"
  +        jdbc-type="INTEGER"/>
  +    </class-descriptor>
  +
  +    <class-descriptor
  +    class="org.apache.ojb.broker.AbstractExtentClassTest$ConcreteZ"
  +    table="ABSTRACT_COLLECTION_Z">
  +
  +        <field-descriptor
  +        name="id"
  +        column="OBJ_ID"
  +        jdbc-type="INTEGER"
  +        primarykey="true"
  +        autoincrement="true"/>
  +
  +        <field-descriptor
  +        name="someValue"
  +        column="SOMEVALUE"
  +        jdbc-type="INTEGER"/>
  +
  +        <field-descriptor
  +        name="containerId"
  +        column="CONTAINER_ID"
  +        jdbc-type="INTEGER"/>
  +    </class-descriptor>
  +
  +    <class-descriptor
  +    class="org.apache.ojb.broker.AbstractExtentClassTest$XContainer"
  +    table="ABSTRACT_COLLECTION_CONTAINER">
  +        <field-descriptor
  +        name="id"
  +        column="OBJ_ID"
  +        jdbc-type="INTEGER"
  +        primarykey="true"
  +        autoincrement="true"/>
  +
  +        <collection-descriptor
  +        name="myXReferences"
  +        element-class-ref="org.apache.ojb.broker.AbstractExtentClassTest$AbstractX"
  +        auto-retrieve="true"
  +        auto-update="true"
  +        auto-delete="false">
  +            <inverse-foreignkey field-ref="containerId"/>
  +        </collection-descriptor>
  +    </class-descriptor>
   
   <!-- Mapping of classes used in junit tests and tutorials ends here -->
  
  
  
  1.37      +11 -0     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.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- ojbtest-schema.xml	10 Jun 2003 06:19:23 -0000	1.36
  +++ ojbtest-schema.xml	13 Jun 2003 10:11:54 -0000	1.37
  @@ -711,4 +711,15 @@
           <column name="SOMEVALUE" type="INTEGER" />
       </table>
   
  +
  +    <!-- Used in tests AbstractExtentClassTest -->
  +   <table name="ABSTRACT_COLLECTION_Z">
  +     <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
  +     <column name="CONTAINER_ID" required="true" type="INTEGER"/>
  +     <column name="SOMEVALUE" type="INTEGER" />
  +   </table>
  +   <!-- Used in tests AbstractExtentClassTest -->
  +   <table name="ABSTRACT_COLLECTION_CONTAINER">
  +     <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
  +   </table>
   </database>
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/AbstractExtentClassTest.java
  
  Index: AbstractExtentClassTest.java
  ===================================================================
  package org.apache.ojb.broker;
  
  import junit.framework.TestCase;
  
  import java.util.Collection;
  import java.util.ArrayList;
  
  /**
   * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
   * @version $Id: AbstractExtentClassTest.java,v 1.1 2003/06/13 10:11:54 arminw Exp $
   */
  public class AbstractExtentClassTest extends TestCase
  {
      private PersistenceBroker broker;
  
      public AbstractExtentClassTest(String name)
      {
          super(name);
      }
  
      public static void main(String args[])
      {
          String[] arr = {AbstractExtentClassTest.class.getName()};
          junit.textui.TestRunner.main(arr);
      }
  
      public void setUp() throws Exception
      {
          broker = PersistenceBrokerFactory.defaultPersistenceBroker();
      }
  
      public void tearDown()
      {
          try
          {
              broker.clearCache();
              broker.close();
          }
          catch (PersistenceBrokerException e)
          {
          }
      }
  
      public void testStoreRetrieve()
      {
          broker.clearCache();
          broker.beginTransaction();
          // create new XContainer with ConcreteZ reference
          XContainer container = new XContainer();
          container.addX(new ConcreteZ());
  
          broker.store(container);
          broker.commitTransaction();
          broker.clearCache();
  
          Identity cont = new Identity(container, broker);
          broker.beginTransaction();
          Object retContainer = broker.getObjectByIdentity(cont);
          // System.out.println("retrieved: " + retContainer);
          broker.commitTransaction();
      }
  
  
      //******************************************************************
      // inner classes / persistent objects
      //******************************************************************
  
      public static abstract class AbstractX
      {
          private int containerId;
  
          public int getContainerId()
          {
              return containerId;
          }
  
          public void setContainerId(int containerId)
          {
              this.containerId = containerId;
          }
      }
  
      public static abstract class AbstractY extends AbstractX
      {
      }
  
      public static class ConcreteZ extends AbstractY
      {
          private int someValue;
          private int id;
  
          public ConcreteZ()
          {
          }
  
          ConcreteZ(int no)
          {
              someValue = no;
          }
  
          public int getId()
          {
              return id;
          }
  
          public void setId(int id)
          {
              this.id = id;
          }
  
          public int getSomeValue()
          {
              return someValue;
          }
  
          public void setSomeValue(int someValue)
          {
              this.someValue = someValue;
          }
  
          public String toString()
          {
              return "(#" + Integer.toHexString(System.identityHashCode(this)) +
                      ", " + id + ", " + someValue + ")";
          }
      }
  
      public static class XContainer
      {
          private int id;
          private Collection myXReferences;
  
          public XContainer()
          {
          }
  
          public XContainer(int id)
          {
              this.id = id;
          }
  
          private void addX(AbstractX someX)
          {
              if(myXReferences == null) myXReferences = new ArrayList();
              myXReferences.add(someX);
          }
  
          public int getId()
          {
              return id;
          }
  
          public void setId(int id)
          {
              this.id = id;
          }
  
          public String toString()
          {
              return "(" + this.getClass().getName() + System.identityHashCode(this) +
                      ", " + myXReferences.toString() + ")";
          }
      }
  }
  
  
  

Mime
View raw message