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 Thu, 16 Sep 2004 12:34:46 GMT
arminw      2004/09/16 05:34:46

  Modified:    src/java/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        ObjectEnvelope.java ObjectEnvelopeTable.java
                        TransactionImpl.java
  Log:
  if within a transaction the client returns a different instance of an already
  locked object (e.g. serialized through network) method tx.lock and tx.markDirty do not
  replace the already locked object instance by the new one. Now it will do so.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.32.2.2  +22 -4     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.32.2.1
  retrieving revision 1.32.2.2
  diff -u -r1.32.2.1 -r1.32.2.2
  --- ObjectEnvelope.java	27 Jul 2004 00:33:12 -0000	1.32.2.1
  +++ ObjectEnvelope.java	16 Sep 2004 12:34:45 -0000	1.32.2.2
  @@ -43,7 +43,8 @@
   import org.odmg.ODMGRuntimeException;
   
   /**
  - * ObjectEnvelope is used during ODMG transactions as a wrapper for a persistent objects
declaration
  + * ObjectEnvelope is used during ODMG transactions as a wrapper for a
  + * persistent objects declaration
    *
    */
   public class ObjectEnvelope implements ObjectModification, Serializable
  @@ -74,9 +75,11 @@
        *
        * Create a wrapper by providing an Object.
        */
  -    public ObjectEnvelope(Object obj, TransactionImpl aTx)
  +    public ObjectEnvelope(Identity oid, Object obj, TransactionImpl aTx)
       {
           tx = aTx;
  +        this.oid = oid;
  +        // TODO: do we really need to materialize??
           myObj = ProxyHelper.getRealObject(obj);
           refreshObjectImage();
           prepareInitialState();
  @@ -94,7 +97,14 @@
           try
           {
               hasChanged = null;
  -            oid = new Identity(myObj, tx.getBroker());
  +            // if an image already exists we
  +            // replace the Identity too, maybe a temporary
  +            // used PK value was replaced by the real one,
  +            // see in docs SequenceManagerNativeImpl
  +            if(beforeImage != null)
  +            {
  +                oid = new Identity(myObj, tx.getBroker());
  +            }
               beforeImage = getMap();
           }
           catch(Exception ex)
  @@ -118,6 +128,14 @@
           return myObj;
       }
   
  +    public void refreshObjectIfNeeded(Object obj)
  +    {
  +        if(this.myObj != obj)
  +        {
  +            this.myObj = obj;
  +        }
  +    }
  +
       /**
        * We need to implement the Two-Phase Commit
        * protocol.
  @@ -214,7 +232,7 @@
           {
               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
                */
  
  
  
  1.32.2.3  +1 -1      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.32.2.2
  retrieving revision 1.32.2.3
  diff -u -r1.32.2.2 -r1.32.2.3
  --- ObjectEnvelopeTable.java	11 Sep 2004 12:20:01 -0000	1.32.2.2
  +++ ObjectEnvelopeTable.java	16 Sep 2004 12:34:45 -0000	1.32.2.3
  @@ -430,7 +430,7 @@
           ObjectEnvelope result = (ObjectEnvelope) mhtObjectEnvelopes.get(id);
           if (result == null)
           {
  -            result = new ObjectEnvelope(pKey, transaction);
  +            result = new ObjectEnvelope(id, pKey, transaction);
               mhtObjectEnvelopes.put(id, result);
               mvOrderOfIds.add(id);
               if (log.isDebugEnabled())
  
  
  
  1.59.2.3  +15 -3     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.59.2.2
  retrieving revision 1.59.2.3
  diff -u -r1.59.2.2 -r1.59.2.3
  --- TransactionImpl.java	11 Sep 2004 12:20:01 -0000	1.59.2.2
  +++ TransactionImpl.java	16 Sep 2004 12:34:45 -0000	1.59.2.3
  @@ -500,6 +500,7 @@
       public void markDirty(Object anObject)
       {
           ObjectEnvelope otw = objectEnvelopeTable.get(anObject);
  +        otw.refreshObjectIfNeeded(anObject);
           otw.setModificationState(otw.getModificationState().markDirty());
       }
   
  @@ -785,15 +786,26 @@
           if (objectToRegister != null)
           {
               ClassDescriptor cld = this.getBroker().getClassDescriptor(objectToRegister.getClass());
  -            ObjectEnvelope envelope = objectEnvelopeTable.getByIdentity(new Identity(objectToRegister,
getBroker(), cld));
  +            Identity oid = getBroker().serviceIdentity().buildIdentity(cld, objectToRegister);
  +            ObjectEnvelope envelope = objectEnvelopeTable.getByIdentity(oid);
               // if we found an envelope, object is already registered and we do nothing!
               if ((envelope == null) || envelope.needsDelete())
               {
                   // 1. register associated objects
                   doLockReferences(cld, objectToRegister, lockMode);
                   // 2. register object itself
  -                objectEnvelopeTable.put(objectToRegister, new ObjectEnvelope(objectToRegister,
this));
  +                objectEnvelopeTable.put(objectToRegister, new ObjectEnvelope(oid, objectToRegister,
this));
                   doLockCollections(cld, objectToRegister, lockMode);
  +            }
  +            else
  +            {
  +                /*
  +                arminw:
  +                if an different instance of the same object was locked
  +                we should replace the old instance with new one to make
  +                accessible the changed fields
  +                */
  +                envelope.refreshObjectIfNeeded(objectToRegister);
               }
           }
       }
  
  
  

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