db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r422241 - in /db/ojb/trunk/src/test/org/apache/ojb/odmg: ./ shared/
Date Sat, 15 Jul 2006 14:54:39 GMT
Author: arminw
Date: Sat Jul 15 07:54:38 2006
New Revision: 422241

URL: http://svn.apache.org/viewvc?rev=422241&view=rev
Log:
merge trunk with 1.0.x

Modified:
    db/ojb/trunk/src/test/org/apache/ojb/odmg/DMapTest.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/DSetTest.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/FieldConversionTest_4.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/InheritanceMultipleTableTest.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/LockingTest.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/ManyToManyTest.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/NamedRootsTest.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/ODMGRollbackTest.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/OQLOrOnForeignKeyTest.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/OQLTest.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/ObjectImageTest.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/OdmgExamples.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/PersonWithArrayTest.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/RITest.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/ScrollableQueryResultsTest.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/UserTestCases.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/shared/Article.java
    db/ojb/trunk/src/test/org/apache/ojb/odmg/shared/ProductGroup.java

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/DMapTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/DMapTest.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/DMapTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/DMapTest.java Sat Jul 15 07:54:38 2006
@@ -4,8 +4,6 @@
 import org.apache.ojb.junit.ODMGTestCase;
 import org.apache.ojb.odmg.shared.Article;
 import org.apache.ojb.odmg.shared.ProductGroup;
-import org.apache.ojb.odmg.collections.DMapExt;
-import org.apache.commons.lang.SerializationUtils;
 import org.odmg.DMap;
 import org.odmg.Transaction;
 
@@ -33,7 +31,7 @@
         Transaction tx = odmg.newTransaction();
         tx.begin();
         productGroup = new ProductGroup();
-        productGroup.setName("DMapTest_" + System.currentTimeMillis() + "_");
+        productGroup.setGroupName("DMapTest_" + System.currentTimeMillis() + "_");
         database.makePersistent(productGroup);
         tx.commit();
     }
@@ -42,7 +40,7 @@
     {
 
         Article a = new Article();
-        a.setArticleName(productGroup.getName() + name);
+        a.setArticleName(productGroup.getGroupName() + name);
         a.setStock(234);
         a.setProductGroup(productGroup);
         return a;
@@ -158,62 +156,5 @@
         val2A = (Article) mapA.get(key2);
         assertNull(val2A);
         tx.commit();
-    }
-
-    /**
-     * current implementation doesn't support serialized objects,
-     * the DMap interface doesn't extend Serializable
-     * @throws Exception
-     */
-    public void YYYtestSerialize() throws Exception
-    {
-        String name = "testSerialize";
-        String namedObject = "testSerialize_" + System.currentTimeMillis();
-        TransactionExt tx = (TransactionExt) odmg.newTransaction();
-
-        tx.begin();
-        DMap map = odmg.newDMap();
-
-        database.bind(map, namedObject);
-        Article key1 = createArticle(name + "_key1");
-        Article val1 = createArticle(name + "_val1");
-        Article key2 = createArticle(name + "_key2");
-        Article val2 = createArticle(name + "_val2");
-
-        map.put(key1, val1);
-        map.put(key2, val2);
-        tx.commit();
-
-
-        tx = (TransactionExt) odmg.newTransaction();
-        tx.begin();
-        tx.getBroker().clearCache();
-
-        DMapExt mapA = (DMapExt) database.lookup(namedObject);
-        assertNotNull(mapA);
-        Article val1A = (Article) mapA.get(key1);
-        assertNotNull(val1A);
-        assertEquals(val1.getArticleId(), val1A.getArticleId());
-        Article val2A = (Article) mapA.get(key2);
-        assertNotNull(val2A);
-        assertEquals(val2.getArticleId(), val2A.getArticleId());
-        tx.commit();
-
-        // serialize object
-        mapA = (DMapExt) SerializationUtils.clone(mapA);
-        tx.begin();
-        tx.lock(mapA, Transaction.WRITE);
-        mapA.remove(key1);
-        tx.commit();
-
-        tx.begin();
-        mapA = (DMapExt) database.lookup(namedObject);
-        tx.commit();
-        assertNotNull(mapA);
-        val1A = (Article) mapA.get(key1);
-        assertNull(val1A);
-        val2A = (Article) mapA.get(key2);
-        assertNotNull(val2A);
-        assertEquals(val2.getArticleId(), val2A.getArticleId());
     }
 }

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/DSetTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/DSetTest.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/DSetTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/DSetTest.java Sat Jul 15 07:54:38 2006
@@ -104,7 +104,7 @@
         lookedUp = (DSet) database.lookup(name);
         iter = lookedUp.iterator();
         iter1 = list.iterator();
-        assertEquals("Wrong number of DListEntry found", 8, list.size());
+        assertEquals("Wrong number of DListEntry found", list.size(), lookedUp.size());
         while (iter.hasNext())
         {
             DListTest.DObject a = (DListTest.DObject) iter.next();

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/FieldConversionTest_4.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/FieldConversionTest_4.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/FieldConversionTest_4.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/FieldConversionTest_4.java Sat Jul 15 07:54:38 2006
@@ -27,6 +27,57 @@
         junit.textui.TestRunner.main(arr);
     }
 
