db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/odmg ObjectEnvelope.java ObjectEnvelopeTable.java TransactionImpl.java
Date Wed, 25 Feb 2004 01:22:55 GMT
arminw      2004/02/24 17:22:55

  Modified:    src/java/org/apache/ojb/odmg/states StateNewDirty.java
                        StateOldDirty.java StateNewClean.java
                        ModificationState.java
               src/test/org/apache/ojb/odmg LockingTest.java
               src/java/org/apache/ojb/odmg ObjectEnvelope.java
                        ObjectEnvelopeTable.java TransactionImpl.java
  Log:
  - disable "restore transient object on rollback" feature, because
  OJB can't really restore a transient object, e.g. how to restore none
  persistent fields or collection references
  - code beautification
  - new test, check multiple "lock" calls
  
  Revision  Changes    Path
  1.4       +2 -2      db-ojb/src/java/org/apache/ojb/odmg/states/StateNewDirty.java
  
  Index: StateNewDirty.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/states/StateNewDirty.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StateNewDirty.java	24 Jan 2003 22:44:10 -0000	1.3
  +++ StateNewDirty.java	25 Feb 2004 01:22:55 -0000	1.4
  @@ -136,7 +136,7 @@
               throws org.apache.ojb.broker.PersistenceBrokerException
       {
           broker.store(mod.getObject(), ObjectModificationDefaultImpl.INSERT);
  -        mod.manage(mod.getObject());
  +        mod.refreshObjectImage();
           mod.setModificationState(StateOldClean.getInstance());
       }
   
  @@ -146,7 +146,7 @@
       public void commit(ObjectEnvelope mod, PersistenceBroker broker) throws org.apache.ojb.broker.PersistenceBrokerException
       {
           broker.store(mod.getObject(), ObjectModificationDefaultImpl.INSERT);
  -        mod.manage(mod.getObject());
  +        mod.refreshObjectImage();
           mod.setModificationState(StateOldClean.getInstance());
       }
   
  
  
  
  1.5       +7 -2      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StateOldDirty.java	28 Apr 2003 17:10:41 -0000	1.4
  +++ StateOldDirty.java	25 Feb 2004 01:22:55 -0000	1.5
  @@ -145,8 +145,13 @@
       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();
  +/*
  +arminw: we can't really restore object state with all dependencies and fields
  +without having a deep copy of the clean object. To avoid side-effects disable this
  +feature
  +*/
  +//        // Call added to rollback the object itself so it has the previous values again
