You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by Sander Hofstee <sa...@topicus.nl> on 2003/02/05 08:43:21 UTC

OJB does not update objects, only inserts when implicitlocking=false

When implicitLocking is false then objects that have WRITE locks and
have been changed
will never get a DirtyModificationState (stays always Clean) and the
needsCommit boolean
stays false.


So i made a patch to
ObjectEnvelopeTable.upgradeImplicitLocksAndCheckIfCommitIsNeeded()
that it checks for changes and if there are changes but implicitlocking
is false
then i do a extra test for if this object has a write lock and set the
modification state
to dirty and the needsCommit to true.

johan


Index: ObjectEnvelopeTable.java
===================================================================
RCS file:
/home/cvspublic/db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java,v
retrieving revision 1.16
diff -u -r1.16 ObjectEnvelopeTable.java
--- ObjectEnvelopeTable.java 1 Feb 2003 15:40:05 -0000 1.16
+++ ObjectEnvelopeTable.java 4 Feb 2003 11:06:56 -0000
@@ -76,6 +76,8 @@
import org.apache.ojb.broker.util.ArrayIterator;
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
+import org.apache.ojb.odmg.locking.LockManager;
+import org.apache.ojb.odmg.locking.LockManagerFactory;
import org.odmg.Transaction;
import org.odmg.TransactionAbortedException;

@@ -231,6 +233,7 @@
     private void upgradeImplicitLocksAndCheckIfCommitIsNeeded()
     {
         boolean useImplicitLocking =
getConfiguration().useImplicitLocking();
+  LockManager lm = LockManagerFactory.getLockManager();
         // using clone to avoid ConcurentModificationException
         Iterator iter = ((ArrayList) mvOrderOfIds.clone()).iterator();
         while (iter.hasNext())
@@ -242,15 +245,24 @@
             // but only if it has not been marked during tx already !!
             if ((!mod.needsDelete()) && (!mod.needsInsert()) &&
(!mod.needsUpdate()))
             {
-                if (useImplicitLocking && mod.hasChanged())
-                {
-                    // implicitely acquire a write lock !
-                    transaction.lock(mod.getObject(),
Transaction.UPGRADE);
-                    // mark object dirty
-
mod.setModificationState(mod.getModificationState().markDirty());
-                    // objects needs commit action, thus set needCommit
to true:
-                    needsCommit = true;
-                }
+             if(mod.hasChanged())
+             {
+                 if (useImplicitLocking )
+                 {
+                     // implicitely acquire a write lock !
+                     transaction.lock(mod.getObject(),
Transaction.UPGRADE);
+                     // mark object dirty
+
mod.setModificationState(mod.getModificationState().markDirty());
+                     // objects needs commit action, thus set
needCommit to true:
+      needsCommit = true;
+                 }
+                 else if(lm.checkWrite(transaction,mod.getObject()))
+                 {
+      mod.setModificationState(mod.getModificationState().markDirty());
+                  needsCommit = true;
+                 }
+     +             }
             }
             else
             {