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/broker/core PersistenceBrokerImpl.java
Date Fri, 13 Feb 2004 12:58:51 GMT
arminw      2004/02/13 04:58:51

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
  Added:       src/java/org/apache/ojb/broker/util IdentityArrayList.java
  Log:
  patch by Guillaume Nodet
  use object identity based List on store/delete
  to prevent problem could arise with user specific
  equals/hashcode implementations of pc objects
  
  Revision  Changes    Path
  1.1                  db-ojb/src/java/org/apache/ojb/broker/util/IdentityArrayList.java
  
  Index: IdentityArrayList.java
  ===================================================================
  package org.apache.ojb.broker.util;
  
  import java.util.ArrayList;
  
  /**
   * Object identity based {@link java.util.List}, use <tt>"=="</tt> instead of
   * <tt>element_1.equals(element_2)</tt> to compare objects.
   *
   * @author Guillaume Nodet
   * @version $Id: IdentityArrayList.java,v 1.1 2004/02/13 12:58:51 arminw Exp $
   */
  public class IdentityArrayList extends ArrayList
  {
      public boolean contains(Object elem)
      {
          return indexOf(elem) >= 0;
      }
  
      public int indexOf(Object elem)
      {
          for(int i = 0; i < size(); i++)
              if(elem == get(i))
                  return i;
          return -1;
      }
  
      public int lastIndexOf(Object elem)
      {
          for(int i = size() - 1; i >= 0; i--)
              if(elem == get(i))
                  return i;
          return -1;
      }
  }
  
  
  
  1.66      +15 -5     db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- PersistenceBrokerImpl.java	6 Feb 2004 13:01:52 -0000	1.65
  +++ PersistenceBrokerImpl.java	13 Feb 2004 12:58:51 -0000	1.66
  @@ -54,7 +54,6 @@
    * <http://www.apache.org/>.
    */
   
  -import java.util.ArrayList;
   import java.util.Arrays;
   import java.util.Collection;
   import java.util.Collections;
  @@ -101,6 +100,7 @@
   import org.apache.ojb.broker.query.QueryBySQL;
   import org.apache.ojb.broker.util.ArrayIterator;
   import org.apache.ojb.broker.util.BrokerHelper;
  +import org.apache.ojb.broker.util.IdentityArrayList;
   import org.apache.ojb.broker.util.ObjectModification;
   import org.apache.ojb.broker.util.ProxyHelper;
   import org.apache.ojb.broker.util.logging.Logger;
  @@ -161,8 +161,14 @@
       /**
        * List of objects being stored now, allows to avoid infinite
        * recursion storeCollections -> storeReferences -> storeCollections...
  +     *
        */
  -    private List nowStoring = new ArrayList();
  +    /*
  +    we use an object identity based List to compare objects to prevent problems
  +    with user implemented equals/hashCode methods of persistence capable objects
  +    (e.g. objects are equals but PK fields not)
  +    */
  +    private List nowStoring = new IdentityArrayList();
   
       /**
        * Lists for object registration during delete operations.
  @@ -170,10 +176,14 @@
        * @see #clearRegistrationLists
        */
       /*
  -    arminw: list was cleared before delete method was end. Intern we only
  +    arminw: list was cleared before delete method end. Internal we only
       call doDelete(...) method. Same procedure as 'nowStoring'
  +
  +    we use an object identity based List to compare objects to prevent problems
  +    with user implemented equals/hashCode methods of persistence capable objects
  +    (e.g. objects are equals but PK fields not)
       */
  -    private List markedForDelete = new ArrayList();
  +    private List markedForDelete = new IdentityArrayList();
   
   
       /**
  
  
  

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