db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: jakarta-ojb/src/schema ojbtest-schema.xml
Date Thu, 16 Jan 2003 17:11:59 GMT
arminw      2003/01/16 09:11:59

  Modified:    src/test/org/apache/ojb/odmg LockingTest.java
                        ManyToManyTest.java
               src/test/org/apache/ojb repository_junit.xml
               src/schema ojbtest-schema.xml
  Added:       src/test/org/apache/ojb/odmg
                        FieldConversion_ForeigenKeyTest.java
                        FieldConversion_LongToBigDecimalConversion.java
                        FieldConversion_Node.java
  Log:
  add test case posted by Oliver Matz
  
  cf. OJB48.  The bug described in OJB48 can still
  be provoked using the ODMG API:
  
  If there is a foreign key field with a FieldConversion,
  it is not invoked properly when using Transaction.lock(..)
  to save an instance.
  
  Revision  Changes    Path
  1.5       +1 -2      jakarta-ojb/src/test/org/apache/ojb/odmg/LockingTest.java
  
  Index: LockingTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/test/org/apache/ojb/odmg/LockingTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LockingTest.java	9 Jan 2003 17:25:18 -0000	1.4
  +++ LockingTest.java	16 Jan 2003 17:11:59 -0000	1.5
  @@ -20,11 +20,10 @@
   {
       public static void main(String[] args)
       {
  -        String[] arr = {CLASS.getName()};
  +        String[] arr = {LockingTest.class.getName()};
           junit.textui.TestRunner.main(arr);
       }
   
  -    private static Class CLASS = LockingTest.class;
       private String databaseName;
   
       /**
  
  
  
  1.5       +6 -0      jakarta-ojb/src/test/org/apache/ojb/odmg/ManyToManyTest.java
  
  Index: ManyToManyTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/test/org/apache/ojb/odmg/ManyToManyTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ManyToManyTest.java	9 Jan 2003 17:25:18 -0000	1.4
  +++ ManyToManyTest.java	16 Jan 2003 17:11:59 -0000	1.5
  @@ -27,6 +27,12 @@
   
   public class ManyToManyTest extends TestCase
   {
  +    public static void main(String[] args)
  +    {
  +        String[] arr = {ManyToManyTest.class.getName()};
  +        junit.textui.TestRunner.main(arr);
  +    }
  +
       private String databaseName;
   
           /**
  
  
  
  1.1                  jakarta-ojb/src/test/org/apache/ojb/odmg/FieldConversion_ForeigenKeyTest.java
  
  Index: FieldConversion_ForeigenKeyTest.java
  ===================================================================
  /**
   * (C) 2003 ppi Media
   * User: om
   */
  
  package org.apache.ojb.odmg;
  
  import junit.framework.TestCase;
  import org.odmg.Database;
  import org.odmg.Implementation;
  import org.odmg.ODMGException;
  import org.odmg.Transaction;
  import org.odmg.OQLQuery;
  import org.apache.ojb.broker.TestHelper;
  
  import java.util.List;
  
  /**
   * class FieldConversion_ForeigenKeyTest
   *
   * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
   * @version $Id: FieldConversion_ForeigenKeyTest.java,v 1.1 2003/01/16 17:11:59 arminw Exp
$
   */
  public class FieldConversion_ForeigenKeyTest extends TestCase
  {
      public static void main(String[] args)
      {
          String[] arr = {FieldConversion_ForeigenKeyTest.class.getName()};
          junit.textui.TestRunner.main(arr);
      }
  
      private Implementation odmg = OJB.getInstance();
      private Database db;
  
      public void setUp() throws ODMGException
      {
          db = odmg.newDatabase();
          db.open(TestHelper.DEF_DATABASE_NAME, Transaction.WRITE);
      }
  
      public void tearDown()
      {
          try
          {
              db.close();
          }
          catch (ODMGException e)
          {
              e.printStackTrace();
          }
      }
  
      public void testMakePersistentNode() throws Exception
      {
          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);
  
  
          List result;
          int before;
          Transaction tx = odmg.newTransaction();
          try
          {
              tx.begin();
  
              OQLQuery query = odmg.newOQLQuery();
              query.create(strQuery);
              result = (List) query.execute();
              before = result.size();
  
              db.makePersistent(child);
  
              tx.commit();
  
              tx.begin();
              query = odmg.newOQLQuery();
              query.create(strQuery);
              result = (List) query.execute();
              tx.commit();
          }
          finally
          {
              if(tx != null && tx.isOpen())
              {
                  tx.abort();
              }
          }
  
          int after = result.size();
  
          assertFalse(after == 0);
          assertEquals(before, after);
  
      }
  
      public void testLockNode() throws Exception
      {
          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);
  
          Transaction tx = odmg.newTransaction();
          List result;
          int before;
  
          try
          {
              tx.begin();
              OQLQuery query = odmg.newOQLQuery();
              query.create(strQuery);
              result = (List) query.execute();
              before = result.size();
  
              tx.lock(child, Transaction.WRITE);
              tx.commit();
  
              tx.begin();
              query = odmg.newOQLQuery();
              query.create(strQuery);
              result = (List) query.execute();
              tx.commit();
          }
          finally
          {
              if(tx != null && tx.isOpen())
              {
                  tx.abort();
              }
          }
  
          int after = result.size();
  
          assertFalse(after == 0);
          assertEquals(before, after);
      }
  }
  
  
  
  1.1                  jakarta-ojb/src/test/org/apache/ojb/odmg/FieldConversion_LongToBigDecimalConversion.java
  
  Index: FieldConversion_LongToBigDecimalConversion.java
  ===================================================================
  /**
   * (C) 2003 ppi Media
   * User: om
   */
  
  package org.apache.ojb.odmg;
  
  import org.apache.ojb.broker.accesslayer.conversions.ConversionException;
  import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
  
  import java.math.BigDecimal;
  
  /**
   * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
   */
  public class FieldConversion_LongToBigDecimalConversion implements FieldConversion
  {
      public Object javaToSql(Object source) throws ConversionException
      {
          Object ret;
          if (source instanceof Long)
          {
              ret = new BigDecimal(((Long) source).doubleValue());
          }
          else
          {
              ret = source;
          }
          return ret;
      }
  
      public Object sqlToJava(Object source) throws ConversionException
      {
          Object ret;
          if (source instanceof BigDecimal)
          {
              ret = new Long(((BigDecimal) source).longValue());
          }
          else
          {
              ret = source;
          }
          return ret;
      }
  }
  
  
  
  1.1                  jakarta-ojb/src/test/org/apache/ojb/odmg/FieldConversion_Node.java
  
  Index: FieldConversion_Node.java
  ===================================================================
  /**
   * (C) 2003 ppi Media
   * User: om
   */
  
  package org.apache.ojb.odmg;
  
  /**
   * can be used to assemble a tree.
   *
   * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
   */
  public class FieldConversion_Node
  {
      private long uid;  // primary key
      private long refId;
      FieldConversion_Node parent;
  
      public FieldConversion_Node(long uid, FieldConversion_Node parent)
      {
          this.uid = uid;
          this.parent = parent;
      }
  }
  
  
  
  1.35      +27 -0     jakarta-ojb/src/test/org/apache/ojb/repository_junit.xml
  
  Index: repository_junit.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/test/org/apache/ojb/repository_junit.xml,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- repository_junit.xml	9 Jan 2003 17:30:48 -0000	1.34
  +++ repository_junit.xml	16 Jan 2003 17:11:59 -0000	1.35
  @@ -2992,4 +2992,31 @@
   <!--      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="UID"
  +       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">
  +  <foreignkey field-ref="refId"/>
  +  </reference-descriptor>
  +</class-descriptor>
  +
   <!-- Mapping of classes used in junit tests and tutorials ends here -->
  
  
  
  1.20      +9 -0      jakarta-ojb/src/schema/ojbtest-schema.xml
  
  Index: ojbtest-schema.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/schema/ojbtest-schema.xml,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- ojbtest-schema.xml	10 Jan 2003 16:51:26 -0000	1.19
  +++ ojbtest-schema.xml	16 Jan 2003 17:11:59 -0000	1.20
  @@ -532,4 +532,13 @@
           <column name="GRADE" type="VARCHAR" size="80"/>
       </table>
   
  +    <!--
  +    private long uid;  // primary key
  +    private long node_refid;
  +    -->
  +    <table name="FIELD_CONVERSION_NODE">
  +        <column name="UID" required="true" primaryKey="true" type="DECIMAL"/>
  +        <column name="PARENT_UID" type="DECIMAL"/>
  +    </table>
  +
   </database>
  
  
  

Mime
View raw message