db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mka...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb repository_junit.xml
Date Wed, 02 Mar 2005 20:13:49 GMT
mkalen      2005/03/02 12:13:49

  Modified:    src/schema Tag: OJB_1_0_RELEASE ojbtest-schema.xml
               src/test/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
                        FieldConversionTest_3.java
               src/test/org/apache/ojb Tag: OJB_1_0_RELEASE
                        repository_junit.xml
  Log:
  New test method for showing problems with StatementManager and oracle9i (StatementManager
is not using setNull() for null-values when binding for deletion). Test passes with hsqldb
and fails with oracle9i.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.80.2.12 +5 -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.80.2.11
  retrieving revision 1.80.2.12
  diff -u -r1.80.2.11 -r1.80.2.12
  --- ojbtest-schema.xml	2 Mar 2005 15:57:26 -0000	1.80.2.11
  +++ ojbtest-schema.xml	2 Mar 2005 20:13:49 -0000	1.80.2.12
  @@ -684,6 +684,10 @@
           <column name="PARENT_UID" type="DECIMAL" size="15,0"/>
       </table>
   
  +    <table name="FIELD_CONVERSION_NODE_NOINC">
  +        <column name="NODE_ID" required="true" primaryKey="true" type="DECIMAL" size="15,0"/>
  +    </table>
  +
       <table name="CONVERSION_VO">
           <column name="PK_WITH_AUTO" required="true" primaryKey="true" type="INTEGER"/>
           <column name="PK_WITHOUT_AUTO" required="true" primaryKey="true" type="INTEGER"/>
  
  
  
  No                   revision
  No                   revision
  1.4.2.1   +76 -15    db-ojb/src/test/org/apache/ojb/broker/FieldConversionTest_3.java
  
  Index: FieldConversionTest_3.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/FieldConversionTest_3.java,v
  retrieving revision 1.4
  retrieving revision 1.4.2.1
  diff -u -r1.4 -r1.4.2.1
  --- FieldConversionTest_3.java	25 Jun 2004 15:58:39 -0000	1.4
  +++ FieldConversionTest_3.java	2 Mar 2005 20:13:49 -0000	1.4.2.1
  @@ -1,13 +1,13 @@
   package org.apache.ojb.broker;
   
  -import java.io.Serializable;
  -import java.math.BigDecimal;
  -
  -import junit.framework.TestCase;
   import org.apache.ojb.broker.accesslayer.conversions.ConversionException;
   import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.QueryFactory;
  +import org.apache.ojb.junit.PBTestCase;
  +
  +import java.io.Serializable;
  +import java.math.BigDecimal;
   
   /**
    * Test using field conversions for PK values.
  @@ -15,9 +15,8 @@
    * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
    * @version $Id$
    */
  -public class FieldConversionTest_3 extends TestCase
  +public class FieldConversionTest_3 extends PBTestCase
   {
  -    private PersistenceBroker broker;
   
       public static void main(String[] args)
       {
  @@ -25,20 +24,16 @@
           junit.textui.TestRunner.main(arr);
       }
   
  -    public void setUp() throws PBFactoryException
  -    {
  -        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -    }
  -
       public void tearDown()
       {
           try
           {
               broker.clearCache();
  -            broker.close();
  +            super.tearDown();
           }
  -        catch (PersistenceBrokerException e)
  +        catch (Exception e)
           {
  +            //ignored
           }
       }
   
  @@ -95,12 +90,46 @@
           assertEquals(before + 1, after);
       }
   
  +    /**
  +     * Assert that StatementManager handles NULL-values correct when binding deletions.
  +     */
  +    public void testDeleteNode() throws Exception
  +    {
  +        NodeWoAutoInc node = new NodeWoAutoInc(0);
  +
  +        try
  +        {
  +            broker.beginTransaction();
  +            // mkalen: Try to issue delete with numeric field=NULL after field conversion,
  +            // which will make eg Oracle JDBC throw SQLException if not using stmt.setNull()
  +            broker.delete(node);
  +            broker.commitTransaction();
  +        }
  +        finally
  +        {
  +            if (broker.isInTransaction())
  +            {
  +                try
  +                {
  +                    broker.abortTransaction();
  +                }
  +                catch (Throwable ignore)
  +                {
  +                    //ignore
  +                }
  +            }
  +        }
  +    }
  +
   
       //****************************************************************************
       // inner class
       //****************************************************************************
       public static class LongToBigDecimalConversion implements FieldConversion
       {
  +        private static final Long NULL_BIG_DECIMAL = null;
  +        private static final Long ZERO = new Long(0);
  +
           public LongToBigDecimalConversion()
           {
           }
  @@ -110,7 +139,14 @@
               Object ret;
               if (source instanceof Long)
               {
  -                ret = new BigDecimal(((Long) source).doubleValue());
  +                if (ZERO.equals(source))
  +                {
  +				    ret = NULL_BIG_DECIMAL;
  +                }
  +                else
  +                {
  +                    ret = new BigDecimal(((Long) source).doubleValue());
  +                }
               }
               else
               {
  @@ -200,4 +236,29 @@
               this.parent = parent;
           }
       }
  +
  +    public static class NodeWoAutoInc implements Serializable
  +    {
  +        private long uid;  // primary key, no auto increment
  +
  +        public NodeWoAutoInc()
  +        {
  +        }
  +
  +        public NodeWoAutoInc(long uid)
  +        {
  +            this.uid = uid;
  +        }
  +
  +        public long getUid()
  +        {
  +            return uid;
  +        }
  +
  +        public void setUid(long uid)
  +        {
  +            this.uid = uid;
  +        }
  +    }
  +
   }
  
  
  
  No                   revision
  No                   revision
  1.112.2.11 +14 -1     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.112.2.10
  retrieving revision 1.112.2.11
  diff -u -r1.112.2.10 -r1.112.2.11
  --- repository_junit.xml	2 Mar 2005 15:57:26 -0000	1.112.2.10
  +++ repository_junit.xml	2 Mar 2005 20:13:49 -0000	1.112.2.11
  @@ -2408,6 +2408,19 @@
           </reference-descriptor>
       </class-descriptor>
   
  +   <!-- Field conversion test using PB-api and BigDecimal -->
  +   <class-descriptor
  +     class="org.apache.ojb.broker.FieldConversionTest_3$NodeWoAutoInc"
  +     table="FIELD_CONVERSION_NODE_NOINC">
  +     <field-descriptor
  +       name="uid"
  +       column="NODE_ID"
  +       jdbc-type="DECIMAL"
  +       primarykey="true"
  +       autoincrement="false"
  +       conversion="org.apache.ojb.broker.FieldConversionTest_3$LongToBigDecimalConversion"
  +     />
  +   </class-descriptor>
   
   <!-- ************************************************* -->
   <!--    PB-api NumberAccuracyTest                      -->
  
  
  

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