db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattba...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/odmg ObjectEnvelopeTable.java
Date Wed, 12 Feb 2003 06:11:16 GMT
mattbaird    2003/02/11 22:11:16

  Modified:    src/java/org/apache/ojb/odmg ObjectEnvelopeTable.java
  Log:
  fix OJB130. If an object is already locked for write, we might miss committing it if the
implicitLocks is off
  
  Revision  Changes    Path
  1.17      +35 -7     db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java
  
  Index: ObjectEnvelopeTable.java
  ===================================================================
  RCS file: /home/cvs//db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- ObjectEnvelopeTable.java	1 Feb 2003 15:40:05 -0000	1.16
  +++ ObjectEnvelopeTable.java	12 Feb 2003 06:11:16 -0000	1.17
  @@ -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;
   
  @@ -242,14 +244,40 @@
               // but only if it has not been marked during tx already !! 
               if ((!mod.needsDelete()) && (!mod.needsInsert()) && (!mod.needsUpdate()))
               {
  -                if (useImplicitLocking && mod.hasChanged())
  +				/**
  +				 * second check is, has the object in the envelope changed.
  +				 */
  +                if (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;
  +					/**
  +					 * now, the quickest thing to check is the useImplicitLocking flag. If we are using
  +					 * implicit locking, let's try to upgrade the lock, and mark the needsCommit
  +					 */
  +					if (useImplicitLocking)
  +					{
  +						// implicitely acquire a write lock !
  +						transaction.lock(mod.getObject(), Transaction.UPGRADE);
  +						// objects needs commit action, thus set needCommit to true:
  +						needsCommit = true;
  +					}
  +					/**
  +					 * If useImplicitLocking is false, we still need to check if the object in the envelope
  +					 * is write locked. If it is, we don't have to upgrade the lock, just mark needsCommit
  +					 */
  +					else if (LockManagerFactory.getLockManager().checkWrite(transaction, mod.getObject()))
  +					{
  +						// objects needs commit action, thus set needCommit to true:
  +						needsCommit = true;
  +					}
  +					/**
  +					 * now the needsCommit flag can be used to set the modification state on the
  +					 * object in the envelope.
  +					 */
  +					if (needsCommit)
  +					{
  +						// mark object dirty
  +						mod.setModificationState(mod.getModificationState().markDirty());
  +					}
                   }
               }
               else
  
  
  

Mime
View raw message