+    public void testSelfReferingParent() throws Exception
+    {
+        String strQuery = "select allNodes from " + Node.class.getName();
+        long id = System.currentTimeMillis();
+        Node node = new Node(id, null, true);
+        node.setParent(node);
+
+        List result;
+        int before;
+        TransactionExt tx = (TransactionExt) odmg.newTransaction();
+        try
+        {
+            tx.begin();
+
+            OQLQuery query = odmg.newOQLQuery();
+            query.create(strQuery);
+            result = (List) query.execute();
+            before = result.size();
+
+            database.makePersistent(node);
+            tx.commit();
+
+            tx.begin();
+            tx.getBroker().clearCache();
+            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 + 1, after);
+
+        tx.begin();
+        database.deletePersistent(node);
+        tx.commit();
+
+        OQLQuery query = odmg.newOQLQuery();
+        query.create(strQuery);
+        result = (List) query.execute();
+        after = result.size();
+        assertEquals(before, after);
+    }
+
     public void testMakePersistentNode() throws Exception
     {
         String strQuery = "select allNodes from " + Node.class.getName();
@@ -200,6 +251,16 @@
         public void setUid(long uid)
         {
             this.uid = uid;
+        }
+
+        public boolean isNodeState()
+        {
+            return nodeState;
+        }
+
+        public void setNodeState(boolean nodeState)
+        {
+            this.nodeState = nodeState;
         }
 
         public boolean isState()

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/InheritanceMultipleTableTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/InheritanceMultipleTableTest.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/InheritanceMultipleTableTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/InheritanceMultipleTableTest.java Sat Jul 15 07:54:38 2006
@@ -146,11 +146,6 @@
 
     public void testQuery_3() throws Exception
     {
-        if(ojbSkipKnownIssueProblem("References of classes (1:1, 1:n) mapped to multiple joined tables only" +
-                " return base class type instances, same thing with queries against a base type"))
-        {
-            return;
-        }
         long timestamp = System.currentTimeMillis();
         Long id_2 = new Long(timestamp);
         String name = "testInsert" + timestamp;
@@ -186,11 +181,6 @@
 
     public void testQuery_2() throws Exception
     {
-        if(ojbSkipKnownIssueProblem("References of classes (1:1, 1:n) mapped to multiple joined tables only" +
-                " return base class type instances, same thing with queries against a base type"))
-        {
-            return;
-        }
         long timestamp = System.currentTimeMillis();
         Long id_2 = new Long(timestamp);
         String name = "testInsert" + timestamp;
@@ -769,7 +759,7 @@
 
         long timestamp = System.currentTimeMillis();
         Long id_2 = new Long(timestamp);
-        String name = "testUpdate" + timestamp;
+        String name = "testDelete_" + timestamp;
         Employee em1 = new Employee(id_2, "employee_" + name);
         Executive ex1 = new Executive(id_2, "executive_" + name, "department_1", null);
         Executive ex2 = new Executive(id_2, "executive_" + name, "department_2", null);
@@ -819,6 +809,52 @@
         assertNull(newEm1);
         assertNull(newEx1);
         assertNull(newM1);
+    }
+
+    public void testDelete_2() throws Exception
+    {
+        // not all objects will be deleted
+        // arminw: fixed
+        // if (ojbSkipKnownIssueProblem()) return;
+
+        long timestamp = System.currentTimeMillis();
+        Long id_2 = new Long(timestamp);
+        String name = "testDelete_2_" + timestamp;
+        Manager m1 = new Manager(id_2, "manager_" + name);
+
+        TransactionExt tx = (TransactionExt) odmg.newTransaction();
+        tx.begin();
+        database.makePersistent(m1);
+        tx.commit();
+
+        tx.begin();
+        Identity m1_oid = tx.getBroker().serviceIdentity().buildIdentity(m1);
+        tx.getBroker().clearCache();
+        Manager newM1 = (Manager) tx.getBroker().getObjectByIdentity(m1_oid);
+        tx.commit();
+
+        assertNotNull(newM1);
+        //*************************************
+        tx.begin();
+        database.deletePersistent(newM1);
+        tx.commit();
+        //*************************************
+
+        tx.begin();
+        newM1 = (Manager) tx.getBroker().getObjectByIdentity(m1_oid);
+        tx.commit();
+
+        assertNull(newM1);
+
+        tx.begin();
+        OQLQuery query = odmg.newOQLQuery();
+        // search for entry in base class table, this should removed too
+        query.create("select m from " + Employee.class.getName() + " where name = $1");
+        query.bind(m1.getName());
+        Collection result = (Collection) query.execute();
+        tx.commit();
+
+        assertEquals(0, result.size());
     }
 
     //************************************************************

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java Sat Jul 15 07:54:38 2006
@@ -28,7 +28,7 @@
     // number of updates each thread performs against the object
     private final int objectUpdates = 30;
     // max number of attemps to get a lock
-    private static final int maxAttempts = 100;
+    private static final int maxAttempts = 150;
     private static final int nearMax = (int) (maxAttempts * 0.75);
 
 
@@ -66,6 +66,8 @@
         LockObject targetObject = createLockObjectWithRef();
         storeObject(targetObject);
 
+        System.out.println("** Start multithreaded lock test **");
+        Thread.sleep(500);
         TestCaseRunnable tct [] = new TestCaseRunnable[concurrentThreads];
         for (int i = 0; i < concurrentThreads; i++)
         {
@@ -83,6 +85,8 @@
         System.out.println("*** Result of multithreaded lock test ***");
         System.out.println(result.toString());
         //System.out.println(targetObject.getReference().getName());
+        String statistic = ((ImplementationImpl) odmg).getLockManager().getLockInfo();
+        System.out.println("Lock-Statistic: " + statistic);
     }
 
     private LockObject createLockObjectWithRef()

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/LockingTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/LockingTest.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/LockingTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/LockingTest.java Sat Jul 15 07:54:38 2006
@@ -8,6 +8,7 @@
 import org.apache.ojb.broker.PersistenceBroker;
 import org.apache.ojb.broker.PersistenceBrokerFactory;
 import org.apache.ojb.broker.TestHelper;
+import org.apache.ojb.broker.Identity;
 import org.apache.ojb.broker.query.Criteria;
 import org.apache.ojb.broker.query.QueryFactory;
 import org.apache.ojb.junit.OJBTestCase;
@@ -71,6 +72,11 @@
         super.tearDown();
     }
 
+    protected Identity createIdentity(TransactionImpl tx, Object obj)
+    {
+        return tx.getBrokerInternal().serviceIdentity().buildIdentity(obj);
+    }
+
     public void testWrite_1() throws Exception
     {
         String name = "testWrite_1_" + System.currentTimeMillis();
@@ -222,10 +228,10 @@
         tx1.begin();
         tx2.begin();
         LockManager lm = ((ImplementationExt) odmg1).getLockManager();
-        boolean success1 = lm.writeLock(tx1, a);
-        boolean success2 = lm.writeLock(tx2, a);
+        boolean success1 = lm.writeLock(tx1, createIdentity(tx1, a));
+        boolean success2 = lm.writeLock(tx2, createIdentity(tx2, a));
 
-        boolean success3 = lm.releaseLock(tx1, a);
+        boolean success3 = lm.releaseLock(tx1, createIdentity(tx1, a));
 
         assertTrue("1st lock should succeed", success1);
         assertTrue("2nd lock should not succeed", !success2);
@@ -258,19 +264,19 @@
 
         assertFalse(tx1.getGUID().equals(tx2.getGUID()));
 
-        assertTrue("1st lock should succeed", lm.writeLock(tx1, a1));
-        assertFalse("2nd lock should not succeed", lm.writeLock(tx2, a2));
-        lm.releaseLock(tx2, a2);
-        lm.releaseLock(tx2, a1);
-        assertFalse(lm.checkWrite(tx2, a1));
-        assertFalse(lm.checkWrite(tx2, a2));
-        assertTrue(lm.checkWrite(tx1, a1));
-        assertTrue(lm.checkWrite(tx1, a2));
+        assertTrue("1st lock should succeed", lm.writeLock(tx1, createIdentity(tx1, a1)));
+        assertFalse("2nd lock should not succeed", lm.writeLock(tx2, createIdentity(tx2, a2)));
+        lm.releaseLock(tx2, createIdentity(tx2, a2));
+        lm.releaseLock(tx2, createIdentity(tx1, a1));
+        assertFalse(lm.checkWrite(tx2, createIdentity(tx1, a1)));
+        assertFalse(lm.checkWrite(tx2, createIdentity(tx1, a2)));
+        assertTrue(lm.checkWrite(tx1, createIdentity(tx1, a1)));
+        assertTrue(lm.checkWrite(tx1, createIdentity(tx1, a2)));
         //assertFalse("2nd release should not succeed", lm.releaseLock(tx2, a2));
         //assertFalse("2nd release should not succeed", lm.releaseLock(tx2, a1));
-        assertTrue("release should succeed", lm.releaseLock(tx1, a2));
-        assertTrue("2nd object lock should succeed", lm.writeLock(tx2, a2));
-        assertTrue("release 2nd object lock should succeed", lm.releaseLock(tx2, a2));
+        assertTrue("release should succeed", lm.releaseLock(tx1, createIdentity(tx1, a2)));
+        assertTrue("2nd object lock should succeed", lm.writeLock(tx2, createIdentity(tx1, a2)));
+        assertTrue("release 2nd object lock should succeed", lm.releaseLock(tx2, createIdentity(tx1, a2)));
 
         try
         {
@@ -323,6 +329,45 @@
         }
     }
 
+    /**
+     * test proper treatment of Optimistic Locking in
+     * ODMG transactions
+     */
+    public void testOptimisticLockBasics_2() throws Exception
+    {
+        TransactionImpl tx1 = (TransactionImpl) odmg1.newTransaction();
+        TransactionImpl tx2 = (TransactionImpl) odmg2.newTransaction();
+
+        LockObjectOpt obj = new LockObjectOpt();
+
+
+        tx1.begin();
+
+        tx1.lock(obj, Transaction.WRITE);
+        obj.setValue("tx1");
+        tx1.commit();
+
+        obj.setVersion(obj.getVersion() - 1);
+        tx2.begin();
+        db2.deletePersistent(obj);
+        try
+        {
+            tx2.commit();
+// OL exceptions should be signalled as ODMG LockNotGrantedExceptions
+// so that users can react accordingly
+            fail("Optimistic locking exception expected");
+        }
+        catch(LockNotGrantedException ex)
+        {
+            assertTrue("expected that a OL exception is caught", true);
+        }
+        catch(Exception e)
+        {
+            e.printStackTrace();
+            fail("Wrong kind of exception thrown, expected 'LockNotGrantedException', but was " + e.getMessage());
+        }
+    }
+
 
     /**
      * factory method that createa an Article
@@ -361,13 +406,13 @@
             tx.lock(arr[i], Transaction.WRITE);
         }
         LockManager lm = ((ImplementationExt) odmg1).getLockManager();
-        boolean success = lm.writeLock(tx, arr[(loops - 2)]);
+        boolean success = lm.writeLock(tx, createIdentity(tx, arr[(loops - 2)]));
         assertTrue("lock should succeed", success);
         tx.commit();
 
         TransactionImpl tx2 = (TransactionImpl) odmg2.newTransaction();
         tx2.begin();
-        success = lm.writeLock(tx2, arr[(loops - 2)]);
+        success = lm.writeLock(tx2, createIdentity(tx2, arr[(loops - 2)]));
         assertTrue("lock should succeed", success);
 
         OQLQuery query = odmg2.newOQLQuery();

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/ManyToManyTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/ManyToManyTest.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/ManyToManyTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/ManyToManyTest.java Sat Jul 15 07:54:38 2006
@@ -169,8 +169,8 @@
     public void testMtoNTogether() throws Exception
     {
         long timestamp = System.currentTimeMillis();
-        Fish tuna = new Fish("tuna_" + timestamp, 242, "salt");
-        Fish trout = new Fish("trout_" + timestamp, 52, "fresh water");
+        Fish tuna = new Fish("tuna_2" + timestamp, 100, "salt_2");
+        Fish trout = new Fish("trout_2" + timestamp, 101, "fresh water_2");
 
         ODMGGourmet paula = new ODMGGourmet("a_testMtoNTogether");
         ODMGGourmet candy = new ODMGGourmet("b_testMtoNTogether");

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/NamedRootsTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/NamedRootsTest.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/NamedRootsTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/NamedRootsTest.java Sat Jul 15 07:54:38 2006
@@ -47,8 +47,8 @@
     private Article createArticle()
     {
         Article example = new Article();
-        example.setArticleName(testProductGroup.getName());
-        example.setProductGroupId(testProductGroup.getId());
+        example.setArticleName(testProductGroup.getGroupName());
+        example.setProductGroupId(testProductGroup.getGroupId());
         return example;
     }
 

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/ODMGRollbackTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/ODMGRollbackTest.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/ODMGRollbackTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/ODMGRollbackTest.java Sat Jul 15 07:54:38 2006
@@ -632,8 +632,9 @@
 
     protected void deleteAll(Implementation odmg, Class target) throws Exception
     {
-        Transaction tx = odmg.newTransaction();
+        TransactionExt tx = (TransactionExt) odmg.newTransaction();
         tx.begin();
+        tx.setCascadingDelete(target, true);
         OQLQuery query = odmg.newOQLQuery();
         query.create("select allObjects from " + target.getName());
         List list = (List) query.execute();

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/OQLOrOnForeignKeyTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/OQLOrOnForeignKeyTest.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/OQLOrOnForeignKeyTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/OQLOrOnForeignKeyTest.java Sat Jul 15 07:54:38 2006
@@ -1,6 +1,6 @@
 package org.apache.ojb.odmg;
 
-/* Copyright 2002-2004 The Apache Software Foundation
+/* Copyright 2002-2005 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/OQLTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/OQLTest.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/OQLTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/OQLTest.java Sat Jul 15 07:54:38 2006
@@ -179,7 +179,7 @@
         tx.commit();
 	}
 
-    public void testQueryIn() throws Exception
+	public void testQueryIn() throws Exception
 	{
 		// deleteData(database, odmg, Article.class);
 
@@ -654,6 +654,11 @@
             return age;
         }
 
+        public void setAge(int age)
+        {
+            this.age = age;
+        }
+
         public int getNumLegs()
         {
             return numLegs;
@@ -688,6 +693,11 @@
         public int getAge()
         {
             return age;
+        }
+
+        public void setAge(int age)
+        {
+            this.age = age;
         }
 
         public int getAnimalId()

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/ObjectImageTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/ObjectImageTest.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/ObjectImageTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/ObjectImageTest.java Sat Jul 15 07:54:38 2006
@@ -20,10 +20,15 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
+import java.util.Iterator;
 
 import org.apache.commons.lang.SerializationUtils;
+import org.apache.commons.lang.SystemUtils;
+import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.ojb.broker.Identity;
-import org.apache.ojb.broker.PersistenceBrokerInternal;
+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.core.proxy.CollectionProxy;
 import org.apache.ojb.broker.core.proxy.CollectionProxyListener;
 import org.apache.ojb.broker.core.proxy.IndirectionHandler;
@@ -42,15 +47,270 @@
  *
  * Test cases for refactored odmg-api implementation. These tests asserts previously outstanding
  * ODMG-issues and proxy object handling in the ODMG API.
- * 
+ *
  * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
  * @version $Id$
  */
 public class ObjectImageTest extends ODMGTestCase
 {
+    static final int NONE = ObjectReferenceDescriptor.CASCADE_NONE;
+    static final int LINK = ObjectReferenceDescriptor.CASCADE_LINK;
+    static final int OBJECT = ObjectReferenceDescriptor.CASCADE_OBJECT;
+    static final String EOL = SystemUtils.LINE_SEPARATOR;
+
+    public static void main(String[] args)
+    {
+        junit.textui.TestRunner.main(new String[]{ObjectImageTest.class.getName()});
+    }
+
+    public void testReplaceOneToOneReference() throws Exception
+    {
+        String prefix = "testReplaceOneToOneReference_" + System.currentTimeMillis();
+        ojbChangeReferenceSetting(Book.class, "reviews", true, NONE, NONE, false);
+
+        TransactionExt tx = (TransactionExt) odmg.newTransaction();
+        tx.begin();
+        Book book = new Book(prefix, null, null);
+        Publisher p_1 = new PublisherImpl(prefix);
+        Publisher p_2 = new PublisherImpl(prefix + "_replaced");
+        book.setPublisher(p_1);
+        database.makePersistent(book);
+        database.makePersistent(p_1);
+        database.makePersistent(p_2);
+        tx.commit();
+
+        Integer book_version = book.getVersion();
+        Integer p1_version = p_1.getVersion();
+        Integer p2_version = p_2.getVersion();
+
+        tx.begin();
+        tx.lock(book, Transaction.WRITE);
+        tx.lock(book.getPublisher(), Transaction.READ);
+        tx.lock(p_2, Transaction.READ);
+        book.setPublisher(p_2);
+        tx.commit();
+
+        assertEquals(book_version.intValue() + 1, book.getVersion().intValue());
+        assertEquals(p1_version, p_1.getVersion());
+        assertEquals(p2_version, p_2.getVersion());
+    }
+
+    public void testAddCollectionObjectToExistingObject() throws Exception
+    {
+        String prefix = "testAddCollectionObjectToExistingObject_" + System.currentTimeMillis();
+        ojbChangeReferenceSetting(Book.class, "reviews", true, NONE, NONE, false);
+
+        TransactionExt tx = (TransactionExt) odmg.newTransaction();
+        tx.begin();
+        Book book = new Book(prefix, null, null);
+        Review r1 = new Review(prefix + "_1");
+        database.makePersistent(book);
+        database.makePersistent(r1);
+        tx.commit();
+
+        Integer book_version = book.getVersion();
+        Integer r_1_version = r1.getVersion();
+
+        Review r2 = new Review(prefix + "_2");
+        tx.begin();
+        tx.lock(r1, Transaction.WRITE);
+        tx.lock(book, Transaction.READ);
+        book.addReview(r1);
+        book.addReview(r2);
+        database.makePersistent(r2);
+        tx.commit();
+
+        assertEquals(book_version, book.getVersion());
+        assertTrue(book.getId() != null);
+
+        Integer r_2_version = r2.getVersion();
+
+        tx.begin();
+        tx.getBroker().clearCache();
+        Book loadedCopy = (Book) tx.getBroker().getObjectByIdentity(
+                tx.getBroker().serviceIdentity().buildIdentity(Book.class, book.getId()));
+        assertNotNull(loadedCopy);
+        assertNotNull(loadedCopy.getReviews());
+        assertEquals(2, loadedCopy.getReviews().size());
+        assertEquals(book_version, loadedCopy.getVersion());
+        Review new_r1 = (Review) loadedCopy.getReviews().get(0);
+        Review new_r2 = (Review) loadedCopy.getReviews().get(1);
+        assertEquals(r_1_version.intValue() + 1, new_r1.getVersion().intValue());
+        assertEquals(r_2_version, new_r2.getVersion());
+
+        tx.getBroker().clearCache();
+        Criteria criteria = new Criteria();
+        criteria.addLike("title", prefix);
+        Query q = QueryFactory.newQuery(Book.class, criteria);
+        Collection books = tx.getBroker().getCollectionByQuery(q);
+        assertNotNull(books);
+        assertEquals(1, books.size());
+        Book new_book = (Book) books.iterator().next();
+        tx.commit();
+        assertEquals(book_version, new_book.getVersion());
+
+        tx.begin();
+        tx.lock(loadedCopy, Transaction.WRITE);
+        Review removed = (Review) loadedCopy.getReviews().remove(0);
+        Review stayed =  (Review) loadedCopy.getReviews().get(0);
+        tx.commit();
+        // expect same version, nothing should be changed
+        assertEquals(r_2_version, stayed.getVersion());
+        //
+        //assertEquals(r_1_version, removed.getVersion());
+
+        tx.begin();
+        OQLQuery query = odmg.newOQLQuery();
+        query.create("select books from " + Book.class.getName() + " where title like $1");
+        query.bind(prefix);
+        Collection result = (Collection) query.execute();
+        assertEquals(1, result.size());
+        Book b = (Book) result.iterator().next();
+        tx.commit();
+
+        assertEquals(1, b.getReviews().size());
+        Review r = (Review) b.getReviews().get(0);
+        if(!r.equals(r1) && !r.equals(r2))
+        {
+            fail("Wrong object or wrong object version returned. Returned obj was "
+                    + EOL + r + " expected object was " + EOL + r1 + " or " + EOL + r2);
+        }
+    }
+
+    /**
+     * test persistence by reachability of collection reference objects
+     */
+    public void testPersistenceByReachability_1() throws Exception
+    {
+        String name = "testPersistenceByReachability_1_" + System.currentTimeMillis();
+        ojbChangeReferenceSetting(Book.class, "reviews", true, NONE, NONE, true);
+
+        Date date = new Date();
+        byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
+        Book book = new Book(name, date, cover);
+        Review r1 = new Review(name);
+        Review r2 = new Review(name);
+        Review r3 = new Review(name + "_not_persistent");
+        ArrayList reviews = new ArrayList();
+        reviews.add(r1);
+        reviews.add(r2);
+        reviews.add(r3);
+        book.setReviews(reviews);
+
+        TransactionExt tx = (TransactionExt) odmg.newTransaction();
+        tx.begin();
+        database.makePersistent(book);
+        Review r4 = new Review(name + "_new_added");
+        // add a new review after make persistent main object
+        book.addReview(r4);
+        tx.setCascadingDelete(Book.class, true);
+        // remove object after make persistent main object
+        book.removeReview(r3);
+        tx.commit();
+        // System.err.println("## Insert main object with 3 referecnes");
+
+        tx.begin();
+        tx.getBroker().clearCache();
+
+        OQLQuery query = odmg.newOQLQuery();
+        query.create("select books from " + Book.class.getName() + " where title like $1");
+        query.bind(name);
+        Collection result = (Collection) query.execute();
+        assertEquals(1, result.size());
+        Book b = (Book) result.iterator().next();
+        assertNotNull(b.getReviews());
+        assertEquals(3, b.getReviews().size());
+
+        query = odmg.newOQLQuery();
+        query.create("select reviews from " + Review.class.getName() + " where summary like $1");
+        query.bind(name + "_new_added");
+        result = (Collection) query.execute();
+        // we expect the delayed added Review object
+        assertEquals(1, result.size());
+
+        query = odmg.newOQLQuery();
+        query.create("select reviews from " + Review.class.getName() + " where summary like $1");
+        query.bind(name + "_not_persistent");
+        result = (Collection) query.execute();
+        // we expect the removed Review object wasn't persistet
+        assertEquals(0, result.size());
+        tx.commit();
+    }
+
+    /**
+     * test persistence by reachability of collection reference objects
+     */
+    public void testPersistenceByReachability_2() throws Exception
+    {
+        String name = "testPersistenceByReachability_2_" + System.currentTimeMillis();
+        ojbChangeReferenceSetting(Book.class, "reviews", true, NONE, NONE, true);
+
+        Date date = new Date();
+        byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
+        Book book = new Book(name, date, cover);
+        Review r1 = new Review(name);
+        Review r2 = new Review(name);
+        Review r3 = new Review(name + "_not_persistent");
+        ArrayList reviews = new ArrayList();
+        reviews.add(r1);
+        reviews.add(r2);
+        reviews.add(r3);
+        book.setReviews(reviews);
+
+        TransactionExt tx = (TransactionExt) odmg.newTransaction();
+        tx.begin();
+        database.makePersistent(book);
+        Review r4 = new Review(name + "_new_added");
+        // add a new review after make persistent main object
+        book.addReview(r4);
+        tx.setCascadingDelete(Book.class, true);
+        // remove object after make persistent main object
+        book.removeReview(r3);
+        tx.checkpoint();
+
+        //tx.begin();
+        tx.getBroker().clearCache();
+
+        OQLQuery query = odmg.newOQLQuery();
+        query.create("select books from " + Book.class.getName() + " where title like $1");
+        query.bind(name);
+        Collection result = (Collection) query.execute();
+        assertEquals(1, result.size());
+        Book b = (Book) result.iterator().next();
+        assertNotNull(b.getReviews());
+        assertEquals(3, b.getReviews().size());
+
+        query = odmg.newOQLQuery();
+        query.create("select reviews from " + Review.class.getName() + " where summary like $1");
+        query.bind(name + "_new_added%");
+        result = (Collection) query.execute();
+        // we expect the delayed added Review object
+        assertEquals(1, result.size());
+
+        query = odmg.newOQLQuery();
+        query.create("select reviews from " + Review.class.getName() + " where summary like $1");
+        query.bind(name + "_not_persistent");
+        result = (Collection) query.execute();
+        // we expect the removed Review object wasn't persistet
+        assertEquals(0, result.size());
+
+        b.setTitle(name + "_updated");
+        tx.commit();
+
+        query = odmg.newOQLQuery();
+        query.create("select books from " + Book.class.getName() + " where title like $1");
+        query.bind(name + "_updated");
+        result = (Collection) query.execute();
+        assertEquals(1, result.size());
+        Book b_updated = (Book) result.iterator().next();
+        assertNotNull(b_updated.getReviews());
+        assertEquals(3, b_updated.getReviews().size());
+        assertEquals(name+"_updated", b_updated.getTitle());
+    }
+
     public void testAddPersistentObjectTo1toN() throws Exception
     {
-        String name = "testAddPersistentObjectOnNSide_" + System.currentTimeMillis();
+        String name = "testAddPersistentObjectTo1toN_" + System.currentTimeMillis();
         Review review = new Review(name);
         TransactionExt tx = (TransactionExt) odmg.newTransaction();
         tx.begin();
@@ -87,7 +347,7 @@
 
     public void testAddPersistentObjectToMtoN() throws Exception
     {
-        String name = "testAddPersistentObjectOnNSide_" + System.currentTimeMillis();
+        String name = "testAddPersistentObjectToMtoN_" + System.currentTimeMillis();
         Author author = new Author(name, null);
         TransactionExt tx = (TransactionExt) odmg.newTransaction();
         tx.begin();
@@ -265,9 +525,8 @@
     public void testChangeOneToOneReference_1b() throws Exception
     {
         String name = "testChangeOneToOneReference_1b_" + System.currentTimeMillis();
-        ojbChangeReferenceSetting(Book.class, "publisher", true,
-                ObjectReferenceDescriptor.CASCADE_LINK,
-                ObjectReferenceDescriptor.CASCADE_LINK, true);
+        ojbChangeReferenceSetting(Book.class, "publisher", true, NONE, NONE, true);
+
         Date date = new Date();
         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
         Book book = new Book(name, date, cover);
@@ -445,9 +704,7 @@
      */
     public void testChangeOneToOneReference_4() throws Exception
     {
-        ojbChangeReferenceSetting(Book.class, "publisher", true,
-                ObjectReferenceDescriptor.CASCADE_LINK,
-                ObjectReferenceDescriptor.CASCADE_LINK, true);
+        ojbChangeReferenceSetting(Book.class, "publisher", true, NONE, NONE, true);
         String name = "testChangeOneToOneReference_4_" + System.currentTimeMillis();
         Date date = new Date();
         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
@@ -470,7 +727,7 @@
         Collection result = (Collection) query.execute();
         assertEquals(1, result.size());
         Book b = (Book) result.iterator().next();
-        IndirectionHandler handler = ((PersistenceBrokerInternal)tx.getBroker()).getProxyFactory().getIndirectionHandler(b.getPublisher());
+        IndirectionHandler handler = getProxyFactory(tx).getIndirectionHandler(b.getPublisher());
         assertNotNull(handler);
         assertFalse(handler.alreadyMaterialized());
         handler.addListener(
@@ -497,9 +754,7 @@
      */
     public void testChangeOneToOneReference_5() throws Exception
     {
-        ojbChangeReferenceSetting(Book.class, "publisher", true,
-                ObjectReferenceDescriptor.CASCADE_LINK,
-                ObjectReferenceDescriptor.CASCADE_LINK, true);
+        ojbChangeReferenceSetting(Book.class, "publisher", true, NONE, NONE, true);
         String name = "testChangeOneToOneReference_5_" + System.currentTimeMillis();
         Date date = new Date();
         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
@@ -524,7 +779,7 @@
         Collection result = (Collection) query.execute();
         assertEquals(1, result.size());
         Book b = (Book) result.iterator().next();
-        IndirectionHandler handler = ((PersistenceBrokerInternal)tx.getBroker()).getProxyFactory().getIndirectionHandler(b.getPublisher());
+        IndirectionHandler handler = getProxyFactory(tx).getIndirectionHandler(b.getPublisher());
         assertNotNull(handler);
         assertFalse(handler.alreadyMaterialized());
         handler.addListener(
@@ -564,6 +819,7 @@
         assertEquals(1, result.size());
         b = (Book) result.iterator().next();
         Publisher newP = b.getPublisher();
+        assertNotNull(newP);
         assertEquals(name+"_new", newP.getName());
     }
 
@@ -783,10 +1039,7 @@
     public void testCollectionReference_1() throws Exception
     {
         String name = "testCollectionReference_1_" + System.currentTimeMillis();
-
-        ojbChangeReferenceSetting(Book.class, "reviews", true,
-                ObjectReferenceDescriptor.CASCADE_LINK,
-                ObjectReferenceDescriptor.CASCADE_NONE, true);
+        ojbChangeReferenceSetting(Book.class, "reviews", true, NONE, NONE, true);
 
         Date date = new Date();
         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
@@ -814,7 +1067,7 @@
         Collection result = (Collection) query.execute();
         assertEquals(1, result.size());
         Book b = (Book) result.iterator().next();
-        CollectionProxy handler = ((PersistenceBrokerInternal)tx.getBroker()).getProxyFactory().getCollectionProxy(b.getReviews());
+        CollectionProxy handler = getProxyFactory(tx).getCollectionProxy(b.getReviews());
         assertFalse("Don't expect an materialized collection proxy", handler.isLoaded());
         handler.addListener(new CollectionProxyListener()
         {
@@ -920,9 +1173,7 @@
     {
         String name = "testCollectionReference_2b_" + System.currentTimeMillis();
 
-        ojbChangeReferenceSetting(Book.class, "reviews", true,
-                ObjectReferenceDescriptor.CASCADE_LINK,
-                ObjectReferenceDescriptor.CASCADE_NONE, true);
+        ojbChangeReferenceSetting(Book.class, "reviews", true, NONE, NONE, true);
 
         Date date = new Date();
         byte[] cover = new byte[]{2,3,4,5,6,7,8,9};
@@ -1357,8 +1608,18 @@
         assertNotNull(b.getAuthors());
         assertEquals(2, b.getAuthors().size());
         Author newA = (Author) b.getAuthors().get(0);
-        // as we have circular references we expect the same object instance
-        assertTrue(newA==((Review) b.getReviews().get(0)).getAuthor());
+        boolean failed = true;
+        for(Iterator iterator = b.getReviews().iterator(); iterator.hasNext();)
+        {
+            Review review =  (Review) iterator.next();
+            if(newA.equals(review.getAuthor()))
+            {
+                // as we have circular references we expect the same object instance
+                assertSame(newA, review.getAuthor());
+                failed = false;
+            }
+        }
+        if(failed) fail("Expect the same object instance, but not found for " + newA);
 
         // Book instance should be already locked
         // now mark Book for delete and disable cascading delete
@@ -1396,11 +1657,6 @@
         assertEquals(0, result.size());
     }
 
-    public static void main(String[] args)
-    {
-        junit.textui.TestRunner.main(new String[]{ObjectImageTest.class.getName()});
-    }
-
     //=======================================================
     // inner test classes
     //=======================================================
@@ -1445,6 +1701,12 @@
             reviews.add(review);
         }
 
+        public boolean removeReview(Review review)
+        {
+            if(reviews != null) return reviews.remove(review);
+            else return false;
+        }
+
         public Integer getId()
         {
             return id;
@@ -1714,6 +1976,23 @@
         public void setAuthor(Author author)
         {
             this.author = author;
+        }
+
+        public boolean equals(Object obj)
+        {
+            boolean result = false;
+            if(obj instanceof Review)
+            {
+                Review other = (Review) obj;
+                result = new EqualsBuilder()
+                        .append(id, other.id)
+                        .append(summary, other.summary)
+                        .append(version, other.version)
+                        .append(fkBook, other.fkBook)
+                        .append(author, other.author)
+                        .isEquals();
+            }
+            return result;
         }
     }
 

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/OdmgExamples.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/OdmgExamples.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/OdmgExamples.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/OdmgExamples.java Sat Jul 15 07:54:38 2006
@@ -4,8 +4,9 @@
 
 import org.apache.ojb.broker.Identity;
 import org.apache.ojb.broker.PersistenceBroker;
+import org.apache.ojb.broker.TestHelper;
 import org.apache.ojb.broker.metadata.ClassDescriptor;
-import org.apache.ojb.junit.ODMGTestCase;
+import org.apache.ojb.junit.OJBTestCase;
 import org.apache.ojb.odmg.collections.DListImpl;
 import org.apache.ojb.odmg.shared.Article;
 import org.apache.ojb.odmg.shared.ProductGroup;
@@ -22,7 +23,7 @@
 /** Demo Application that shows basic concepts for Applications using the OJB ODMG
  * implementation as an transactional object server.
  */
-public class OdmgExamples extends ODMGTestCase
+public class OdmgExamples extends OJBTestCase
 {
     public static void main(String[] args)
     {
@@ -30,24 +31,38 @@
         junit.textui.TestRunner.main(arr);
     }
 
+    private String databaseName;
+
     public OdmgExamples(String name)
     {
         super(name);
     }
 
-    public void setUp() throws Exception
+    public void setUp()
     {
-        super.setUp();
+        databaseName = TestHelper.DEF_DATABASE_NAME;
     }
 
-    public void tearDown() throws Exception
+    public void tearDown()
     {
-        super.tearDown();
+        databaseName = null;
     }
 
     /**TestThreadsNLocks state transition of modification states*/
     public void testModificationStates()
     {
+        // get facade instance
+        Implementation odmg = OJB.getInstance();
+        Database db = odmg.newDatabase();
+        //open database
+        try
+        {
+            db.open(databaseName, Database.OPEN_READ_WRITE);
+        }
+        catch (ODMGException ex)
+        {
+            fail("ODMGException: " + ex.getMessage());
+        }
         ModificationState oldState = StateNewClean.getInstance();
         ModificationState newState = oldState.markDirty();
         assertEquals(StateNewDirty.getInstance(), newState);
@@ -55,10 +70,33 @@
         oldState = newState;
         newState = oldState.markDirty();
         assertEquals(oldState, newState);
+
+        // close database
+        try
+        {
+            db.close();
+        }
+        catch (ODMGException ex)
+        {
+            fail("ODMGException: " + ex.getMessage());
+        }
+
     }
 
     public void testOdmgSession()
     {
+        // get facade instance
+        Implementation odmg = OJB.getInstance();
+        Database db = odmg.newDatabase();
+        //open database
+        try
+        {
+            db.open(databaseName, Database.OPEN_READ_WRITE);
+        }
+        catch (ODMGException ex)
+        {
+            fail("ODMGException: " + ex.getMessage());
+        }
         Transaction tx = odmg.newTransaction();
 
         //perform transaction
@@ -67,11 +105,11 @@
             tx.begin();
 
             ProductGroup pg = new ProductGroup();
-            pg.setName("PG A");
+            pg.setGroupName("PG A");
             Article example = new Article();
             example.setProductGroup(pg);
             pg.addArticle(example);
-            database.makePersistent(pg);
+            db.makePersistent(pg);
 
             // modify Object after persist call is allowed
             example.setStock(333);
@@ -86,10 +124,32 @@
         {
             tx.abort();
         }
+
+        // close database
+        try
+        {
+            db.close();
+        }
+        catch (ODMGException ex)
+        {
+            fail("ODMGException: " + ex.getMessage());
+        }
     }
 
     public void testOQLQuery()
     {
+        // get facade instance
+        Implementation odmg = OJB.getInstance();
+        Database db = odmg.newDatabase();
+        //open database
+        try
+        {
+            db.open(databaseName, Database.OPEN_READ_WRITE);
+        }
+        catch (ODMGException ex)
+        {
+            fail("ODMGException: " + ex.getMessage());
+        }
         Transaction tx = odmg.newTransaction();
 
         //perform transaction
@@ -107,7 +167,7 @@
             // 1. get OID
             Article example = new Article();
             example.setArticleId(60);
-            Identity oid = new Identity(example, ((TransactionImpl) tx).getBroker());
+            Identity oid = ((TransactionExt) tx).getBroker().serviceIdentity().buildIdentity(example);
             // 2. lookup object by OID
             PersistenceBroker broker = ((TransactionImpl) tx).getBroker();
             broker.clearCache();
@@ -123,10 +183,32 @@
             tx.abort();
             fail("ODMGException: " + ex.getMessage());
         }
+
+        // close database
+        try
+        {
+            db.close();
+        }
+        catch (ODMGException ex)
+        {
+            fail("ODMGException: " + ex.getMessage());
+        }
     }
 
     public void testPathExpressionOqlQuery() throws Exception
     {
+        // get facade instance
+        Implementation odmg = OJB.getInstance();
+        Database db = odmg.newDatabase();
+        //open database
+        try
+        {
+            db.open(databaseName, Database.OPEN_READ_WRITE);
+        }
+        catch (ODMGException ex)
+        {
+            fail("ODMGException: " + ex.getMessage());
+        }
         Transaction tx = odmg.newTransaction();
 
         // perform transaction
@@ -147,14 +229,32 @@
                     "select aPG from " + ProductGroup.class.getName() + " where groupName like \"Fruit*\"");
         ProductGroup pg = (ProductGroup) check.get(0);
 
-        assertEquals(pg.getAllArticlesInGroup().size(), results.size());
         assertTrue((results.size() > 0));
+        assertNotNull(pg.getAllArticlesInGroup());
+        assertEquals(pg.getAllArticlesInGroup().size(), results.size());
 
         tx.commit();
+
+
+        // close database
+
+        db.close();
     }
 
     public void testNrmAndDlists() throws Exception
     {
+        // get facade instance
+        Implementation odmg = OJB.getInstance();
+        Database db = odmg.newDatabase();
+        //open database
+        try
+        {
+            db.open(databaseName, Database.OPEN_READ_WRITE);
+        }
+        catch (ODMGException ex)
+        {
+            fail("ODMGException: " + ex.getMessage());
+        }
         Transaction tx = odmg.newTransaction();
 
         //perform transaction
@@ -162,7 +262,7 @@
         {
             //=============================
             // this test needs DList impl as oql query collection class
-            odmg.setOqlCollectionClass(DListImpl.class);
+            ((ImplementationImpl) odmg).setOqlCollectionClass(DListImpl.class);
             //=============================
 
             tx.begin();
@@ -178,7 +278,7 @@
 
             String name = "gimme fruits_" + System.currentTimeMillis();
 
-            database.bind(results, name);
+            db.bind(results, name);
             tx.commit();
 
             tx = odmg.newTransaction();
@@ -187,7 +287,7 @@
             ((TransactionImpl) tx).getBroker().clearCache();
 
             // look it up again
-            List newResults = (List) database.lookup(name);
+            List newResults = (List) db.lookup(name);
 
             assertEquals(originalSize, newResults.size());
             Article art = (Article) newResults.get(0);
@@ -203,10 +303,32 @@
             tx.abort();
             throw e;
         }
+
+        // close database
+        try
+        {
+            db.close();
+        }
+        catch (ODMGException ex)
+        {
+            fail("ODMGException: " + ex.getMessage());
+        }
     }
 
     public void testOQLQueryBind()
     {
+        // get facade instance
+        Implementation odmg = OJB.getInstance();
+        Database db = odmg.newDatabase();
+        //open database
+        try
+        {
+            db.open(databaseName, Database.OPEN_READ_WRITE);
+        }
+        catch (ODMGException ex)
+        {
+            fail("ODMGException: " + ex.getMessage());
+        }
         Transaction tx = odmg.newTransaction();
 
         //perform transaction
@@ -226,7 +348,7 @@
             // 1. get OID
             Article example = new Article();
             example.setArticleId(30);
-            Identity oid = new Identity(example, ((TransactionImpl) tx).getBroker());
+            Identity oid = ((TransactionImpl) tx).getBroker().serviceIdentity().buildIdentity(example);
 
             // 2. lookup object by OID
             PersistenceBroker broker = ((TransactionImpl) tx).getBroker();
@@ -244,32 +366,55 @@
             tx.abort();
             fail("ODMGException: " + ex.getMessage());
         }
+
+        // close database
+        try
+        {
+            db.close();
+        }
+        catch (ODMGException ex)
+        {
+            fail("ODMGException: " + ex.getMessage());
+        }
     }
 
     public void YYYtestOQLQueryOnCollections() throws Exception
     {
+        // get facade instance
+        Implementation odmg = OJB.getInstance();
+        Database db = odmg.newDatabase();
+        //open database
+        db.open(databaseName, Database.OPEN_READ_WRITE);
         Transaction tx = odmg.newTransaction();
 
         //perform transaction
-        tx.begin();
-        OQLQuery query = odmg.newOQLQuery();
-        query.create("select aLotOfArticles from " + Article.class.getName() + " where productGroupId = 4");
+        try
+        {
+            tx.begin();
+            OQLQuery query = odmg.newOQLQuery();
+            query.create("select aLotOfArticles from " + Article.class.getName() + " where productGroupId = 4");
 
-        DCollection results = (DCollection) query.execute();
-        results = results.query("price > 35");
+            DCollection results = (DCollection) query.execute();
+            results = results.query("price > 35");
 
-        // now perform control query
-        query = odmg.newOQLQuery();
-        query.create(
-                "select aLotOfArticles from "
-                + Article.class.getName()
-                + " where productGroupId = 4 and price  > 35");
+            // now perform control query
+            query = odmg.newOQLQuery();
+            query.create(
+                    "select aLotOfArticles from "
+                    + Article.class.getName()
+                    + " where productGroupId = 4 and price  > 35");
 
-        DCollection check = (DCollection) query.execute();
+            DCollection check = (DCollection) query.execute();
 
-        assertEquals(results, check);
+            assertEquals(results, check);
 
-        tx.commit();
+            tx.commit();
+        }
+                // close database
+        finally
+        {
+            db.close();
+        }
     }
 
     /**try to open non-existing db*/
@@ -288,18 +433,29 @@
         }
         catch (ODMGException ex)
         {
-            // expected exception
-            assertTrue(true);
+            return;
         }
     }
 
     /**try to crash odmg and broker tx*/
     public void YYYtestBrokerCrash()
     {
-        PersistenceBroker broker;
+        // get facade instance
+        Implementation odmg = OJB.getInstance();
+        Database db = odmg.newDatabase();
+        PersistenceBroker broker = null;
         ClassDescriptor cld = null;
         String tablename = null;
 
+        //open database
+        try
+        {
+            db.open(databaseName, Database.OPEN_READ_WRITE);
+        }
+        catch (ODMGException ex)
+        {
+            fail("ODMGException: " + ex.getMessage());
+        }
         try
         {
             Transaction tx = odmg.newTransaction();
@@ -330,7 +486,9 @@
         }
         finally
         {
-            if(tablename != null) cld.setTableName(tablename);
+            cld.setTableName(tablename);
+            broker.getDescriptorRepository().setClassDescriptor(cld);
         }
+
     }
 }

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/PersonWithArrayTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/PersonWithArrayTest.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/PersonWithArrayTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/PersonWithArrayTest.java Sat Jul 15 07:54:38 2006
@@ -8,10 +8,13 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 
 import org.apache.ojb.junit.ODMGTestCase;
 import org.apache.ojb.odmg.shared.Person;
 import org.apache.ojb.odmg.shared.PersonImpl;
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.collections.ListUtils;
 import org.odmg.OQLQuery;
 import org.odmg.Transaction;
 
@@ -262,10 +265,14 @@
         assertNotNull(lookupFather);
         assertEquals(returnedFather.getFirstname(), lookupFather.getFirstname());
         // unfortunately, PersonImpl does not have a suitable equals method.
-        assertEquals(
-                "children's names are equal",
-                Arrays.asList(getFirstNames(returnedChildren)),
-                Arrays.asList(getFirstNames(children)));
+// comment out, because of child object order problem (it's not a bug, it's bad test writing)
+//        assertEquals(
+//                "children's names are equal",
+//                Arrays.asList(getFirstNames(returnedChildren)),
+//                Arrays.asList(getFirstNames(children)));
+        // we expect the same names in both array, thus intersection result have to be '2'
+        List list = ListUtils.intersection(Arrays.asList(getFirstNames(returnedChildren)), Arrays.asList(getFirstNames(children)));
+        assertEquals(2, list.size());
         // System.out.println(Arrays.asList(getFirstNames(returnedChildren)));
         tx.commit();
 

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/RITest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/RITest.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/RITest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/RITest.java Sat Jul 15 07:54:38 2006
@@ -1,7 +1,11 @@
 package org.apache.ojb.odmg;
 
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
 import org.apache.ojb.broker.Contract;
-import org.apache.ojb.broker.Identity;
 import org.apache.ojb.junit.ODMGTestCase;
 import org.apache.ojb.odmg.shared.DetailFKinPK;
 import org.apache.ojb.odmg.shared.DetailFKnoPK;
@@ -10,11 +14,6 @@
 import org.odmg.OQLQuery;
 import org.odmg.Transaction;
 
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Vector;
-import java.util.List;
-
 /** Demo Application that shows basic concepts for Applications using the OJB ODMG
  * implementation as an transactional object server.
  */
@@ -97,7 +96,7 @@
         Master master = new Master();
         master.masterText = "Master_timestamp_" + timestamp;
         master.collDetailFKnoPK = new Vector();
-        new Identity(master, ((HasBroker) tx).getBroker());
+        ((TransactionExt) tx).getBroker().serviceIdentity().buildIdentity(master);
         for (int i = 0; i < countDetailObjects; i++)
         {
             DetailFKnoPK aDetail = new DetailFKnoPK();
@@ -114,7 +113,7 @@
         Master master = new Master();
         master.masterText = "Master_timestamp_" + timestamp;
         master.collDetailFKinPK = new Vector();
-        new Identity(master, ((HasBroker) tx).getBroker());
+        ((TransactionExt) tx).getBroker().serviceIdentity().buildIdentity(master);
         for (int i = 0; i < countDetailObjects; i++)
         {
             DetailFKinPK aDetail = new DetailFKinPK();

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/ScrollableQueryResultsTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/ScrollableQueryResultsTest.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/ScrollableQueryResultsTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/ScrollableQueryResultsTest.java Sat Jul 15 07:54:38 2006
@@ -119,7 +119,7 @@
         // 3. Get a list of some articles
         Transaction tx = odmg.newTransaction();
         tx.begin();
-        EnhancedOQLQuery query = odmg.newOQLQuery();
+        EnhancedOQLQuery query = (EnhancedOQLQuery) odmg.newOQLQuery();
         String sql = "select somePersons from " + Person.class.getName();
         query.create(sql, start, end);
         Collection somePersons = (Collection) query.execute();
@@ -162,7 +162,7 @@
             Transaction tx = odmg.newTransaction();
             tx.begin();
 
-            EnhancedOQLQuery query = odmg.newOQLQuery();
+            EnhancedOQLQuery query = (EnhancedOQLQuery) odmg.newOQLQuery();
             String sql = "select somePersons from " + Person.class.getName();
             query.create(sql, start, end);
             Collection somePersons = (Collection) query.execute();
@@ -221,7 +221,7 @@
             return;
         }
 
-        EnhancedOQLQuery query = odmg.newOQLQuery();
+        EnhancedOQLQuery query = (EnhancedOQLQuery) odmg.newOQLQuery();
         String sql = "select somePersons from " + Person.class.getName();
         query.create(sql, start, end);
         Collection somePersons = (Collection) query.execute();
@@ -256,7 +256,7 @@
         try
         {
             tx.begin();
-            EnhancedOQLQuery query = odmg.newOQLQuery();
+            EnhancedOQLQuery query = (EnhancedOQLQuery) odmg.newOQLQuery();
             String sql = "select somePersons from " + Person.class.getName();
             query.create(sql, start, end);
             query.execute();
@@ -282,7 +282,7 @@
         {
             tx = odmg.newTransaction();
             tx.begin();
-            EnhancedOQLQuery query = odmg.newOQLQuery();
+            EnhancedOQLQuery query = (EnhancedOQLQuery) odmg.newOQLQuery();
             String sql = "select somePersons from " + Person.class.getName();
             query.create(sql, start, end);
             query.execute();

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/UserTestCases.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/UserTestCases.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/UserTestCases.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/UserTestCases.java Sat Jul 15 07:54:38 2006
@@ -1,6 +1,8 @@
 package org.apache.ojb.odmg;
 
 import java.util.List;
+import java.util.ArrayList;
+import java.util.Collection;
 
 import org.apache.ojb.broker.Identity;
 import org.apache.ojb.junit.ODMGTestCase;
@@ -252,12 +254,14 @@
     {
         try
         {
+            TransactionExt txn = (TransactionExt) odmg.newTransaction();
+            txn.begin();
             // construct an id that does not exist in the database
-            Identity id = new Identity(Person.class, Person.class, new Integer[]{new Integer(-1)});
-            TransactionImpl txn = (TransactionImpl) odmg.newTransaction();
+            Identity id = txn.getBroker().serviceIdentity().buildIdentity(Person.class, Person.class, new Integer[]{new Integer(-1)});
+            txn.commit();
             try
             {
-                txn.getObjectByIdentity(id);
+                txn.getBroker().getObjectByIdentity(id);
                 fail("expected TransactionNotInProgressException not thrown");
             }
             catch(TransactionNotInProgressException exc)
@@ -269,6 +273,184 @@
         {
             exc.printStackTrace();
             fail("caught unexpected exception: " + exc.toString());
+        }
+    }
+
+    /**
+     * Test for OJB-118
+     */
+    public void testFKConstraintIssue() throws Exception
+    {
+        int startId = (int) (System.currentTimeMillis() % Integer.MAX_VALUE);
+
+        String queryA = "select allA from " + A.class.getName() + " where id = $1";
+        String queryB = "select allB from " + B.class.getName() + " where id = $1";
+
+
+        Transaction tx = odmg.newTransaction();
+        tx.begin();
+        // Create A and B objects and make persistent
+        A a = new A();
+        a.setId(new Integer(startId));
+        a.setName("Ten_1");
+        tx.lock(a, Transaction.WRITE);
+        B b = new B();
+        b.setId(a.getId());
+        b.setDescription("Detail_1");
+        a.getItems().add(b);
+        tx.lock(b, Transaction.WRITE);
+        // Delete A and B
+        database.deletePersistent(a);
+        database.deletePersistent(b);
+        tx.commit();
+        tx.begin();
+        OQLQuery query = odmg.newOQLQuery();
+        query.create(queryA);
+        query.bind(new Integer(startId));
+        Collection result = (Collection) query.execute();
+        assertEquals(0, result.size());
+
+        query = odmg.newOQLQuery();
+        query.create(queryB);
+        query.bind(new Integer(startId));
+        result = (Collection) query.execute();
+        assertEquals(0, result.size());
+        tx.commit();
+
+
+        ++startId;
+        tx.begin();
+        // Create A and B objects and make persistent
+        a = new A();
+        a.setId(new Integer(startId));
+        a.setName("Ten_2");
+        b = new B();
+        b.setId(a.getId());
+        b.setDescription("Detail_2");
+        a.getItems().add(b);
+        database.makePersistent(b);
+        database.makePersistent(a);
+        // Delete A and B
+        database.deletePersistent(a);
+        database.deletePersistent(b);
+        tx.commit();
+        tx.begin();
+        query = odmg.newOQLQuery();
+        query.create(queryA);
+        query.bind(new Integer(startId));
+        result = (Collection) query.execute();
+        assertEquals(0, result.size());
+
+        query = odmg.newOQLQuery();
+        query.create(queryB);
+        query.bind(new Integer(startId));
+        result = (Collection) query.execute();
+        assertEquals(0, result.size());
+        tx.commit();
+
+        ++startId;
+        tx = odmg.newTransaction();
+        tx.begin();
+        // Create A and B objects and make persistent
+        a = new A();
+        a.setId(new Integer(startId));
+        a.setName("Ten");
+        tx.lock(a, Transaction.WRITE);
+        b = new B();
+        b.setId(a.getId());
+        b.setDescription("Detail");
+        a.getItems().add(b);
+        tx.lock(b, Transaction.WRITE);
+        tx.checkpoint();
+        // Delete A and B
+        database.deletePersistent(a);
+        database.deletePersistent(b);
+        tx.commit();
+        tx.begin();
+        query = odmg.newOQLQuery();
+        query.create(queryA);
+        query.bind(new Integer(startId));
+        result = (Collection) query.execute();
+        assertEquals(0, result.size());
+
+        query = odmg.newOQLQuery();
+        query.create(queryB);
+        query.bind(new Integer(startId));
+        result = (Collection) query.execute();
+        assertEquals(0, result.size());
+        tx.commit();
+    }
+
+
+    public static class A
+    {
+        private Integer id;
+        private String name;
+        private List items;
+
+        public A()
+        {
+            items = new ArrayList();
+        }
+
+        public Integer getId()
+        {
+            return id;
+        }
+
+        public void setId(Integer id)
+        {
+            this.id = id;
+        }
+
+        public String getName()
+        {
+            return name;
+        }
+
+        public void setName(String name)
+        {
+            this.name = name;
+        }
+
+        public List getItems()
+        {
+            return items;
+        }
+
+        public void setItems(List items)
+        {
+            this.items = items;
+        }
+    }
+
+    public static class B
+    {
+        private Integer id;
+        private String description;
+
+        public B()
+        {
+        }
+
+        public Integer getId()
+        {
+            return id;
+        }
+
+        public void setId(Integer id)
+        {
+            this.id = id;
+        }
+
+        public String getDescription()
+        {
+            return description;
+        }
+
+        public void setDescription(String description)
+        {
+            this.description = description;
         }
     }
 }

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/shared/Article.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/shared/Article.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/shared/Article.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/shared/Article.java Sat Jul 15 07:54:38 2006
@@ -1,6 +1,5 @@
 package org.apache.ojb.odmg.shared;
 
-import org.apache.ojb.odmg.shared.ProductGroup;
 import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.lang.builder.EqualsBuilder;
 
@@ -17,7 +16,7 @@
         return new ToStringBuilder(this)
                 .append("articleId", articleId)
                 .append("articleName", articleName)
-                .append("productGroup", (productGroup != null ? productGroup.getName() : null))
+                .append("productGroup", (productGroup != null ? productGroup.getGroupName() : null))
                 .append("productGroupId", productGroupId)
                 .append("isSelloutArticle", isSelloutArticle)
                 .append("minimumStock", minimumStock)

Modified: db/ojb/trunk/src/test/org/apache/ojb/odmg/shared/ProductGroup.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/odmg/shared/ProductGroup.java?rev=422241&r1=422240&r2=422241&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/odmg/shared/ProductGroup.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/odmg/shared/ProductGroup.java Sat Jul 15 07:54:38 2006
@@ -1,18 +1,25 @@
 package org.apache.ojb.odmg.shared;
 
 import java.io.Serializable;
+import java.util.Vector;
 import java.util.List;
-import java.util.ArrayList;
 
 /** represents a product group containing a set of Articles.
  * @see org.apache.ojb.odmg.shared.Article
  */
 public class ProductGroup implements org.apache.ojb.odmg.TransactionAware, Serializable
 {
-    /** return group id*/
-    public int getId()
+    /** collection containing all articles of a given product group*/
+    private List allArticlesInGroup;
+    /** a textual description of the group*/
+    private String description;
+    /** the unique id of a product group*/
+    private int groupId;
+    /** the name of a group*/
+    private String groupName;
+
+    public ProductGroup()
     {
-        return groupId;
     }
 
     /**return string representation*/
@@ -26,96 +33,39 @@
                 "articles in group: " + allArticlesInGroup;
     }
 
-    public ProductGroup(int pGroupId, String pGroupName,
-                        String pDescription)
+    public int getGroupId()
     {
-        groupId = pGroupId;
-        groupName = pGroupName;
-        description = pDescription;
+        return groupId;
     }
 
-    public ProductGroup()
+    public void setGroupId(int groupId)
     {
+        this.groupId = groupId;
     }
 
-    /** return groupname*/
-    public String getName()
+    public String getGroupName()
     {
         return groupName;
     }
 
-    /** collection containing all articles of a given product group*/
-    private List allArticlesInGroup;
-    /** a textual description of the group*/
-    private String description;
-    /** the unique id of a product group*/
-    private int groupId;
-    /** the name of a group*/
-    private String groupName;
+    public void setGroupName(String groupName)
+    {
+        this.groupName = groupName;
+    }
 
     public String getDescription()
     {
         return description;
     }
 
-    /**
-     * Sets the description.
-     * @param description The description to set
-     */
     public void setDescription(String description)
     {
         this.description = description;
     }
 
     /**
-     * afterAbort will be called after a transaction has been aborted.
-     * The values of fields which get persisted will have changed to
-     * what they were at the begining of the transaction.  This method
-     * should be overridden to reset any transient or non-persistent
-     * fields.
-     */
-    public void afterAbort()
-    {
-        //System.out.println("afterAbort: " + new Identity(this));
-    }
-
-    /**
-     * afterCommit is called only after a successful commit has taken
-     * place.
-     */
-    public void afterCommit()
-    {
-        //System.out.println("afterCommit: " + new Identity(this));
-    }
-
-    /**
-     * beforeAbort is called before a transaction is aborted.
-     */
-    public void beforeAbort()
-    {
-        //System.out.println("beforeAbort: " + new Identity(this));
-    }
-
-    /**
-     * beforeCommit will give an object a chance to kill a
-     * transaction before it is committed.
-     *
-     * To kill a transaction, throw a new TransactionAbortedException.
-     */
-    public void beforeCommit() throws org.odmg.TransactionAbortedException
-    {
-        //System.out.println("beforeCommit: " + new Identity(this));
-    }
-
-
-    /** set groupname*/
-    public void setName(String newName)
-    {
-        groupName = newName;
-    }
-    /**
      * Gets the allArticlesInGroup.
-     * @return Returns a Vector
+     * @return Returns a List
      */
     public List getAllArticlesInGroup()
     {
@@ -135,45 +85,48 @@
     {
         if(allArticlesInGroup == null)
         {
-            allArticlesInGroup = new ArrayList();
+            allArticlesInGroup = new Vector();
         }
         allArticlesInGroup.add(article);
     }
 
     /**
-     * Gets the groupId.
-     * @return Returns a int
+     * afterAbort will be called after a transaction has been aborted.
+     * The values of fields which get persisted will have changed to
+     * what they were at the begining of the transaction.  This method
+     * should be overridden to reset any transient or non-persistent
+     * fields.
      */
-    public int getGroupId()
+    public void afterAbort()
     {
-        return groupId;
+        //System.out.println("afterAbort: " + new Identity(this));
     }
 
     /**
-     * Sets the groupId.
-     * @param groupId The groupId to set
+     * afterCommit is called only after a successful commit has taken
+     * place.
      */
-    public void setGroupId(int groupId)
+    public void afterCommit()
     {
-        this.groupId = groupId;
+        //System.out.println("afterCommit: " + new Identity(this));
     }
 
     /**
-     * Gets the groupName.
-     * @return Returns a String
+     * beforeAbort is called before a transaction is aborted.
      */
-    public String getGroupName()
+    public void beforeAbort()
     {
-        return groupName;
+        //System.out.println("beforeAbort: " + new Identity(this));
     }
 
     /**
-     * Sets the groupName.
-     * @param groupName The groupName to set
+     * beforeCommit will give an object a chance to kill a
+     * transaction before it is committed.
+     *
+     * To kill a transaction, throw a new TransactionAbortedException.
      */
-    public void setGroupName(String groupName)
+    public void beforeCommit() throws org.odmg.TransactionAbortedException
     {
-        this.groupName = groupName;
+        //System.out.println("beforeCommit: " + new Identity(this));
     }
-
 }



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