db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r357840 - in /db/ddlutils/trunk/src/java/org/apache/ddlutils/model: Column.java IndexColumn.java Table.java UniqueIndex.java
Date Mon, 19 Dec 2005 23:54:59 GMT
Author: tomdz
Date: Mon Dec 19 15:54:53 2005
New Revision: 357840

URL: http://svn.apache.org/viewcvs?rev=357840&view=rev
Log:
Adjustments to the equals/hashCode methods catering for numerical types

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexColumn.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/UniqueIndex.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java?rev=357840&r1=357839&r2=357840&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java Mon Dec 19 15:54:53 2005
@@ -427,20 +427,26 @@
     {
         if (obj instanceof Column)
         {
-            Column other = (Column)obj;
+            Column        other      = (Column)obj;
+            EqualsBuilder comparator = new EqualsBuilder();
 
             // Note that this compares case sensitive
-            return new EqualsBuilder().append(_name,          other._name)
-                                      .append(_primaryKey,    other._primaryKey)
-                                      .append(_required,      other._required)
-                                      .append(_autoIncrement, other._autoIncrement)
-                                      .append(_typeCode,      other._typeCode)
-                                      .append(_type,          other._type)
-                                      .append(_size,          other._size)
-                                      .append(_sizeAsInt,     other._sizeAsInt)
-                                      .append(_scale,         other._scale)
-                                      .append(_defaultValue,  other._defaultValue)
-                                      .isEquals();
+            comparator.append(_name,          other._name);
+            comparator.append(_primaryKey,    other._primaryKey);
+            comparator.append(_required,      other._required);
+            comparator.append(_autoIncrement, other._autoIncrement);
+            comparator.append(_typeCode,      other._typeCode);
+            comparator.append(_type,          other._type);
+            comparator.append(_scale,         other._scale);
+            comparator.append(_defaultValue,  other._defaultValue);
+
+            // comparing the size makes only sense for types where it is relevant
+            if (!TypeMap.isNumericType(_typeCode) && TypeMap.isNumericType(other._typeCode))
+            {
+                comparator.append(_size, other._size);
+            }
+
+            return comparator.isEquals();
         }
         else
         {
@@ -453,17 +459,22 @@
      */
     public int hashCode()
     {
-        return new HashCodeBuilder(17, 37).append(_name)
-                                          .append(_primaryKey)
-                                          .append(_required)
-                                          .append(_autoIncrement)
-                                          .append(_typeCode)
-                                          .append(_type)
-                                          .append(_size)
-                                          .append(_sizeAsInt)
-                                          .append(_scale)
-                                          .append(_defaultValue)
-                                          .toHashCode();
+        HashCodeBuilder builder = new HashCodeBuilder(17, 37);
+
+        builder.append(_name);
+        builder.append(_primaryKey);
+        builder.append(_required);
+        builder.append(_autoIncrement);
+        builder.append(_typeCode);
+        builder.append(_type);
+        builder.append(_scale);
+        builder.append(_defaultValue);
+        if (!TypeMap.isNumericType(_typeCode))
+        {
+            builder.append(_size);
+        }
+        
+        return builder.toHashCode();
     }
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexColumn.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexColumn.java?rev=357840&r1=357839&r2=357840&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexColumn.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexColumn.java Mon Dec 19 15:54:53
2005
@@ -40,6 +40,23 @@
     // TODO: It might be useful if the referenced column is directly acessible here ?
 
     /**
+     * Creates a new index column object.
+     */
+    public IndexColumn()
+    {
+    }
+    
+    /**
+     * Creates a new index column object.
+     * 
+     * @param columnName The name of the corresponding table column
+     */
+    public IndexColumn(String columnName)
+    {
+        _name = columnName;
+    }
+    
+    /**
      * Returns the name of the column.
      * 
      * @return The name

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java?rev=357840&r1=357839&r2=357840&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java Mon Dec 19 15:54:53 2005
@@ -624,10 +624,8 @@
             Table other = (Table)obj;
 
             // Note that this compares case sensitive
-            return new EqualsBuilder().append(_catalog,     other._catalog)
-                                      .append(_schema,      other._schema)
-                                      .append(_name,        other._name)
-                                      .append(_type,        other._type)
+            // TODO: For now we ignore catalog and schema (type should be irrelevant anyways)
+            return new EqualsBuilder().append(_name,        other._name)
                                       .append(_columns,     other._columns)
                                       .append(_foreignKeys, other._foreignKeys)
                                       .append(_indices,     other._indices)
@@ -644,10 +642,8 @@
      */
     public int hashCode()
     {
-        return new HashCodeBuilder(17, 37).append(_catalog)
-                                          .append(_schema)
-                                          .append(_name)
-                                          .append(_type)
+        // TODO: For now we ignore catalog and schema (type should be irrelevant anyways)
+        return new HashCodeBuilder(17, 37).append(_name)
                                           .append(_columns)
                                           .append(_foreignKeys)
                                           .append(_indices)

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/UniqueIndex.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/UniqueIndex.java?rev=357840&r1=357839&r2=357840&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/UniqueIndex.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/UniqueIndex.java Mon Dec 19 15:54:53
2005
@@ -18,9 +18,6 @@
 
 import java.util.ArrayList;
 
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-
 /**
  * Provides compatibility with Torque-style xml with separate <index> and
  * <unique> tags, but adds no functionality.  All indexes are treated the
@@ -64,9 +61,8 @@
         {
             UniqueIndex other = (UniqueIndex)obj;
 
-            return new EqualsBuilder().append(_name,    other._name)
-                                      .append(_columns, other._columns)
-                                      .isEquals();
+            // Note that we ignore the name here
+            return _columns.equals(other._columns);
         }
         else
         {
@@ -79,9 +75,7 @@
      */
     public int hashCode()
     {
-        return new HashCodeBuilder(17, 37).append(_name)
-                                          .append(_columns)
-                                          .toHashCode();
+        return _columns.hashCode();
     }
 
     /**



Mime
View raw message