db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r581413 - /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
Date Tue, 02 Oct 2007 22:09:46 GMT
Author: arminw
Date: Tue Oct  2 15:09:46 2007
New Revision: 581413

URL: http://svn.apache.org/viewvc?rev=581413&view=rev
Log:
improve cascading delete

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java?rev=581413&r1=581412&r2=581413&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
Tue Oct  2 15:09:46 2007
@@ -187,6 +187,7 @@
     (e.g. objects are equals but PK fields not)
     */
     private Collection nowDeleting = new IdentityArrayList();
+    private int deleteCounter = 0;
 
     /**
      * Used for performance optimization of method
@@ -611,16 +612,9 @@
             return;
         }
         doTxCheck();
-        try
-        {
-            ClassDescriptor cld = getClassDescriptor(getProxyFactory().getRealClass(obj));
-            Identity oid = serviceIdentity().buildIdentity(cld, obj);
-            internalDelete(obj, oid, cld, ignoreReferences);
-        }
-        finally
-        {
-            nowDeleting.clear();
-        }
+        ClassDescriptor cld = getClassDescriptor(getProxyFactory().getRealClass(obj));
+        Identity oid = serviceIdentity().buildIdentity(cld, obj);
+        internalDelete(obj, oid, cld, ignoreReferences);
     }
 
     public void delete(Object obj, Identity oid, ClassDescriptor cld, boolean ignoreReferences)
@@ -632,14 +626,7 @@
             return;
         }
         doTxCheck();
-        try
-        {
-            internalDelete(obj, oid, cld, ignoreReferences);
-        }
-        finally
-        {
-            nowDeleting.clear();
-        }
+        internalDelete(obj, oid, cld, ignoreReferences);
     }
 
     /**
@@ -662,14 +649,8 @@
         if(cld == null) cld = getClassDescriptor(obj.getClass());
         if(oid == null) oid = serviceIdentity().buildIdentity(cld, obj);
 
-        /*
-        MBAIRD
-        1. if we are marked for delete already, avoid recursing on this object
-        arminw:
-        use object identity based list, because using objects we get a
-        better performance. I can't find side-effects in doing so.
-        */
-        if (nowDeleting.contains(obj))
+        // first check for already deleted objects (cirluar object graph)
+        if (nowDeleting.contains(obj) || deletedDuringTransaction.contains(oid))
         {
             return;
         }
@@ -684,27 +665,33 @@
             return;
         }
 
-        /**
-         * MBAIRD
-         * 2. register object in markedForDelete map.
-         */
-        nowDeleting.add(obj);
-
-        // Invoke events on PersistenceBrokerAware instances and listeners
-        BEFORE_DELETE_EVENT.setTarget(obj);
-        fireBrokerEvent(BEFORE_DELETE_EVENT);
-        BEFORE_DELETE_EVENT.setTarget(null);
-
-        // now perform deletion
-        performDeletion(cld, obj, oid, ignoreReferences);
-
-        // Invoke events on PersistenceBrokerAware instances and listeners
-        AFTER_DELETE_EVENT.setTarget(obj);
-        fireBrokerEvent(AFTER_DELETE_EVENT);
-        AFTER_DELETE_EVENT.setTarget(null);
+        try
+        {
+            // register delete object
+            nowDeleting.add(obj);
+            ++deleteCounter;
+
+            // Invoke events on PersistenceBrokerAware instances and listeners
+            BEFORE_DELETE_EVENT.setTarget(obj);
+            fireBrokerEvent(BEFORE_DELETE_EVENT);
+            BEFORE_DELETE_EVENT.setTarget(null);
+
+            // now perform deletion
+            performDeletion(cld, obj, oid, ignoreReferences);
+
+            // Invoke events on PersistenceBrokerAware instances and listeners
+            AFTER_DELETE_EVENT.setTarget(obj);
+            fireBrokerEvent(AFTER_DELETE_EVENT);
+            AFTER_DELETE_EVENT.setTarget(null);
 
-        // let the connection manager to execute batch
-        connectionManager.executeBatchIfNecessary();
+            // let the connection manager to execute batch
+            connectionManager.executeBatchIfNecessary();
+        }
+        finally
+        {
+            --deleteCounter;
+            if(deleteCounter == 0) nowDeleting.clear();
+        }
     }
 
     /**
@@ -1040,7 +1027,10 @@
         }
         finally
         {
-            // to optimize calls to DB don't remove already stored objects
+            // remove from store list after performing insert/update. This allows
+            // to re-store the same object in case of circular or multi-circular
+            // references to this object - this will keep all FK's in correct stand
+            // (but possibly can cause some overhead - unneeded DB roundup)
             nowStoring.remove(obj);
         }
 



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