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 Sat, 04 Oct 2003 17:44:14 GMT
arminw      2003/10/04 10:44:14

  Modified:    src/test/org/apache/ojb repository_junit.xml
               src/test/org/apache/ojb/odmg ODMGRollbackTest.java
               src/schema ojbtest-schema.xml
  Log:
  add new test
  change test
  
  Revision  Changes    Path
  1.95      +48 -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.94
  retrieving revision 1.95
  diff -u -r1.94 -r1.95
  --- repository_junit.xml	19 Sep 2003 15:16:23 -0000	1.94
  +++ repository_junit.xml	4 Oct 2003 17:44:14 -0000	1.95
  @@ -1766,6 +1766,53 @@
        />
   </class-descriptor>
   
  +
  +    <class-descriptor
  +        class="org.apache.ojb.odmg.ODMGRollbackTest$RollbackObjectOne"
  +        table="ROLLBACK_ONE"
  +     >
  +         <field-descriptor
  +            name="objId"
  +            column="OBJ_ID"
  +            jdbc-type="INTEGER"
  +            primarykey="true"
  +            autoincrement="true"
  +         />
  +         <field-descriptor
  +           name="name"
  +           column="NAME"
  +           jdbc-type="VARCHAR"
  +         />
  +        <field-descriptor
  +           name="description"
  +           column="DESCRIPTION"
  +           jdbc-type="VARCHAR"
  +         />
  +    </class-descriptor>
  +
  +    <class-descriptor
  +        class="org.apache.ojb.odmg.ODMGRollbackTest$RollbackObjectTwo"
  +        table="ROLLBACK_TWO"
  +     >
  +         <field-descriptor
  +            name="objId"
  +            column="OBJ_ID"
  +            jdbc-type="INTEGER"
  +            primarykey="true"
  +            autoincrement="true"
  +         />
  +         <field-descriptor
  +           name="name"
  +           column="NAME"
  +           jdbc-type="VARCHAR"
  +         />
  +        <field-descriptor
  +           name="description"
  +           column="DESCRIPTION"
  +           jdbc-type="VARCHAR"
  +         />
  +    </class-descriptor>
  +
   <!--
       Definitions for contract-version-effectiveness testing
       Contract-Version-Effectiveness is a common model in business
  
  
  
  1.15      +214 -28   db-ojb/src/test/org/apache/ojb/odmg/ODMGRollbackTest.java
  
  Index: ODMGRollbackTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/ODMGRollbackTest.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ODMGRollbackTest.java	28 Jul 2003 14:34:20 -0000	1.14
  +++ ODMGRollbackTest.java	4 Oct 2003 17:44:14 -0000	1.15
  @@ -6,7 +6,6 @@
   import java.util.List;
   
   import junit.framework.TestCase;
  -import org.apache.ojb.broker.Contract;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.Project;
  @@ -32,21 +31,6 @@
           super(s);
       }
   
  -//    public void testNoop() throws Exception
  -//    {
  -//        Implementation ojb = OJB.getInstance();
  -//        Database db = ojb.newDatabase();
  -//        db.open(databaseName, Database.OPEN_READ_WRITE);
  -//        try
  -//        {
  -//
  -//        }
  -//        finally
  -//        {
  -//            db.close();
  -//        }
  -//    }
  -//
       /**
        * Tests behavior within transactions. If i store 5 odmgZoos within a transaction
        * and after that within the same transaction i do query 'select all odmgZoos'
  @@ -516,12 +500,88 @@
           Implementation odmg = OJB.getInstance();
           Database db = odmg.newDatabase();
           db.open(databaseName, Database.OPEN_READ_WRITE);
  +        RollbackObjectOne ro = null;
  +        try
  +        {
  +            Transaction tx = odmg.newTransaction();
  +
  +            tx.begin();
  +            ro = new RollbackObjectOne();
  +            ro.setName("test_step_1");
  +            tx.lock(ro, Transaction.WRITE);
  +            tx.lock(ro, Transaction.WRITE);
  +            tx.commit();
  +
  +            tx.begin();
  +            tx.lock(ro, Transaction.WRITE);
  +            tx.lock(ro, Transaction.WRITE);
  +            ro.setName("test_step_2");
  +            tx.commit();
   
  +            tx.begin();
  +            tx.lock(ro, Transaction.WRITE);
  +            ro.setName("test_step_3");
  +            tx.lock(ro, Transaction.WRITE);
  +            tx.commit();
  +        }
  +        finally
  +        {
  +            db.close();
  +        }
  +    }
  +
  +    public void testCheckCacheAfterRollback() throws Exception
  +    {
  +        Implementation odmg = OJB.getInstance();
  +        Database db = odmg.newDatabase();
  +        db.open(databaseName, Database.OPEN_READ_WRITE);
  +        RollbackObjectOne ro = null;
  +        RollbackObjectOne ro_2 = null;
  +        String name = "testCheckCacheAfterRollback_"+System.currentTimeMillis();
           try
           {
  -            storeNewContractObject(odmg, 5444);
  -            storeNewContractObject(odmg, 5444);
  -            storeNewContractObject(odmg, 5445);
  +            Transaction tx = odmg.newTransaction();
  +            tx.begin();
  +            ro = new RollbackObjectOne();
  +            ro.setName(name);
  +            tx.lock(ro, Transaction.WRITE);
  +
  +            ro_2 = new RollbackObjectOne();
  +            ro_2.setName(name);
  +            tx.lock(ro_2, Transaction.WRITE);
  +            tx.commit();
  +
  +            tx = odmg.newTransaction();
  +            tx.begin();
  +            OQLQuery query = odmg.newOQLQuery();
  +            query.create("select all from " + RollbackObjectOne.class.getName() + " where
name like $1");
  +            query.bind(name);
  +            List list = (List) query.execute();
  +            tx.commit();
  +            assertEquals(2,list.size());
  +
  +            tx = odmg.newTransaction();
  +            tx.begin();
  +            tx.lock(ro, Transaction.WRITE);
  +            ro = new RollbackObjectOne();
  +            ro.setDescription(name);
  +
  +            tx.lock(ro_2, Transaction.WRITE);
  +            ro_2 = new RollbackObjectOne();
  +            ro_2.setDescription(name);
  +
  +            tx.abort();
  +
  +            tx = odmg.newTransaction();
  +            tx.begin();
  +            query = odmg.newOQLQuery();
  +            query.create("select all from " + RollbackObjectOne.class.getName() + " where
name like $1");
  +            query.bind(name);
  +            list = (List) query.execute();
  +            tx.commit();
  +            assertEquals(2,list.size());
  +            assertNull(((RollbackObjectOne)list.get(0)).getDescription());
  +            assertNull(((RollbackObjectOne)list.get(1)).getDescription());
           }
           finally
           {
  @@ -529,15 +589,141 @@
           }
       }
   
  -    private void storeNewContractObject(Implementation odmg, int value) throws Exception
  +    /**
  +     * test empty usage of methods
  +     */
  +    public void testEmpty() throws Exception
       {
  -        Transaction tx = odmg.newTransaction();
  -        Contract contract = null;
  -        tx.begin();
  -        contract = new Contract();
  -        contract.setPk(""+value);
  -        tx.lock(contract, Transaction.WRITE);
  -        tx.lock(contract, Transaction.WRITE);
  -        tx.commit();
  +        Implementation ojb = OJB.getInstance();
  +        Database db = ojb.newDatabase();
  +        db.open(databaseName, Database.OPEN_READ_WRITE);
  +        try
  +        {
  +            // get new tx instance each time
  +            Transaction tx = ojb.newTransaction();
  +            tx.begin();
  +            tx.abort();
  +
  +            tx = ojb.newTransaction();
  +            tx.begin();
  +            tx.checkpoint();
  +            tx.checkpoint();
  +            tx.abort();
  +
  +            tx = ojb.newTransaction();
  +            tx.begin();
  +            tx.checkpoint();
  +            tx.checkpoint();
  +            tx.commit();
  +
  +            tx = ojb.newTransaction();
  +            tx.begin();
  +            tx.commit();
  +
  +            // with same tx instance
  +            tx = ojb.newTransaction();
  +            tx.begin();
  +            tx.abort();
  +
  +            tx.begin();
  +            tx.checkpoint();
  +            tx.checkpoint();
  +            tx.abort();
  +
  +            tx.begin();
  +            tx.checkpoint();
  +            tx.checkpoint();
  +            tx.commit();
  +
  +            tx.begin();
  +            tx.commit();
  +        }
  +        catch(Exception e)
  +        {
  +            e.printStackTrace();
  +            throw e;
  +        }
  +        finally
  +        {
  +            db.close();
  +        }
  +    }
  +
  +
  +    //**************************************************************
  +    // test classes
  +    //**************************************************************
  +    public static class RollbackObjectOne
  +    {
  +        Integer objId;
  +        String name;
  +        String description;
  +
  +        public Integer getObjId()
  +        {
  +            return objId;
  +        }
  +
  +        public void setObjId(Integer objId)
  +        {
  +            this.objId = objId;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +
  +        public String getDescription()
  +        {
  +            return description;
  +        }
  +
  +        public void setDescription(String description)
  +        {
  +            this.description = description;
  +        }
  +    }
  +
  +    public static class RollbackObjectTwo
  +    {
  +        Integer objId;
  +        String name;
  +        String description;
  +
  +        public Integer getObjId()
  +        {
  +            return objId;
  +        }
  +
  +        public void setObjId(Integer objId)
  +        {
  +            this.objId = objId;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +
  +        public String getDescription()
  +        {
  +            return description;
  +        }
  +
  +        public void setDescription(String description)
  +        {
  +            this.description = description;
  +        }
       }
   }
  
  
  
  1.53      +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.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- ojbtest-schema.xml	19 Sep 2003 15:16:22 -0000	1.52
  +++ ojbtest-schema.xml	4 Oct 2003 17:44:14 -0000	1.53
  @@ -421,6 +421,17 @@
           <column name="RND_NAME" required="true" type="VARCHAR" size="100"/>
     </table>
   
  +    <table name="ROLLBACK_ONE">
  +        <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="NAME" required="false" type="VARCHAR" size="100"/>
  +        <column name="DESCRIPTION" required="false" type="VARCHAR" size="100"/>
  +    </table>
  +    <table name="ROLLBACK_TWO">
  +        <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="NAME" required="false" type="VARCHAR" size="100"/>
  +        <column name="DESCRIPTION" required="false" type="VARCHAR" size="100"/>
  +    </table>
  +
   
     <!-- ======================================================== -->
     <!--                                                          -->
  
  
  

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