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 ojbtest-data.xml ojbtest-data.dtd
Date Wed, 19 Feb 2003 10:37:55 GMT
arminw      2003/02/19 02:37:55

  Modified:    src/test/org/apache/ojb repository_junit.xml
               src/test/org/apache/ojb/odmg UserTestCases.java
                        FieldConversion_Node.java
                        FieldConversion_ForeigenKeyTest.java
               src/test/org/apache/ojb/broker TestInt2IntConverter.java
                        FieldConversionForeigenKeyTest.java
                        ConvertedKeyReferenceTest.java
                        ConversionReferrer.java ConversionReferred.java
               src/schema ojbtest-schema.xml ojbtest-data.xml
                        ojbtest-data.dtd
  Log:
  add test cases posted by users,
  add new test cases, modify test cases
  
  Revision  Changes    Path
  1.42      +74 -33    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.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- repository_junit.xml	15 Feb 2003 16:05:26 -0000	1.41
  +++ repository_junit.xml	19 Feb 2003 10:37:54 -0000	1.42
  @@ -2424,6 +2424,8 @@
         </collection-descriptor>
    	</class-descriptor>
   
  +
  +
    <!-- Definitions for org.apache.ojb.broker.GuidTestEntity -->
      <class-descriptor
      	  class="org.apache.ojb.broker.GuidTestEntity"
  @@ -2442,6 +2444,12 @@
   	        jdbc-type="VARCHAR"
   	  	/>
   	</class-descriptor>
  +
  +
  +
  +<!-- ************************************************* -->
  +<!--      Tests checking field conversion              -->
  +<!-- ************************************************* -->
       <class-descriptor
      	  class="org.apache.ojb.broker.ConversionReferrer"
      	  table="CONV_REFERER"
  @@ -2458,6 +2466,15 @@
            jdbc-type="INTEGER"
            conversion="org.apache.ojb.broker.TestInt2IntConverter"
           />
  +
  +        <field-descriptor
  +         name="testId"
  +         column="TEST_ID"
  +         jdbc-type="INTEGER"
  +         primarykey="false"
  +         conversion="org.apache.ojb.broker.TestInt2IntConverter"
  +        />
  +
           <reference-descriptor
             name="referred"
             class-ref="org.apache.ojb.broker.ConversionReferred"
  @@ -2465,6 +2482,7 @@
             <foreignkey field-ref="ref1"/>
            </reference-descriptor>
       </class-descriptor>
  +
       <class-descriptor
     	  class="org.apache.ojb.broker.ConversionReferred"
      	  table="CONV_REFERED"
  @@ -2476,8 +2494,63 @@
            primarykey="true"
            conversion="org.apache.ojb.broker.TestInt2IntConverter"
           />
  +
  +        <field-descriptor
  +         name="testId"
  +         column="TEST_ID"
  +         jdbc-type="INTEGER"
  +         primarykey="false"
  +         conversion="org.apache.ojb.broker.TestInt2IntConverter"
  +        />
  +    </class-descriptor>
  +
  +
  +
  +
  +    <class-descriptor
  +        class="org.apache.ojb.odmg.FieldConversion_Node"
  +        table="FIELD_CONVERSION_NODE"
  +    >
  +        <field-descriptor
  +            name="uid"
  +            column="NODE_ID"
  +            jdbc-type="DECIMAL"
  +            primarykey="true"
  +            autoincrement="true"
  +            conversion="org.apache.ojb.odmg.FieldConversion_LongToBigDecimalConversion"
  +        />
  +
  +        <field-descriptor
  +            name="nodeState"
  +            column="NODE_STATE"
  +            jdbc-type="INTEGER"
  +            primarykey="true"
  +            autoincrement="false"
  +            conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldConversion"
  +        />
  +
  +        <field-descriptor
  +            name="refId"
  +            column="PARENT_UID"
  +            jdbc-type="DECIMAL"
  +            conversion="org.apache.ojb.odmg.FieldConversion_LongToBigDecimalConversion"
  +        />
  +
  +        <reference-descriptor
  +            name="parent"
  +            class-ref="org.apache.ojb.odmg.FieldConversion_Node"
  +            auto-update="true"
  +        >
  +            <foreignkey field-ref="refId"/>
  +        </reference-descriptor>
       </class-descriptor>
   
  +
  +
  +
  +<!-- ************************************************* -->
  +<!--      User posted test case                        -->
  +<!-- ************************************************* -->
       <class-descriptor
      	  class="org.apache.ojb.odmg.Site"
      	  table="SITE"
  @@ -2931,9 +3004,7 @@
   
   
   
  -<!-- ************************************************* -->
  -<!--      END  -  Sequence manager test classes        -->
  -<!-- ************************************************* -->
  +
   
   
   <!-- ************************************************* -->
  @@ -2995,38 +3066,8 @@
         />
   </class-descriptor>
   
  -<!-- ************************************************* -->
  -<!--      END - user data for second test database     -->
  -<!-- ************************************************* -->
   
   
  -<class-descriptor
  -      class="org.apache.ojb.odmg.FieldConversion_Node"
  -      table="FIELD_CONVERSION_NODE"
  ->
  -    <field-descriptor
  -       name="uid"
  -       column="NODE_ID"
  -       jdbc-type="DECIMAL"
  -       primarykey="true"
  -       autoincrement="true"
  -      conversion="org.apache.ojb.odmg.FieldConversion_LongToBigDecimalConversion"
  -    />
  -  <field-descriptor
  -    name="refId"
  -    column="PARENT_UID"
  -    jdbc-type="DECIMAL"
  -    conversion="org.apache.ojb.odmg.FieldConversion_LongToBigDecimalConversion"
  -  />
  -
  -  <reference-descriptor
  -    name="parent"
  -    class-ref="org.apache.ojb.odmg.FieldConversion_Node"
  -    auto-update="true"
  -  >
  -  <foreignkey field-ref="refId"/>
  -  </reference-descriptor>
  -</class-descriptor>
   
   <!-- ************************************************* -->
   <!--      Performance/Stress test descriptor           -->
  
  
  
  1.7       +101 -3    db-ojb/src/test/org/apache/ojb/odmg/UserTestCases.java
  
  Index: UserTestCases.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/UserTestCases.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- UserTestCases.java	5 Feb 2003 20:04:40 -0000	1.6
  +++ UserTestCases.java	19 Feb 2003 10:37:55 -0000	1.7
  @@ -1,14 +1,19 @@
   package org.apache.ojb.odmg;
   
  -import java.util.List;
  -
   import junit.framework.TestCase;
   import org.apache.ojb.broker.TestHelper;
  +import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
  +import org.apache.ojb.broker.util.configuration.impl.OjbConfiguration;
  +import org.apache.ojb.broker.metadata.MetadataManager;
  +import org.apache.ojb.broker.metadata.DescriptorRepository;
  +import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
   import org.odmg.Database;
   import org.odmg.Implementation;
   import org.odmg.OQLQuery;
   import org.odmg.Transaction;
   
  +import java.util.List;
  +
   
   /**
    * Collection of test cases sent by OJB users
  @@ -126,6 +131,99 @@
               fail("We should not found deleted objects");
           }
           tx.commit();
  +    }
  +
  +    /**
  +     * User test case posted by Charles:
  +     *
  +     * Up to now, we've been just using the broker layer. I now have a usecase
  +        where we will need to use the ODMG layer. We do not want to use implicit
  +        locking; I want my developers to explicit lock each object to an ODMG
  +        transaction (implicit locking generates loads of queries for all the proxy
  +        collections).
  +
  +        It seems that something 'funny' happens if implicit locking is turned off -
  +        objects are not marked as being "dirty" when changed - even when they are
  +        explicitly lock to the transaction.
  +
  +        As I am a complete novice in the ways of the ODMG, I don't really know where
  +        to look to sort this issue out so I have added a new test method to
  +        org.apache.ojb.odmg.UserTestCases (it should be attached to this email).
  +        Essentially, it creates an object and persists it; retrieves and updates it;
  +        then flushes the cache, and retrieves it again to ensure the update worked.
  +        If ImplicitLocking is TRUE, the test passes. If ImplicitLocking is FALSE,
  +        the test fails.
  +
  +        I think this is incorrect, and would dearly like this to be resolved.
  +     */
  +    public void testImplicitLocking() throws Exception
  +    {
  +        OjbConfiguration conf = (OjbConfiguration)OjbConfigurator.getInstance().getConfigurationFor(null);
  +        boolean useImplicitLocking = conf.useImplicitLocking();
  +        boolean restore = false;
  +
  +        // prepare test case
  +        try
  +        {
  +            if(useImplicitLocking)
  +            {
  +                restore = true;
  +                conf.setUseImplicitLocking(false);
  +            }
  +            Implementation odmg = OJB.getInstance();
  +            Database db = odmg.newDatabase();
  +            db.open(databaseName, Database.OPEN_READ_WRITE);
  +
  +            String name = "testImplicitLocking - " + System.currentTimeMillis();
  +            String queryString = "select sites from " + Site.class.getName() + " where
name = $1";
  +
  +            /* Create an object */
  +            Site site = new Site();
  +            site.setName(name);
  +
  +            Transaction tx = odmg.newTransaction();
  +            tx.begin();
  +            tx.lock(site, Transaction.WRITE);
  +            tx.commit();
  +
  +            /* Retrieve from the object created, and set the year*/
  +            OQLQuery query = odmg.newOQLQuery();
  +            query.create(queryString);
  +            query.bind(name);
  +
  +            tx.begin();
  +            List result = (List) query.execute();
  +            assertEquals(1, result.size());
  +            site = (Site) result.get(0);
  +            assertNotNull(site);
  +            assertNull(site.getYear());
  +            site.setYear(new Integer(2003));
  +            tx.lock(site, Transaction.UPGRADE);
  +            tx.commit();
  +
  +            /* Flush the cache, and retrieve the object again */
  +            query = odmg.newOQLQuery();
  +            query.create(queryString);
  +            query.bind(name);
  +            tx.begin();
  +            ((HasBroker) tx).getBroker().clearCache();
  +            result = (List) query.execute();
  +            assertEquals(1, result.size());
  +            site = (Site) result.get(0);
  +            assertNotNull(site);
  +            assertNotNull("year should not be null", site.getYear());
  +            tx.commit();
  +
  +            db.close();
  +        }
  +        finally
  +        {
  +            // reset configuration
  +            if(restore)
  +            {
  +                conf.setUseImplicitLocking(useImplicitLocking);
  +            }
  +        }
       }
   
   
  
  
  
  1.3       +13 -1     db-ojb/src/test/org/apache/ojb/odmg/FieldConversion_Node.java
  
  Index: FieldConversion_Node.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/FieldConversion_Node.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FieldConversion_Node.java	29 Jan 2003 10:52:57 -0000	1.2
  +++ FieldConversion_Node.java	19 Feb 2003 10:37:55 -0000	1.3
  @@ -14,16 +14,18 @@
   {
       private long uid;  // primary key
       private long refId;
  +    private boolean nodeState;
       FieldConversion_Node parent;
   
       public FieldConversion_Node()
       {
       }
   
  -    public FieldConversion_Node(long uid, FieldConversion_Node parent)
  +    public FieldConversion_Node(long uid, FieldConversion_Node parent, boolean nodeState)
       {
           this.uid = uid;
           this.parent = parent;
  +        this.nodeState = nodeState;
       }
   
       public long getUid()
  @@ -34,6 +36,16 @@
       public void setUid(long uid)
       {
           this.uid = uid;
  +    }
  +
  +    public boolean isState()
  +    {
  +        return nodeState;
  +    }
  +
  +    public void setState(boolean state)
  +    {
  +        this.nodeState = state;
       }
   
       public long getRefId()
  
  
  
  1.3       +7 -6      db-ojb/src/test/org/apache/ojb/odmg/FieldConversion_ForeigenKeyTest.java
  
  Index: FieldConversion_ForeigenKeyTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/FieldConversion_ForeigenKeyTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FieldConversion_ForeigenKeyTest.java	29 Jan 2003 10:52:57 -0000	1.2
  +++ FieldConversion_ForeigenKeyTest.java	19 Feb 2003 10:37:55 -0000	1.3
  @@ -16,7 +16,8 @@
   import java.util.List;
   
   /**
  - * class FieldConversion_ForeigenKeyTest
  + * class FieldConversion_ForeigenKeyTest,
  + * check the field conversion behaviour.
    *
    * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
    * @version $Id$
  @@ -54,8 +55,8 @@
       {
           String strQuery = "select allNodes from "+FieldConversion_Node.class.getName();
           long id = System.currentTimeMillis();
  -        FieldConversion_Node node = new FieldConversion_Node(id, null);
  -        FieldConversion_Node child = new FieldConversion_Node(id + 1, node);
  +        FieldConversion_Node node = new FieldConversion_Node(id, null, true);
  +        FieldConversion_Node child = new FieldConversion_Node(id + 1, node, false);
   
   
           List result;
  @@ -99,8 +100,8 @@
       {
           String strQuery = "select allNodes from "+FieldConversion_Node.class.getName();
           long id = System.currentTimeMillis();
  -        FieldConversion_Node node = new FieldConversion_Node(id, null);
  -        FieldConversion_Node child = new FieldConversion_Node(id + 1, node);
  +        FieldConversion_Node node = new FieldConversion_Node(id, null, true);
  +        FieldConversion_Node child = new FieldConversion_Node(id + 1, node, false);
   
           Transaction tx = odmg.newTransaction();
           List result;
  
  
  
  1.2       +4 -4      db-ojb/src/test/org/apache/ojb/broker/TestInt2IntConverter.java
  
  Index: TestInt2IntConverter.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/TestInt2IntConverter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestInt2IntConverter.java	10 Oct 2002 19:11:01 -0000	1.1
  +++ TestInt2IntConverter.java	19 Feb 2003 10:37:55 -0000	1.2
  @@ -14,23 +14,23 @@
    * @author  drfish
    */
   public class TestInt2IntConverter implements FieldConversion {
  -    
  +
       /** Creates a new instance of FromMaxInt2IntConversion */
       public TestInt2IntConverter() {
       }
  -    
  +
       /** convert a Java object to its SQL pendant, used for insert & update */
       public Object javaToSql(Object source) throws ConversionException {
  +
           int val = ((Integer)source).intValue();
           val = Integer.MAX_VALUE - val;
           return new Integer(val);
       }
  -    
  +
       /** convert a SQL value to a Java Object, used for SELECT */
       public Object sqlToJava(Object source) throws ConversionException {
           int val = ((Integer)source).intValue();
           val = Integer.MAX_VALUE - val;
           return new Integer(val);
       }
  -    
   }
  
  
  
  1.3       +4 -5      db-ojb/src/test/org/apache/ojb/broker/FieldConversionForeigenKeyTest.java
  
  Index: FieldConversionForeigenKeyTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/FieldConversionForeigenKeyTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FieldConversionForeigenKeyTest.java	2 Feb 2003 10:23:00 -0000	1.2
  +++ FieldConversionForeigenKeyTest.java	19 Feb 2003 10:37:55 -0000	1.3
  @@ -11,8 +11,7 @@
   import org.apache.ojb.odmg.FieldConversion_Node;
   
   /**
  - * Test using field conversion from <code>long</code>
  - * to <code>BigDecimal</code>.
  + * Test using field conversions for PK values.
    *
    * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
    * @version $Id$
  @@ -60,8 +59,8 @@
       {
           //String strQuery = "select allNodes from " + FieldConversion_Node.class.getName();
           long id = System.currentTimeMillis();
  -        FieldConversion_Node node = new FieldConversion_Node(id, null);
  -        FieldConversion_Node child = new FieldConversion_Node(id + 1, node);
  +        FieldConversion_Node node = new FieldConversion_Node(id, null, true);
  +        FieldConversion_Node child = new FieldConversion_Node(id + 1, node, false);
   
           int before;
   
  
  
  
  1.4       +140 -71   db-ojb/src/test/org/apache/ojb/broker/ConvertedKeyReferenceTest.java
  
  Index: ConvertedKeyReferenceTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ConvertedKeyReferenceTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ConvertedKeyReferenceTest.java	5 Feb 2003 20:03:42 -0000	1.3
  +++ ConvertedKeyReferenceTest.java	19 Feb 2003 10:37:55 -0000	1.4
  @@ -7,12 +7,14 @@
   
   package org.apache.ojb.broker;
   
  -import junit.framework.*;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
  +import junit.framework.TestCase;
  +import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryFactory;
  -import org.apache.ojb.broker.query.Criteria;
  -import java.util.*;
  +import org.apache.ojb.broker.util.logging.LoggerFactory;
  +
  +import java.util.Collection;
  +import java.util.Iterator;
   
   /**
    *
  @@ -21,72 +23,139 @@
   public class ConvertedKeyReferenceTest extends TestCase
   {
   
  -	PersistenceBroker broker;
  -
  -	public ConvertedKeyReferenceTest(java.lang.String testName)
  -	{
  -		super(testName);
  -	}
  -
  -	public void setUp()
  -	{
  -		try
  -		{
  -			broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -		}
  -		catch (Throwable t)
  -		{
  -			LoggerFactory.getBootLogger().error("error getting broker", t);
  -		}
  -	}
  -
  -	public static void main(java.lang.String[] args)
  -	{
  -		junit.textui.TestRunner.run(suite());
  -	}
  -
  -	public static Test suite()
  -	{
  -		TestSuite suite = new TestSuite(ConvertedKeyReferenceTest.class);
  -		return suite;
  -	}
  -
  -	public void testConvertedReferenceLookup()
  -	{
  -		Collection coll = null;
  -		Criteria c = null;
  -		Query q = QueryFactory.newQuery(ConversionReferrer.class, c);
  -		coll = broker.getCollectionByQuery(q);
  -		assertTrue("There should be more than 0 matching items", coll.size() > 0);
  -
  -		Iterator i = coll.iterator();
  -		while (i.hasNext())
  -		{
  -			ConversionReferrer cref = (ConversionReferrer) i.next();
  -			assertTrue("reference should be non-null", cref.getReferred() != null);
  -			assertEquals("Reference selected correct item", cref.getRef1(), cref.getReferred().getPk1());
  -		}
  -
  -	}
  -	public void testConvertedReferenceInsert()
  -	{
  -		int no = 105;
  -		ConversionReferrer cref = new ConversionReferrer();
  -		ConversionReferred crefed = new ConversionReferred();
  -		// store an item to referr to
  -		crefed.setPk1(no);
  -		broker.store(crefed);
  -		// create a referrer
  -		cref.setPk1(no);
  -		// set the reference
  -		cref.setReferred(crefed);
  -		// store the object
  -		broker.store(cref);
  -		// save id for recapturing object
  -		Identity id = new Identity(cref, broker);
  -		cref = (ConversionReferrer) broker.getObjectByIdentity(id);
  -		assertEquals("Stored reference ID should match refed object pk", crefed.getPk1(), cref.getRef1());
  -
  -	}
  +    PersistenceBroker broker;
   
  +    public ConvertedKeyReferenceTest(java.lang.String testName)
  +    {
  +        super(testName);
  +    }
  +
  +    public static void main(String[] args)
  +    {
  +        String[] arr = {ConvertedKeyReferenceTest.class.getName()};
  +        junit.textui.TestRunner.main(arr);
  +    }
  +
  +    public void setUp()
  +    {
  +        try
  +        {
  +            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +        }
  +        catch (Throwable t)
  +        {
  +            LoggerFactory.getBootLogger().error("error getting broker", t);
  +        }
  +    }
  +
  +    protected void tearDown() throws Exception
  +    {
  +        super.tearDown();
  +        if (broker != null) broker.close();
  +    }
  +
  +    public void testConvertedReferenceLookup()
  +    {
  +        Collection coll = null;
  +        Criteria c = null;
  +        Query q = QueryFactory.newQuery(ConversionReferrer.class, c);
  +        coll = broker.getCollectionByQuery(q);
  +        assertTrue("There should be more than 0 matching items", coll.size() > 0);
  +
  +        Iterator i = coll.iterator();
  +        while (i.hasNext())
  +        {
  +            ConversionReferrer cref = (ConversionReferrer) i.next();
  +            assertTrue("PK value not converted, id should be > 1000, found " + cref,
cref.getPk1() > 1000);
  +            assertTrue("Reference id should be > 1000, found " + cref, cref.getRef1()
> 1000);
  +            assertTrue("Reference should be non-null, found "+cref, cref.getReferred()
!= null);
  +            assertEquals("Reference does not select correct item", cref.getRef1(), cref.getReferred().getPk1());
  +        }
  +
  +    }
  +
  +    public void testMultipleConverted()
  +    {
  +        String error = "Indicate that the field conversion was not/or multiple times called
for a value, expected > 100 - found ";
  +        Collection coll = null;
  +        Criteria c = null;
  +        Query q = QueryFactory.newQuery(ConversionReferrer.class, c);
  +        coll = broker.getCollectionByQuery(q);
  +        assertTrue("There should be more than 0 matching items", coll.size() > 0);
  +
  +        Iterator i = coll.iterator();
  +        while (i.hasNext())
  +        {
  +            ConversionReferrer cref = (ConversionReferrer) i.next();
  +            assertTrue("PK value not converted, id should be > 1000, found " + cref,
cref.getPk1() > 1000);
  +            assertTrue("Reference should be non-null, found "+cref, cref.getReferred()
!= null);
  +            assertEquals("Reference selected incorrect item", cref.getRef1(), cref.getReferred().getPk1());
  +
  +            /*
  +            The used conversion does the following
  +            val = Integer.MAX_VALUE - val;
  +            for both conversion directions.
  +            The result was e.g.
  +            ++ sqlToJava: 10 --> 2147483637
  +            ## javaToSql: 2147483637 --> 10
  +
  +            */
  +
  +            int value = 0;
  +            value = cref.getRef1();
  +            assertTrue(error + cref, value > 1000);
  +
  +            value = cref.getTestId();
  +            assertTrue(error + cref, value > 1000);
  +
  +            value = cref.getReferred().getPk1();
  +            assertTrue(error + cref, value > 1000);
  +
  +            value = cref.getReferred().getTestId();
  +            assertTrue(error + cref, value > 1000);
  +        }
  +
  +    }
  +
  +    public void testConvertedReferenceInsert()
  +    {
  +        String error = "Maybe field conversion was not called or multiple times";
  +        int no = Integer.MAX_VALUE - 110;
  +        int noRef = Integer.MAX_VALUE - 109;
  +        int noTest = Integer.MAX_VALUE - 108;
  +        int noTestRef = Integer.MAX_VALUE - 107;
  +
  +        ConversionReferrer cref = new ConversionReferrer();
  +        cref.setPk1(no);
  +        cref.setTestId(noTest);
  +
  +        ConversionReferred crefed = new ConversionReferred();
  +        crefed.setPk1(noRef);
  +        crefed.setTestId(noTestRef);
  +        // set reference
  +        cref.setReferred(crefed);
  +
  +        broker.store(crefed);
  +        broker.store(cref);
  +
  +        broker.clearCache();
  +
  +        // save id for recapturing object
  +        Identity id = new Identity(cref, broker);
  +        broker.clearCache();
  +
  +        ConversionReferrer referrer = (ConversionReferrer) broker.getObjectByIdentity(id);
  +        assertNotNull(cref.getReferred());
  +        assertNotNull("We should found a reference, found "+referrer, referrer.getReferred());
  +        assertEquals("Stored reference ID should match refed object pk", referrer.getRef1(),
crefed.getPk1());
  +        assertEquals(error, cref.getPk1(), referrer.getPk1());
  +        assertEquals(error, cref.getTestId(), referrer.getTestId());
  +        assertEquals(error, cref.getReferred().getPk1(), referrer.getReferred().getPk1());
  +
  +        assertEquals(error, cref.getReferred().getTestId(), referrer.getReferred().getTestId());
  +
  +        // delete objects
  +        broker.delete(crefed);
  +        broker.delete(cref);
  +    }
   }
  
  
  
  1.2       +49 -19    db-ojb/src/test/org/apache/ojb/broker/ConversionReferrer.java
  
  Index: ConversionReferrer.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ConversionReferrer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConversionReferrer.java	10 Oct 2002 19:11:01 -0000	1.1
  +++ ConversionReferrer.java	19 Feb 2003 10:37:55 -0000	1.2
  @@ -6,69 +6,99 @@
   
   package org.apache.ojb.broker;
   
  +import org.apache.commons.lang.builder.ToStringBuilder;
  +import org.apache.commons.lang.builder.ToStringStyle;
  +
   /**
    * Used by ConvertedKeyReferenceTest
    *
    * @author  J. Russell Smyth
    */
  -public class ConversionReferrer {
  -    
  +public class ConversionReferrer
  +{
  +
       private int pk1;
  -    
  +    private int testId;
       private int ref1;
  -    
       private ConversionReferred referred;
  -    
  +
       /** Creates a new instance of ConversionParent */
  -    public ConversionReferrer() {
  +    public ConversionReferrer()
  +    {
       }
  -    
  +
  +    public String toString()
  +    {
  +        ToStringBuilder buf = new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE);
  +        buf.append("pk1", pk1);
  +        buf.append("ref1", ref1);
  +        buf.append("testId", testId);
  +        buf.append("referred", referred);
  +        return buf.toString();
  +    }
  +
  +    public int getTestId()
  +    {
  +        return testId;
  +    }
  +
  +    public void setTestId(int testId)
  +    {
  +        this.testId = testId;
  +    }
  +
       /** Getter for property pk1.
        * @return Value of property pk1.
        *
        */
  -    public int getPk1() {
  +    public int getPk1()
  +    {
           return pk1;
       }
  -    
  +
       /** Setter for property pk1.
        * @param pk1 New value of property pk1.
        *
        */
  -    public void setPk1(int pk1) {
  +    public void setPk1(int pk1)
  +    {
           this.pk1 = pk1;
       }
  -    
  +
       /** Getter for property ref1.
        * @return Value of property ref1.
        *
        */
  -    public int getRef1() {
  +    public int getRef1()
  +    {
           return ref1;
       }
  -    
  +
       /** Setter for property ref1.
        * @param ref1 New value of property ref1.
        *
        */
  -    public void setRef1(int ref1) {
  +    public void setRef1(int ref1)
  +    {
           this.ref1 = ref1;
       }
  -    
  +
       /** Getter for property referred.
        * @return Value of property referred.
        *
        */
  -    public org.apache.ojb.broker.ConversionReferred getReferred() {
  +    public org.apache.ojb.broker.ConversionReferred getReferred()
  +    {
           return referred;
       }
  -    
  +
       /** Setter for property referred.
        * @param referred New value of property referred.
        *
        */
  -    public void setReferred(org.apache.ojb.broker.ConversionReferred referred) {
  +    public void setReferred(org.apache.ojb.broker.ConversionReferred referred)
  +    {
           this.referred = referred;
       }
  -    
  +
   }
  
  
  
  1.2       +35 -9     db-ojb/src/test/org/apache/ojb/broker/ConversionReferred.java
  
  Index: ConversionReferred.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ConversionReferred.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConversionReferred.java	10 Oct 2002 19:11:01 -0000	1.1
  +++ ConversionReferred.java	19 Feb 2003 10:37:55 -0000	1.2
  @@ -6,33 +6,59 @@
   
   package org.apache.ojb.broker;
   
  +import org.apache.commons.lang.builder.ToStringBuilder;
  +import org.apache.commons.lang.builder.ToStringStyle;
  +
   /**
    * Used by ConvertedKeyReferenceTest
    *
    * @author  J. Russell Smyth
    */
  -public class ConversionReferred {
  -    
  +public class ConversionReferred
  +{
  +
       private int pk1;
  -    
  +    private int testId;
  +
       /** Creates a new instance of ConversionReferred */
  -    public ConversionReferred() {
  +    public ConversionReferred()
  +    {
       }
  -    
  +
  +    public String toString()
  +    {
  +        ToStringBuilder buf = new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE);
  +        buf.append("pk1", pk1);
  +        buf.append("testId", testId);
  +        return buf.toString();
  +    }
  +
  +    public int getTestId()
  +    {
  +        return testId;
  +    }
  +
  +    public void setTestId(int testId)
  +    {
  +        this.testId = testId;
  +    }
  +
       /** Getter for property pk1.
        * @return Value of property pk1.
        *
        */
  -    public int getPk1() {
  +    public int getPk1()
  +    {
           return pk1;
       }
  -    
  +
       /** Setter for property pk1.
        * @param pk1 New value of property pk1.
        *
        */
  -    public void setPk1(int pk1) {
  +    public void setPk1(int pk1)
  +    {
           this.pk1 = pk1;
       }
  -    
  +
   }
  
  
  
  1.23      +9 -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.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- ojbtest-schema.xml	6 Feb 2003 01:20:54 -0000	1.22
  +++ ojbtest-schema.xml	19 Feb 2003 10:37:55 -0000	1.23
  @@ -375,10 +375,12 @@
     <table name="CONV_REFERER" javaName="ConversionReferrer">
       <column name="PK1" required="true" primaryKey="true" type="INTEGER"/>
       <column name="REF1" type="INTEGER"/>
  +    <column name="TEST_ID" type="INTEGER"/>
     </table>
   
     <table name="CONV_REFERED" javaName="ConversionReferred">
       <column name="PK1" required="true" primaryKey="true" type="INTEGER"/>
  +    <column name="TEST_ID" type="INTEGER"/>
     </table>
   
   
  @@ -532,16 +534,22 @@
           <column name="GRADE" type="VARCHAR" size="80"/>
       </table>
   
  +    <!-- =================================================== -->
  +    <!-- Field conversion test                               -->
  +    <!-- =================================================== -->
       <!--
       private long uid;  // primary key
       private long node_refid;
       -->
       <table name="FIELD_CONVERSION_NODE">
           <column name="NODE_ID" required="true" primaryKey="true" type="DECIMAL"/>
  +        <column name="NODE_STATE" required="true" primaryKey="true" type="INTEGER"/>
           <column name="PARENT_UID" type="DECIMAL"/>
       </table>
   
  -
  +    <!-- =================================================== -->
  +    <!-- Perf-test table                                     -->
  +    <!-- =================================================== -->
       <!--
       private Long articleId;
       private String articleName;
  
  
  
  1.7       +6 -6      db-ojb/src/schema/ojbtest-data.xml
  
  Index: ojbtest-data.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/schema/ojbtest-data.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ojbtest-data.xml	9 Dec 2002 18:24:57 -0000	1.6
  +++ ojbtest-data.xml	19 Feb 2003 10:37:55 -0000	1.7
  @@ -137,12 +137,12 @@
       <Task TaskId="3" PersonId="2" ProjectId="2" Taskname="Project Cleanup"/>
       <Task TaskId="4" PersonId="2" ProjectId="3" Taskname="Testing Scripts"/>
   
  -    <ConversionReferrer Pk1="1" Ref1="1"/>
  -    <ConversionReferrer Pk1="2" Ref1="2"/>
  -    <ConversionReferrer Pk1="3" Ref1="3"/>
  -    <ConversionReferred Pk1="1"/>
  -    <ConversionReferred Pk1="2"/>
  -    <ConversionReferred Pk1="3"/>
  +    <ConversionReferrer Pk1="1" Ref1="50" TestId="10"/>
  +    <ConversionReferrer Pk1="2" Ref1="51" TestId="11"/>
  +    <ConversionReferrer Pk1="3" Ref1="52" TestId="12"/>
  +    <ConversionReferred Pk1="50" TestId="60"/>
  +    <ConversionReferred Pk1="51" TestId="61"/>
  +    <ConversionReferred Pk1="52" TestId="62"/>
   
       <SMMaxA id="120" name="A"/>
       <SMMaxA id="121" name="A"/>
  
  
  
  1.7       +2 -0      db-ojb/src/schema/ojbtest-data.dtd
  
  Index: ojbtest-data.dtd
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/schema/ojbtest-data.dtd,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ojbtest-data.dtd	8 Dec 2002 12:22:40 -0000	1.6
  +++ ojbtest-data.dtd	19 Feb 2003 10:37:55 -0000	1.7
  @@ -228,11 +228,13 @@
   <!ATTLIST ConversionReferrer
     Pk1 CDATA #REQUIRED
     Ref1 CDATA #REQUIRED
  +  TestId CDATA #REQUIRED
   >
   
   <!ELEMENT ConversionReferred EMPTY>
   <!ATTLIST ConversionReferred
     Pk1 CDATA #REQUIRED
  +  TestId CDATA #REQUIRED
   >
   
   
  
  
  

Mime
View raw message