db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/odmg/states StateOldDirty.java
Date Mon, 28 Apr 2003 17:10:42 GMT
thma        2003/04/28 10:10:42

  Modified:    src/java/org/apache/ojb/odmg ObjectEnvelopeTable.java
                        ObjectEnvelope.java
               src/java/org/apache/ojb/odmg/states StateOldDirty.java
  Log:
  Now ODMG tx rollback also rolls back the state of the managed instances.
  Thanks to Klaasjan Brands for this patch
  
  Revision  Changes    Path
  1.25      +28 -0     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.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- ObjectEnvelopeTable.java	26 Apr 2003 09:13:35 -0000	1.24
  +++ ObjectEnvelopeTable.java	28 Apr 2003 17:10:41 -0000	1.25
  @@ -78,6 +78,7 @@
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.odmg.locking.LockManagerFactory;
  +import org.apache.ojb.odmg.states.StateOldClean;
   import org.odmg.LockNotGrantedException;
   import org.odmg.Transaction;
   import org.odmg.TransactionAbortedException;
  @@ -189,6 +190,10 @@
   
               // 4. execute batch
               connMan.executeBatch();
  +            
  +            // 5.Update all Envelopes to new CleanState
  +            setCleanState();
  +            
           }
           catch (Throwable t)
           {
  @@ -230,6 +235,29 @@
               }
           }
       }
  +
  +	/**
  +	 * commit all envelopes against the current broker
  +	 * @param broker the PB to persist all objects
  +	 */
  +	private void setCleanState()
  +	{
  +		 if (needsCommit)
  +		 {
  +			  Iterator iter;
  +			  // using clone to avoid ConcurentModificationException
  +			  iter = ((List) mvOrderOfIds.clone()).iterator();
  +			  while (iter.hasNext())
  +			  {
  +					ObjectEnvelope mod = (ObjectEnvelope) mhtObjectEnvelopes.get(iter.next());
  +					if(mod.getModificationState() != StateOldClean.getInstance())
  +					{
  +						mod.manage(mod.getObject());
  +						mod.setModificationState(StateOldClean.getInstance());
  +					}
  +			  }
  +		 }
  +	}
   
       /**
        * Implicitely upgrade locks on modified objects.
  
  
  
  1.19      +48 -0     db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelope.java
  
  Index: ObjectEnvelope.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelope.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ObjectEnvelope.java	26 Apr 2003 23:18:24 -0000	1.18
  +++ ObjectEnvelope.java	28 Apr 2003 17:10:41 -0000	1.19
  @@ -508,4 +508,52 @@
           else
               return true;
       }
  +    
  +    public void rollback()
  +    {
  +    	if(myObj != null && beforeImage != null)
  +    	{
  +			ClassDescriptor mif = tx.getBroker().getClassDescriptor(getObject().getClass());
  +			/**
  +			 * Set all the field values back.
  +			 */
  +			FieldDescriptor[] fieldDescs = mif.getFieldDescriptions();
  +			for (int i = 0; i < fieldDescs.length; i++)
  +			{
  +				 FieldDescriptor fd = fieldDescs[i];
  +				 PersistentField f = fd.getPersistentField();
  +				 
  +				 Object value = beforeImage.get(fd.getColumnName());
  +				 
  +				 f.set(myObj, value);
  +			}
  +			
  +			/**
  +			 * Set all the Object Reference values back
  +			 * Don't know exactly what to do when the are identiy objects
  +			 * (VirtualProxy or proxy classes)
  +			 */
  +			Iterator iter = mif.getObjectReferenceDescriptors().iterator();
  +			while (iter.hasNext())
  +			{
  +				ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) iter.next();
  +			 	Object temp = beforeImage.get(rds);
  +			 	
  +			 	if(temp instanceof Identity)
  +				{
  +					// TODO what to do now? It was a VirtualProxy instance or a Proxy class.		 	
  +				}
  +				else
  +				{
  +					rds.getPersistentField().set(myObj, temp);
  +				}
  +			}		
  +			
  +			/**
  +			 * Now set all collections back. But we only stored DirtyMarks.
  +			 * So what can be rolledback.?
  +			 */
  +			Iterator collections = mif.getCollectionDescriptors().iterator();	
  +    	}
  +    }
   }
  
  
  
  1.4       +3 -4      db-ojb/src/java/org/apache/ojb/odmg/states/StateOldDirty.java
  
  Index: StateOldDirty.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/states/StateOldDirty.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StateOldDirty.java	24 Jan 2003 22:44:10 -0000	1.3
  +++ StateOldDirty.java	28 Apr 2003 17:10:41 -0000	1.4
  @@ -128,18 +128,15 @@
               throws org.apache.ojb.broker.PersistenceBrokerException
       {
           broker.store(mod.getObject(), ObjectModificationDefaultImpl.UPDATE);
  -        mod.manage(mod.getObject());
  -        mod.setModificationState(StateOldClean.getInstance());
       }
   
  +
       /**
        * commit the associated transaction
        */
       public void commit(ObjectEnvelope mod, PersistenceBroker broker) throws org.apache.ojb.broker.PersistenceBrokerException
       {
           broker.store(mod.getObject(), ObjectModificationDefaultImpl.UPDATE);
  -        mod.manage(mod.getObject());
  -        mod.setModificationState(StateOldClean.getInstance());
       }
   
       /**
  @@ -148,6 +145,8 @@
       public void rollback(ObjectEnvelope mod, PersistenceBroker broker)
       {
           this.removeFromCache(mod.getObject(), broker);
  +        // Call added to rollback the object itself so it has the previous values again
when it is used further on.
  +        mod.rollback();
       }
   
       /*
  
  
  

Mime
View raw message