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/test/org/apache/ojb repository_junit_meta_seq.xml
Date Thu, 29 Jul 2004 06:34:43 GMT
arminw      2004/07/28 23:34:43

  Modified:    src/test/org/apache/ojb/broker/sequence Tag: OJB_1_0_RELEASE
                        NativeIdentifierTest.java
               src/test/org/apache/ojb Tag: OJB_1_0_RELEASE
                        repository_junit_meta_seq.xml
  Log:
  add new test case to show problem with
  FK assignment when native DB Identity columns are used
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.10.2.1  +444 -71   db-ojb/src/test/org/apache/ojb/broker/sequence/NativeIdentifierTest.java
  
  Index: NativeIdentifierTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/sequence/NativeIdentifierTest.java,v
  retrieving revision 1.10
  retrieving revision 1.10.2.1
  diff -u -r1.10 -r1.10.2.1
  --- NativeIdentifierTest.java	11 May 2004 11:55:57 -0000	1.10
  +++ NativeIdentifierTest.java	29 Jul 2004 06:34:43 -0000	1.10.2.1
  @@ -1,33 +1,35 @@
   package org.apache.ojb.broker.sequence;
   
  -import junit.framework.TestCase;
  +import java.io.Serializable;
  +import java.sql.Connection;
  +import java.sql.Statement;
  +import java.util.ArrayList;
  +import java.util.Collection;
  +import java.util.Iterator;
  +import java.util.List;
  +
   import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.TestHelper;
  +import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.MetadataManager;
  +import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   import org.apache.ojb.broker.metadata.SequenceDescriptor;
  +import org.apache.ojb.broker.platforms.Platform;
   import org.apache.ojb.broker.platforms.PlatformHsqldbImpl;
   import org.apache.ojb.broker.platforms.PlatformMySQLImpl;
  -import org.apache.ojb.broker.platforms.Platform;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.query.QueryFactory;
   import org.apache.ojb.broker.util.sequence.SequenceManagerNativeImpl;
  +import org.apache.ojb.junit.PBTestCase;
   import org.apache.ojb.odmg.OJB;
  -import org.odmg.Implementation;
   import org.odmg.Database;
  +import org.odmg.Implementation;
   import org.odmg.Transaction;
   
  -import java.io.Serializable;
  -import java.sql.Connection;
  -import java.sql.Statement;
  -import java.util.ArrayList;
  -import java.util.Iterator;
  -import java.util.List;
  -import java.util.Collection;
  -
   /**
    * Test case for {@link SequenceManagerNativeImpl}. These test check
    * support for native identity columns. Test case only works for
  @@ -36,7 +38,7 @@
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
  -public class NativeIdentifierTest extends TestCase
  +public class NativeIdentifierTest extends PBTestCase
   {
       // Statements for MainObject table
       private static final String DROP = "DROP TABLE NATIVE_MAIN_OBJECT";
  @@ -59,8 +61,6 @@
       private static final String DROP_REF = "DROP TABLE NATIVE_REFERENCE_OBJECT";
       private static final String INSERT_DUMMY_REF = "INSERT INTO NATIVE_REFERENCE_OBJECT
(NAME) VALUES ('Dummy_2')";
   
  -
  -    private PersistenceBroker broker;
       private Platform platform;
       private Class oldSequenceManager;
   
  @@ -81,21 +81,38 @@
           return skip;
       }
   
  -    protected void setUp() throws Exception
  +    public void setUp() throws Exception
       {
           super.setUp();
   
  -
  -        PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker();
  -        platform = pb.serviceConnectionManager().getSupportedPlatform();
  +        platform = broker.serviceConnectionManager().getSupportedPlatform();
           if (skipTest()) return;
  +
           Connection con;
           Statement stmt;
   
  +        PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker();
           try
           {
               con = pb.serviceConnectionManager().getConnection();
               stmt = con.createStatement();
  +            stmt.execute(DROP);
  +            stmt.close();
  +
  +            stmt = con.createStatement();
  +            stmt.execute(DROP_REF);
  +            stmt.close();
  +        }
  +        finally
  +        {
  +            if (pb != null) pb.close();
  +        }
  +
  +
  +        try
  +        {
  +            con = broker.serviceConnectionManager().getConnection();
  +            stmt = con.createStatement();
               if(platform instanceof PlatformMySQLImpl)
               {
                   stmt.execute(CREATE_MYSQL);
  @@ -126,34 +143,25 @@
               stmt.close();
   
               SequenceDescriptor sd = MetadataManager.getInstance().connectionRepository().
  -                    getDescriptor(pb.getPBKey()).getSequenceDescriptor();
  +                    getDescriptor(broker.getPBKey()).getSequenceDescriptor();
               oldSequenceManager = sd.getSequenceManagerClass();
               sd.setSequenceManagerClass(SequenceManagerNativeImpl.class);
           }
           finally
           {
  -            if (pb != null) pb.close();
  +            if (broker != null) broker.close();
           }
   
           PersistenceBrokerFactory.releaseAllInstances();
  -
           broker = PersistenceBrokerFactory.defaultPersistenceBroker();
           SequenceDescriptor sd = MetadataManager.getInstance().connectionRepository().
                   getDescriptor(broker.getPBKey()).getSequenceDescriptor();
           assertEquals(SequenceManagerNativeImpl.class, sd.getSequenceManagerClass());
       }
   
  -    protected void tearDown() throws Exception
  +    public void tearDown() throws Exception
       {
           super.tearDown();
  -
  -        try
  -        {
  -            broker.close();
  -        }
  -        catch (Exception e)
  -        {
  -        }
           if (skipTest()) return;
   
           Connection con;
  @@ -161,14 +169,14 @@
           PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker();
           try
           {
  -            con = pb.serviceConnectionManager().getConnection();
  -            stmt = con.createStatement();
  -            stmt.execute(DROP);
  -            stmt.close();
  -
  -            stmt = con.createStatement();
  -            stmt.execute(DROP_REF);
  -            stmt.close();
  +//            con = pb.serviceConnectionManager().getConnection();
  +//            stmt = con.createStatement();
  +//            stmt.execute(DROP);
  +//            stmt.close();
  +//
  +//            stmt = con.createStatement();
  +//            stmt.execute(DROP_REF);
  +//            stmt.close();
   
               SequenceDescriptor sd = MetadataManager.getInstance().connectionRepository().
                       getDescriptor(pb.getPBKey()).getSequenceDescriptor();
  @@ -184,16 +192,41 @@
           SequenceDescriptor sd = MetadataManager.getInstance().connectionRepository().
                   getDescriptor(broker.getPBKey()).getSequenceDescriptor();
           assertEquals(oldSequenceManager, sd.getSequenceManagerClass());
  +
  +        changeAutoSetting(MainObject.class, "singleReference", true, false, false, false);
  +        changeAutoSetting(MainObject.class, "allReferences", true, false, false, false);
  +        changeAutoSetting(CollectionReference.class, "singleReference", true, false, false,
false);
  +        changeAutoSetting(SingleReference.class, "mainObject", true, false, false, false);
           broker.close();
       }
   
  -    public void testSimpleInsert() throws Exception
  +    public void testSimpleInsert_1() throws Exception
       {
  -        long timestamp = (long) (System.currentTimeMillis() * Math.random());
  -        String name = "testSimpleInsert_" + timestamp;
  +        // prepare for PB-api test
  +        changeAutoSetting(MainObject.class, "singleReference", true, true, true, false);
  +        changeAutoSetting(MainObject.class, "allReferences", true, true, true, false);
  +        changeAutoSetting(CollectionReference.class, "singleReference", true, true, true,
false);
  +        changeAutoSetting(SingleReference.class, "mainObject", true, true, true, false);
  +        doTtestSimpleInsert();
  +    }
   
  +    public void testSimpleInsert_2() throws Exception
  +    {
  +        // prepare for PB-api test
  +        changeAutoSetting(MainObject.class, "singleReference", true, true, true, true);
  +        changeAutoSetting(MainObject.class, "allReferences", true, true, true, true);
  +        changeAutoSetting(CollectionReference.class, "singleReference", true, true, true,
true);
  +        changeAutoSetting(SingleReference.class, "mainObject", true, true, true, true);
  +        doTtestSimpleInsert();
  +    }
  +
  +    public void doTtestSimpleInsert() throws Exception
  +    {
           if (skipTest()) return;
   
  +        long timestamp = System.currentTimeMillis();
  +        String name = "testSimpleInsert_" + timestamp;
  +
           MainObject obj_1 = new MainObject(null, name);
           MainObject obj_2 = new MainObject(null, name);
           MainObject obj_3 = new MainObject(null, name);
  @@ -213,15 +246,32 @@
           int result = broker.getCount(query);
           assertEquals("Not all objects created", 3, result);
           assertNotNull(obj_1.getIdentifier());
  +        assertTrue(obj_1.getIdentifier().longValue() > 0);
  +        assertTrue(obj_3.getIdentifier().longValue() > 0);
       }
   
  -    public void testSimpleInsertODMG() throws Exception
  +    public void testSimpleInsertODMG_1() throws Exception
       {
  -        long timestamp = (long) (System.currentTimeMillis() * Math.random());
  -        String name = "testSimpleInsert_" + timestamp;
  +        changeAutoSetting(MainObject.class, "singleReference", true, false, false, false);
  +        changeAutoSetting(MainObject.class, "allReferences", true, false, false, false);
  +        changeAutoSetting(CollectionReference.class, "singleReference", true, false, false,
false);
  +        changeAutoSetting(SingleReference.class, "mainObject", true, false, false, false);
  +    }
   
  +    public void testSimpleInsertODMG_2() throws Exception
  +    {
  +        changeAutoSetting(MainObject.class, "singleReference", true, false, false, true);
  +        changeAutoSetting(MainObject.class, "allReferences", true, false, false, true);
  +        changeAutoSetting(CollectionReference.class, "singleReference", true, false, false,
true);
  +        changeAutoSetting(SingleReference.class, "mainObject", true, false, false, true);
  +    }
  +    public void doTestSimpleInsertODMG() throws Exception
  +    {
           if (skipTest()) return;
   
  +        long timestamp = System.currentTimeMillis();
  +        String name = "testSimpleInsert_" + timestamp;
  +
           MainObject obj_1 = new MainObject(null, name);
           MainObject obj_2 = new MainObject(null, name);
           MainObject obj_3 = new MainObject(null, name);
  @@ -243,20 +293,34 @@
           int result = broker.getCount(query);
           assertEquals("Not all objects created", 3, result);
           assertNotNull(obj_1.getIdentifier());
  +        assertTrue(obj_1.getIdentifier().longValue() > 0);
  +        assertTrue(obj_3.getIdentifier().longValue() > 0);
       }
   
  -    public void testAllInOne() throws Exception
  +    public void testReferenceInsertUpdate_1() throws Exception
       {
  -        testSimpleInsert();
  -        testSimpleInsert();
  -        testReferenceInsertUpdate();
  -        testReferenceInsertUpdate();
  +        // prepare for PB-api test
  +        changeAutoSetting(MainObject.class, "singleReference", true, true, true, false);
  +        changeAutoSetting(MainObject.class, "allReferences", true, true, true, false);
  +        changeAutoSetting(CollectionReference.class, "singleReference", true, true, true,
false);
  +        changeAutoSetting(SingleReference.class, "mainObject", true, true, true, false);
  +        doTestReferenceInsertUpdate();
       }
   
  -    public void testReferenceInsertUpdate() throws Exception
  +    public void testReferenceInsertUpdate_2() throws Exception
  +    {
  +        // prepare for PB-api test
  +        changeAutoSetting(MainObject.class, "singleReference", true, true, true, true);
  +        changeAutoSetting(MainObject.class, "allReferences", true, true, true, true);
  +        changeAutoSetting(CollectionReference.class, "singleReference", true, true, true,
true);
  +        changeAutoSetting(SingleReference.class, "mainObject", true, true, true, true);
  +        doTestReferenceInsertUpdate();
  +    }
  +
  +    public void doTestReferenceInsertUpdate() throws Exception
       {
           if (skipTest()) return;
  -        long timestamp = (long) (System.currentTimeMillis() * Math.random());
  +        long timestamp = System.currentTimeMillis();
           String name = "testReferenceInsert_main_" + timestamp;
           String nameRef = "testReferenceInsert_reference_" + timestamp;
           String nameSingleRef = "testReferenceInsert_single_reference_" + timestamp;
  @@ -312,6 +376,8 @@
           assertNotSame(obj_1.getIdentifier(), obj_2.getIdentifier());
           assertTrue(obj_1.getIdentifier().longValue() > 0);
           assertTrue(obj_2.getIdentifier().longValue() > 0);
  +        assertTrue(s_ref_3.getId().longValue() > 0);
  +        assertTrue(ref_3.getRefIdentifier().longValue() > 0);
   
           // get Identity objects
           Identity oid_1 = new Identity(obj_1, broker);
  @@ -427,10 +493,220 @@
           assertEquals(id_2, obj_2.getIdentifier());
       }
   
  -    public void testDelete() throws Exception
  +    public void testReferenceInsertUpdateODMG() throws Exception
       {
           if (skipTest()) return;
  -        long timestamp = (long) (System.currentTimeMillis() * Math.random());
  +
  +        // prepare metadata for odmg-api
  +        changeAutoSetting(MainObject.class, "singleReference", true, false, false, false);
  +        changeAutoSetting(MainObject.class, "allReferences", true, false, false, false);
  +        changeAutoSetting(CollectionReference.class, "singleReference", true, false, false,
false);
  +        changeAutoSetting(SingleReference.class, "mainObject", true, false, false, false);
  +
  +        long timestamp = System.currentTimeMillis();
  +        String name = "testReferenceInsert_main_" + timestamp;
  +        String nameRef = "testReferenceInsert_reference_" + timestamp;
  +        String nameSingleRef = "testReferenceInsert_single_reference_" + timestamp;
  +
  +        MainObject obj_1 = new MainObject(null, name);
  +        MainObject obj_2 = new MainObject(null, name);
  +
  +        SingleReference s_ref_1 = new SingleReference(nameSingleRef);
  +        SingleReference s_ref_2 = new SingleReference(nameSingleRef);
  +
  +        CollectionReference ref_1 = new CollectionReference(null, nameRef);
  +        CollectionReference ref_2 = new CollectionReference(null, nameRef);
  +        CollectionReference ref_3 = new CollectionReference(null, nameRef);
  +        CollectionReference ref_4 = new CollectionReference(null, nameRef);
  +        ref_1.setSingleReference(s_ref_1);
  +        ref_4.setSingleReference(s_ref_2);
  +
  +        SingleReference s_ref_3 = new SingleReference(nameSingleRef);
  +        SingleReference s_ref_4 = new SingleReference(nameSingleRef);
  +
  +        obj_1.addReference(ref_1);
  +        obj_1.addReference(ref_2);
  +        obj_1.addReference(ref_3);
  +        obj_1.addReference(ref_4);
  +
  +        obj_1.setSingleReference(s_ref_3);
  +        s_ref_3.setMainObject(obj_1);
  +        obj_2.setSingleReference(s_ref_4);
  +        s_ref_3.setMainObject(obj_1);
  +
  +        Implementation odmg = OJB.getInstance();
  +        Database db = odmg.newDatabase();
  +        db.open(TestHelper.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);
  +
  +        Transaction tx = odmg.newTransaction();
  +        tx.begin();
  +        //db.makePersistent(ref_1);
  +        db.makePersistent(obj_1);
  +        db.makePersistent(obj_2);
  +        tx.commit();
  +
  +        // try to find both objects
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("name", name);
  +        QueryByCriteria query = QueryFactory.newQuery(MainObject.class, crit);
  +        int result = broker.getCount(query);
  +        assertEquals("Wrong object count", 2, result);
  +
  +        // pk have to set and have to be different
  +        assertNotNull(obj_1.getIdentifier());
  +        assertNotNull(obj_2.getIdentifier());
  +        assertNotSame(obj_1.getIdentifier(), obj_2.getIdentifier());
  +        assertTrue(obj_1.getIdentifier().longValue() > 0);
  +        assertTrue(obj_2.getIdentifier().longValue() > 0);
  +        assertTrue(s_ref_3.getId().longValue() > 0);
  +        assertTrue(ref_3.getRefIdentifier().longValue() > 0);
  +        // check anonymous FK setting
  +        Long fk = (Long) broker.getClassDescriptor(MainObject.class)
  +                .getFieldDescriptorByName("refFK")
  +                .getPersistentField().get(obj_1);
  +        assertTrue("The assigned FK should be > 0 after store of main object, but was
" + fk.longValue(), fk.longValue() > 0);
  +
  +        // get Identity objects
  +        Identity oid_1 = new Identity(obj_1, broker);
  +        Identity oid_2 = new Identity(obj_2, broker);
  +        // get identifier (PK) values
  +        Long id_1 = obj_1.getIdentifier();
  +        Long id_2 = obj_2.getIdentifier();
  +
  +        broker.clearCache();
  +
  +        // get object with references
  +        obj_1 = (MainObject) broker.getObjectByIdentity(oid_1);
  +        assertNotNull(obj_1);
  +        List references = obj_1.getAllReferences();
  +        assertNotNull(references);
  +        assertEquals("4 references expected for object: "+obj_1, 4, references.size());
  +        Iterator it = references.iterator();
  +        while (it.hasNext())
  +        {
  +            CollectionReference ref = (CollectionReference) it.next();
  +            assertEquals("Main object fk expected", obj_1.getIdentifier(), ref.fkIdentifier);
  +            assertTrue("We expect a positive value, identity columns have to start >
0",
  +                    (ref.getRefIdentifier().longValue() > 0));
  +        }
  +        assertNotNull(obj_1.getSingleReference());
  +        obj_2 = (MainObject) broker.getObjectByIdentity(oid_2);
  +        assertTrue(obj_1.getIdentifier().longValue() > 0);
  +        assertTrue(obj_2.getIdentifier().longValue() > 0);
  +        assertNotNull(obj_2.getSingleReference());
  +        assertTrue(obj_2.getSingleReference().getId().longValue() > 0);
  +        assertTrue(obj_1.getSingleReference().getId().longValue() > 0);
  +        assertNotSame(obj_1.getSingleReference(), obj_2.getSingleReference());
  +        broker.clearCache();
  +
  +        // get references only
  +        Criteria crit_2 = new Criteria();
  +        crit_2.addEqualTo("refName", nameRef);
  +        QueryByCriteria query_2 = QueryFactory.newQuery(CollectionReference.class, crit_2);
  +        int result_2 = broker.getCount(query_2);
  +        assertEquals("Not all objects created", 4, result_2);
  +        assertNotNull(ref_3.getRefIdentifier());
  +
  +        broker.clearCache();
  +
  +        // get second object
  +        MainObject retObj = (MainObject) broker.getObjectByIdentity(oid_2);
  +        List refList = retObj.getAllReferences();
  +        assertNotNull(refList);
  +        assertEquals("object do not have references", 0, refList.size());
  +
  +        // add new reference to object
  +        CollectionReference ref_5 = new CollectionReference(null, nameRef);
  +        CollectionReference ref_6 = new CollectionReference(null, nameRef);
  +        obj_1.addReference(ref_5);
  +        obj_2.addReference(ref_6);
  +        broker.beginTransaction();
  +        broker.store(obj_1);
  +        broker.store(obj_2);
  +        broker.commitTransaction();
  +        assertNotNull(ref_5.getRefIdentifier());
  +        assertNotNull(ref_6.getRefIdentifier());
  +        assertEquals(id_1, obj_1.getIdentifier());
  +        assertEquals(id_2, obj_2.getIdentifier());
  +
  +        obj_1 = (MainObject) broker.getObjectByIdentity(oid_1);
  +        assertNotNull(obj_1);
  +        references = obj_1.getAllReferences();
  +        assertNotNull(references);
  +        assertEquals("5 references expected for object: "+obj_1, 5, references.size());
  +
  +        obj_2 = (MainObject) broker.getObjectByIdentity(oid_2);
  +        assertNotNull(obj_2);
  +        references = obj_2.getAllReferences();
  +        assertNotNull(references);
  +        assertEquals("1 references expected for object: "+obj_2, 1, references.size());
  +
  +        assertEquals(id_1, obj_1.getIdentifier());
  +        assertEquals(id_2, obj_2.getIdentifier());
  +
  +        // now update main objects
  +        tx.begin();
  +        tx.lock(obj_1, Transaction.WRITE);
  +        tx.lock(obj_2, Transaction.WRITE);
  +        obj_1.setName(name+"_update");
  +        obj_2.setName(name+"_update");
  +        tx.commit();
  +
  +        obj_1 = (MainObject) broker.getObjectByIdentity(oid_1);
  +        obj_2 = (MainObject) broker.getObjectByIdentity(oid_2);
  +
  +        assertNotNull(obj_1);
  +        assertNotNull(obj_2);
  +        assertEquals(obj_1.getName(), name+"_update");
  +        assertEquals(obj_2.getName(), name+"_update");
  +        assertEquals(id_1, obj_1.getIdentifier());
  +        assertEquals(id_2, obj_2.getIdentifier());
  +
  +        // now update reference
  +        obj_2 = (MainObject) broker.getObjectByIdentity(oid_2);
  +        assertNotNull(obj_2);
  +        tx.begin();
  +        tx.lock(obj_2, Transaction.WRITE);
  +        references = obj_2.getAllReferences();
  +        CollectionReference ref = (CollectionReference) references.get(0);
  +        tx.lock(ref, Transaction.WRITE);
  +        ref.setRefName(nameRef+"_update");
  +        tx.commit();
  +
  +        obj_2 = (MainObject) broker.getObjectByIdentity(oid_2);
  +        assertNotNull(obj_2);
  +        references = obj_2.getAllReferences();
  +        ref = (CollectionReference) references.get(0);
  +        assertEquals(nameRef+"_update", ref.getRefName());
  +        assertEquals(id_1, obj_1.getIdentifier());
  +        assertEquals(id_2, obj_2.getIdentifier());
  +    }
  +
  +    public void testDelete_1() throws Exception
  +    {
  +        // prepare for PB-api test
  +        changeAutoSetting(MainObject.class, "singleReference", true, true, true, false);
  +        changeAutoSetting(MainObject.class, "allReferences", true, true, true, false);
  +        changeAutoSetting(CollectionReference.class, "singleReference", true, true, true,
false);
  +        changeAutoSetting(SingleReference.class, "mainObject", true, true, true, false);
  +        doTestDelete();
  +    }
  +
  +    public void testDelete_2() throws Exception
  +    {
  +        // prepare for PB-api test
  +        changeAutoSetting(MainObject.class, "singleReference", true, true, true, true);
  +        changeAutoSetting(MainObject.class, "allReferences", true, true, true, true);
  +        changeAutoSetting(CollectionReference.class, "singleReference", true, true, true,
true);
  +        changeAutoSetting(SingleReference.class, "mainObject", true, true, true, true);
  +        doTestDelete();
  +    }
  +
  +    public void doTestDelete() throws Exception
  +    {
  +        if (skipTest()) return;
  +
  +        long timestamp = System.currentTimeMillis();
           String name = "testDelete_main_" + timestamp;
           String nameRef = "testDelete_reference_" + timestamp;
   
  @@ -467,12 +743,32 @@
           assertEquals(0, result_2);
       }
   
  -    public void testDelete_2() throws Exception
  +    public void testDeleteTwo_1() throws Exception
  +    {
  +        // prepare for PB-api test
  +        changeAutoSetting(MainObject.class, "singleReference", true, true, true, false);
  +        changeAutoSetting(MainObject.class, "allReferences", true, true, true, false);
  +        changeAutoSetting(CollectionReference.class, "singleReference", true, true, true,
false);
  +        changeAutoSetting(SingleReference.class, "mainObject", true, true, true, false);
  +        doTestDeleteTwo();
  +    }
  +
  +    public void testDeleteTwo_2() throws Exception
  +    {
  +        // prepare for PB-api test
  +        changeAutoSetting(MainObject.class, "singleReference", true, true, true, true);
  +        changeAutoSetting(MainObject.class, "allReferences", true, true, true, true);
  +        changeAutoSetting(CollectionReference.class, "singleReference", true, true, true,
true);
  +        changeAutoSetting(SingleReference.class, "mainObject", true, true, true, true);
  +        doTestDeleteTwo();
  +    }
  +
  +    public void doTestDeleteTwo() throws Exception
       {
           if (skipTest()) return;
  -        long timestamp = (long) (System.currentTimeMillis() * Math.random());
  -        String name = "testDelete_2_main_" + timestamp;
  -        String nameRef = "testDelete_2_reference_" + timestamp;
  +        long timestamp = System.currentTimeMillis();
  +        String name = "testDeleteTwo_main_" + timestamp;
  +        String nameRef = "testDeleteTwo_reference_" + timestamp;
   
           MainObject obj_1 = new MainObject(null, name);
   
  @@ -528,19 +824,74 @@
           crit_2.addEqualTo("refName", nameRef);
           QueryByCriteria query_2 = QueryFactory.newQuery(CollectionReference.class, crit_2);
           int result_2 = broker.getCount(query_2);
  -        // System.out.println("## result: "+broker.getCollectionByQuery(query_2));
           assertEquals(0, result_2);
       }
   
  +//    public void testAllInOne() throws Exception
  +//    {
  +//        // sleep thread to make timestamp based tests work
  +//        testSimpleInsert();
  +//        ojbSleep();
  +//        ojbSleep();
  +//        testSimpleInsert();
  +//        ojbSleep();
  +//        ojbSleep();
  +//        testReferenceInsertUpdate();
  +//        ojbSleep();
  +//        ojbSleep();
  +//        // testReferenceInsertUpdate_2();
  +//        ojbSleep();
  +//        ojbSleep();
  +//        testReferenceInsertUpdate();
  +//    }
   
  +    void changeAutoSetting(Class clazz, String referenceField, boolean autoRetrieve, int
autoUpdate, int autoDelete, boolean useProxy)
  +    {
  +        ClassDescriptor cld = broker.getClassDescriptor(clazz);
  +        ObjectReferenceDescriptor ref = cld.getCollectionDescriptorByName(referenceField);
  +        if(ref == null) ref = cld.getObjectReferenceDescriptorByName(referenceField);
  +        ref.setLazy(useProxy);
  +        ref.setCascadeRetrieve(autoRetrieve);
  +        ref.setCascadingStore(autoUpdate);
  +        ref.setCascadingDelete(autoDelete);
  +    }
   
  -    public static class MainObject implements Serializable
  +    void changeAutoSetting(Class clazz, String referenceField, boolean autoRetrieve, boolean
autoUpdate, boolean autoDelete, boolean useProxy)
  +    {
  +        ClassDescriptor cld = broker.getClassDescriptor(clazz);
  +        ObjectReferenceDescriptor ref = cld.getCollectionDescriptorByName(referenceField);
  +        if(ref == null) ref = cld.getObjectReferenceDescriptorByName(referenceField);
  +        ref.setLazy(useProxy);
  +        ref.setCascadeRetrieve(autoRetrieve);
  +        ref.setCascadeStore(autoUpdate);
  +        ref.setCascadeDelete(autoDelete);
  +    }
  +
  +
  +    //========================================================================
  +    // inner classes, used for test
  +    //========================================================================
  +
  +    public static interface MainObjectIF extends Serializable
  +    {
  +        public SingleReferenceIF getSingleReference();
  +        public void setSingleReference(SingleReferenceIF singleReference);
  +        public List getAllReferences();
  +        public void addReference(CollectionReference reference);
  +        public void setAllReferences(List allReferences);
  +        public Long getIdentifier();
  +        public void setIdentifier(Long identifier);
  +        public String getName();
  +        public void setName(String name);
  +    }
  +
  +    public static class MainObject implements MainObjectIF
       {
           private Long identifier;
           private String name;
           private List allReferences;
           // we use anonymous field for FK
  -        private SingleReference singleReference;
  +        private SingleReferenceIF singleReference;
   
   
           public MainObject()
  @@ -553,12 +904,12 @@
               this.name = name;
           }
   
  -        public SingleReference getSingleReference()
  +        public SingleReferenceIF getSingleReference()
           {
               return singleReference;
           }
   
  -        public void setSingleReference(SingleReference singleReference)
  +        public void setSingleReference(SingleReferenceIF singleReference)
           {
               this.singleReference = singleReference;
           }
  @@ -608,11 +959,21 @@
           }
       }
   
  -    public static class SingleReference
  +    public static interface SingleReferenceIF extends Serializable
  +    {
  +        public MainObjectIF getMainObject();
  +        public void setMainObject(MainObjectIF mainObject);
  +        public Long getId();
  +        public void setId(Long id);
  +        public String getName();
  +        public void setName(String name);
  +    }
  +
  +    public static class SingleReference implements SingleReferenceIF
       {
           Long id;
           String name;
  -        MainObject mainObject;
  +        MainObjectIF mainObject;
   
           public SingleReference()
           {
  @@ -625,12 +986,12 @@
               // id = new Long((long)(Math.random() * Integer.MAX_VALUE));
           }
   
  -        public MainObject getMainObject()
  +        public MainObjectIF getMainObject()
           {
               return mainObject;
           }
   
  -        public void setMainObject(MainObject mainObject)
  +        public void setMainObject(MainObjectIF mainObject)
           {
               this.mainObject = mainObject;
           }
  @@ -656,12 +1017,24 @@
           }
       }
   
  -    public static class CollectionReference implements Serializable
  +    public static interface CollectionReferenceIF extends Serializable
  +    {
  +        public Long getRefIdentifier();
  +        public void setRefIdentifier(Long refIdentifier);
  +        public SingleReferenceIF getSingleReference();
  +        public void setSingleReference(SingleReferenceIF singleReference);
  +        public Long getFkIdentifier();
  +        public void setFkIdentifier(Long fkIdentifier);
  +        public String getRefName();
  +        public void setRefName(String refName);
  +    }
  +
  +    public static class CollectionReference implements CollectionReferenceIF
       {
           private Long refIdentifier;
           private String refName;
           private Long fkIdentifier;
  -        private SingleReference singleReference;
  +        private SingleReferenceIF singleReference;
   
           public CollectionReference()
           {
  @@ -683,12 +1056,12 @@
               this.refIdentifier = refIdentifier;
           }
   
  -        public SingleReference getSingleReference()
  +        public SingleReferenceIF getSingleReference()
           {
               return singleReference;
           }
   
  -        public void setSingleReference(SingleReference singleReference)
  +        public void setSingleReference(SingleReferenceIF singleReference)
           {
               this.singleReference = singleReference;
           }
  
  
  
  No                   revision
  No                   revision
  1.7.2.1   +10 -10    db-ojb/src/test/org/apache/ojb/repository_junit_meta_seq.xml
  
  Index: repository_junit_meta_seq.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit_meta_seq.xml,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- repository_junit_meta_seq.xml	4 Jun 2004 16:02:44 -0000	1.7
  +++ repository_junit_meta_seq.xml	29 Jul 2004 06:34:43 -0000	1.7.2.1
  @@ -543,8 +543,8 @@
           class-ref="org.apache.ojb.broker.sequence.NativeIdentifierTest$SingleReference"
           proxy="false"
           auto-retrieve="true"
  -        auto-update="true"
  -        auto-delete="true">
  +        auto-update="false"
  +        auto-delete="false">
               <foreignkey field-ref="refFK"/>
         </reference-descriptor>
   
  @@ -552,8 +552,8 @@
            name="allReferences"
            element-class-ref="org.apache.ojb.broker.sequence.NativeIdentifierTest$CollectionReference"
            auto-retrieve="true"
  -         auto-update="true"
  -         auto-delete="true"
  +         auto-update="false"
  +         auto-delete="false"
         >
            <orderby name="refIdentifier" sort="DESC"/>
            <inverse-foreignkey field-ref="fkIdentifier"/>
  @@ -600,8 +600,8 @@
           class-ref="org.apache.ojb.broker.sequence.NativeIdentifierTest$SingleReference"
           proxy="false"
           auto-retrieve="true"
  -        auto-update="true"
  -        auto-delete="true">
  +        auto-update="false"
  +        auto-delete="false">
               <foreignkey field-ref="singleRefFK"/>
         </reference-descriptor>
       </class-descriptor>
  @@ -639,9 +639,9 @@
           name="mainObject"
           class-ref="org.apache.ojb.broker.sequence.NativeIdentifierTest$MainObject"
           proxy="false"
  -        auto-retrieve="false"
  -        auto-update="true"
  -        auto-delete="true">
  +        auto-retrieve="true"
  +        auto-update="false"
  +        auto-delete="false">
               <foreignkey field-ref="refFK"/>
         </reference-descriptor>
       </class-descriptor>
  
  
  

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