db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/core MtoNBroker.java ValueContainer.java
Date Sat, 20 Dec 2003 16:07:54 GMT
brj         2003/12/20 08:07:54

  Modified:    src/java/org/apache/ojb/broker/core MtoNBroker.java
                        ValueContainer.java
  Log:
  use Arrays.equals in MtoNBroker.Key
  
  Revision  Changes    Path
  1.3       +12 -24    db-ojb/src/java/org/apache/ojb/broker/core/MtoNBroker.java
  
  Index: MtoNBroker.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/MtoNBroker.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MtoNBroker.java	9 Dec 2003 17:19:59 -0000	1.2
  +++ MtoNBroker.java	20 Dec 2003 16:07:54 -0000	1.3
  @@ -62,12 +62,14 @@
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
   import org.apache.ojb.broker.metadata.DescriptorRepository;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
  +import org.apache.ojb.broker.metadata.JdbcType;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.util.ProxyHelper;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
   import java.util.ArrayList;
  +import java.util.Arrays;
   import java.util.Collection;
   import java.util.Iterator;
   import java.util.List;
  @@ -316,19 +318,18 @@
   
               for (int i = 0; i < containers.length; i++)
               {
  -                m_containers[i] = new ValueContainer();
  +                Object value = containers[i].getValue();
  +                JdbcType type = containers[i].getJdbcType();
  +                
                   // BRJ:
                   // convert all Numbers to Long to simplify equals
                   // could lead to problems when Floats are used as key
  -                if (containers[i].getValue() instanceof Number)
  +                if (value instanceof Number)
                   {
  -                    m_containers[i].setValue(new Long(((Number) containers[i].getValue()).longValue()));
  +                    value = new Long(((Number) containers[i].getValue()).longValue());
                   }
  -                else
  -                {
  -                    m_containers[i].setValue(containers[i].getValue());
  -                }
  -                m_containers[i].setJdbcType(containers[i].getJdbcType());
  +                
  +                m_containers[i] = new ValueContainer(value, type);
               }
           }
   
  @@ -339,22 +340,9 @@
               if (other instanceof Key)
               {
                   Key otherKey = (Key)other;
  -                if (otherKey.m_containers.length == m_containers.length)
  -                {
  -                    for (int i= 0;i < m_containers.length; i++)
  -                    {
  -                        if (otherKey.m_containers[i].getValue().equals(m_containers[i].getValue()))
  -                        {
  -                            result = true;
  -                        }
  -                        else
  -                        {
  -                            result = false;
  -                            break;
  -                        }
  -                    }
  -                }
  +                result = Arrays.equals(m_containers, otherKey.m_containers);          
     
               }
  +            
               return result;
           }
       }
  
  
  
  1.3       +27 -20    db-ojb/src/java/org/apache/ojb/broker/core/ValueContainer.java
  
  Index: ValueContainer.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/ValueContainer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ValueContainer.java	9 Dec 2003 17:19:59 -0000	1.2
  +++ ValueContainer.java	20 Dec 2003 16:07:54 -0000	1.3
  @@ -14,19 +14,8 @@
    */
   public final class ValueContainer
   {
  -    private JdbcType jdbcType;
  -    private Object value;
  -
  -    /*
  -    arminw:
  -    first version of this class encapsulated value and field-descriptor to describe
  -    the value object, but when using non-decomposed m:n references it is not possible to
get an
  -    field-descriptor represents the columns of the indirection table. Thus
  -    I this version only use value and jdbcType to describe the the value object.
  -    */
  -    public ValueContainer()
  -    {
  -    }
  +    private JdbcType m_jdbcType;
  +    private Object m_value;
   
       public ValueContainer(Object value, JdbcType jdbcType)
       {
  @@ -36,17 +25,17 @@
   
       public JdbcType getJdbcType()
       {
  -        return jdbcType;
  +        return m_jdbcType;
       }
   
       public void setJdbcType(JdbcType jdbcType)
       {
  -        this.jdbcType = jdbcType;
  +        this.m_jdbcType = jdbcType;
       }
   
       public Object getValue()
       {
  -        return value;
  +        return m_value;
       }
   
       public void setValue(Object value)
  @@ -55,13 +44,31 @@
           {
               throw new RuntimeException("We can't nest ValueContainers");
           }
  -        this.value = value;
  +        this.m_value = value;
  +    }
  +
  +    public boolean equals(Object obj)
  +    {
  +        if (obj instanceof ValueContainer)
  +        {
  +            return m_value.equals(((ValueContainer)obj).m_value);
  +        }
  +        else
  +        {
  +            return false;
  +        }
       }
   
  +    public int hashCode()
  +    {
  +        return m_value.hashCode();
  +    }
  +    
       public String toString()
       {
           return this.getClass().getName() + "[jdbcType: "
  -                + jdbcType
  -                + ", value: " + value + "]";
  +        + m_jdbcType
  +        + ", value: " + m_value + "]";
       }
  +    
   }
  
  
  

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