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 Tue, 08 Jul 2003 00:34:55 GMT
arminw      2003/07/07 17:34:54

  Modified:    src/test/org/apache/ojb repository_junit.xml
               src/test/org/apache/ojb/broker NestedFieldsTest.java
               src/schema ojbtest-schema.xml
  Log:
  upgrade nested fields test
  
  Revision  Changes    Path
  1.79      +36 -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.78
  retrieving revision 1.79
  diff -u -r1.78 -r1.79
  --- repository_junit.xml	30 Jun 2003 21:16:21 -0000	1.78
  +++ repository_junit.xml	8 Jul 2003 00:34:54 -0000	1.79
  @@ -4384,4 +4384,40 @@
           </collection-descriptor>
       </class-descriptor>
   
  +
  +    <!-- ************************************************* -->
  +    <!--      nested fields test                           -->
  +    <!-- ************************************************* -->
  +    <class-descriptor
  +    class="org.apache.ojb.broker.NestedFieldsTest$NestedMain"
  +    table="NESTED_FIELDS_TAB">
  +
  +        <field-descriptor
  +        name="objId"
  +        column="OBJ_ID"
  +        jdbc-type="BIGINT"
  +        primarykey="true"
  +        autoincrement="true"/>
  +
  +        <field-descriptor
  +            name="name"
  +            column="NAME"
  +            jdbc-type="VARCHAR"
  +        />
  +
  +        <field-descriptor
  +            name="detail::detail::realDetailName"
  +            column="NESTED_VALUE"
  +            jdbc-type="VARCHAR"
  +        />
  +
  +        <field-descriptor
  +            name="detail::detail::realDetailDescription"
  +            column="NESTED_DESCRIPTION"
  +            jdbc-type="VARCHAR"
  +        />
  +    </class-descriptor>
  +
  +
  +
   <!-- Mapping of classes used in junit tests and tutorials ends here -->
  
  
  
  1.2       +241 -57   db-ojb/src/test/org/apache/ojb/broker/NestedFieldsTest.java
  
  Index: NestedFieldsTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/NestedFieldsTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NestedFieldsTest.java	30 Jun 2003 21:16:04 -0000	1.1
  +++ NestedFieldsTest.java	8 Jul 2003 00:34:54 -0000	1.2
  @@ -1,8 +1,8 @@
   package org.apache.ojb.broker;
   
   import junit.framework.TestCase;
  -import org.apache.ojb.broker.metadata.fieldaccess.PersistentNestedFieldMaxPerformanceImpl;
  -import org.apache.ojb.broker.util.configuration.impl.OjbConfiguration;
  +import org.apache.commons.lang.builder.ToStringBuilder;
  +import org.apache.commons.lang.builder.ToStringStyle;
   
   
   /**
  @@ -11,9 +11,8 @@
    */
   public class NestedFieldsTest extends TestCase
   {
  -
  -	private Class normalPersistentFieldClass;
       PersistenceBroker broker;
  +
       public NestedFieldsTest(String name)
       {
           super(name);
  @@ -34,70 +33,255 @@
        */
       public void setUp()
       {
  -        try
  +        // obtain broker instance
  +        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +    }
  +
  +    /**
  +     * tearing down the test fixture.
  +     */
  +    public void tearDown()
  +    {
  +        broker.close();
  +    }
  +
  +    public void testStoreReadNestedField()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        String ddName = "second_level_detail_" + timestamp;
  +        String ddDescription = "a real detail description" + timestamp;
  +
  +        NestedDetailDetail dd = new NestedDetailDetail(ddName, ddDescription);
  +        NestedDetail d = new NestedDetail(dd);
  +        NestedMain nested = new NestedMain("main_object_" + timestamp, d);
  +        Identity oid = new Identity(nested, broker);
  +
  +        broker.beginTransaction();
  +        broker.store(nested);
  +        broker.commitTransaction();
  +
  +        assertNotNull(nested.getDetail());
  +        assertNotNull(nested.getDetail().getDetail());
  +        assertNotNull(nested.getDetail().getDetail().getRealDetailName());
  +        dd = nested.getDetail().getDetail();
  +        assertEquals(ddName, dd.getRealDetailName());
  +        assertEquals(ddDescription, dd.getRealDetailDescription());
  +
  +        // retrieve copy of nested object
  +        NestedMain nestedCopy = (NestedMain) broker.getObjectByIdentity(oid);
  +        assertNotNull(nestedCopy.getDetail());
  +        assertNotNull(nestedCopy.getDetail().getDetail());
  +        assertNotNull(nestedCopy.getDetail().getDetail().getRealDetailName());
  +        dd = nested.getDetail().getDetail();
  +        assertEquals(ddName, dd.getRealDetailName());
  +        assertEquals(ddDescription, dd.getRealDetailDescription());
  +
  +        // clear cache and retrieve copy of nested object
  +        broker.clearCache();
  +        nestedCopy = (NestedMain) broker.getObjectByIdentity(oid);
  +        assertNotNull(nestedCopy.getDetail());
  +        assertNotNull(nestedCopy.getDetail().getDetail());
  +        assertNotNull(nestedCopy.getDetail().getDetail().getRealDetailName());
  +        dd = nested.getDetail().getDetail();
  +        assertEquals(ddName, dd.getRealDetailName());
  +        assertEquals(ddDescription, dd.getRealDetailDescription());
  +    }
  +
  +    public void testUpdateNestedField()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        String ddName = "second_level_detail_" + timestamp;
  +        String ddDescription = "a real detail description" + timestamp;
  +
  +        NestedDetailDetail dd = new NestedDetailDetail(ddName, ddDescription);
  +        NestedDetail d = new NestedDetail(dd);
  +        NestedMain nested = new NestedMain("main_object_" + timestamp, d);
  +        Identity oid = new Identity(nested, broker);
  +
  +        broker.beginTransaction();
  +        broker.store(nested);
  +        broker.commitTransaction();
  +
  +        // clear cache and retrieve copy of nested object
  +        broker.clearCache();
  +        nested = (NestedMain) broker.getObjectByIdentity(oid);
  +
  +        /*
  +        till now we do the same as in the test above
  +        now change nested field and store
  +        */
  +        nested.getDetail().getDetail().setRealDetailName("update_name_"+timestamp);
  +        broker.beginTransaction();
  +        broker.store(nested);
  +        broker.commitTransaction();
  +
  +        // clear cache and retrieve copy of nested object
  +        broker.clearCache();
  +        nested = (NestedMain) broker.getObjectByIdentity(oid);
  +        assertEquals("update_name_"+timestamp, nested.getDetail().getDetail().getRealDetailName());
  +    }
  +
  +    public void testDeleteNestedField()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        String ddName = "second_level_detail_" + timestamp;
  +        String ddDescription = "a real detail description" + timestamp;
  +
  +        NestedDetailDetail dd = new NestedDetailDetail(ddName, ddDescription);
  +        NestedDetail d = new NestedDetail(dd);
  +        NestedMain nested = new NestedMain("main_object_" + timestamp, d);
  +        Identity oid = new Identity(nested, broker);
  +
  +        broker.beginTransaction();
  +        broker.store(nested);
  +        broker.commitTransaction();
  +
  +        // clear cache and retrieve copy of nested object
  +        broker.clearCache();
  +        nested = (NestedMain) broker.getObjectByIdentity(oid);
  +
  +        broker.beginTransaction();
  +        broker.delete(nested);
  +        broker.commitTransaction();
  +
  +        nested = (NestedMain) broker.getObjectByIdentity(oid);
  +        assertNull("Object was not deleted", nested);
  +    }
  +
  +
  +
  +    //************************************************************************
  +    // inner classes - used test classes
  +    //************************************************************************
  +
  +    public static class NestedMain
  +    {
  +        private Long objId;
  +        private String name;
  +        private NestedDetail detail;
  +
  +        public NestedMain()
  +        {
  +        }
  +
  +        public NestedMain(String name, NestedDetail detail)
  +        {
  +            this.name = name;
  +            this.detail = detail;
  +        }
  +
  +        public Long getObjId()
  +        {
  +            return objId;
  +        }
  +
  +        public void setObjId(Long objId)
  +        {
  +            this.objId = objId;
  +        }
  +
  +        public String getName()
           {
  -            // obtain broker instance
  -            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -            // manipulate configuration to use proper field access
  -            OjbConfiguration conf = (OjbConfiguration) PersistenceBrokerFactory.
  -                    getConfigurator().getConfigurationFor(null);
  -            normalPersistentFieldClass = conf.getPersistentFieldClass();
  -            conf.setPersistentFieldClass(PersistentNestedFieldMaxPerformanceImpl.class);
  +            return name;
           }
  -        catch (PBFactoryException e)
  +
  +        public void setName(String name)
           {
  +            this.name = name;
           }
   
  +        public NestedDetail getDetail()
  +        {
  +            return detail;
  +        }
  +
  +        public void setDetail(NestedDetail detail)
  +        {
  +            this.detail = detail;
  +        }
  +
  +        public String toString()
  +        {
  +            ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE);
  +            buf.append("objId", objId).
  +                    append("name", name).
  +                    append("detail", detail);
  +            return buf.toString();
  +        }
       }
   
  -    /**
  -     * tearing down the test fixture.
  -     */
  -    public void tearDown()
  +    public static class NestedDetail
       {
  -        try
  -        {            
  -            // manipulate configuration to reset field access
  -            OjbConfiguration conf = (OjbConfiguration) PersistenceBrokerFactory.
  -                    getConfigurator().getConfigurationFor(null);
  -            conf.setPersistentFieldClass(normalPersistentFieldClass);
  +        private NestedDetailDetail detail;
  +
  +        public NestedDetail()
  +        {
           }
  -        catch (PBFactoryException e)
  +
  +        public NestedDetail(NestedDetailDetail detail)
           {
  -        }    	
  -        broker.close();
  +            this.detail = detail;
  +        }
  +
  +        public NestedDetailDetail getDetail()
  +        {
  +            return detail;
  +        }
  +
  +        public void setDetail(NestedDetailDetail detail)
  +        {
  +            this.detail = detail;
  +        }
  +
  +        public String toString()
  +        {
  +            ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE);
  +            buf.append("detail", detail);
  +            return buf.toString();
  +        }
       }
   
  -	public void testLoading()
  -	{
  -		ArticleWithNestedStockDetail article = new ArticleWithNestedStockDetail();
  -		article.setArticleName("an article with a stock detail");
  -		article.setPrice(23);
  -		article.setProductGroupId(1);
  -		
  -		StockDetail detail = new StockDetail();
  -		detail.setStock(500);
  -		detail.setIsSelloutArticle(true);
  -		detail.setMinimumStock(100);
  -		detail.setOrderedUnits(0);
  -		detail.setUnit("bottle");
  -		
  -		article.setStockDetail(detail);
  -		
  -		broker.beginTransaction();
  -		broker.store(article);
  -		Identity oid = new Identity(article, broker);
  -		broker.commitTransaction();
  -		
  -		broker.clearCache();
  -		ArticleWithNestedStockDetail copy = null;
  -		StockDetail detailCopy = null;
  -		broker.beginTransaction();
  -		copy = (ArticleWithNestedStockDetail) broker.getObjectByIdentity(oid);
  -		detailCopy = copy.getStockDetail();
  -		
  -		assertEquals(detail.getStock(), detailCopy.getStock());	
  -			
  -	}
  +    public static class NestedDetailDetail
  +    {
  +        private String realDetailName;
  +        private String realDetailDescription;
  +
  +        public NestedDetailDetail()
  +        {
  +        }
  +
  +        public NestedDetailDetail(String realDetailName, String realDetailDescription)
  +        {
  +            this.realDetailName = realDetailName;
  +            this.realDetailDescription = realDetailDescription;
  +        }
  +
  +        public String getRealDetailName()
  +        {
  +            return realDetailName;
  +        }
   
  +        public void setRealDetailName(String realDetailName)
  +        {
  +            this.realDetailName = realDetailName;
  +        }
  +
  +        public String getRealDetailDescription()
  +        {
  +            return realDetailDescription;
  +        }
  +
  +        public void setRealDetailDescription(String realDetailDescription)
  +        {
  +            this.realDetailDescription = realDetailDescription;
  +        }
  +
  +        public String toString()
  +        {
  +            ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE);
  +            buf.append("realDetailName", realDetailName).
  +                    append("realDetailDescription", realDetailDescription);
  +            return buf.toString();
  +        }
  +    }
   }
  
  
  
  1.42      +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.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- ojbtest-schema.xml	27 Jun 2003 21:03:13 -0000	1.41
  +++ ojbtest-schema.xml	8 Jul 2003 00:34:54 -0000	1.42
  @@ -731,4 +731,15 @@
      <table name="ABSTRACT_COLLECTION_CONTAINER">
        <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
      </table>
  +
  +    <!-- =================================================== -->
  +    <!-- PB nested fields test                               -->
  +    <!-- =================================================== -->
  +    <table name="NESTED_FIELDS_TAB">
  +     <column name="OBJ_ID" required="true" primaryKey="true" type="DECIMAL"/>
  +     <column name="NAME" type="VARCHAR" size="150"/>
  +     <column name="NESTED_VALUE" type="VARCHAR" size="150"/>
  +     <column name="NESTED_DESCRIPTION" type="VARCHAR" size="150"/>
  +   </table>
  +
   </database>
  
  
  

---------------------------------------------------------------------
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