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
Date Sun, 13 Mar 2005 03:53:30 GMT
arminw      2005/03/12 19:53:30

  Modified:    src/java/org/apache/ojb/broker/core Tag: OJB_1_0_RELEASE
                        QueryReferenceBroker.java
               src/java/org/apache/ojb/broker/metadata Tag: OJB_1_0_RELEASE
                        FieldDescriptor.java
               src/java/org/apache/ojb/broker/util Tag: OJB_1_0_RELEASE
                        BrokerHelper.java
               src/java/org/apache/ojb/odmg/states Tag: OJB_1_0_RELEASE
                        StateNewClean.java StateNewDirty.java
                        StateOldDirty.java
               src/java/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        ObjectEnvelope.java ObjectEnvelopeTable.java
  Log:
  fix some problems with state detection on odmg-api
  - improved field value handling when build object image
  - improved proxy handling for 1:1 relation when build object image
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.17.2.5  +3 -19     db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java
  
  Index: QueryReferenceBroker.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java,v
  retrieving revision 1.17.2.4
  retrieving revision 1.17.2.5
  diff -u -r1.17.2.4 -r1.17.2.5
  --- QueryReferenceBroker.java	4 Mar 2005 18:07:23 -0000	1.17.2.4
  +++ QueryReferenceBroker.java	13 Mar 2005 03:53:30 -0000	1.17.2.5
  @@ -43,7 +43,6 @@
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.metadata.FieldHelper;
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
  -import org.apache.ojb.broker.metadata.fieldaccess.AnonymousPersistentField;
   import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
  @@ -53,6 +52,7 @@
   import org.apache.ojb.broker.util.collections.RemovalAwareCollection;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  +import org.apache.ojb.broker.util.BrokerHelper;
   
   /**
    * Encapsulates 1:1 and 1:n references and collection references stuff.
  @@ -470,7 +470,7 @@
           */
           if (hasNullifiedFKValue)
           {
  -            if(isAnonymousKeyReference(cld, rds))
  +            if(BrokerHelper.hasAnonymousKeyReference(cld, rds))
               {
                   Object referencedObject = rds.getPersistentField().get(obj);
                   if(referencedObject != null)
  @@ -504,22 +504,6 @@
           return result;
       }
   
  -    private boolean isAnonymousKeyReference(ClassDescriptor cld, ObjectReferenceDescriptor
rds)
  -    {
  -        boolean result = false;
  -        FieldDescriptor[] fkFields = rds.getForeignKeyFieldDescriptors(cld);
  -        for(int i = 0; i < fkFields.length; i++)
  -        {
  -            FieldDescriptor fkField = fkFields[i];
  -            if(AnonymousPersistentField.class.isAssignableFrom(fkField.getPersistentField().getClass()))
  -            {
  -                result = true;
  -                break;
  -            }
  -        }
  -        return result;
  -    }
  -
       /**
        * retrieves an Object reference by its Identity.
        * <br>
  
  
  
  No                   revision
  No                   revision
  1.36.2.2  +12 -41    db-ojb/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java
  
  Index: FieldDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java,v
  retrieving revision 1.36.2.1
  retrieving revision 1.36.2.2
  diff -u -r1.36.2.1 -r1.36.2.2
  --- FieldDescriptor.java	10 Mar 2005 17:55:30 -0000	1.36.2.1
  +++ FieldDescriptor.java	13 Mar 2005 03:53:30 -0000	1.36.2.2
  @@ -23,6 +23,7 @@
   import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.commons.lang.builder.ToStringStyle;
   import org.apache.ojb.broker.OJBRuntimeException;
  +import org.apache.ojb.broker.metadata.fieldaccess.AnonymousPersistentField;
   import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
   import org.apache.ojb.broker.accesslayer.conversions.FieldConversionDefaultImpl;
   import org.apache.ojb.broker.util.ClassHelper;
  @@ -159,8 +160,7 @@
        */
       public JdbcType getJdbcType()
       {
  -        // check for 'null' in any case, because after serialisation
  -        // field can be null
  +        // check if jdbcType is assigned
           if(m_jdbcType == null)
           {
               m_jdbcType = lookupJdbcType();
  @@ -211,44 +211,6 @@
       }
   
       /**
  -     * Returns the {@link FieldType} of this field  defined by the
  -     * JDBC 3.0 specification, e.g. a <em>String</em>, <em>byte[]</em>
...
  -     * <p/>
  -     * The complement class is {@link JdbcType}) which manage the corresponding database
  -     * type, e.g. <em>VARCHAR</em>, <em>VARBINARY</em>.
  -     *
  -     * @return The jdbc java field type of this field.
  -     */
  -    public FieldType getFieldType()
  -    {
  -        return getJdbcType().getFieldType();
  -    }
  -
  -    /**
  -     * Returns a copy of the field value specified by
  -     * given persistent object. Internally method
  -     * {@link FieldType#copy(Object)} is used to create the copy
  -     * of the object.
  -     *
  -     * @param source The persistent object to copy the field
  -     * (Note: the whole object is expected, not the field to copy).
  -     * @return A copy of the field value, a field conversion is already
  -     * done.
  -     */
  -    public Object copyFieldValue(Object source)
  -    {
  -        // get the value
  -        Object value = getPersistentField().get(source);
  -        // convert value to a supported type if needed
  -        value = getFieldConversion().javaToSql(value);
  -        // copy the value
  -        value = getFieldType().copy(value);
  -        // convert back to type of the persistent class
  -        return getFieldConversion().sqlToJava(value);
  -    }
  -
  -
  -    /**
        * Returns a string representation of this class.
        */
       public String toString()
  @@ -261,6 +223,7 @@
           buf.append("isAutoincrement", m_autoIncrement);
           buf.append("access", m_access);
           buf.append("sequenceName", m_sequenceName);
  +        buf.append("jdbcType", m_jdbcType);
           buf.append("super_class_fields ", "=> " + super.toString());
           buf.append(SystemUtils.LINE_SEPARATOR);
           return buf.toString();
  @@ -495,6 +458,14 @@
           return ACCESS_READONLY.equals(getAccess());
       }
   
  +    /**
  +     * Returns <em>true</em> if this field is declared as anonymous field.
  +     */
  +    public boolean isAnonymous()
  +    {
  +        return AnonymousPersistentField.class.isAssignableFrom(getPersistentField().getClass())
? true : false;
  +    }
  +
       /*
        * @see XmlCapable#toXML()
        */
  
  
  
  No                   revision
  No                   revision
  1.57.2.8  +23 -1     db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java
  
  Index: BrokerHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java,v
  retrieving revision 1.57.2.7
  retrieving revision 1.57.2.8
  diff -u -r1.57.2.7 -r1.57.2.8
  --- BrokerHelper.java	7 Feb 2005 20:42:42 -0000	1.57.2.7
  +++ BrokerHelper.java	13 Mar 2005 03:53:30 -0000	1.57.2.8
  @@ -937,6 +937,28 @@
           return result;
       }
   
  +    /**
  +     * Returns <em>true</em> if one or more anonymous FK fields are used.
  +     * @param cld The {@link org.apache.ojb.broker.metadata.ClassDescriptor} of the main
object.
  +     * @param rds The {@link org.apache.ojb.broker.metadata.ObjectReferenceDescriptor}
of the referenced object.
  +     * @return <em>true</em> if one or more anonymous FK fields are used for
specified reference.
  +     */
  +    public static boolean hasAnonymousKeyReference(ClassDescriptor cld, ObjectReferenceDescriptor
rds)
  +    {
  +        boolean result = false;
  +        FieldDescriptor[] fkFields = rds.getForeignKeyFieldDescriptors(cld);
  +        for(int i = 0; i < fkFields.length; i++)
  +        {
  +            FieldDescriptor fkField = fkFields[i];
  +            if(fkField.isAnonymous())
  +            {
  +                result = true;
  +                break;
  +            }
  +        }
  +        return result;
  +    }
  +
   //    /**
   //     * Returns a {@link java.util.List} instance of the specified object in method argument,
   //     * in which the argument must be of type {@link java.util.Collection}, array or
  
  
  
  No                   revision
  No                   revision
  1.7.2.3   +0 -2      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.7.2.2
  retrieving revision 1.7.2.3
  diff -u -r1.7.2.2 -r1.7.2.3
  --- StateNewClean.java	16 Nov 2004 17:45:35 -0000	1.7.2.2
  +++ StateNewClean.java	13 Mar 2005 03:53:30 -0000	1.7.2.3
  @@ -94,7 +94,6 @@
               throws org.apache.ojb.broker.PersistenceBrokerException
       {
           mod.doInsert();
  -        mod.refreshObjectImage();
           mod.setModificationState(StateOldClean.getInstance());
       }
   
  @@ -105,7 +104,6 @@
       public void commit(ObjectEnvelope mod) throws org.apache.ojb.broker.PersistenceBrokerException
       {
           mod.doInsert();
  -        mod.refreshObjectImage();
           mod.setModificationState(StateOldClean.getInstance());
       }
   
  
  
  
  1.6.2.3   +0 -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.6.2.2
  retrieving revision 1.6.2.3
  diff -u -r1.6.2.2 -r1.6.2.3
  --- StateNewDirty.java	16 Nov 2004 17:45:35 -0000	1.6.2.2
  +++ StateNewDirty.java	13 Mar 2005 03:53:30 -0000	1.6.2.3
  @@ -95,7 +95,6 @@
               throws org.apache.ojb.broker.PersistenceBrokerException
       {
           mod.doInsert();
  -        mod.refreshObjectImage();
           mod.setModificationState(StateOldClean.getInstance());
       }
   
  @@ -105,7 +104,6 @@
       public void commit(ObjectEnvelope mod) throws org.apache.ojb.broker.PersistenceBrokerException
       {
           mod.doInsert();
  -        mod.refreshObjectImage();
           mod.setModificationState(StateOldClean.getInstance());
       }
   
  
  
  
  1.7.2.2   +1 -0      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.7.2.1
  retrieving revision 1.7.2.2
  diff -u -r1.7.2.1 -r1.7.2.2
  --- StateOldDirty.java	16 Nov 2004 17:45:35 -0000	1.7.2.1
  +++ StateOldDirty.java	13 Mar 2005 03:53:30 -0000	1.7.2.2
  @@ -96,6 +96,7 @@
       public void commit(ObjectEnvelope mod) throws org.apache.ojb.broker.PersistenceBrokerException
       {
           mod.doUpdate();
  +        mod.setModificationState(StateOldClean.getInstance());
       }
   
       /**
  
  
  
  No                   revision
  No                   revision
  1.32.2.8  +342 -35   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.7
  retrieving revision 1.32.2.8
  diff -u -r1.32.2.7 -r1.32.2.8
  --- ObjectEnvelope.java	10 Mar 2005 17:55:31 -0000	1.32.2.7
  +++ ObjectEnvelope.java	13 Mar 2005 03:53:30 -0000	1.32.2.8
  @@ -32,16 +32,21 @@
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.core.proxy.CollectionProxy;
  +import org.apache.ojb.broker.core.proxy.CollectionProxyDefaultImpl;
  +import org.apache.ojb.broker.core.proxy.CollectionProxyListener;
   import org.apache.ojb.broker.core.proxy.IndirectionHandler;
   import org.apache.ojb.broker.core.proxy.ProxyHelper;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
  +import org.apache.ojb.broker.metadata.FieldType;
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
  +import org.apache.ojb.broker.util.BrokerHelper;
   import org.apache.ojb.broker.util.ObjectModification;
   import org.apache.ojb.broker.util.ObjectModificationDefaultImpl;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.broker.util.logging.Logger;
  +import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.odmg.states.ModificationState;
   import org.apache.ojb.odmg.states.StateNewDirty;
   import org.apache.ojb.odmg.states.StateOldClean;
  @@ -55,6 +60,8 @@
   public class ObjectEnvelope implements ObjectModification
   {
       static final long serialVersionUID = -829177767933340522L;
  +    static final int MATERIALIZED_OBJECT = 11;
  +    static final int IS_PROXY = 13;
       private Logger log = LoggerFactory.getLogger(ObjectEnvelope.class);
   
       /**
  @@ -76,6 +83,7 @@
        * end of the transaction.
        */
       private Map beforeImage;
  +    private Map currentImage;
       private ObjectEnvelopeTable buffer;
   
       /**
  @@ -107,9 +115,22 @@
           return buffer;
       }
   
  +    public Map getBeforeImage()
  +    {
  +        if(beforeImage == null) beforeImage = getMap(getBroker());
  +        return beforeImage;
  +    }
  +
  +    public Map getCurrentImage()
  +    {
  +        if(currentImage == null) currentImage = getMap(getBroker());
  +        return currentImage;
  +    }
  +
       public void close()
       {
           myObj = null;
  +        currentImage = null;
           beforeImage = null;
       }
   
  @@ -118,7 +139,6 @@
           PersistenceBroker broker = getBroker();
           try
           {
  -            hasChanged = null;
               // if an image already exists we
               // replace the Identity too, maybe a temporary
               // used PK value was replaced by the real one,
  @@ -127,11 +147,25 @@
               {
                   oid = broker.serviceIdentity().buildIdentity(myObj);
               }
  -            beforeImage = getMap(broker);
  +            if(currentImage != null)
  +            {
  +                beforeImage = currentImage;
  +            }
  +            else
  +            {
  +                if(beforeImage == null)
  +                {
  +                    beforeImage = getMap(getBroker());
  +                }
  +            }
  +            currentImage = null;
  +            hasChanged = null;
           }
           catch(Exception ex)
           {
               beforeImage = null;
  +            currentImage = null;
  +            hasChanged = null;
               log.error("Can't refresh object image", ex);
               throw new org.odmg.ClassNotPersistenceCapableException(ex.toString());
           }
  @@ -228,20 +262,10 @@
       {
           Map fieldValues = new HashMap();
           ClassDescriptor mif = broker.getClassDescriptor(getObject().getClass());
  +
           /**
            * MBAIRD
  -         * 1. register all fields of object that aren't collections or references
  -         */
  -        FieldDescriptor[] fieldDescs = mif.getFieldDescriptions();
  -        for(int i = 0; i < fieldDescs.length; i++)
  -        {
  -            FieldDescriptor fd = fieldDescs[i];
  -            // map copies of all field values
  -            fieldValues.put(fd.getColumnName(), fd.copyFieldValue(myObj));
  -        }
  -        /**
  -         * MBAIRD
  -         * 2. register all 1:1 references
  +         * 1. register all 1:1 references
            * field changes to 1:1 mapped objects should also be registered in the map,
            * so that alterations to those related objects will trigger an object to be
            * marked "dirty", otherwise attaching or detaching a 1:1 referenced object will
  @@ -269,25 +293,63 @@
                * if it hasn't been materialized, it hasn't changed.
                *
                * Also handles virtual proxies.
  +             *
  +             * arminw:
  +             * wrap Object or Identity with a helper class. The main object will get
  +             * dirty when the 1:1 reference change: add or replaced by another object or
deleted
                */
               IndirectionHandler handler = ProxyHelper.getIndirectionHandler(temp);
  -
  +            // if it is a not materialized proxy, use the Identity
               if(handler != null)
               {
  -                /**
  -                 * only register if the proxy has been materialized
  -                 * if it's materialized later and the map is compared, it will
  -                 * trigger the update
  -                 */
  -                fieldValues.put(rds, handler.getIdentity());
  +                temp = handler.alreadyMaterialized()
  +                        ? new EqualsRefHelper(handler.getRealSubject())
  +                        : new EqualsRefHelper(handler.getIdentity());
               }
               else
               {
  -                fieldValues.put(rds, temp);
  +                temp = new EqualsRefHelper(temp);
               }
  +            /*
  +            arminw:
  +            if object was serialized and anonymous FK are used in the main object, the
FK
  +            values are null, we have to refresh (re-assign) this values before building
field images
  +            */
  +            if(handler == null && temp != null && BrokerHelper.hasAnonymousKeyReference(mif,
rds))
  +            {
  +                getBroker().serviceBrokerHelper().link(myObj, rds, false);
  +            }
  +            /*
  +             register the Identity for 1:1 relations only, if change we have
  +             to update the main object
  +             */
  +            fieldValues.put(rds, temp);
           }
  +
  +
           /**
            * MBAIRD
  +         * 2. register all fields of object that aren't collections or references
  +         */
  +        FieldDescriptor[] fieldDescs = mif.getFieldDescriptions();
  +        for(int i = 0; i < fieldDescs.length; i++)
  +        {
  +            FieldDescriptor fld = fieldDescs[i];
  +            // map copies of all field values
  +            Object value = fld.getPersistentField().get(myObj);
  +            // get the real sql type value
  +            value = fld.getFieldConversion().javaToSql(value);
  +            // make copy of the sql type value
  +            value = fld.getJdbcType().getFieldType().copy(value);
  +            // buffer in image the field name and the sql type value
  +            // wrapped by a helper class
  +            fieldValues.put(fld.getPersistentField().getName(), new EqualsFieldHelper(fld.getJdbcType().getFieldType(),
value));
  +        }
  +
  +
  +        /**
  +         * TODO: fix bug, proxy collections will always be materialized
  +         * MBAIRD
            * 3. now let's register the collection descriptors
            * How do we handle proxied collections and collections of proxies
            */
  @@ -438,10 +500,9 @@
        */
       public boolean hasChanged(PersistenceBroker broker)
       {
  -        Map currentImage = null;
           try
           {
  -            currentImage = getMap(broker);
  +            currentImage = getCurrentImage();
           }
           catch(Exception e)
           {
  @@ -458,26 +519,46 @@
        */
       void markCollectionElements(PersistenceBroker broker)
       {
  -        Map currentImage = getMap(broker);
  +        Map currentImage = getCurrentImage();
   
           Iterator iter = currentImage.entrySet().iterator();
           while (iter.hasNext())
           {
               Map.Entry entry = (Map.Entry) iter.next();
  -            if (entry.getKey() instanceof CollectionDescriptor)
  +            if(entry.getKey() instanceof ObjectReferenceDescriptor)
               {
  -                CollectionDescriptor cds = (CollectionDescriptor) entry.getKey();
  +                if (entry.getKey() instanceof CollectionDescriptor)
  +                {
  +                    CollectionDescriptor cds = (CollectionDescriptor) entry.getKey();
  +                    Collection oldCol = (Collection) beforeImage.get(cds);
  +                    Collection newCol = (Collection) entry.getValue();
   
  -                Collection oldCol = (Collection) beforeImage.get(entry.getKey());
  -                Collection newCol = (Collection) entry.getValue();
  +                    if (!cds.isMtoNRelation())
  +                    {
  +                        markDelete(oldCol, newCol);
  +                    }
   
  -                if (!cds.isMtoNRelation())
  +                    // requires fix in InvocationHandler
  +                    markNew(oldCol, newCol);
  +                }
  +                else
                   {
  -                    markDelete(oldCol, newCol);
  +                    /*
  +                    check for new 1:1 reference object
  +                    */
  +                    ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) entry.getKey();
  +                    EqualsRefHelper oldEh = (EqualsRefHelper) beforeImage.get(rds);
  +                    EqualsRefHelper newEh = (EqualsRefHelper) currentImage.get(rds);
  +                    if(!oldEh.equals(newEh))
  +                    {
  +                        // if the new reference helper value is not null
  +                        // lock the object, because it can be a new unregistered object.
  +                        if(newEh.value != null)
  +                        {
  +                            getTx().lock(newEh.value, TransactionExt.WRITE);
  +                        }
  +                    }
                   }
  -
  -                // requires fix in InvocationHandler
  -                markNew(oldCol, newCol);
               }
           }
       }
  @@ -573,4 +654,230 @@
       {
           getBroker().removeFromCache(getIdentity());
       }
  +
  +
  +    //====================================================
  +    // inner class
  +    //====================================================
  +    /**
  +     * Help to compare field values.
  +     */
  +    class EqualsFieldHelper
  +    {
  +        FieldType type;
  +        Object value;
  +
  +        public EqualsFieldHelper(FieldType type, Object value)
  +        {
  +            this.type = type;
  +            this.value = value;
  +        }
  +
  +        public boolean equals(Object valueNew)
  +        {
  +            boolean result = false;
  +            if(this==valueNew)
  +            {
  +                result = true;
  +            }
  +            else
  +            {
  +                if(valueNew instanceof EqualsFieldHelper)
  +                {
  +                    result = type.equals(value, ((EqualsFieldHelper) valueNew).value);
  +                }
  +            }
  +            if(!result)
  +            {
  +                System.out.println("** changed field: " + getIdentity() + ", this="+this
+ ", other=" + valueNew);
  +            }
  +            return result;
  +        }
  +
  +        public String toString()
  +        {
  +            return "EqualsFieldHelper[type=" + type + "->value=" + value + "]";
  +        }
  +    }
  +
  +    //====================================================
  +    // inner class
  +    //====================================================
  +    /**
  +     * Help to compare 1:1 references of the main object.
  +     */
  +    class EqualsRefHelper
  +    {
  +        Identity oid;
  +        Object value;
  +
  +        public EqualsRefHelper(Object refObject)
  +        {
  +            this.value = refObject;
  +        }
  +
  +        public EqualsRefHelper(Identity oid)
  +        {
  +            this.oid = oid;
  +        }
  +
  +        public boolean equals(Object toCompare)
  +        {
  +            boolean result = false;
  +            if(this==toCompare)
  +            {
  +                result = true;
  +            }
  +            else
  +            {
  +                if(toCompare instanceof EqualsRefHelper)
  +                {
  +                    EqualsRefHelper other = (EqualsRefHelper) toCompare;
  +                    if(oid == null)
  +                    {
  +                        if(value != null)
  +                        {
  +                            oid = getBroker().serviceIdentity().buildIdentity(value);
  +                        }
  +                    }
  +                    if(other.oid == null)
  +                    {
  +                        if(other.value != null)
  +                        {
  +                            other.oid = getBroker().serviceIdentity().buildIdentity(other.value);
  +                        }
  +                    }
  +                    // return oid != null ? oid.equals(other.oid) : other.oid == null;
  +                    result = oid != null ? oid.equals(other.oid) : other.oid == null;
  +                }
  +            }
  +            if(!result)
  +            {
  +                System.out.println("** changed 1:1: " + getIdentity() + ", ref: " + oid);
  +            }
  +            return result;
  +        }
  +    }
  +
  +    //====================================================
  +    // inner class
  +    //====================================================
  +    /**
  +     * Help to compare 1:1 references of the main object.
  +     */
  +    class EqualsColHelper implements CollectionProxyListener
  +    {
  +        private CollectionProxy collectionHandler;
  +        private int status;
  +        private Map references;
  +
  +        void destroy()
  +        {
  +            if(collectionHandler != null)
  +            {
  +                collectionHandler.removeListener(this);
  +                collectionHandler = null;
  +            }
  +        }
  +
  +        void assignReferenceObject(Object collOrArray)
  +        {
  +            CollectionProxy colProxy = ProxyHelper.getCollectionProxy(collOrArray);
  +            if(colProxy != null)
  +            {
  +                if(colProxy.isLoaded())
  +                {
  +                    status = MATERIALIZED_OBJECT;
  +                    /*
  +                    TODO: avoid dependency to CollectionProxyDefaultImpl
  +                    e.g. change CollectionProxy interface - CollectionProxy should
  +                    extend Collection to support Iterator
  +                    */
  +                    handleCollectionProxy((CollectionProxyDefaultImpl) colProxy);
  +                }
  +                else
  +                {
  +                    status = IS_PROXY;
  +// TODO: ObjectEnvelopeTable#register take care of proxy objects/collection, no need to
handle proxy objects??
  +                    colProxy.addListener(this);
  +                    collectionHandler = colProxy;
  +                }
  +            }
  +            else
  +            {
  +                status = MATERIALIZED_OBJECT;
  +                handleCollectionOrArray(collOrArray);
  +            }
  +        }
  +
  +        public void beforeLoading(CollectionProxyDefaultImpl colProxy)
  +        {
  +        }
  +
  +        public void afterLoading(CollectionProxyDefaultImpl colProxy)
  +        {
  +            handleCollectionProxy(colProxy);
  +            status = MATERIALIZED_OBJECT;
  +            colProxy.removeListener(this);
  +            collectionHandler = null;
  +        }
  +
  +        void addReference(Identity oid, Object obj)
  +        {
  +            if(references == null)
  +            {
  +                references = new HashMap();
  +            }
  +            references.put(oid, obj);
  +        }
  +
  +        void handleCollectionOrArray(Object collOrArray)
  +        {
  +            if(collOrArray == null) return;
  +            Iterator it = BrokerHelper.getCollectionIterator(collOrArray);
  +            Object obj;
  +            while(it.hasNext())
  +            {
  +                obj = it.next();
  +                addReference(getBroker().serviceIdentity().buildIdentity(obj), obj);
  +            }
  +        }
  +
  +        void handleCollectionProxy(CollectionProxyDefaultImpl colProxy)
  +        {
  +            if(colProxy.getData() == null || colProxy.getData().size() == 0)
  +            {
  +                // nothing to do
  +                return;
  +            }
  +            // if the object materialize outside of a running tx (should not happen), we
have to lookup
  +            // a broker instance itself, so use PBCapsule to handle this
  +            PBCapsule capsule = new PBCapsule(colProxy.getBrokerKey(), getTx());
  +            try
  +            {
  +                PersistenceBroker broker = capsule.getBroker();
  +                Iterator it = colProxy.ojbIterator();
  +                Object tempObj;
  +                IndirectionHandler tempHandler;
  +                while(it.hasNext())
  +                {
  +                    tempObj = it.next();
  +                    // the referenced objects can be proxy objects too
  +                    tempHandler = ProxyHelper.getIndirectionHandler(tempObj);
  +                    if(tempHandler != null)
  +                    {
  +                        addReference(tempHandler.getIdentity(), tempObj);
  +                    }
  +                    else
  +                    {
  +                        addReference(broker.serviceIdentity().buildIdentity(tempObj), tempObj);
  +                    }
  +                }
  +            }
  +            finally
  +            {
  +                if(capsule != null) capsule.destroy();
  +            }
  +        }
  +    }
   }
  \ No newline at end of file
  
  
  
  1.32.2.10 +12 -15    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.9
  retrieving revision 1.32.2.10
  diff -u -r1.32.2.9 -r1.32.2.10
  --- ObjectEnvelopeTable.java	27 Nov 2004 23:46:07 -0000	1.32.2.9
  +++ ObjectEnvelopeTable.java	13 Mar 2005 03:53:30 -0000	1.32.2.10
  @@ -357,21 +357,18 @@
   	 */
   	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.refreshObjectImage();
  -						mod.setModificationState(StateOldClean.getInstance());
  -					}
  -			  }
  -		 }
  +          Iterator iter;
  +          // using clone to avoid ConcurentModificationException
  +          iter = ((List) mvOrderOfIds.clone()).iterator();
  +          while (iter.hasNext())
  +          {
  +                ObjectEnvelope mod = (ObjectEnvelope) mhtObjectEnvelopes.get(iter.next());
  +                mod.refreshObjectImage();
  +                if(needsCommit && mod.getModificationState() != StateOldClean.getInstance())
  +                {
  +                    mod.setModificationState(StateOldClean.getInstance());
  +                }
  +          }
   	}
   
       /**
  
  
  

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