db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r504014 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/model/ java/org/apache/ddlutils/platform/ java/org/apache/ddlutils/platform/db2/ java/org/apache/ddlutils/platform/derby/ java/org/apache/ddlutils/platform/firebird/ java/org/apa...
Date Tue, 06 Feb 2007 07:19:08 GMT
Author: tomdz
Date: Mon Feb  5 23:19:03 2007
New Revision: 504014

URL: http://svn.apache.org/viewvc?view=rev&rev=504014
Log:
Fixed DDLUTILS-153
Added support for identity override for Sql Server

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Database.java
    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/IndexImpBase.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Builder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseBuilder.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestMisc.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Database.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Database.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Database.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Database.java Mon Feb  5 23:19:03 2007
@@ -386,10 +386,15 @@
                 for (int indexColumnIdx = 0; indexColumnIdx < index.getColumnCount(); indexColumnIdx++)
                 {
                     IndexColumn indexColumn = index.getColumn(indexColumnIdx);
+                    Column      column      = curTable.findColumn(indexColumn.getName(), true);
 
-                    if (curTable.findColumn(indexColumn.getName(), true) == null)
+                    if (column == null)
                     {
                         throw new ModelException("The index "+indexDesc+" in table "+curTable.getName()+" references the undefined column "+indexColumn.getName());
+                    }
+                    else
+                    {
+                        indexColumn.setColumn(column);
                     }
                 }
             }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/ForeignKey.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/ForeignKey.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/ForeignKey.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/ForeignKey.java Mon Feb  5 23:19:03 2007
