db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r394581 [1/2] - in /db/ddlutils/trunk/src: check/ java/org/apache/ddlutils/alteration/ java/org/apache/ddlutils/model/ test/org/apache/ddlutils/alteration/
Date Sun, 16 Apr 2006 23:47:20 GMT
Author: tomdz
Date: Sun Apr 16 16:47:18 2006
New Revision: 394581

URL: http://svn.apache.org/viewcvs?rev=394581&view=rev
Log:
Added first part of new alteration algorithm

Added:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddColumnChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddForeignKeyChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddIndexChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddPrimaryKeyChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddTableChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnAutoIncrementChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDataTypeChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDefaultValueChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnRequiredChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnSizeChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ModelComparator.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/PrimaryKeyChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveColumnChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveForeignKeyChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveIndexChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemovePrimaryKeyChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveTableChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/package.html
    db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestModelComparator.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/package.html
Modified:
    db/ddlutils/trunk/src/check/ddlutils-checks.xml
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/ForeignKey.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Index.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexColumn.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/NonUniqueIndex.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/UniqueIndex.java

Modified: db/ddlutils/trunk/src/check/ddlutils-checks.xml
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/check/ddlutils-checks.xml?rev=394581&r1=394580&r2=394581&view=diff
==============================================================================
--- db/ddlutils/trunk/src/check/ddlutils-checks.xml (original)
+++ db/ddlutils/trunk/src/check/ddlutils-checks.xml Sun Apr 16 16:47:18 2006
@@ -13,7 +13,6 @@
 
         <module name="JavadocType">
             <property name="versionFormat" value="${checkstyle.version.pattern}"/>
