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 MtoNBroker.java GenericObject.java
Date Tue, 21 Sep 2004 00:30:42 GMT
arminw      2004/09/20 17:30:42

  Modified:    src/java/org/apache/ojb/broker/core MtoNBroker.java
  Removed:     src/java/org/apache/ojb/broker/core GenericObject.java
  Log:
  make GenericObject an inner class of MtoNBroker
  
  Revision  Changes    Path
  1.12      +124 -1    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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- MtoNBroker.java	14 Sep 2004 16:16:35 -0000	1.11
  +++ MtoNBroker.java	21 Sep 2004 00:30:42 -0000	1.12
  @@ -20,11 +20,14 @@
   import java.util.Iterator;
   import java.util.List;
   import java.util.Vector;
  +import java.io.Serializable;
   
   import org.apache.commons.lang.builder.EqualsBuilder;
   import org.apache.commons.lang.builder.HashCodeBuilder;
  +import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.ojb.broker.MtoNImplementor;
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.core.proxy.ProxyHelper;
   import org.apache.ojb.broker.accesslayer.ResultSetAndStatement;
   import org.apache.ojb.broker.accesslayer.sql.SqlGenerator;
  @@ -404,6 +407,126 @@
               hb.append(m_containers);
   
               return hb.toHashCode();
  +        }
  +    }
  +
  +
  +
  +    // ************************************************************************
  +    // inner class
  +    // ************************************************************************
  +    final class GenericObject implements Serializable
  +    {
  +        private String tablename;
  +        private String[] columnNames;
  +        private ValueContainer[] values;
  +
  +        public GenericObject(String tablename, String[] columnNames, ValueContainer[] values)
  +        {
  +            this.tablename = tablename;
  +            this.columnNames = columnNames;
  +            this.values = values;
  +            if(values != null && columnNames.length != values.length)
  +            {
  +                throw new OJBRuntimeException("Column name array and value array have NOT
same length");
  +            }
  +        }
  +
  +        public boolean equals(Object obj)
  +        {
  +            if(this == obj)
  +            {
  +                return true;
  +            }
  +            boolean result = false;
  +            if(obj instanceof GenericObject)
  +            {
  +                GenericObject other = (GenericObject) obj;
  +                if(result = (tablename.equalsIgnoreCase(other.tablename)
  +                        && (columnNames != null)
  +                        && (other.columnNames != null)
  +                        && (columnNames.length == other.columnNames.length)))
  +                {
  +                    for (int i = 0; i < columnNames.length; i++)
  +                    {
  +                        // System.out.println("## test: " + this);
  +                        int otherIndex = other.indexForColumn(columnNames[i]);
  +                        if(otherIndex < 0)
  +                        {
  +                            result = false;
  +                            break;
  +                        }
  +                        result = result && values[i].equals(other.values[otherIndex]);
  +                        if(!result) break;
  +                    }
  +    //                if(result)
  +    //                {
  +    //                    System.out.println("## Match: " + this);
  +    //                }
  +                }
  +            }
  +            return result;
  +        }
  +
  +        int indexForColumn(String name)
  +        {
  +            int result = -1;
  +            for (int i = 0; i < columnNames.length; i++)
  +            {
  +                if(columnNames[i].equals(name))
  +                {
  +                    result = i;
  +                    break;
  +                }
  +            }
  +            return result;
  +        }
  +
  +        public int hashCode()
  +        {
  +            return super.hashCode();
  +        }
  +
  +        public ValueContainer getValueFor(String columnName)
  +        {
  +            try
  +            {
  +                return values[indexForColumn(columnName)];
  +            }
  +            catch(Exception e)
  +            {
  +                throw new OJBRuntimeException("Can't find value for column " + columnName
  +                        + (indexForColumn(columnName) < 0 ? ". Column name was not found"
: ""), e);
  +            }
  +        }
  +
  +        public String getTablename()
  +        {
  +            return tablename;
  +        }
  +
  +        public String[] getColumnNames()
  +        {
  +            return columnNames;
  +        }
  +
  +        public ValueContainer[] getValues()
  +        {
  +            return values;
  +        }
  +
  +        public void setValues(ValueContainer[] values)
  +        {
  +            this.values = values;
  +        }
  +
  +        public String toString()
  +        {
  +            return new ToStringBuilder(this)
  +                    .append("tableName", tablename)
  +                    .append("columnNames", columnNames)
  +                    .append("values", values)
  +                    .toString();
           }
       }
   }
  
  
  

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