@@ -218,6 +218,46 @@
     }
 
     /**
+     * Determines whether this foreign key uses the given column as a local
+     * column in a reference.
+     * 
+     * @param column The column to check
+     * @return <code>true</code> if a reference uses the column as a local
+     *         column
+     */
+    public boolean hasLocalColumn(Column column)
+    {
+        for (int idx = 0; idx < getReferenceCount(); idx++)
+        {
+            if (column.equals(getReference(idx).getLocalColumn()))
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Determines whether this foreign key uses the given column as a foreign
+     * column in a reference.
+     * 
+     * @param column The column to check
+     * @return <code>true</code> if a reference uses the column as a foreign
+     *         column
+     */
+    public boolean hasForeignColumn(Column column)
+    {
+        for (int idx = 0; idx < getReferenceCount(); idx++)
+        {
+            if (column.equals(getReference(idx).getForeignColumn()))
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    /**
      * Determines whether this foreign key has an auto-generated associated index.
      * 
      * @return <code>true</code> if an auto-generated index exists

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Index.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Index.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Index.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Index.java Mon Feb  5 23:19:03 2007
@@ -72,6 +72,14 @@
     public IndexColumn[] getColumns();
 
     /**
+     * Determines whether this index includes the given column.
+     * 
+     * @param column The column to check for
+     * @return <code>true</code> if the column is included in this index
+     */
+    public boolean hasColumn(Column column);
+
+    /**
      * Adds a column that makes up this index.
      * 
      * @param column The column to add

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexColumn.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexColumn.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexColumn.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexColumn.java Mon Feb  5 23:19:03 2007
@@ -36,6 +36,8 @@
 
     /** The position within the owning index. */
     private int    _ordinalPosition;
+    /** The indexed column. */
+    private Column _column;
     /** The name of the column. */
     protected String _name;
     /** The size of the column in the index. */
@@ -53,6 +55,17 @@
     /**
      * Creates a new index column object.
      * 
+     * @param column The indexed column
+     */
+    public IndexColumn(Column column)
+    {
+        _column = column;
+        _name   = column.getName();
+    }
+
+    /**
+     * Creates a new index column object.
+     * 
      * @param columnName The name of the corresponding table column
      */
     public IndexColumn(String columnName)
@@ -99,6 +112,27 @@
     public void setName(String name)
     {
         _name = name;
+    }
+
+    /**
+     * Returns the indexed column.
+     *
+     * @return The column
+     */
+    public Column getColumn()
+    {
+        return _column;
+    }
+
+    /**
+     * Sets the indexed column.
+     *
+     * @param column The column
+     */
+    public void setColumn(Column column)
+    {
+        _column = column;
+        _name   = (column == null ? null : column.getName());
     }
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexImpBase.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexImpBase.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexImpBase.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexImpBase.java Mon Feb  5 23:19:03 2007
@@ -76,6 +76,23 @@
     /**
      * {@inheritDoc}
      */
+    public boolean hasColumn(Column column)
+    {
+        for (int idx = 0; idx < _columns.size(); idx++)
+        {
+            IndexColumn curColumn = getColumn(idx);
+
+            if (column.equals(curColumn.getColumn()))
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public void addColumn(IndexColumn column)
     {
         if (column != null)

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java Mon Feb  5 23:19:03 2007
@@ -1272,6 +1272,8 @@
                 connection.setAutoCommit(false);
             }
 
+            beforeInsert(connection, dynaClass.getTable());
+            
             statement = connection.prepareStatement(insertSql);
 
             for (int idx = 0; idx < properties.length; idx++ )
@@ -1281,6 +1283,8 @@
 
             int count = statement.executeUpdate();
 
+            afterInsert(connection, dynaClass.getTable());
+
             if (count != 1)
             {
                 _log.warn("Attempted to insert a single row " + dynaBean +
@@ -1414,7 +1418,7 @@
             {
                 if (dynaClass != null)
                 {
-                    executeBatch(statement, addedStmts, dynaClass.getTableName());
+                    executeBatch(statement, addedStmts, dynaClass.getTable());
                     addedStmts = 0;
                 }
 
@@ -1464,7 +1468,7 @@
         }
         if (dynaClass != null)
         {
-            executeBatch(statement, addedStmts, dynaClass.getTableName());
+            executeBatch(statement, addedStmts, dynaClass.getTable());
         }
     }
 
@@ -1473,17 +1477,22 @@
      * 
      * @param statement The prepared statement
      * @param numRows   The number of rows that should change
-     * @param tableName The name of the changed table
+     * @param table     The changed table
      */
-    private void executeBatch(PreparedStatement statement, int numRows, String tableName) throws DatabaseOperationException
+    private void executeBatch(PreparedStatement statement, int numRows, Table table) throws DatabaseOperationException
     {
         if (statement != null)
         {
             try
             {
+                Connection connection = statement.getConnection();
+
+                beforeInsert(connection, table);
+
                 int[] results = statement.executeBatch();
 
                 closeStatement(statement);
+                afterInsert(connection, table);
 
                 int sum = 0;
 
@@ -1493,7 +1502,7 @@
                 }
                 if (sum != numRows)
                 {
-                    _log.warn("Attempted to insert " + numRows + " rows into table " + tableName + " but changed " + sum + " rows");
+                    _log.warn("Attempted to insert " + numRows + " rows into table " + table.getName() + " but changed " + sum + " rows");
                 }
             }
             catch (SQLException ex)
@@ -1521,6 +1530,28 @@
     }
 
     /**
+     * Allows platforms to issue statements directly before rows are inserted into
+     * the specified table.
+     *  
+     * @param connection The connection used for the insertion
+     * @param table      The table that the rows are inserted into
+     */
+    protected void beforeInsert(Connection connection, Table table) throws SQLException
+    {
+    }
+    
+    /**
+     * Allows platforms to issue statements directly after rows have been inserted into
+     * the specified table.
+     *  
+     * @param connection The connection used for the insertion
+     * @param table      The table that the rows have been inserted into
+     */
+    protected void afterInsert(Connection connection, Table table) throws SQLException
+    {
+    }
+
+    /**
      * Creates the SQL for updating an object of the given type. If a concrete bean is given,
      * then a concrete update statement is created, otherwise an update statement usable in a
      * prepared statement is build.
@@ -1583,6 +1614,8 @@
         }
         try
         {
+            beforeUpdate(connection, dynaClass.getTable());
+
             statement = connection.prepareStatement(sql);
 
             int sqlIndex = 1;
@@ -1598,6 +1631,8 @@
 
             int count = statement.executeUpdate();
 
+            afterUpdate(connection, dynaClass.getTable());
+
             if (count != 1)
             {
                 _log.warn("Attempted to insert a single row " + dynaBean +
@@ -1630,6 +1665,28 @@
         {
             returnConnection(connection);
         }
+    }
+
+    /**
+     * Allows platforms to issue statements directly before rows are updated in
+     * the specified table.
+     *  
+     * @param connection The connection used for the update
+     * @param table      The table that the rows are updateed into
+     */
+    protected void beforeUpdate(Connection connection, Table table) throws SQLException
+    {
+    }
+    
+    /**
+     * Allows platforms to issue statements directly after rows have been updated in
+     * the specified table.
+     *  
+     * @param connection The connection used for the update
+     * @param table      The table that the rows have been updateed into
+     */
+    protected void afterUpdate(Connection connection, Table table) throws SQLException
+    {
     }
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java Mon Feb  5 23:19:03 2007
@@ -618,6 +618,7 @@
                                  RemoveForeignKeyChange change) throws IOException
     {
         writeExternalForeignKeyDropStmt(change.getChangedTable(), change.getForeignKey());
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -635,6 +636,7 @@
                                  RemoveIndexChange  change) throws IOException
     {
         writeExternalIndexDropStmt(change.getChangedTable(), change.getIndex());
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -652,6 +654,7 @@
                                  RemoveTableChange  change) throws IOException
     {
         dropTable(change.getChangedTable());
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -669,6 +672,7 @@
                                  AddTableChange     change) throws IOException
     {
         createTable(desiredModel, change.getNewTable(), params == null ? null : params.getParametersFor(change.getNewTable()));
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -688,6 +692,7 @@
         writeExternalForeignKeyCreateStmt(desiredModel,
                                           change.getChangedTable(),
                                           change.getNewForeignKey());
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -705,6 +710,7 @@
                                  AddIndexChange     change) throws IOException
     {
         writeExternalIndexCreateStmt(change.getChangedTable(), change.getNewIndex());
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -952,7 +958,6 @@
             if (change instanceof AddPrimaryKeyChange)
             {
                 processChange(currentModel, desiredModel, (AddPrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changes.clear();
             }
         }
@@ -1145,6 +1150,7 @@
                                  AddPrimaryKeyChange change) throws IOException
     {
         writeExternalPrimaryKeysCreateStmt(change.getChangedTable(), change.getPrimaryKeyColumns());
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Builder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Builder.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Builder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Builder.java Mon Feb  5 23:19:03 2007
@@ -156,7 +156,6 @@
                 if ((addColumnChange.getNextColumn() == null) && !addColumnChange.getNewColumn().isAutoIncrement())
                 {
                     processChange(currentModel, desiredModel, addColumnChange);
-                    change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                     changeIt.remove();
                 }
             }
@@ -169,19 +168,16 @@
             if (change instanceof AddPrimaryKeyChange)
             {
                 processChange(currentModel, desiredModel, (AddPrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof PrimaryKeyChange)
             {
                 processChange(currentModel, desiredModel, (PrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof RemovePrimaryKeyChange)
             {
                 processChange(currentModel, desiredModel, (RemovePrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
         }
@@ -204,6 +200,7 @@
         print("ADD COLUMN ");
         writeColumn(change.getChangedTable(), change.getNewColumn());
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -223,6 +220,7 @@
         print("DROP COLUMN ");
         printIdentifier(getColumnName(change.getColumn()));
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -241,6 +239,7 @@
         printIndent();
         print("DROP PRIMARY KEY");
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -260,5 +259,6 @@
         print("DROP PRIMARY KEY");
         printEndOfStatement();
         writeExternalPrimaryKeysCreateStmt(change.getChangedTable(), change.getNewPrimaryKeyColumns());
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyBuilder.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyBuilder.java Mon Feb  5 23:19:03 2007
@@ -138,7 +138,6 @@
                 if (addColumnChange.isAtEnd() && !addColumnChange.getNewColumn().isAutoIncrement())
                 {
                     processChange(currentModel, desiredModel, addColumnChange);
-                    change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                     changeIt.remove();
                 }
             }
@@ -163,5 +162,6 @@
         print("ADD COLUMN ");
         writeColumn(change.getChangedTable(), change.getNewColumn());
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdBuilder.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdBuilder.java Mon Feb  5 23:19:03 2007
@@ -247,7 +247,6 @@
                 else
             	{
 	            	processChange(currentModel, desiredModel, addColumnChange);
-	                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
 	                changeIt.remove();
             	}
             }
@@ -261,7 +260,6 @@
             	if (!removeColumnChange.getColumn().isPrimaryKey())
             	{
 	            	processChange(currentModel, desiredModel, removeColumnChange);
-	                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
 	                changeIt.remove();
             	}
             }
@@ -275,7 +273,6 @@
             if ((change instanceof AddPrimaryKeyChange) && !pkColumnAdded)
             {
                 processChange(currentModel, desiredModel, (AddPrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
         }
@@ -325,6 +322,7 @@
         {
             writeAutoIncrementCreateStmts(currentModel, curTable, change.getNewColumn());
         }
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -348,5 +346,6 @@
         print("DROP ");
         printIdentifier(getColumnName(change.getColumn()));
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbBuilder.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbBuilder.java Mon Feb  5 23:19:03 2007
@@ -103,7 +103,6 @@
             AddColumnChange addColumnChange = (AddColumnChange)changeIt.previous();
 
             processChange(currentModel, desiredModel, addColumnChange);
-            addColumnChange.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
             changeIt.remove();
         }
 
@@ -119,7 +118,6 @@
                 if (!removeColumnChange.getColumn().isPrimaryKey())
                 {
                     processChange(currentModel, desiredModel, removeColumnChange);
-                    change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                     changeIt.remove();
                 }
             }
@@ -148,6 +146,7 @@
             printIdentifier(getColumnName(change.getNextColumn()));
         }
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -167,5 +166,6 @@
         print("DROP COLUMN ");
         printIdentifier(getColumnName(change.getColumn()));
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java Mon Feb  5 23:19:03 2007
@@ -235,7 +235,6 @@
                 else
                 {
                     processChange(currentModel, desiredModel, addColumnChange);
-                    change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                     changeIt.remove();
                 }
             }
@@ -249,7 +248,6 @@
                 if (!removeColumnChange.getColumn().isPrimaryKey())
                 {
                     processChange(currentModel, desiredModel, removeColumnChange);
-                    change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                     changeIt.remove();
                 }
             }
@@ -263,7 +261,6 @@
             if ((change instanceof AddPrimaryKeyChange) && !pkColumnAdded)
             {
                 processChange(currentModel, desiredModel, (AddPrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
         }
@@ -313,6 +310,7 @@
         {
             writeAutoIncrementCreateStmts(currentModel, curTable, change.getNewColumn());
         }
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -336,5 +334,6 @@
         print("DROP ");
         printIdentifier(getColumnName(change.getColumn()));
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java Mon Feb  5 23:19:03 2007
@@ -31,11 +31,17 @@
 
 import org.apache.ddlutils.Platform;
 import org.apache.ddlutils.alteration.AddColumnChange;
+import org.apache.ddlutils.alteration.AddForeignKeyChange;
+import org.apache.ddlutils.alteration.AddIndexChange;
 import org.apache.ddlutils.alteration.AddPrimaryKeyChange;
 import org.apache.ddlutils.alteration.ColumnAutoIncrementChange;
 import org.apache.ddlutils.alteration.ColumnChange;
+import org.apache.ddlutils.alteration.ColumnDataTypeChange;
+import org.apache.ddlutils.alteration.ColumnSizeChange;
 import org.apache.ddlutils.alteration.PrimaryKeyChange;
 import org.apache.ddlutils.alteration.RemoveColumnChange;
+import org.apache.ddlutils.alteration.RemoveForeignKeyChange;
+import org.apache.ddlutils.alteration.RemoveIndexChange;
 import org.apache.ddlutils.alteration.RemovePrimaryKeyChange;
 import org.apache.ddlutils.alteration.TableChange;
 import org.apache.ddlutils.model.Column;
@@ -249,18 +255,31 @@
     }
 
     /**
-     * Writes the statement that turns on the ability to write delimited identifiers.
+     * Returns the statement that turns on the ability to write delimited identifiers.
+     * 
+     * @return The quotation-on statement
      */
-    private void writeQuotationOnStatement() throws IOException
+    private String getQuotationOnStatement()
     {
         if (getPlatform().isDelimitedIdentifierModeOn())
         {
-            print("SET quoted_identifier on");
-            printEndOfStatement();
+            return "SET quoted_identifier on" + getPlatformInfo().getSqlCommandDelimiter() + "\n";
+        }
+        else
+        {
+            return "";
         }
     }
 
     /**
+     * Writes the statement that turns on the ability to write delimited identifiers.
+     */
+    private void writeQuotationOnStatement() throws IOException
+    {
+        print(getQuotationOnStatement());
+    }
+
+    /**
      * {@inheritDoc}
      */
     public String getSelectLastIdentityValues(Table table)
@@ -269,13 +288,51 @@
     }
 
     /**
+     * Returns the SQL to enable identity override mode.
+     * 
+     * @param table The table to enable the mode for
+     * @return The SQL
+     */
+    protected String getEnableIdentityOverrideSql(Table table)
+    {
+        StringBuffer result = new StringBuffer();
+
+        result.append(getQuotationOnStatement());
+        result.append("SET IDENTITY_INSERT ");
+        result.append(getDelimitedIdentifier(getTableName(table)));
+        result.append(" ON");
+        result.append(getPlatformInfo().getSqlCommandDelimiter());
+
+        return result.toString();
+    }
+
+    /**
+     * Returns the SQL to disable identity override mode.
+     * 
+     * @param table The table to disable the mode for
+     * @return The SQL
+     */
+    protected String getDisableIdentityOverrideSql(Table table)
+    {
+        StringBuffer result = new StringBuffer();
+
+        result.append(getQuotationOnStatement());
+        result.append("SET IDENTITY_INSERT ");
+        result.append(getDelimitedIdentifier(getTableName(table)));
+        result.append(" OFF");
+        result.append(getPlatformInfo().getSqlCommandDelimiter());
+
+        return result.toString();
+    }
+
+    /**
      * {@inheritDoc}
      */
     public String getDeleteSql(Table table, Map pkValues, boolean genPlaceholders)
     {
         return getQuotationOnStatement() + super.getDeleteSql(table, pkValues, genPlaceholders);
     }
-
+    
     /**
      * {@inheritDoc}
      */
@@ -293,23 +350,6 @@
     }
 
     /**
-     * Returns the statement that turns on the ability to write delimited identifiers.
-     * 
-     * @return The quotation-on statement
-     */
-    private String getQuotationOnStatement()
-    {
-        if (getPlatform().isDelimitedIdentifierModeOn())
-        {
-            return "SET quoted_identifier on" + getPlatformInfo().getSqlCommandDelimiter() + "\n";
-        }
-        else
-        {
-            return "";
-        }
-    }
-
-    /**
      * Prints the given identifier with enforced single quotes around it regardless of whether 
      * delimited identifiers are turned on or not.
      * 
@@ -358,6 +398,84 @@
         {
             writeQuotationOnStatement();
         }
+        // For column data type and size changes, we need to drop and then re-create indexes
+        // and foreign keys using the column, as well as any primary keys containg
+        // these columns
+        // However, if the index/foreign key/primary key is already slated for removal or
+        // change, then we don't want to generate change duplication
+        HashSet removedIndexes     = new HashSet();
+        HashSet removedForeignKeys = new HashSet();
+        HashSet removedPKs         = new HashSet();
+
+        for (Iterator changeIt = changes.iterator(); changeIt.hasNext();)
+        {
+            Object change = changeIt.next();
+
+            if (change instanceof RemoveIndexChange)
+            {
+                removedIndexes.add(((RemoveIndexChange)change).getIndex());
+            }
+            else if (change instanceof RemoveForeignKeyChange)
+            {
+                removedForeignKeys.add(((RemoveForeignKeyChange)change).getForeignKey());
+            }
+            else if (change instanceof RemovePrimaryKeyChange)
+            {
+                removedPKs.add(((RemovePrimaryKeyChange)change).getChangedTable());
+            }
+        }
+
+        ArrayList additionalChanges = new ArrayList();
+
+        for (Iterator changeIt = changes.iterator(); changeIt.hasNext();)
+        {
+            Object change = changeIt.next();
+
+            if ((change instanceof ColumnDataTypeChange) ||
+                (change instanceof ColumnSizeChange))
+            {
+                Column column = ((ColumnChange)change).getChangedColumn();
+                Table  table  = ((ColumnChange)change).getChangedTable();
+
+                if (column.isPrimaryKey() && !removedPKs.contains(table))
+                {
+                    Column[] pk = table.getPrimaryKeyColumns();
+
+                    additionalChanges.add(new RemovePrimaryKeyChange(table, pk));
+                    additionalChanges.add(new AddPrimaryKeyChange(table, pk));
+                    removedPKs.add(table);
+                }
+                for (int idx = 0; idx < table.getIndexCount(); idx++)
+                {
+                    Index index = table.getIndex(idx);
+
+                    if (index.hasColumn(column) && !removedIndexes.contains(index))
+                    {
+                        additionalChanges.add(new RemoveIndexChange(table, index));
+                        additionalChanges.add(new AddIndexChange(table, index));
+                        removedIndexes.add(index);
+                    }
+                }
+                for (int tableIdx = 0; tableIdx < currentModel.getTableCount(); tableIdx++)
+                {
+                    Table curTable = currentModel.getTable(tableIdx);
+
+                    for (int fkIdx = 0; fkIdx < curTable.getForeignKeyCount(); fkIdx++)
+                    {
+                        ForeignKey curFk = curTable.getForeignKey(fkIdx);
+
+                        if ((curFk.hasLocalColumn(column) || curFk.hasForeignColumn(column)) &&
+                            !removedForeignKeys.contains(curFk))
+                        {
+                            additionalChanges.add(new RemoveForeignKeyChange(curTable, curFk));
+                            additionalChanges.add(new AddForeignKeyChange(curTable, curFk));
+                            removedForeignKeys.add(curFk);
+                        }
+                    }
+                }
+            }
+        }
+        changes.addAll(additionalChanges);
         super.processChanges(currentModel, desiredModel, changes, params);
     }
 
@@ -379,7 +497,6 @@
             if (change instanceof RemovePrimaryKeyChange)
             {
                 processChange(currentModel, desiredModel, (RemovePrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof PrimaryKeyChange)
@@ -389,11 +506,9 @@
                                                                                    pkChange.getOldPrimaryKeyColumns());
 
                 processChange(currentModel, desiredModel, removePkChange);
-                removePkChange.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
             }
         }
 
-
         ArrayList columnChanges = new ArrayList();
 
         // Next we add/remove columns
@@ -409,19 +524,17 @@
                 if (addColumnChange.isAtEnd())
                 {
                     processChange(currentModel, desiredModel, addColumnChange);
-                    change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                     changeIt.remove();
                 }
             }
             else if (change instanceof RemoveColumnChange)
             {
                 processChange(currentModel, desiredModel, (RemoveColumnChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof ColumnAutoIncrementChange)
             {
-                // Sql Server has no way of adding or removing a IDENTITY constraint
+                // Sql Server has no way of adding or removing an IDENTITY constraint
                 // Thus we have to rebuild the table anyway and can ignore all the other 
                 // column changes
                 columnChanges = null;
@@ -445,7 +558,11 @@
 
                 if (!processedColumns.contains(targetColumn))
                 {
-                    processColumnChange(sourceTable, targetTable, sourceColumn, targetColumn);
+                    processColumnChange(sourceTable,
+                                        targetTable,
+                                        sourceColumn,
+                                        targetColumn,
+                                        (change instanceof ColumnDataTypeChange) || (change instanceof ColumnSizeChange));
                     processedColumns.add(targetColumn);
                 }
                 changes.remove(change);
@@ -460,7 +577,6 @@
             if (change instanceof AddPrimaryKeyChange)
             {
                 processChange(currentModel, desiredModel, (AddPrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof PrimaryKeyChange)
@@ -470,7 +586,6 @@
                                                                           pkChange.getNewPrimaryKeyColumns());
 
                 processChange(currentModel, desiredModel, addPkChange);
-                addPkChange.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
         }
@@ -493,6 +608,7 @@
         print("ADD ");
         writeColumn(change.getChangedTable(), change.getNewColumn());
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -512,6 +628,7 @@
         print("DROP COLUMN ");
         printIdentifier(getColumnName(change.getColumn()));
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -549,6 +666,7 @@
         println("  DEALLOCATE refcursor");
         print("END");
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -558,11 +676,13 @@
      * @param targetTable  The desired table
      * @param sourceColumn The current column
      * @param targetColumn The desired column
+     * @param typeChange   Whether this is a type change
      */
-    protected void processColumnChange(Table  sourceTable,
-                                       Table  targetTable,
-                                       Column sourceColumn,
-                                       Column targetColumn) throws IOException
+    protected void processColumnChange(Table   sourceTable,
+                                       Table   targetTable,
+                                       Column  sourceColumn,
+                                       Column  targetColumn,
+                                       boolean typeChange) throws IOException
     {
         boolean hasDefault       = sourceColumn.getParsedDefaultValue() != null;
         boolean shallHaveDefault = targetColumn.getParsedDefaultValue() != null;

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java Mon Feb  5 23:19:03 2007
@@ -19,9 +19,12 @@
  * under the License.
  */
 
+import java.sql.Connection;
+import java.sql.SQLException;
 import java.sql.Types;
 
 import org.apache.ddlutils.PlatformInfo;
+import org.apache.ddlutils.model.Table;
 import org.apache.ddlutils.platform.PlatformImplBase;
 
 /**
@@ -90,5 +93,60 @@
     public String getName()
     {
         return DATABASENAME;
+    }
+
+    /**
+     * Determines whether we need to use identity override mode for the given table.
+     * 
+     * @param table The table
+     * @return <code>true</code> if identity override mode is needed
+     */
+    private boolean useIdentityOverrideFor(Table table)
+    {
+        return isIdentityOverrideOn() &&
+               getPlatformInfo().isIdentityOverrideAllowed() &&
+               (table.getAutoIncrementColumns().length > 0);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void beforeInsert(Connection connection, Table table) throws SQLException
+    {
+        if (useIdentityOverrideFor(table))
+        {
+            MSSqlBuilder builder = (MSSqlBuilder)getSqlBuilder();
+    
+            connection.createStatement().execute(builder.getEnableIdentityOverrideSql(table));
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void afterInsert(Connection connection, Table table) throws SQLException
+    {
+        if (useIdentityOverrideFor(table))
+        {
+            MSSqlBuilder builder = (MSSqlBuilder)getSqlBuilder();
+    
+            connection.createStatement().execute(builder.getDisableIdentityOverrideSql(table));
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void beforeUpdate(Connection connection, Table table) throws SQLException
+    {
+        beforeInsert(connection, table);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void afterUpdate(Connection connection, Table table) throws SQLException
+    {
+        afterInsert(connection, table);
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlBuilder.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlBuilder.java Mon Feb  5 23:19:03 2007
@@ -192,7 +192,6 @@
             AddColumnChange addColumnChange = (AddColumnChange)changeIt.next();
 
             processChange(currentModel, desiredModel, addColumnChange);
-            addColumnChange.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
             changeIt.remove();
         }
 
@@ -207,25 +206,21 @@
             if (change instanceof RemoveColumnChange)
             {
                 processChange(currentModel, desiredModel, (RemoveColumnChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof AddPrimaryKeyChange)
             {
                 processChange(currentModel, desiredModel, (AddPrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof PrimaryKeyChange)
             {
                 processChange(currentModel, desiredModel, (PrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof RemovePrimaryKeyChange)
             {
                 processChange(currentModel, desiredModel, (RemovePrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof ColumnChange)
@@ -271,6 +266,7 @@
             print(" FIRST");
         }
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -290,6 +286,7 @@
         print("DROP COLUMN ");
         printIdentifier(getColumnName(change.getColumn()));
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -308,6 +305,7 @@
         printIndent();
         print("DROP PRIMARY KEY");
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -327,6 +325,7 @@
         print("DROP PRIMARY KEY");
         printEndOfStatement();
         writeExternalPrimaryKeysCreateStmt(change.getChangedTable(), change.getNewPrimaryKeyColumns());
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java Mon Feb  5 23:19:03 2007
@@ -380,7 +380,6 @@
             if (change instanceof RemovePrimaryKeyChange)
             {
                 processChange(currentModel, desiredModel, (RemovePrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof PrimaryKeyChange)
@@ -390,7 +389,6 @@
                                                                                    pkChange.getOldPrimaryKeyColumns());
 
                 processChange(currentModel, desiredModel, removePkChange);
-                removePkChange.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
             }
         }
 
@@ -411,14 +409,12 @@
                     (!addColumnChange.getNewColumn().isRequired() || (addColumnChange.getNewColumn().getDefaultValue() != null)))
                 {
                     processChange(currentModel, desiredModel, addColumnChange);
-                    change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                     changeIt.remove();
                 }
             }
             else if (change instanceof RemoveColumnChange)
             {
                 processChange(currentModel, desiredModel, (RemoveColumnChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
         }
@@ -430,7 +426,6 @@
             if (change instanceof AddPrimaryKeyChange)
             {
                 processChange(currentModel, desiredModel, (AddPrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof PrimaryKeyChange)
@@ -440,7 +435,6 @@
                                                                           pkChange.getNewPrimaryKeyColumns());
 
                 processChange(currentModel, desiredModel, addPkChange);
-                addPkChange.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
         }
@@ -468,6 +462,7 @@
             createAutoIncrementSequence(change.getChangedTable(), change.getNewColumn());
             createAutoIncrementTrigger(change.getChangedTable(), change.getNewColumn());
         }
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -492,6 +487,7 @@
         print("DROP COLUMN ");
         printIdentifier(getColumnName(change.getColumn()));
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -510,5 +506,6 @@
         printIndent();
         print("DROP PRIMARY KEY");
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java Mon Feb  5 23:19:03 2007
@@ -203,14 +203,12 @@
                     (addColumnChange.getNextColumn() == null))
                 {
                     processChange(currentModel, desiredModel, addColumnChange);
-                    change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                     changeIt.remove();
                 }
             }
             else if (change instanceof RemoveColumnChange)
             {
                 processChange(currentModel, desiredModel, (RemoveColumnChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
         }
@@ -234,6 +232,7 @@
         print("ADD COLUMN ");
         writeColumn(change.getChangedTable(), change.getNewColumn());
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -257,5 +256,6 @@
         {
             dropAutoIncrementSequence(change.getChangedTable(), change.getColumn());
         }
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java Mon Feb  5 23:19:03 2007
@@ -106,7 +106,6 @@
             if (change instanceof RemovePrimaryKeyChange)
             {
                 processChange(currentModel, desiredModel, (RemovePrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof PrimaryKeyChange)
@@ -116,7 +115,6 @@
                                                                                    pkChange.getOldPrimaryKeyColumns());
 
                 processChange(currentModel, desiredModel, removePkChange);
-                removePkChange.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
             }
         }
         // Next we add/change/remove columns
@@ -134,26 +132,22 @@
                 if (addColumnChange.isAtEnd())
                 {
                     processChange(currentModel, desiredModel, addColumnChange);
-                    change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                     changeIt.remove();
                 }
             }
             else if (change instanceof ColumnDefaultValueChange)
             {
                 processChange(currentModel, desiredModel, (ColumnDefaultValueChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof ColumnRequiredChange)
             {
                 processChange(currentModel, desiredModel, (ColumnRequiredChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof RemoveColumnChange)
             {
                 processChange(currentModel, desiredModel, (RemoveColumnChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
         }
@@ -165,7 +159,6 @@
             if (change instanceof AddPrimaryKeyChange)
             {
                 processChange(currentModel, desiredModel, (AddPrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof PrimaryKeyChange)
@@ -175,7 +168,6 @@
                                                                           pkChange.getNewPrimaryKeyColumns());
 
                 processChange(currentModel, desiredModel, addPkChange);
-                addPkChange.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
         }
@@ -198,6 +190,7 @@
         print("ADD ");
         writeColumn(change.getChangedTable(), change.getNewColumn());
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -218,6 +211,7 @@
         printIdentifier(getColumnName(change.getColumn()));
         print(" RELEASE SPACE");
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -236,6 +230,7 @@
         printIndent();
         print("DROP PRIMARY KEY");
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -263,6 +258,7 @@
             print(" NOT NULL");
         }
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -303,5 +299,6 @@
             print(" DROP DEFAULT");
         }
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseBuilder.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseBuilder.java Mon Feb  5 23:19:03 2007
@@ -284,7 +284,6 @@
             if (change instanceof RemovePrimaryKeyChange)
             {
                 processChange(currentModel, desiredModel, (RemovePrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof PrimaryKeyChange)
@@ -294,7 +293,6 @@
                                                                                    pkChange.getOldPrimaryKeyColumns());
 
                 processChange(currentModel, desiredModel, removePkChange);
-                removePkChange.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
             }
         }
 
@@ -314,14 +312,12 @@
                 if (addColumnChange.isAtEnd())
                 {
                     processChange(currentModel, desiredModel, addColumnChange);
-                    change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                     changeIt.remove();
                 }
             }
             else if (change instanceof RemoveColumnChange)
             {
                 processChange(currentModel, desiredModel, (RemoveColumnChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof ColumnAutoIncrementChange)
@@ -384,7 +380,6 @@
             if (change instanceof AddPrimaryKeyChange)
             {
                 processChange(currentModel, desiredModel, (AddPrimaryKeyChange)change);
-                change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
             else if (change instanceof PrimaryKeyChange)
@@ -394,7 +389,6 @@
                                                                           pkChange.getNewPrimaryKeyColumns());
 
                 processChange(currentModel, desiredModel, addPkChange);
-                addPkChange.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
                 changeIt.remove();
             }
         }
@@ -418,6 +412,7 @@
         print("ADD ");
         writeColumn(change.getChangedTable(), change.getNewColumn());
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -437,6 +432,7 @@
         print("DROP ");
         printIdentifier(getColumnName(change.getColumn()));
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -473,6 +469,7 @@
         println("  END");
         print("END");
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -506,6 +503,7 @@
             print("NULL");
         }
         printEndOfStatement();
+        change.apply(currentModel, getPlatform().isDelimitedIdentifierModeOn());
     }
 
     /**
@@ -568,5 +566,5 @@
             }
             printEndOfStatement();
         }
-    }
+   }
 }

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java Mon Feb  5 23:19:03 2007
@@ -154,10 +154,11 @@
      * Returns a "SELECT * FROM [table name]" statement. It also takes
      * delimited identifier mode into account if enabled.
      *  
-     * @param table The table
+     * @param table       The table
+     * @param orderColumn The column to order the rows by (can be <code>null</code>)
      * @return The statement
      */
-    protected String getSelectQueryForAllString(Table table)
+    protected String getSelectQueryForAllString(Table table, String orderColumn)
     {
         StringBuffer query = new StringBuffer();
 
@@ -171,9 +172,22 @@
         {
             query.append(getPlatformInfo().getDelimiterToken());
         }
+        if (orderColumn != null)
+        {
+            query.append(" ORDER BY ");
+            if (getPlatform().isDelimitedIdentifierModeOn())
+            {
+                query.append(getPlatformInfo().getDelimiterToken());
+            }
+            query.append(orderColumn);
+            if (getPlatform().isDelimitedIdentifierModeOn())
+            {
+                query.append(getPlatformInfo().getDelimiterToken());
+            }
+        }
         return query.toString();
     }
-    
+
     /**
      * Retrieves all rows from the given table.
      * 
@@ -184,7 +198,25 @@
     {
         Table table = getModel().findTable(tableName, getPlatform().isDelimitedIdentifierModeOn());
         
-        return getPlatform().fetch(getModel(), getSelectQueryForAllString(table), new Table[] { table });
+        return getPlatform().fetch(getModel(),
+                                   getSelectQueryForAllString(table, null),
+                                   new Table[] { table });
+    }
+
+    /**
+     * Retrieves all rows from the given table.
+     * 
+     * @param tableName   The table
+     * @param orderColumn The column to order the rows by
+     * @return The rows
+     */
+    protected List getRows(String tableName, String orderColumn)
+    {
+        Table table = getModel().findTable(tableName, getPlatform().isDelimitedIdentifierModeOn());
+        
+        return getPlatform().fetch(getModel(),
+                                   getSelectQueryForAllString(table, orderColumn),
+                                   new Table[] { table });
     }
 
     /**

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java Mon Feb  5 23:19:03 2007
@@ -182,6 +182,59 @@
     }
 
     /**
+     * Tests the alteration of the datatypes of columns of a PK and FK that
+     * will be dropped.
+     */
+    public void testChangeDroppedPKAndFKDatatypes()
+    {
+        final String model1Xml = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+            "<database name='roundtriptest'>\n"+
+            "  <table name='roundtrip1'>\n"+
+            "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "  </table>\n"+
+            "  <table name='roundtrip2'>\n"+
+            "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='fk' type='INTEGER' required='false'/>\n"+
+            "    <foreign-key foreignTable='roundtrip1'>\n"+
+            "      <reference local='fk' foreign='pk'/>\n"+
+            "    </foreign-key>\n"+
+            "  </table>\n"+
+            "</database>";
+        final String model2Xml = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+            "<database name='roundtriptest'>\n"+
+            "  <table name='roundtrip1'>\n"+
+            "    <column name='pk' type='VARCHAR' primaryKey='false' required='true'/>\n"+
+            "  </table>\n"+
+            "  <table name='roundtrip2'>\n"+
+            "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='fk' type='VARCHAR' required='false'/>\n"+
+            "  </table>\n"+
+            "</database>";
+
+        createDatabase(model1Xml);
+
+        insertRow("roundtrip1", new Object[] { new Integer(1) });
+        insertRow("roundtrip2", new Object[] { new Integer(1), new Integer(1) });
+
+        alterDatabase(model2Xml);
+
+        assertEquals(getAdjustedModel(),
+                     readModelFromDatabase("roundtriptest"));
+
+        List     beans = getRows("roundtrip2");
+        DynaBean bean  = (DynaBean)beans.get(0);
+
+        // Some databases (e.g. DB2) pad the string for some reason, so we manually trim it
+        if (bean.get("fk") instanceof String)
+        {
+            bean.set("fk", ((String)bean.get("fk")).trim());
+        }
+        assertEquals((Object)"1", bean, "fk");
+    }
+    
+    /**
      * Tests the alteration of the datatypes of a column that is indexed.
      */
     public void testChangeIndexColumnDatatype()
@@ -206,6 +259,48 @@
             "    <index name='avalue_index'>\n"+
             "      <index-column name='avalue'/>\n"+
             "    </index>\n"+
+            "  </table>\n"+
+            "</database>";
+
+        createDatabase(model1Xml);
+
+        insertRow("roundtrip", new Object[] { new Integer(1), new Integer(1) });
+        insertRow("roundtrip", new Object[] { new Integer(2), new Integer(10) });
+
+        alterDatabase(model2Xml);
+
+        assertEquals(getAdjustedModel(),
+                     readModelFromDatabase("roundtriptest"));
+
+        List beans = getRows("roundtrip");
+
+        assertEquals(new Integer(1), beans.get(0), "avalue");
+        assertEquals(new Integer(10), beans.get(1), "avalue");
+    }
+
+    /**
+     * Tests the alteration of the datatypes of an indexed column where
+     * the index will be dropped.
+     */
+    public void testChangeDroppedIndexColumnDatatype()
+    {
+        final String model1Xml = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+            "<database name='roundtriptest'>\n"+
+            "  <table name='roundtrip'>\n"+
+            "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='avalue' type='NUMERIC' size='8' required='false'/>\n"+
+            "    <index name='avalue_index'>\n"+
+            "      <index-column name='avalue'/>\n"+
+            "    </index>\n"+
+            "  </table>\n"+
+            "</database>";
+        final String model2Xml = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+            "<database name='roundtriptest'>\n"+
+            "  <table name='roundtrip'>\n"+
+            "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='avalue' type='INTEGER' required='false'/>\n"+
             "  </table>\n"+
             "</database>";
 

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestMisc.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestMisc.java?view=diff&rev=504014&r1=504013&r2=504014
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestMisc.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestMisc.java Mon Feb  5 23:19:03 2007
@@ -454,31 +454,29 @@
 
         dataIO.writeDataToDatabase(getPlatform(), new Reader[] { stringReader });
 
-        List beans = getRows("misc");
+        List beans = getRows("misc", "id");
 
         assertEquals(12, beans.size());
-        // this is the order of actual insertion (the fk order)
-        // expected insertion order is: 1, 4, 7, 10, 8, 2, 3, 5, 6, 9, 11, 12
         assertEquals(new Integer(1),  beans.get(0), "id");
         assertNull(((DynaBean)beans.get(0)).get("parent_id"));
-        assertEquals(new Integer(4),  beans.get(1), "id");
-        assertEquals(new Integer(1),  beans.get(1), "parent_id");
-        assertEquals(new Integer(7),  beans.get(2), "id");
-        assertEquals(new Integer(1),  beans.get(2), "parent_id");
-        assertEquals(new Integer(10), beans.get(3), "id");
-        assertEquals(new Integer(4),  beans.get(3), "parent_id");
-        assertEquals(new Integer(8),  beans.get(4), "id");
-        assertEquals(new Integer(7),  beans.get(4), "parent_id");
-        assertEquals(new Integer(2),  beans.get(5), "id");
+        assertEquals(new Integer(2),  beans.get(1), "id");
+        assertNull(((DynaBean)beans.get(1)).get("parent_id"));
+        assertEquals(new Integer(3),  beans.get(2), "id");
+        assertEquals(new Integer(2),  beans.get(2), "parent_id");
+        assertEquals(new Integer(4),  beans.get(3), "id");
+        assertEquals(new Integer(1),  beans.get(3), "parent_id");
+        assertEquals(new Integer(5),  beans.get(4), "id");
+        assertEquals(new Integer(3),  beans.get(4), "parent_id");
+        assertEquals(new Integer(6),  beans.get(5), "id");
         assertNull(((DynaBean)beans.get(5)).get("parent_id"));
-        assertEquals(new Integer(3),  beans.get(6), "id");
-        assertEquals(new Integer(2),  beans.get(6), "parent_id");
-        assertEquals(new Integer(5),  beans.get(7), "id");
-        assertEquals(new Integer(3),  beans.get(7), "parent_id");
-        assertEquals(new Integer(6),  beans.get(8), "id");
-        assertNull(((DynaBean)beans.get(8)).get("parent_id"));
-        assertEquals(new Integer(9),  beans.get(9), "id");
-        assertEquals(new Integer(6),  beans.get(9), "parent_id");
+        assertEquals(new Integer(7),  beans.get(6), "id");
+        assertEquals(new Integer(1),  beans.get(6), "parent_id");
+        assertEquals(new Integer(8),  beans.get(7), "id");
+        assertEquals(new Integer(7),  beans.get(7), "parent_id");
+        assertEquals(new Integer(9),  beans.get(8), "id");
+        assertEquals(new Integer(6),  beans.get(8), "parent_id");
+        assertEquals(new Integer(10), beans.get(9), "id");
+        assertEquals(new Integer(4),  beans.get(9), "parent_id");
         assertEquals(new Integer(11), beans.get(10), "id");
         assertNull(((DynaBean)beans.get(10)).get("parent_id"));
         assertEquals(new Integer(12), beans.get(11), "id");
@@ -532,29 +530,27 @@
 
         dataIO.writeDataToDatabase(getPlatform(), new Reader[] { stringReader });
 
-        List beans = getRows("misc");
+        List beans = getRows("misc", "id");
 
         assertEquals(6, beans.size());
-        // this is the order of actual insertion (the fk order)
-        // expected insertion order is: 6, 5, 4, 2, 3, 1
-        assertEquals(new Integer(6), beans.get(0), "id");
-        assertEquals((Object)null,   beans.get(0), "left_id");
-        assertEquals((Object)null,   beans.get(0), "right_id");
-        assertEquals(new Integer(5), beans.get(1), "id");
-        assertEquals((Object)null,   beans.get(1), "left_id");
-        assertEquals(new Integer(6), beans.get(1), "right_id");
-        assertEquals(new Integer(4), beans.get(2), "id");
-        assertEquals(new Integer(6), beans.get(2), "left_id");
-        assertEquals((Object)null,   beans.get(2), "right_id");
-        assertEquals(new Integer(2), beans.get(3), "id");
-        assertEquals(new Integer(5), beans.get(3), "left_id");
-        assertEquals(new Integer(4), beans.get(3), "right_id");
-        assertEquals(new Integer(3), beans.get(4), "id");
-        assertEquals(new Integer(2), beans.get(4), "left_id");
-        assertEquals(new Integer(4), beans.get(4), "right_id");
-        assertEquals(new Integer(1), beans.get(5), "id");
-        assertEquals(new Integer(2), beans.get(5), "left_id");
-        assertEquals(new Integer(3), beans.get(5), "right_id");
+        assertEquals(new Integer(1), beans.get(0), "id");
+        assertEquals(new Integer(2), beans.get(0), "left_id");
+        assertEquals(new Integer(3), beans.get(0), "right_id");
+        assertEquals(new Integer(2), beans.get(1), "id");
+        assertEquals(new Integer(5), beans.get(1), "left_id");
+        assertEquals(new Integer(4), beans.get(1), "right_id");
+        assertEquals(new Integer(3), beans.get(2), "id");
+        assertEquals(new Integer(2), beans.get(2), "left_id");
+        assertEquals(new Integer(4), beans.get(2), "right_id");
+        assertEquals(new Integer(4), beans.get(3), "id");
+        assertEquals(new Integer(6), beans.get(3), "left_id");
+        assertEquals((Object)null,   beans.get(3), "right_id");
+        assertEquals(new Integer(5), beans.get(4), "id");
+        assertEquals((Object)null,   beans.get(4), "left_id");
+        assertEquals(new Integer(6), beans.get(4), "right_id");
+        assertEquals(new Integer(6), beans.get(5), "id");
+        assertEquals((Object)null,   beans.get(5), "left_id");
+        assertEquals((Object)null,   beans.get(5), "right_id");
     }
 
     /**
@@ -623,7 +619,7 @@
 
         createDatabase(modelXml);
 
-        getPlatform().setIdentityOverrideOn(false);
+        getPlatform().setIdentityOverrideOn(true);
 
         // this is the optimal insertion order
         insertRow("E", new Object[] { new Integer(1) });



Mime
View raw message