db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sander Hofstee <sander.hofs...@topicus.nl>
Subject OJB does not update objects, only inserts when implicitlocking=false still not fixed
Date Mon, 10 Feb 2003 08:18:05 GMT
This is a resend of a previous message I posted, but I had no reply and 
it is still not fixed.
I added some additional information, maybe this helps:

Objects that should be updated are not updated to the database. When I 
am running
an my applucation I can load an obejct and save it. When I reload the 
object again
through OBJ it seems te be saved in the database. But when we check the 
database
nothing has changed. If I close the applicaton at this point I will lose all
date that I thought I had saved.

Inserts work fine, it's only updates. If I set de SQLGenerator logger to 
debug
I see a lot of INSERT en SELECT statements coming across, but that's it, 
nothing else.


We tried to track the problem and this seems to be the problem AND the FIX:

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.

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
            {


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