-            <property name="authorFormat" value="${checkstyle.author.pattern}"/>
         </module>
 
         <module name="JavadocMethod">

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddColumnChange.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddColumnChange.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddColumnChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddColumnChange.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,65 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Represents the addition of a column to a table.
+ * 
+ * @version $Revision: $
+ */
+public class AddColumnChange
+{
+    /** The table to add the column to. */
+    private Table _table;
+    /** The new column. */
+    private Column _newColumn;
+
+    /**
+     * Creates a new change object.
+     * 
+     * @param table     The table to add the column to
+     * @param newColumn The new column
+     */
+    public AddColumnChange(Table table, Column newColumn)
+    {
+        _table     = table;
+        _newColumn = newColumn;
+    }
+
+    /**
+     * Returns the new column.
+     *
+     * @return The new column
+     */
+    public Column getNewColumn()
+    {
+        return _newColumn;
+    }
+
+    /**
+     * Returns the table to add the column to.
+     *
+     * @return The table
+     */
+    public Table getTable()
+    {
+        return _table;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddForeignKeyChange.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddForeignKeyChange.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddForeignKeyChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddForeignKeyChange.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,65 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.model.ForeignKey;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Represents the addition of a foreign key to a table.
+ * 
+ * @version $Revision: $
+ */
+public class AddForeignKeyChange
+{
+    /** The table to add the foreign key to. */
+    private Table _table;
+    /** The new foreign key. */
+    private ForeignKey _newForeignKey;
+
+    /**
+     * Creates a new change object.
+     * 
+     * @param table         The table to add the foreign key to
+     * @param newForeignKey The new foreign key
+     */
+    public AddForeignKeyChange(Table table, ForeignKey newForeignKey)
+    {
+        _table         = table;
+        _newForeignKey = newForeignKey;
+    }
+
+    /**
+     * Returns the new foreign key.
+     *
+     * @return The new foreign key
+     */
+    public ForeignKey getNewForeignKey()
+    {
+        return _newForeignKey;
+    }
+
+    /**
+     * Returns the table where the foreign key is to be added.
+     *
+     * @return The table
+     */
+    public Table getTable()
+    {
+        return _table;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddIndexChange.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddIndexChange.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddIndexChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddIndexChange.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,65 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.model.Index;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Represents the addition of an index to a table.
+ * 
+ * @version $Revision: $
+ */
+public class AddIndexChange
+{
+    /** The table to add the index to. */
+    private Table _table;
+    /** The new index. */
+    private Index _newIndex;
+
+    /**
+     * Creates a new change object.
+     * 
+     * @param table    The table to add the index to
+     * @param newIndex The new index
+     */
+    public AddIndexChange(Table table, Index newIndex)
+    {
+        _table    = table;
+        _newIndex = newIndex;
+    }
+
+    /**
+     * Returns the new index.
+     *
+     * @return The new index
+     */
+    public Index getNewIndex()
+    {
+        return _newIndex;
+    }
+
+    /**
+     * Returns the table where the index is to be added.
+     *
+     * @return The table
+     */
+    public Table getTable()
+    {
+        return _table;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddPrimaryKeyChange.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddPrimaryKeyChange.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddPrimaryKeyChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddPrimaryKeyChange.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,65 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Represents the addition of a primary key to a table which does not have one.
+ * 
+ * @version $Revision: $
+ */
+public class AddPrimaryKeyChange
+{
+    /** The table to add the primary key to. */
+    private Table    _table;
+    /** The columns making up the primary key. */
+    private Column[] _primaryKeyColumns;
+
+    /**
+     * Creates a new change object.
+     * 
+     * @param table             The table to add the primary key to
+     * @param primaryKeyColumns The columns making up the primary key
+     */
+    public AddPrimaryKeyChange(Table table, Column[] primaryKeyColumns)
+    {
+        _table             = table;
+        _primaryKeyColumns = primaryKeyColumns;
+    }
+
+    /**
+     * Returns the primary key columns making up the new primary key.
+     *
+     * @return The primary key columns
+     */
+    public Column[] getPrimaryKeyColumns()
+    {
+        return _primaryKeyColumns;
+    }
+
+    /**
+     * Returns the table to add the primary key to.
+     *
+     * @return The table
+     */
+    public Table getTable()
+    {
+        return _table;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddTableChange.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddTableChange.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddTableChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddTableChange.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,53 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Represents the addition of a table to a model. Note that this change does not include foreign keys
+ * originating from the new table.
+ * 
+ * @version $Revision: $
+ */
+public class AddTableChange
+{
+    /** The new table. */
+    private Table _newTable;
+
+    /**
+     * Creates a new change object.
+     * 
+     * @param newTable The new table
+     */
+    public AddTableChange(Table newTable)
+    {
+        _newTable = newTable;
+    }
+
+    /**
+     * Returns the new table. Note that only the columns and table-level constraints are to be used.
+     * Any model-level constraints (e.g. foreign keys) shall be ignored as there are different change
+     * objects for them.
+     * 
+     * @return The new table
+     */
+    public Table getNewTable()
+    {
+        return _newTable;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnAutoIncrementChange.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnAutoIncrementChange.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnAutoIncrementChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnAutoIncrementChange.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,66 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Represents the change of the auto-increment constraint of a column. Since it is a boolean value,
+ * this means the required constraint will simply be toggled.
+ * 
+ * @version $Revision: $
+ */
+public class ColumnAutoIncrementChange
+{
+    /** The table of the column. */
+    private Table _table;
+    /** The column. */
+    private Column _column;
+
+    /**
+     * Creates a new change object.
+     * 
+     * @param table  The table of the column
+     * @param column The column
+     */
+    public ColumnAutoIncrementChange(Table table, Column column)
+    {
+        _table  = table;
+        _column = column;
+    }
+
+    /**
+     * Returns the column.
+     *
+     * @return The column
+     */
+    public Column getColumn()
+    {
+        return _column;
+    }
+
+    /**
+     * Returns the table of the column.
+     *
+     * @return The table
+     */
+    public Table getTable()
+    {
+        return _table;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDataTypeChange.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDataTypeChange.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDataTypeChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDataTypeChange.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,79 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Represents the change of the data type of a column.
+ * 
+ * @version $Revision: $
+ */
+public class ColumnDataTypeChange
+{
+    /** The table of the column. */
+    private Table _table;
+    /** The column. */
+    private Column _column;
+    /** The JDBC type code of the new type. */
+    private int _newTypeCode;
+
+    /**
+     * Creates a new change object.
+     * 
+     * @param table       The table of the column
+     * @param column      The column
+     * @param newTypeCode The JDBC type code of the new type
+     */
+    public ColumnDataTypeChange(Table table, Column column, int newTypeCode)
+    {
+        _table       = table;
+        _column      = column;
+        _newTypeCode = newTypeCode;
+    }
+
+    /**
+     * Returns the column.
+     *
+     * @return The column
+     */
+    public Column getColumn()
+    {
+        return _column;
+    }
+
+    /**
+     * Returns the JDBC type code of the new type.
+     *
+     * @return The type code
+     */
+    public int getNewTypeCode()
+    {
+        return _newTypeCode;
+    }
+
+    /**
+     * Returns the table of the column.
+     *
+     * @return The table
+     */
+    public Table getTable()
+    {
+        return _table;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDefaultValueChange.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDefaultValueChange.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDefaultValueChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDefaultValueChange.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,79 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Represents the change of the default value of a column.
+ * 
+ * @version $Revision: $
+ */
+public class ColumnDefaultValueChange
+{
+    /** The table of the column. */
+    private Table _table;
+    /** The column. */
+    private Column _column;
+    /** The new default value. */
+    private String _newDefaultValue;
+
+    /**
+     * Creates a new change object.
+     * 
+     * @param table           The table of the column
+     * @param column          The column
+     * @param newDefaultValue The new default value
+     */
+    public ColumnDefaultValueChange(Table table, Column column, String newDefaultValue)
+    {
+        _table           = table;
+        _column          = column;
+        _newDefaultValue = newDefaultValue;
+    }
+
+    /**
+     * Returns the column.
+     *
+     * @return The column
+     */
+    public Column getColumn()
+    {
+        return _column;
+    }
+
+    /**
+     * Returns the new default value.
+     *
+     * @return The new default value
+     */
+    public String getNewDefaultValue()
+    {
+        return _newDefaultValue;
+    }
+
+    /**
+     * Returns the table of the column.
+     *
+     * @return The table
+     */
+    public Table getTable()
+    {
+        return _table;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnRequiredChange.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnRequiredChange.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnRequiredChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnRequiredChange.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,66 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Represents the change of the required constraint of a column. Since it is a boolean value,
+ * this means the required constraint will simply be toggled.
+ * 
+ * @version $Revision: $
+ */
+public class ColumnRequiredChange
+{
+    /** The table of the column. */
+    private Table _table;
+    /** The column. */
+    private Column _column;
+
+    /**
+     * Creates a new change object.
+     * 
+     * @param table  The table of the column
+     * @param column The column
+     */
+    public ColumnRequiredChange(Table table, Column column)
+    {
+        _table  = table;
+        _column = column;
+    }
+
+    /**
+     * Returns the column.
+     *
+     * @return The column
+     */
+    public Column getColumn()
+    {
+        return _column;
+    }
+
+    /**
+     * Returns the table of the column.
+     *
+     * @return The table
+     */
+    public Table getTable()
+    {
+        return _table;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnSizeChange.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnSizeChange.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnSizeChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnSizeChange.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,93 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Represents the change of the size or scale of a column.
+ * 
+ * @version $Revision: $
+ */
+public class ColumnSizeChange
+{
+    /** The table of the column. */
+    private Table _table;
+    /** The column. */
+    private Column _column;
+    /** The new size. */
+    private int _newSize;
+    /** The new scale. */
+    private int _newScale;
+
+    /**
+     * Creates a new change object.
+     * 
+     * @param table    The table of the column
+     * @param column   The column
+     * @param newSize  The new size
+     * @param newScale The new scale
+     */
+    public ColumnSizeChange(Table table, Column column, int newSize, int newScale)
+    {
+        _table    = table;
+        _column   = column;
+        _newSize  = newSize;
+        _newScale = newScale;
+    }
+
+    /**
+     * Returns the column.
+     *
+     * @return The column
+     */
+    public Column getColumn()
+    {
+        return _column;
+    }
+
+    /**
+     * Returns the new size of the column.
+     *
+     * @return The new size
+     */
+    public int getNewSize()
+    {
+        return _newSize;
+    }
+
+    /**
+     * Returns the new scale of the column.
+     *
+     * @return The new scale
+     */
+    public int getNewScale()
+    {
+        return _newScale;
+    }
+
+    /**
+     * Returns the table of the column.
+     *
+     * @return The table
+     */
+    public Table getTable()
+    {
+        return _table;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ModelComparator.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ModelComparator.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ModelComparator.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ModelComparator.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,379 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Database;
+import org.apache.ddlutils.model.ForeignKey;
+import org.apache.ddlutils.model.Index;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Compares two database models and creates change objects that express how to
+ * adapt the first model so that it becomes the second one. Neither of the models
+ * are changed in the process, however, it is also assumed that the models do not
+ * change in between.
+ * 
+ * @version $Revision: $
+ */
+public class ModelComparator
+{
+    /** The log for this comparator. */
+    private final Log _log = LogFactory.getLog(ModelComparator.class);
+
+    /** Whether comparison is case sensitive. */
+    private boolean _caseSensitive;
+
+    /**
+     * Creates a new model comparator object.
+     * 
+     * @param caseSensitive Whether comparison is case sensitive
+     */
+    public ModelComparator(boolean caseSensitive)
+    {
+        _caseSensitive = caseSensitive;
+    }
+
+    /**
+     * Compares the two models and returns the changes necessary to create the second
+     * model from the first one.
+     *  
+     * @param sourceModel The source model
+     * @param targetModel The target model
+     * @return The changes
+     */
+    public List compare(Database sourceModel, Database targetModel)
+    {
+        ArrayList changes = new ArrayList();
+
+        for (int tableIdx = 0; tableIdx < targetModel.getTableCount(); tableIdx++)
+        {
+            Table targetTable = targetModel.getTable(tableIdx);
+            Table sourceTable = sourceModel.findTable(targetTable.getName(), _caseSensitive);
+
+            if (sourceTable == null)
+            {
+                if (_log.isInfoEnabled())
+                {
+                    _log.info("Table " + targetTable.getName() + " needs to be added");
+                }
+                changes.add(new AddTableChange(targetTable));
+                for (int fkIdx = 0; fkIdx < targetTable.getForeignKeyCount(); fkIdx++)
+                {
+                    changes.add(new AddForeignKeyChange(sourceTable, targetTable.getForeignKey(fkIdx)));
+                }
+            }
+            else
+            {
+                changes.addAll(compareTables(sourceModel, sourceTable, targetModel, targetTable));
+            }
+        }
+
+        for (int tableIdx = 0; tableIdx < sourceModel.getTableCount(); tableIdx++)
+        {
+            Table sourceTable = sourceModel.getTable(tableIdx);
+            Table targetTable = targetModel.findTable(sourceTable.getName(), _caseSensitive);
+
+            if ((targetTable == null) && (sourceTable.getName() != null) && (sourceTable.getName().length() > 0))
+            {
+                if (_log.isInfoEnabled())
+                {
+                    _log.info("Table " + sourceTable.getName() + " needs to be removed");
+                }
+                changes.add(new RemoveTableChange(sourceTable));
+                // we assume that the target model is sound, ie. that there are no longer any foreign
+                // keys to this table in the target model; thus we already have removeFK changes for
+                // these from the compareTables method and we only need to create changes for the fks
+                // originating from this table
+                for (int fkIdx = 0; fkIdx < sourceTable.getForeignKeyCount(); fkIdx++)
+                {
+                    changes.add(new RemoveForeignKeyChange(sourceTable, sourceTable.getForeignKey(fkIdx)));
+                }
+            }
+        }
+        return changes;
+    }
+
+    /**
+     * Compares the two tables and returns the changes necessary to create the second
+     * table from the first one.
+     *  
+     * @param sourceModel The source model which contains the source table
+     * @param sourceTable The source table
+     * @param targetModel The target model which contains the target table
+     * @param targetTable The target table
+     * @return The changes
+     */
+    public List compareTables(Database sourceModel,
+                              Table    sourceTable,
+                              Database targetModel,
+                              Table    targetTable)
+    {
+        ArrayList changes = new ArrayList();
+
+        for (int fkIdx = 0; fkIdx < sourceTable.getForeignKeyCount(); fkIdx++)
+        {
+            ForeignKey sourceFk = sourceTable.getForeignKey(fkIdx);
+            ForeignKey targetFk = findCorrespondingForeignKey(targetTable, sourceFk);
+
+            if (targetFk == null)
+            {
+                if (_log.isInfoEnabled())
+                {
+                    _log.info("Foreign key " + sourceFk + " needs to be removed from table " + sourceTable.getName());
+                }
+                changes.add(new RemoveForeignKeyChange(sourceTable, sourceFk));
+            }
+        }
+
+        for (int fkIdx = 0; fkIdx < targetTable.getForeignKeyCount(); fkIdx++)
+        {
+            ForeignKey targetFk = targetTable.getForeignKey(fkIdx);
+            ForeignKey sourceFk = findCorrespondingForeignKey(sourceTable, targetFk);
+
+            if (sourceFk == null)
+            {
+                if (_log.isInfoEnabled())
+                {
+                    _log.info("Foreign key " + targetFk + " needs to be created for table " + sourceTable.getName());
+                }
+                changes.add(new AddForeignKeyChange(sourceTable, targetFk));
+            }
+        }
+
+        for (int indexIdx = 0; indexIdx < sourceTable.getIndexCount(); indexIdx++)
+        {
+            Index sourceIndex = sourceTable.getIndex(indexIdx);
+            Index targetIndex = findCorrespondingIndex(targetTable, sourceIndex);
+
+            if (targetIndex == null)
+            {
+                if (_log.isInfoEnabled())
+                {
+                    _log.info("Index " + sourceIndex.getName() + " needs to be removed from table " + sourceTable.getName());
+                }
+                changes.add(new RemoveIndexChange(sourceTable, sourceIndex));
+            }
+        }
+        for (int indexIdx = 0; indexIdx < targetTable.getIndexCount(); indexIdx++)
+        {
+            Index targetIndex = targetTable.getIndex(indexIdx);
+            Index sourceIndex = findCorrespondingIndex(sourceTable, targetIndex);
+
+            if (sourceIndex == null)
+            {
+                if (_log.isInfoEnabled())
+                {
+                    _log.info("Index " + targetIndex.getName() + " needs to be created for table " + sourceTable.getName());
+                }
+                changes.add(new AddIndexChange(sourceTable, targetIndex));
+            }
+        }
+
+        for (int columnIdx = 0; columnIdx < targetTable.getColumnCount(); columnIdx++)
+        {
+            Column targetColumn = targetTable.getColumn(columnIdx);
+            Column sourceColumn = sourceTable.findColumn(targetColumn.getName(), _caseSensitive);
+
+            if (sourceColumn == null)
+            {
+                if (_log.isInfoEnabled())
+                {
+                    _log.info("Column " + targetColumn.getName() + " needs to be created for table " + sourceTable.getName());
+                }
+                changes.add(new AddColumnChange(sourceTable, targetColumn));
+            }
+            else
+            {
+                changes.addAll(compareColumns(sourceTable, sourceColumn, targetTable, targetColumn));
+            }
+        }
+
+        Column[] sourcePK = sourceTable.getPrimaryKeyColumns();
+        Column[] targetPK = targetTable.getPrimaryKeyColumns();
+
+        if ((sourcePK.length == 0) && (targetPK.length > 0))
+        {
+            if (_log.isInfoEnabled())
+            {
+                _log.info("A primary key needs to be added to the table " + sourceTable.getName());
+            }
+            changes.add(new AddPrimaryKeyChange(sourceTable, targetPK));
+        }
+        else if ((targetPK.length == 0) && (sourcePK.length > 0))
+        {
+            if (_log.isInfoEnabled())
+            {
+                _log.info("The primary key needs to be removed from the table " + sourceTable.getName());
+            }
+            changes.add(new RemovePrimaryKeyChange(sourceTable, sourcePK));
+        }
+        else if ((sourcePK.length > 0) && (targetPK.length > 0))
+        {
+            boolean changePK = false;
+
+            if (sourcePK.length != targetPK.length)
+            {
+                changePK = true;
+            }
+            else
+            {
+                for (int pkColumnIdx = 0; (pkColumnIdx < sourcePK.length) && !changePK; pkColumnIdx++)
+                {
+                    if ((_caseSensitive  && !sourcePK[pkColumnIdx].getName().equals(targetPK[pkColumnIdx].getName())) ||
+                        (!_caseSensitive && !sourcePK[pkColumnIdx].getName().equalsIgnoreCase(targetPK[pkColumnIdx].getName())))
+                    {
+                        changePK = true;
+                    }
+                }
+            }
+            if (changePK)
+            {
+                if (_log.isInfoEnabled())
+                {
+                    _log.info("The primary key of table " + sourceTable.getName() + " needs to be changed");
+                }
+                changes.add(new PrimaryKeyChange(sourceTable, sourcePK, targetPK));
+            }
+        }
+        
+        for (int columnIdx = 0; columnIdx < sourceTable.getColumnCount(); columnIdx++)
+        {
+            Column sourceColumn = sourceTable.getColumn(columnIdx);
+            Column targetColumn = targetTable.findColumn(sourceColumn.getName(), _caseSensitive);
+
+            if (targetColumn == null)
+            {
+                if (_log.isInfoEnabled())
+                {
+                    _log.info("Column " + sourceColumn.getName() + " needs to be removed from table " + sourceTable.getName());
+                }
+                changes.add(new RemoveColumnChange(sourceTable, sourceColumn));
+            }
+        }
+
+        return changes;
+    }
+
+    /**
+     * Compares the two columns and returns the changes necessary to create the second
+     * column from the first one.
+     *  
+     * @param sourceTable  The source table which contains the source column
+     * @param sourceColumn The source column
+     * @param targetTable  The target table which contains the target column
+     * @param targetColumn The target column
+     * @return The changes
+     */
+    public List compareColumns(Table  sourceTable,
+                               Column sourceColumn,
+                               Table  targetTable,
+                               Column targetColumn)
+    {
+        ArrayList changes = new ArrayList();
+
+        if (sourceColumn.getTypeCode() != targetColumn.getTypeCode())
+        {
+            changes.add(new ColumnDataTypeChange(sourceTable, sourceColumn, targetColumn.getTypeCode()));
+        }
+
+        // the concrete platform decides whether the size matters for a given data type
+        // so when the size differs we create a change object and the platform can filter
+        // it later if the size is not relevant
+        if ((sourceColumn.getSizeAsInt() != targetColumn.getSizeAsInt()) ||
+            (sourceColumn.getScale()     != targetColumn.getScale()))
+        {
+            changes.add(new ColumnSizeChange(sourceTable, sourceColumn, targetColumn.getSizeAsInt(), targetColumn.getScale()));
+        }
+
+        Object sourceDefaultValue = sourceColumn.getParsedDefaultValue();
+        Object targetDefaultValue = targetColumn.getParsedDefaultValue();
+
+        if (((sourceDefaultValue == null) && (targetDefaultValue != null)) ||
+            ((sourceDefaultValue != null) && !sourceDefaultValue.equals(targetDefaultValue)))
+        {
+            changes.add(new ColumnDefaultValueChange(sourceTable, sourceColumn, targetColumn.getDefaultValue()));
+        }
+
+        if (sourceColumn.isRequired() != targetColumn.isRequired())
+        {
+            changes.add(new ColumnRequiredChange(sourceTable, sourceColumn));
+        }
+        if (sourceColumn.isAutoIncrement() != targetColumn.isAutoIncrement())
+        {
+            changes.add(new ColumnAutoIncrementChange(sourceTable, sourceColumn));
+        }
+
+        return changes;
+    }
+
+    /**
+     * Searches in the given table for a corresponding foreign key. If the given key
+     * has no name, then a foreign key to the same table with the same columns (but not
+     * necessarily in the same order) is searched. If the given key has a name, then the
+     * corresponding key also needs to have the same name, or no name at all, but not a
+     * different one. 
+     * 
+     * @param table The table to search in
+     * @param fk    The original foreign key
+     * @return The corresponding foreign key if found
+     */
+    private ForeignKey findCorrespondingForeignKey(Table table, ForeignKey fk)
+    {
+        for (int fkIdx = 0; fkIdx < table.getForeignKeyCount(); fkIdx++)
+        {
+            ForeignKey curFk = table.getForeignKey(fkIdx);
+
+            if ((_caseSensitive  && fk.equals(curFk)) ||
+                (!_caseSensitive && fk.equalsIgnoreCase(curFk)))
+            {
+                return curFk;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Searches in the given table for a corresponding index. If the given index
+     * has no name, then a index to the same table with the same columns in the
+     * same order is searched. If the given index has a name, then the a corresponding
+     * index also needs to have the same name, or no name at all, but not a different one. 
+     * 
+     * @param table The table to search in
+     * @param index The original index
+     * @return The corresponding index if found
+     */
+    private Index findCorrespondingIndex(Table table, Index index)
+    {
+        for (int indexIdx = 0; indexIdx < table.getForeignKeyCount(); indexIdx++)
+        {
+            Index curIndex = table.getIndex(indexIdx);
+
+            if ((_caseSensitive  && index.equals(curIndex)) ||
+                (!_caseSensitive && index.equalsIgnoreCase(curIndex)))
+            {
+                return curIndex;
+            }
+        }
+        return null;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/PrimaryKeyChange.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/PrimaryKeyChange.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/PrimaryKeyChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/PrimaryKeyChange.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,79 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Represents the change of the primary key of a table.
+ * 
+ * @version $Revision: $
+ */
+public class PrimaryKeyChange
+{
+    /** The table to where the primary key is defined. */
+    private Table _table;
+    /** The columns making up the original primary key. */
+    private Column[] _oldPrimaryKeyColumns;
+    /** The columns making up the new primary key. */
+    private Column[] _newPrimaryKeyColumns;
+
+    /**
+     * Creates a new change object.
+     * 
+     * @param table                The table whose primary key is to be changed
+     * @param oldPrimaryKeyColumns The columns making up the original primary key
+     * @param newPrimaryKeyColumns The columns making up the new primary key
+     */
+    public PrimaryKeyChange(Table table, Column[] oldPrimaryKeyColumns, Column[] newPrimaryKeyColumns)
+    {
+        _table                = table;
+        _oldPrimaryKeyColumns = oldPrimaryKeyColumns;
+        _newPrimaryKeyColumns = newPrimaryKeyColumns;
+    }
+
+    /**
+     * Returns the columns making up the original primary key.
+     *
+     * @return The columns
+     */
+    public Column[] getOldPrimaryKeyColumns()
+    {
+        return _oldPrimaryKeyColumns;
+    }
+
+    /**
+     * Returns the columns making up the new primary key.
+     *
+     * @return The columns
+     */
+    public Column[] getNewPrimaryKeyColumns()
+    {
+        return _newPrimaryKeyColumns;
+    }
+
+    /**
+     * Returns the table whose primary key is to be changed.
+     *
+     * @return The table
+     */
+    public Table getTable()
+    {
+        return _table;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveColumnChange.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveColumnChange.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveColumnChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveColumnChange.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,65 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Represents the removal of a column from a table.
+ * 
+ * @version $Revision: $
+ */
+public class RemoveColumnChange
+{
+    /** The table to remove the column from. */
+    private Table _table;
+    /** The column. */
+    private Column _column;
+
+    /**
+     * Creates a new change object.
+     * 
+     * @param table  The table to remove the column from
+     * @param column The column
+     */
+    public RemoveColumnChange(Table table, Column column)
+    {
+        _table  = table;
+        _column = column;
+    }
+
+    /**
+     * Returns the column.
+     *
+     * @return The column
+     */
+    public Column getColumn()
+    {
+        return _column;
+    }
+
+    /**
+     * Returns the table to remove the column from.
+     *
+     * @return The table
+     */
+    public Table getTable()
+    {
+        return _table;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveForeignKeyChange.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveForeignKeyChange.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveForeignKeyChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveForeignKeyChange.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,65 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.model.ForeignKey;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Represents the removal of a foreign key from a table.
+ * 
+ * @version $Revision: $
+ */
+public class RemoveForeignKeyChange
+{
+    /** The table to add the foreign key to. */
+    private Table _table;
+    /** The foreign key. */
+    private ForeignKey _foreignKey;
+
+    /**
+     * Creates a new change object.
+     * 
+     * @param table      The table to remove the foreign key from
+     * @param foreignKey The foreign key
+     */
+    public RemoveForeignKeyChange(Table table, ForeignKey foreignKey)
+    {
+        _table      = table;
+        _foreignKey = foreignKey;
+    }
+
+    /**
+     * Returns the foreign key to be removed.
+     *
+     * @return The foreign key
+     */
+    public ForeignKey getForeignKey()
+    {
+        return _foreignKey;
+    }
+
+    /**
+     * Returns the table where the foreign key is to be removed.
+     *
+     * @return The table
+     */
+    public Table getTable()
+    {
+        return _table;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveIndexChange.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveIndexChange.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveIndexChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveIndexChange.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,65 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.model.Index;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Represents the removal of an index from a table.
+ * 
+ * @version $Revision: $
+ */
+public class RemoveIndexChange
+{
+    /** The table to add the index to. */
+    private Table _table;
+    /** The index to be removed. */
+    private Index _index;
+
+    /**
+     * Creates a new change object.
+     * 
+     * @param table The table to remove the index from
+     * @param index The index
+     */
+    public RemoveIndexChange(Table table, Index index)
+    {
+        _table = table;
+        _index = index;
+    }
+
+    /**
+     * Returns the index.
+     *
+     * @return The index
+     */
+    public Index getIndex()
+    {
+        return _index;
+    }
+
+    /**
+     * Returns the table where the index is to be removed from.
+     *
+     * @return The table
+     */
+    public Table getTable()
+    {
+        return _table;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemovePrimaryKeyChange.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemovePrimaryKeyChange.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemovePrimaryKeyChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemovePrimaryKeyChange.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,65 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Represents the removal of the primary key from a table.
+ * 
+ * @version $Revision: $
+ */
+public class RemovePrimaryKeyChange
+{
+    /** The table to remove the primary key from. */
+    private Table    _table;
+    /** The columns making up the primary key. */
+    private Column[] _primaryKeyColumns;
+
+    /**
+     * Creates a new change object.
+     * 
+     * @param table             The table to remove the primary key from
+     * @param primaryKeyColumns The columns making up the primary key
+     */
+    public RemovePrimaryKeyChange(Table table, Column[] primaryKeyColumns)
+    {
+        _table             = table;
+        _primaryKeyColumns = primaryKeyColumns;
+    }
+
+    /**
+     * Returns the primary key columns making up the primary key.
+     *
+     * @return The primary key columns
+     */
+    public Column[] getPrimaryKeyColumns()
+    {
+        return _primaryKeyColumns;
+    }
+
+    /**
+     * Returns the table to remove the primary key from.
+     *
+     * @return The table
+     */
+    public Table getTable()
+    {
+        return _table;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveTableChange.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveTableChange.java?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveTableChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveTableChange.java Sun Apr 16 16:47:18 2006
@@ -0,0 +1,50 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Represents the removal of a table from a model.
+ * 
+ * @version $Revision: $
+ */
+public class RemoveTableChange
+{
+    /** The table. */
+    private Table _table;
+
+    /**
+     * Creates a new change object.
+     * 
+     * @param table The table
+     */
+    public RemoveTableChange(Table table)
+    {
+        _table = table;
+    }
+
+    /**
+     * Returns the table.
+     * 
+     * @return The table
+     */
+    public Table getTable()
+    {
+        return _table;
+    }
+}

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/package.html
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/package.html?rev=394581&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/package.html (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/package.html Sun Apr 16 16:47:18 2006
@@ -0,0 +1,27 @@
+<html>
+<head>
+<!-- 
+ Copyright 2006 The Apache Software Foundation.
+ 
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ 
+      http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+   <meta name="Author" content="Thomas Dudziak">
+</head>
+<body bgcolor="white">
+  <p>
+  	Contains the algorithm for comparing two database models and determining
+    what needs to be changed to migrate one to the other.
+  </p>
+</body>
+</html>

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/ForeignKey.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/ForeignKey.java?rev=394581&r1=394580&r2=394581&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/ForeignKey.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/ForeignKey.java Sun Apr 16 16:47:18 2006
@@ -239,15 +239,20 @@
     {
         if (obj instanceof ForeignKey)
         {
-            ForeignKey other = (ForeignKey)obj;
+            ForeignKey otherFk = (ForeignKey)obj;
 
             // Note that this compares case sensitive
             // Note also that we can simply compare the references regardless of their order
             // (which is irrelevant for fks) because they are contained in a set
-            return new EqualsBuilder().append(_name,             other._name)
-                                      .append(_foreignTableName, other._foreignTableName)
-                                      .append(_references,       other._references)
-                                      .isEquals();
+            EqualsBuilder builder = new EqualsBuilder();
+
+            if ((_name != null) && (_name.length() > 0) && (otherFk._name != null) && (otherFk._name.length() > 0))
+            {
+                builder.append(_name, otherFk._name);
+            }
+            return builder.append(_foreignTableName, otherFk._foreignTableName)
+                          .append(_references,       otherFk._references)
+                          .isEquals();
         }
         else
         {
@@ -263,11 +268,14 @@
      */
     public boolean equalsIgnoreCase(ForeignKey otherFk)
     {
-        if (_name.equalsIgnoreCase(otherFk._name) &&
+        boolean checkName = (_name != null) && (_name.length() > 0) &&
+                            (otherFk._name != null) && (otherFk._name.length() > 0);
+
+        if ((!checkName || _name.equalsIgnoreCase(otherFk._name)) &&
             _foreignTableName.equalsIgnoreCase(otherFk._foreignTableName))
         {
             HashSet otherRefs = new HashSet();
-    
+
             otherRefs.addAll(otherFk._references);
             for (Iterator it = _references.iterator(); it.hasNext();)
             {

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Index.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Index.java?rev=394581&r1=394580&r2=394581&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Index.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Index.java Sun Apr 16 16:47:18 2006
@@ -91,6 +91,14 @@
     public void removeColumn(int idx);
 
     /**
+     * Compares this index to the given one while ignoring the case of identifiers.
+     * 
+     * @param otherIndex The other index
+     * @return <code>true</code> if this index is equal (ignoring case) to the given one
+     */
+    public boolean equalsIgnoreCase(Index otherIndex);
+
+    /**
      * Returns a verbose string representation of this index.
      * 
      * @return The string representation

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=394581&r1=394580&r2=394581&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 Sun Apr 16 16:47:18 2006
@@ -140,7 +140,6 @@
         {
             IndexColumn other = (IndexColumn)obj;
 
-            // Note that this compares case sensitive
             return new EqualsBuilder().append(_name, other._name)
                                       .append(_size, other._size)
                                       .isEquals();
@@ -149,6 +148,16 @@
         {
             return false;
         }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean equalsIgnoreCase(IndexColumn other)
+    {
+        return new EqualsBuilder().append(_name.toUpperCase(), other._name.toUpperCase())
+                                  .append(_size, other._size)
+                                  .isEquals();
     }
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/NonUniqueIndex.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/NonUniqueIndex.java?rev=394581&r1=394580&r2=394581&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/NonUniqueIndex.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/NonUniqueIndex.java Sun Apr 16 16:47:18 2006
@@ -157,6 +157,34 @@
     /**
      * {@inheritDoc}
      */
+    public boolean equalsIgnoreCase(Index other)
+    {
+        if (other instanceof NonUniqueIndex)
+        {
+            NonUniqueIndex otherIndex = (NonUniqueIndex)other;
+
+            boolean checkName = (_name != null) && (_name.length() > 0) &&
+                                (otherIndex._name != null) && (otherIndex._name.length() > 0);
+
+            if ((!checkName || _name.equalsIgnoreCase(otherIndex._name)) &&
+                (getColumnCount() == otherIndex.getColumnCount()))
+            {
+                for (int idx = 0; idx < getColumnCount(); idx++)
+                {
+                    if (!getColumn(idx).equalsIgnoreCase(otherIndex.getColumn(idx)))
+                    {
+                        return false;
+                    }
+                }
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public int hashCode()
     {
         return new HashCodeBuilder(17, 37).append(_name)

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=394581&r1=394580&r2=394581&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 Sun Apr 16 16:47:18 2006
@@ -73,6 +73,34 @@
     /**
      * {@inheritDoc}
      */
+    public boolean equalsIgnoreCase(Index other)
+    {
+        if (other instanceof UniqueIndex)
+        {
+            UniqueIndex otherIndex = (UniqueIndex)other;
+
+            boolean checkName = (_name != null) && (_name.length() > 0) &&
+                                (otherIndex._name != null) && (otherIndex._name.length() > 0);
+
+            if ((!checkName || _name.equalsIgnoreCase(otherIndex._name)) &&
+                (getColumnCount() == otherIndex.getColumnCount()))
+            {
+                for (int idx = 0; idx < getColumnCount(); idx++)
+                {
+                    if (!getColumn(idx).equalsIgnoreCase(otherIndex.getColumn(idx)))
+                    {
+                        return false;
+                    }
+                }
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public int hashCode()
     {
         return _columns.hashCode();



Mime
View raw message