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 ReferenceTest.java
Date Wed, 28 Jan 2004 23:55:30 GMT
arminw      2004/01/28 15:55:30

  Modified:    src/test/org/apache/ojb repository_junit_reference.xml
               src/schema ojbtest-schema.xml
               src/test/org/apache/ojb/broker ReferenceTest.java
  Log:
  add tests for changed PB behaviour on store of new object
  
  Revision  Changes    Path
  1.4       +76 -1     db-ojb/src/test/org/apache/ojb/repository_junit_reference.xml
  
  Index: repository_junit_reference.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit_reference.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- repository_junit_reference.xml	12 Jan 2004 10:55:47 -0000	1.3
  +++ repository_junit_reference.xml	28 Jan 2004 23:55:30 -0000	1.4
  @@ -352,6 +352,81 @@
           />
       </class-descriptor>
   
  +    <class-descriptor
  +        class="org.apache.ojb.broker.ReferenceTest$Wine"
  +        table="REF_WINE">
  +
  +        <field-descriptor
  +         name="id"
  +         column="OBJ_ID"
  +         jdbc-type="VARCHAR"
  +         primarykey="true"
  +         autoincrement="false"
  +        />
  +
  +        <field-descriptor
  +         name="grape"
  +         column="GRAPE"
  +         jdbc-type="VARCHAR"
  +        />
  +
  +        <field-descriptor
  +         name="year"
  +         column="VINTAGE"
  +         jdbc-type="VARCHAR"
  +        />
  +
  +        <field-descriptor
  +         name="regionName"
  +         column="REGION_NAME"
  +         jdbc-type="VARCHAR"
  +        />
  +
  +        <field-descriptor
  +         name="regionCountry"
  +         column="REGION_COUNTRY"
  +         jdbc-type="VARCHAR"
  +        />
  +
  +        <reference-descriptor
  +            name="region"
  +            class-ref="org.apache.ojb.broker.ReferenceTest$Region"
  +            proxy="false"
  +            auto-retrieve="true"
  +            auto-update="false"
  +            auto-delete="false">
  +                <foreignkey field-ref="regionName"/>
  +                <foreignkey field-ref="regionCountry"/>
  +        </reference-descriptor>
  +    </class-descriptor>
  +
  +    <class-descriptor
  +        class="org.apache.ojb.broker.ReferenceTest$Region"
  +        table="REF_REGION">
  +
  +        <field-descriptor
  +         name="name"
  +         column="NAME"
  +         jdbc-type="VARCHAR"
  +         primarykey="true"
  +         autoincrement="false"
  +        />
  +
  +        <field-descriptor
  +         name="country"
  +         column="COUNTRY"
  +         jdbc-type="VARCHAR"
  +         primarykey="true"
  +         autoincrement="false"
  +        />
  +
  +        <field-descriptor
  +         name="description"
  +         column="DESCRIPTION"
  +         jdbc-type="VARCHAR"
  +        />
  +    </class-descriptor>
  +
   
   
   
  
  
  
  1.61      +18 -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.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- ojbtest-schema.xml	13 Jan 2004 21:53:58 -0000	1.60
  +++ ojbtest-schema.xml	28 Jan 2004 23:55:30 -0000	1.61
  @@ -722,6 +722,24 @@
           <column name="LENGTH_" type="DOUBLE"/>
       </table>
   
  +    <table name="REF_WINE">
  +        <column name="OBJ_ID" required="true" primaryKey="true" type="VARCHAR" size="100"/>
  +        <column name="REGION_NAME" type="VARCHAR" size="100" required="true"/>
  +        <column name="REGION_COUNTRY" type="VARCHAR" size="100" required="true"/>
  +        <column name="VINTAGE" type="VARCHAR" size="100"/>
  +        <column name="GRAPE" type="VARCHAR" size="100"/>
  +        <foreign-key foreignTable="REF_REGION">
  +            <reference local="REGION_NAME" foreign="NAME"/>
  +            <reference local="REGION_COUNTRY" foreign="COUNTRY"/>
  +        </foreign-key>
  +    </table>
  +
  +    <table name="REF_REGION">
  +        <column name="NAME" required="true" primaryKey="true" type="VARCHAR" size="100"/>
  +        <column name="COUNTRY" required="true" primaryKey="true" type="VARCHAR" size="100"/>
  +        <column name="DESCRIPTION" type="VARCHAR" size="100"/>
  +    </table>
  +
   
   
       <!-- =================================================== -->
  
  
  
  1.10      +198 -1    db-ojb/src/test/org/apache/ojb/broker/ReferenceTest.java
  
  Index: ReferenceTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ReferenceTest.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ReferenceTest.java	9 Dec 2003 13:46:46 -0000	1.9
  +++ ReferenceTest.java	28 Jan 2004 23:55:30 -0000	1.10
  @@ -50,6 +50,74 @@
           }
       }
   
  +    public void testStoreWithMultiplePK_1() throws Exception
  +    {
  +        String timestamp = ""+System.currentTimeMillis();
  +        String regionName = "baden_"+timestamp;
  +        String countryName = "germany_"+timestamp;
  +        Region region = new Region(regionName, countryName, "brrr");
  +        Wine wine = new Wine(timestamp, "silvaner", "2003", regionName, countryName);
  +
  +        broker.beginTransaction();
  +        broker.store(region);
  +        broker.commitTransaction();
  +
  +        /*
  +        class Wine has a 1:1 reference with Region, we set set the FK in Wine but don't
  +        set the Region reference object in Wine. But retriveAllReferences materialize
  +        the reference object before store.
  +        */
  +        broker.beginTransaction();
  +        broker.retrieveAllReferences(wine);
  +        broker.store(wine);
  +        broker.commitTransaction();
  +    }
  +
  +    public void testStoreWithMultiplePK_2() throws Exception
  +    {
  +        String timestamp = ""+System.currentTimeMillis();
  +        String regionName = "baden_"+timestamp;
  +        String countryName = "germany_"+timestamp;
  +        /*
  +        Wine has a 1:1 reference with Region, we set the reference object in
  +        Wine class. We don't set the FK fields in Wine, this should be done by OJB
  +        automatic
  +        */
  +        Region region = new Region(regionName, countryName, "brrr");
  +        Wine wine = new Wine(timestamp, "silvaner", "2003", null, null);
  +        wine.setRegion(region);
  +
  +        broker.beginTransaction();
  +        broker.store(region);
  +        broker.commitTransaction();
  +
  +        broker.beginTransaction();
  +        broker.store(wine);
  +        broker.commitTransaction();
  +    }
  +
  +    public void testStoreWithMultiplePK_3() throws Exception
  +    {
  +        String timestamp = ""+System.currentTimeMillis();
  +        String regionName = "baden_"+timestamp;
  +        String countryName = "germany_"+timestamp;
  +        /*
  +        Wine has a 1:1 reference with Region, we set set the FK fields
  +        of an existing Region object in Wine
  +        but don't set the Region reference object itself in Wine object
  +        */
  +        Region region = new Region(regionName, countryName, "brrr");
  +        Wine wine = new Wine(timestamp, "silvaner", "2003", regionName, countryName);
  +
  +        broker.beginTransaction();
  +        broker.store(region);
  +        broker.commitTransaction();
  +
  +        broker.beginTransaction();
  +        broker.store(wine);
  +        broker.commitTransaction();
  +    }
  +
       public void testStoreReferencesMappedToSameTable()
       {
           String referenceNamePrefix = "testStoreReferencesMappedToSameTable"+System.currentTimeMillis();
  @@ -591,6 +659,8 @@
   
   
   
  +
  +
   //***************************************************************************
   // Inner classes used by the test case
   //***************************************************************************
  @@ -988,6 +1058,133 @@
           public void setLength(Double length)
           {
               this.length = length;
  +        }
  +    }
  +
  +
  +    //***************************************************************
  +    // classes for test with multiple, non-autoincrement PK
  +    //***************************************************************
  +    public static class Wine
  +    {
  +        private String id;
  +        private String grape;
  +        private String year;
  +        private String regionName;
  +        private String regionCountry;
  +        private Region region;
  +
  +        public Wine(String id, String grape, String year, String regionName, String regionCountry)
  +        {
  +            this.id = id;
  +            this.grape = grape;
  +            this.year = year;
  +            this.regionName = regionName;
  +            this.regionCountry = regionCountry;
  +        }
  +
  +        public Region getRegion()
  +        {
  +            return region;
  +        }
  +
  +        public void setRegion(Region region)
  +        {
  +            this.region = region;
  +        }
  +
  +        public String getId()
  +        {
  +            return id;
  +        }
  +
  +        public void setId(String id)
  +        {
  +            this.id = id;
  +        }
  +
  +        public String getGrape()
  +        {
  +            return grape;
  +        }
  +
  +        public void setGrape(String grape)
  +        {
  +            this.grape = grape;
  +        }
  +
  +        public String getYear()
  +        {
  +            return year;
  +        }
  +
  +        public void setYear(String year)
  +        {
  +            this.year = year;
  +        }
  +
  +        public String getRegionName()
  +        {
  +            return regionName;
  +        }
  +
  +        public void setRegionName(String regionName)
  +        {
  +            this.regionName = regionName;
  +        }
  +
  +        public String getRegionCountry()
  +        {
  +            return regionCountry;
  +        }
  +
  +        public void setRegionCountry(String regionCountry)
  +        {
  +            this.regionCountry = regionCountry;
  +        }
  +    }
  +
  +    public static class Region
  +    {
  +        private String name;
  +        private String country;
  +        private String description;
  +
  +        public Region(String name, String country, String description)
  +        {
  +            this.name = name;
  +            this.country = country;
  +            this.description = description;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +
  +        public String getCountry()
  +        {
  +            return country;
  +        }
  +
  +        public void setCountry(String country)
  +        {
  +            this.country = country;
  +        }
  +
  +        public String getDescription()
  +        {
  +            return description;
  +        }
  +
  +        public void setDescription(String description)
  +        {
  +            this.description = description;
           }
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message