when it is used further on.
  +//        mod.rollback();
       }
   
       /*
  
  
  
  1.5       +2 -3      db-ojb/src/java/org/apache/ojb/odmg/states/StateNewClean.java
  
  Index: StateNewClean.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/states/StateNewClean.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StateNewClean.java	13 Nov 2003 14:52:40 -0000	1.4
  +++ StateNewClean.java	25 Feb 2004 01:22:55 -0000	1.5
  @@ -135,7 +135,7 @@
               throws org.apache.ojb.broker.PersistenceBrokerException
       {
           broker.store(mod.getObject(), ObjectModificationDefaultImpl.INSERT);
  -        mod.manage(mod.getObject());
  +        mod.refreshObjectImage();
           mod.setModificationState(StateOldClean.getInstance());
       }
   
  @@ -146,7 +146,7 @@
       public void commit(ObjectEnvelope mod, PersistenceBroker broker) throws org.apache.ojb.broker.PersistenceBrokerException
       {
           broker.store(mod.getObject(), ObjectModificationDefaultImpl.INSERT);
  -        mod.manage(mod.getObject());
  +        mod.refreshObjectImage();
           mod.setModificationState(StateOldClean.getInstance());
       }
   
  @@ -157,5 +157,4 @@
       {
           this.removeFromCache(mod.getObject(), broker);
       }
  -
   }
  
  
  
  1.10      +3 -13     db-ojb/src/java/org/apache/ojb/odmg/states/ModificationState.java
  
  Index: ModificationState.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/states/ModificationState.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ModificationState.java	7 Jan 2004 11:41:21 -0000	1.9
  +++ ModificationState.java	25 Feb 2004 01:22:55 -0000	1.10
  @@ -153,26 +153,16 @@
       /**
        * remove Object from the ObjectCache
        */
  -    protected void removeFromCache(Object objToBeRemoved, PersistenceBroker broker)
  +    protected void removeFromCache(Object objectOrIdentity, PersistenceBroker broker)
       {
           try
           {
  -            broker.removeFromCache(objToBeRemoved);
  -            /*
  -            arminw:
  -            TODO: check out
  -            objects must also be remove from
  -            LoadedObjectsRegistry - Fix by Jamie Burns ????
  -
  -            arminw:
  -            remove LOR from code base
  -            */
  -            // LoadedObjectsRegistry.remove(objToBeRemoved);
  +            broker.removeFromCache(objectOrIdentity);
           }
           catch (PersistenceBrokerException e)
           {
               LoggerFactory.getDefaultLogger().error("[" + this.getClass().getName() + "]"
+
  -                    " Can't remove object from cache. obj was " + objToBeRemoved + ", 
used PB " + broker, e);
  +                    " Can't remove object from cache. obj was " + objectOrIdentity + ",
 used PB " + broker, e);
           }
       }
   }
  
  
  
  1.12      +41 -0     db-ojb/src/test/org/apache/ojb/odmg/LockingTest.java
  
  Index: LockingTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/LockingTest.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- LockingTest.java	11 Dec 2003 20:13:23 -0000	1.11
  +++ LockingTest.java	25 Feb 2004 01:22:55 -0000	1.12
  @@ -18,6 +18,7 @@
   import org.odmg.Transaction;
   
   import java.util.List;
  +import java.util.Collection;
   
   /**
    * Test optimistic and pessimistic locking mechanisms
  @@ -77,6 +78,46 @@
   
           if (odmg2.currentTransaction() != null) odmg2.currentTransaction().abort();
           db2.close();
  +    }
  +
  +    /**
  +     * Test multiple locks on the same object
  +     */
  +    public void testMultipleLocks() throws Exception
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        String name = "testMultipleLocks_" + timestamp;
  +        String nameUpdated = "testMultipleLocks_Updated_" + timestamp;
  +        TransactionExt tx = (TransactionExt) odmg1.newTransaction();
  +        LockedByVersion obj = new LockedByVersion();
  +        tx.begin();
  +        tx.lock(obj, Transaction.WRITE);
  +        obj.setValue(name);
  +        tx.lock(obj, Transaction.WRITE);
  +        tx.lock(obj, Transaction.UPGRADE);
  +        tx.commit();
  +
  +        OQLQuery query = odmg1.newOQLQuery();
  +        query.create("select all from " + LockedByVersion.class.getName() + " where value
like $1");
  +        query.bind(name);
  +        Collection result = (Collection) query.execute();
  +        assertNotNull(result);
  +        assertEquals(1, result.size());
  +
  +        tx.begin();
  +        tx.lock(obj, Transaction.WRITE);
  +        tx.lock(obj, Transaction.WRITE);
  +        obj.setValue(nameUpdated);
  +        tx.lock(obj, Transaction.WRITE);
  +        tx.lock(obj, Transaction.UPGRADE);
  +        tx.commit();
  +
  +        query = odmg1.newOQLQuery();
  +        query.create("select all from " + LockedByVersion.class.getName() + " where value
like $1");
  +        query.bind(nameUpdated);
  +        result = (Collection) query.execute();
  +        assertNotNull(result);
  +        assertEquals(1, result.size());
       }
   
       public void testLockBasics() throws Exception
  
  
  
  1.28      +143 -144  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.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- ObjectEnvelope.java	8 Feb 2004 13:19:47 -0000	1.27
  +++ ObjectEnvelope.java	25 Feb 2004 01:22:55 -0000	1.28
  @@ -59,6 +59,14 @@
    * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird</a>
    *
    */
  +
  +import java.io.Serializable;
  +import java.lang.reflect.Array;
  +import java.util.Collection;
  +import java.util.HashMap;
  +import java.util.Iterator;
  +import java.util.Map;
  +
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.accesslayer.IndirectionHandler;
  @@ -73,23 +81,19 @@
   import org.apache.ojb.odmg.states.ModificationState;
   import org.odmg.ODMGRuntimeException;
   
  -import java.io.Serializable;
  -
  -import java.util.Collection;
  -import java.util.HashMap;
  -import java.util.Iterator;
  -import java.util.Map;
  -
   /**
    * ObjectEnvelope is used during ODMG transactions as a wrapper for a persistent objects
declaration
    *
    */
   public class ObjectEnvelope implements ObjectModification, Serializable
   {
  -	static final long serialVersionUID = -829177767933340522L;    /**
  +    static final long serialVersionUID = -829177767933340522L;
  +    /**
        * The objects modification state, e.g. Old and Clean
        */
       private ModificationState modificationState = null;
  +    private Identity oid;
  +    private Boolean hasChanged;
   
       /**
        * myObj holds the object we are wrapping.
  @@ -112,34 +116,39 @@
       public ObjectEnvelope(Object obj, TransactionImpl aTx)
       {
           tx = aTx;
  -        manage(obj);
  -        setInitialModificationState();
  +        myObj = ProxyHelper.getRealObject(obj);
  +        refreshObjectImage();
  +        prepareInitialState();
       }
   
       public void close()
  -	{
  -		myObj = null;
  -		beforeImage = null;
  -		tx = null;
  -	}
  +    {
  +        myObj = null;
  +        beforeImage = null;
  +        tx = null;
  +    }
   
  -    /**
  -     * Manage an object.
  -     */
  -    public void manage(Object obj)
  +    public void refreshObjectImage()
       {
  -        myObj = ProxyHelper.getRealObject(obj);
           try
           {
  +            hasChanged = null;
  +            oid = new Identity(myObj, tx.getBroker());
               beforeImage = getMap();
           }
  -        catch (Exception ex)
  +        catch(Exception ex)
           {
               beforeImage = null;
  +            oid = null;
               throw new org.odmg.ClassNotPersistenceCapableException(ex.toString());
           }
       }
   
  +    public Identity getIdentity()
  +    {
  +        return oid;
  +    }
  +
       /**
        * returns the managed object.
        */
  @@ -168,7 +177,7 @@
        */
       public void beforeCommit()
       {
  -        if (myObj instanceof TransactionAware)
  +        if(myObj instanceof TransactionAware)
           {
               TransactionAware ta = (TransactionAware) myObj;
               ta.beforeCommit();
  @@ -180,7 +189,7 @@
        */
       public void afterCommit()
       {
  -        if (myObj instanceof TransactionAware)
  +        if(myObj instanceof TransactionAware)
           {
               TransactionAware ta = (TransactionAware) myObj;
               ta.afterCommit();
  @@ -192,7 +201,7 @@
        */
       public void beforeAbort()
       {
  -        if (myObj instanceof TransactionAware)
  +        if(myObj instanceof TransactionAware)
           {
               TransactionAware ta = (TransactionAware) myObj;
               ta.beforeAbort();
  @@ -204,7 +213,7 @@
        */
       public void afterAbort()
       {
  -        if (myObj instanceof TransactionAware)
  +        if(myObj instanceof TransactionAware)
           {
               TransactionAware ta = (TransactionAware) myObj;
               ta.afterAbort();
  @@ -223,7 +232,7 @@
            * 1. register all fields of object that aren't collections or references
            */
           FieldDescriptor[] fieldDescs = mif.getFieldDescriptions();
  -        for (int i = 0; i < fieldDescs.length; i++)
  +        for(int i = 0; i < fieldDescs.length; i++)
           {
               FieldDescriptor fd = fieldDescs[i];
               PersistentField f = fd.getPersistentField();
  @@ -237,14 +246,14 @@
            * marked "dirty", otherwise attaching or detaching a 1:1 referenced object will
            * not be updated in ODMG.
            */
  -		Iterator iter = mif.getObjectReferenceDescriptors().iterator();
  -		ObjectReferenceDescriptor rds = null;
  +        Iterator iter = mif.getObjectReferenceDescriptors().iterator();
  +        ObjectReferenceDescriptor rds = null;
           Object temp = null;
  -		while (iter.hasNext())
  -		{
  -			rds = (ObjectReferenceDescriptor) iter.next();
  +        while(iter.hasNext())
  +        {
  +            rds = (ObjectReferenceDescriptor) iter.next();
   
  -            /*
  +/*
                * synchronize on myObj so the ODMG-layer can take a snapshot only of
                * fully cached (i.e. with all references + collections) objects
                */
  @@ -262,7 +271,7 @@
                */
               IndirectionHandler handler = ProxyHelper.getIndirectionHandler(temp);
   
  -            if (handler != null)
  +            if(handler != null)
               {
                   /**
                    * only register if the proxy has been materialized
  @@ -272,10 +281,10 @@
                   fieldValues.put(rds, handler.getIdentity());
               }
               else
  -            {    
  +            {
                   fieldValues.put(rds, temp);
               }
  -		}
  +        }
           /**
            * MBAIRD
            * 3. now let's register the collection descriptors
  @@ -284,30 +293,34 @@
            */
           Iterator collections = mif.getCollectionDescriptors().iterator();
           CollectionDescriptor collectionDescriptor = null;
  -        while (collections.hasNext())
  +        while(collections.hasNext())
           {
               collectionDescriptor = (CollectionDescriptor) collections.next();
  -            Object items = collectionDescriptor.getPersistentField().get(myObj);
  -            if (items != null)
  +            Object collectionOrArray = collectionDescriptor.getPersistentField().get(myObj);
  +            if(collectionOrArray != null)
               {
  -                // items might be a Collection or an array.
  -                if (items instanceof Collection)
  +                int referencesId = 0;
  +                // no special treatment for CollectionProxies required,
  +                // their size() method does not materialize the elements.
  +                /**
  +                 * MBAIRD
  +                 * size isn't the safest thing to use as the dirty bit. This will
  +                 * need to be fixed.
  +                 */
  +                if(collectionOrArray instanceof Collection)
  +                {
  +                    referencesId = ((Collection) collectionOrArray).size();
  +                }
  +                else if(collectionOrArray.getClass().isArray())
                   {
  -					// no special treatment for CollectionProxies required,
  -					// their size() method does not materialize the elements.
  -                    /**
  -                     * MBAIRD
  -                     * size isn't the safest thing to use as the dirty bit. This will
  -                     * need to be fixed.
  -                     */
  -                    Object dirtyMark = new Integer(((Collection)items).size());
  -                    fieldValues.put(collectionDescriptor, dirtyMark);
  +                    referencesId = Array.getLength(collectionOrArray);
                   }
  -                else  // items instanceof Object[]
  +                else
                   {
  -                    Object dirtyMark = new Integer(items.hashCode());
  -                    fieldValues.put(collectionDescriptor, dirtyMark);
  +                    referencesId = collectionOrArray.hashCode();
                   }
  +
  +                fieldValues.put(collectionDescriptor, new Integer(referencesId));
               }
           }
           return fieldValues;
  @@ -350,51 +363,30 @@
        * sets the initial MoificationState of the wrapped object myObj. The initial state
will be StateNewDirty if myObj
        * is not persisten already. The state will be set to StateOldClean if the object is
already persistent.
        */
  -    private void setInitialModificationState()
  +    private void prepareInitialState()
       {
           // determine appropriate modification state
           ModificationState initialState = null;
  -        Object result;
  -
  -// remove LOR from code base
  -//        if (LoadedObjectsRegistry.isRegistered(myObj))
  -//        {
  -//            initialState = org.apache.ojb.odmg.states.StateOldClean.getInstance();
  -//        }
  -//        else
  -//        {
  -//            ...
  -//        }
  -
  -        /*
  -        arminw:
  -        TODO: check out
  -        initial point to register used objects
  -        DO we really need LoadedObjectsRegistry???
  -        arminw:
  -        remove LOR from code base
  -        */
  -        // LoadedObjectsRegistry.register(myObj);
  -
  -        Identity id = new Identity(myObj, tx.getBroker());
  -
  +        boolean needsInsert;
           try
           {
               // try to lookup the object.
  -            result = tx.getBroker().getObjectByIdentity(id);
  +            needsInsert = tx.getBroker().serviceObjectCache().lookup(oid) == null
  +                    && !tx.getBroker().serviceBrokerHelper().doesExist(
  +                    tx.getBroker().getClassDescriptor(myObj.getClass()), oid, myObj);
           }
  -        catch (PersistenceBrokerException ex)
  +        catch(PersistenceBrokerException ex)
           {
               LoggerFactory.getDefaultLogger().error("ObjectEnvelope: ", ex);
  -            throw new ODMGRuntimeException(ex.getMessage());
  +            throw new ODMGRuntimeException("Unexpected error while check existence of "
+ myObj, ex);
           }
  -        if (result == null)
  +        if(needsInsert)
           {
               // if object is not already persistent it must be marked as new
               // it must be marked as dirty because it must be stored even if it will not
modified during tx
               initialState = org.apache.ojb.odmg.states.StateNewDirty.getInstance();
           }
  -        else if (tx.isDeleted(id))
  +        else if(tx.isDeleted(oid))
           {
               // if object is already persistent it will be marked as old.
               // it is marked as dirty as it has been deleted during tx and now it is inserted
again,
  @@ -417,7 +409,7 @@
        */
       public void setModificationState(ModificationState newModificationState)
       {
  -        if (newModificationState != modificationState)
  +        if(newModificationState != modificationState)
           {
               if(LoggerFactory.getDefaultLogger().isDebugEnabled())
               {
  @@ -435,13 +427,13 @@
       public String toString()
       {
           String obj = null;
  -        if (myObj == null)
  +        if(myObj == null)
           {
               obj = "null";
           }
           else
           {
  -            obj = new Identity(myObj,tx.getBroker()).toString();
  +            obj = new Identity(myObj, tx.getBroker()).toString();
           }
           return obj + "(" + modificationState + ")";
       }
  @@ -452,67 +444,74 @@
        */
       public boolean hasChanged()
       {
  -        Map currentImage = null;
  -        try
  +        if(hasChanged == null)
           {
  -            currentImage = getMap();
  -        }
  -        catch (Exception e)
  -        {
  -            LoggerFactory.getDefaultLogger().warn("Could not verify object changes, return
hasChanged 'true'",e);
  -        }
  +            Map currentImage = null;
  +            try
  +            {
  +                currentImage = getMap();
  +            }
  +            catch(Exception e)
  +            {
  +                LoggerFactory.getDefaultLogger().warn("Could not verify object changes,
return hasChanged 'true'", e);
  +            }
   
  -        if (beforeImage.equals(currentImage))
  -            return false;
  -        else
  -            return true;
  +            hasChanged = (beforeImage != null && beforeImage.equals(currentImage)
? Boolean.FALSE : Boolean.TRUE);
  +        }
  +        return hasChanged.booleanValue();
       }
   
  -    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();
  -    	}
  -    }
  +/*
  +arminw: we can't really restore object state with all dependencies and fields
  +without having a deep copy of the clean object. To avoid side-effects disable this
  +feature
  +*/
  +
  +//    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.28      +2 -4      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.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- ObjectEnvelopeTable.java	13 Nov 2003 14:52:40 -0000	1.27
  +++ ObjectEnvelopeTable.java	25 Feb 2004 01:22:55 -0000	1.28
  @@ -244,7 +244,7 @@
       }
   
   	/**
  -	 * 
  +	 *
   	 */
   	private void setCleanState()
   	{
  @@ -258,7 +258,7 @@
   					ObjectEnvelope mod = (ObjectEnvelope) mhtObjectEnvelopes.get(iter.next());
   					if(mod.getModificationState() != StateOldClean.getInstance())
   					{
  -						mod.manage(mod.getObject());
  +						mod.refreshObjectImage();
   						mod.setModificationState(StateOldClean.getInstance());
   					}
   			  }
  @@ -278,8 +278,6 @@
           {
   			boolean markDirty = false;
               ObjectEnvelope mod = (ObjectEnvelope) mhtObjectEnvelopes.get(iter.next());
  -            if (log.isDebugEnabled())
  -                log.debug("commit: " + mod);
               // if the Object has been modified by transaction, mark object as dirty
               // but only if it has not been marked during tx already !!
               if ((!mod.needsDelete()) && (!mod.needsInsert()) && (!mod.needsUpdate()))
  
  
  
  1.54      +39 -28    db-ojb/src/java/org/apache/ojb/odmg/TransactionImpl.java
  
  Index: TransactionImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/TransactionImpl.java,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- TransactionImpl.java	10 Feb 2004 15:28:18 -0000	1.53
  +++ TransactionImpl.java	25 Feb 2004 01:22:55 -0000	1.54
  @@ -823,42 +823,53 @@
               {
                   registerToIndirectionHandler(handler);
                   registerUnmaterializedLocks(newTxObject);
  -                return;
  +                // all work is done, so set to null
  +                objectToRegister = null;
               }
           }
   
  -        // no Proxy:
  -        if (objectToRegister == null)
  -            return;
  -        ObjectEnvelope envelope = objectEnvelopeTable.getByIdentity(new Identity(objectToRegister,
getBroker()));
  -        if ((envelope == null) || envelope.needsDelete())
  -        {
  -            // if OJB is configured to use only implicit readlocks, change the lockmode
  -            int assLockMode = lockMode;
  -            if (!useWriteLocks)
  +        // no Proxy and is not null, register real object
  +        if (objectToRegister != null)
  +        {
  +            ClassDescriptor cld = this.getBroker().getClassDescriptor(objectToRegister.getClass());
  +            ObjectEnvelope envelope = objectEnvelopeTable.getByIdentity(new Identity(objectToRegister,
getBroker(), cld));
  +            // if we found an envelope, object is already registered and we do nothing!
  +            if ((envelope == null) || envelope.needsDelete())
               {
  -                assLockMode = Transaction.READ;
  +                // 1. register associated objects
  +                doLockReferences(cld, objectToRegister, lockMode);
  +                // 2. register object itself
  +                objectEnvelopeTable.put(objectToRegister, new ObjectEnvelope(objectToRegister,
this));
  +                doLockCollections(cld, objectToRegister, lockMode);
               }
  +        }
  +    }
   
  -            ClassDescriptor cld = null;
  -            cld = this.getBroker().getClassDescriptor(objectToRegister.getClass());
  -            // 1. register associated objects
  -            if (useImplicitLocking)
  -            {
  -                lockReferences(cld, objectToRegister, assLockMode);
  -            }
  -            // 2. register object itself
  -            objectEnvelopeTable.put(objectToRegister, new ObjectEnvelope(objectToRegister,
this));
  +    protected void doLockReferences(ClassDescriptor cld, Object objectToRegister,
  +                                    int assLockMode) throws LockNotGrantedException
  +    {
  +        // if OJB is configured to use only implicit readlocks, change the lockmode
  +        if (!useWriteLocks)
  +        {
  +            assLockMode = Transaction.READ;
  +        }
  +        if (useImplicitLocking)
  +        {
  +            lockReferences(cld, objectToRegister, assLockMode);
  +        }
  +    }
   
  -            // 3. register objects in collection attributes
  -            if (useImplicitLocking)
  -            {
  -                lockCollections(cld, objectToRegister, assLockMode);
  -            }
  +    protected void doLockCollections(ClassDescriptor cld, Object objectToRegister,
  +                                    int assLockMode) throws LockNotGrantedException
  +    {
  +        // if OJB is configured to use only implicit readlocks, change the lockmode
  +        if (!useWriteLocks)
  +        {
  +            assLockMode = Transaction.READ;
           }
  -        else
  +        if (useImplicitLocking)
           {
  -            // Object already registered, do nothing!
  +            lockCollections(cld, objectToRegister, assLockMode);
           }
       }
   
  @@ -870,7 +881,7 @@
               {
                   Object refInstance = ProxyHelper.getRealObject(ref);
                   ClassDescriptor objCld = this.getBroker().getClassDescriptor(obj.getClass());
  -                org.apache.ojb.broker.metadata.FieldDescriptor[] objFkFields = rds.getForeignKeyFieldDescriptors(objCld);
  +                FieldDescriptor[] objFkFields = rds.getForeignKeyFieldDescriptors(objCld);
   
                   // oma: refInstance might be null in case of dangling foreign keys.
                   ValueContainer[] refPkValues;
  
  
  

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