db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r426396 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/platform/ java/org/apache/ddlutils/platform/mssql/ java/org/apache/ddlutils/platform/sybase/ java/org/apache/ddlutils/task/ test/org/apache/ddlutils/alteration/
Date Fri, 28 Jul 2006 06:12:15 GMT
Author: tomdz
Date: Thu Jul 27 23:12:15 2006
New Revision: 426396

URL: http://svn.apache.org/viewvc?rev=426396&view=rev
Log:
Removed old alteration algorithm (also fixes DDLUTILS-118)

Modified:
    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/mssql/MSSqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestAlterationAlgorithm.java

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?rev=426396&r1=426395&r2=426396&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java Thu Jul
27 23:12:15 2006
@@ -568,7 +568,7 @@
 
             getSqlBuilder().setWriter(buffer);
             //getSqlBuilder().alterDatabase(currentModel, desiredModel, doDrops, modifyColumns);
-            getSqlBuilder().alterDatabase2(currentModel, desiredModel, null);
+            getSqlBuilder().alterDatabase(currentModel, desiredModel, null);
             sql = buffer.toString();
         }
         catch (IOException ex)
@@ -602,7 +602,7 @@
 
             getSqlBuilder().setWriter(buffer);
             //getSqlBuilder().alterDatabase(currentModel, desiredModel, params, doDrops,
modifyColumns);
-            getSqlBuilder().alterDatabase2(currentModel, desiredModel, params);
+            getSqlBuilder().alterDatabase(currentModel, desiredModel, params);
             sql = buffer.toString();
         }
         catch (IOException ex)
@@ -704,7 +704,7 @@
 
             getSqlBuilder().setWriter(buffer);
             //getSqlBuilder().alterDatabase(currentModel, desiredModel, doDrops, modifyColumns);
-            getSqlBuilder().alterDatabase2(currentModel, desiredModel, null);
+            getSqlBuilder().alterDatabase(currentModel, desiredModel, null);
             sql = buffer.toString();
         }
         catch (IOException ex)
@@ -738,7 +738,7 @@
 
             getSqlBuilder().setWriter(buffer);
             //getSqlBuilder().alterDatabase(currentModel, desiredModel, params, doDrops,
modifyColumns);
-            getSqlBuilder().alterDatabase2(currentModel, desiredModel, params);
+            getSqlBuilder().alterDatabase(currentModel, desiredModel, params);
             sql = buffer.toString();
         }
         catch (IOException ex)

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?rev=426396&r1=426395&r2=426396&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java Thu Jul 27 23:12:15
2006
@@ -352,7 +352,7 @@
      * @param params        The parameters used in the creation of new tables. Note that
for existing
      *                      tables, the parameters won't be applied
      */
-    public void alterDatabase2(Database currentModel, Database desiredModel, CreationParameters
params) throws IOException
+    public void alterDatabase(Database currentModel, Database desiredModel, CreationParameters
params) throws IOException
     {
         ModelComparator comparator = new ModelComparator(getPlatformInfo(),
                                                          getPlatform().isDelimitedIdentifierModeOn());
@@ -1053,294 +1053,6 @@
     }
 
     /**
-     * Generates the DDL to modify an existing database so the schema matches
-     * the current specified database schema. Drops and modifications will
-     * not be made.
-     *
-     * @param currentModel  The current database schema
-     * @param desiredModel  The desired database schema
-     */
-    public void alterDatabase(Database currentModel, Database desiredModel) throws IOException
-    {
-        alterDatabase(currentModel, desiredModel, false, false);
-    }
-
-    /**
-     * Generates the DDL to modify an existing database so the schema matches
-     * the current specified database schema.
-     *
-     * @param currentModel  The current database schema
-     * @param desiredModel  The desired database schema
-     * @param doDrops       Whether columns and indexes should be dropped if not in the
-     *                      new schema
-     * @param modifyColumns Whether columns should be altered for datatype, size as required
-     */
-    public void alterDatabase(Database currentModel, Database desiredModel, boolean doDrops,
boolean modifyColumns) throws IOException
-    {
-        alterDatabase(currentModel, desiredModel, null, doDrops, modifyColumns);
-    }        
-
-    /**
-     * Generates the DDL to modify an existing database so the schema matches
-     * the current specified database schema.
-     *
-     * @param currentModel  The current database schema
-     * @param desiredModel  The desired database schema
-     * @param params        The parameters used in the creation of new tables. Note that
for existing
-     *                      tables, parameters won't be applied
-     * @param doDrops       Whether columns and indexes should be dropped if not in the
-     *                      new schema
-     * @param modifyColumns Whether columns should be altered for datatype, size as required
-     */
-    public void alterDatabase(Database currentModel, Database desiredModel, CreationParameters
params, boolean doDrops, boolean modifyColumns) throws IOException
-    {
-        ArrayList newTables = new ArrayList();
-
-        for (int tableIdx = 0; tableIdx < desiredModel.getTableCount(); tableIdx++)
-        {
-            Table desiredTable = desiredModel.getTable(tableIdx);
-            Table currentTable = currentModel.findTable(desiredTable.getName());
-
-            if (currentTable == null)
-            {
-                if (_log.isInfoEnabled())
-                {
-                    _log.info("Creating table " + desiredTable.getName());
-                }
-                createTable(desiredModel,
-                            desiredTable,
-                            params == null ? null : params.getParametersFor(desiredTable));
-                // we're deferring foreignkey generation
-                newTables.add(desiredTable);
-            }
-            else
-            {
-                alterTable(currentModel, currentTable,
-                           desiredModel, desiredTable,
-                           doDrops, modifyColumns);
-            }
-        }
-
-        // generating deferred foreignkeys
-        //TODO should we try to generate new FKs on existing tables?
-        for (Iterator fkIt = newTables.iterator(); fkIt.hasNext();)
-        {
-            createExternalForeignKeys(desiredModel, (Table)fkIt.next());
-        }
-
-        // check for table drops
-        for (int idx = 0; idx < currentModel.getTableCount(); idx++)
-        {
-            Table currentTable = currentModel.getTable(idx);
-            Table desiredTable = desiredModel.findTable(currentTable.getName());
-
-            if ((desiredTable == null) && (currentTable.getName() != null) &&
(currentTable.getName().length() > 0))
-            {
-                if (doDrops)
-                {
-                    if (_log.isInfoEnabled())
-                    {
-                        _log.info("Dropping table " + currentTable.getName());
-                    }
-                    dropTable(currentTable);
-                }
-                else
-                {
-                    String text = "Table " + currentTable.getName() + " can be dropped";
-
-                    if (_log.isInfoEnabled())
-                    {
-                        _log.info(text);
-                    }
-                    printComment(text);
-                }
-            }
-        }
-    }
-
-    /**
-     * Alters the given currently existing table object to match the given desired table
object.
-     * 
-     * @param currentModel The current model
-     * @param currentTable The current table definition
-     * @param desiredModel The desired model
-     * @param desiredTable The desired table definition
-     * @param doDrops       Whether columns and indexes should be dropped if not in the
-     *                      new schema
-     * @param modifyColumns Whether columns should be altered for datatype, size as required
-     */
-    protected void alterTable(Database currentModel, Table currentTable, Database desiredModel,
Table desiredTable, boolean doDrops, boolean modifyColumns) throws IOException
-    {
-        // we need to do this in the following order:
-        // - drop foreign keys (so that columns might be removed)
-        // - drop indices (same reason)
-        // - drop/alter/add columns
-        // - add indices
-        // - add foreign keys
-
-        // Drop foreign keys
-        for (int fkIdx = 0; fkIdx < currentTable.getForeignKeyCount(); fkIdx++)
-        {
-            ForeignKey currentFk = currentTable.getForeignKey(fkIdx);
-            ForeignKey desiredFk = findCorrespondingForeignKey(desiredTable, currentFk);
-
-            if (desiredFk == null)
-            {
-                if (_log.isInfoEnabled())
-                {
-                    _log.info((doDrops ? "" : "Not ") + "Dropping foreign key " + currentTable.getName()
+ "." + currentFk);
-                }
-                if (doDrops)
-                {
-                    writeExternalForeignKeyDropStmt(currentTable, currentFk);
-                }
-            }
-        }
-
-        // Drop indexes
-        for (int indexIdx = 0; indexIdx < currentTable.getIndexCount(); indexIdx++)
-        {
-            Index currentIndex = currentTable.getIndex(indexIdx);
-            Index desiredIndex = desiredTable.findIndex(currentIndex.getName(),
-                                                        getPlatform().isDelimitedIdentifierModeOn());
-
-            if (desiredIndex == null)
-            {
-                // make sure this isn't the primary key index
-                boolean  isPk = true;
-
-                for (int columnIdx = 0; columnIdx < currentIndex.getColumnCount(); columnIdx++)
-                {
-                    IndexColumn indexColumn = currentIndex.getColumn(columnIdx);
-                    Column      column      = currentTable.findColumn(indexColumn.getName());
-
-                    if ((column != null) && !column.isPrimaryKey())
-                    {
-                        isPk = false;
-                        break;
-                    }
-                }
-                if (!isPk)
-                {
-                    if (_log.isInfoEnabled())
-                    {
-                        _log.info((doDrops ? "" : "Not ") + "Dropping non-primary index "
+ currentTable.getName() + "." + currentIndex.getName());
-                    }
-                    if (doDrops)
-                    {
-                        writeExternalIndexDropStmt(currentTable, currentIndex);
-                    }
-                }
-            }
-        }
-
-        // Add/alter columns
-        for (int columnIdx = 0; columnIdx < desiredTable.getColumnCount(); columnIdx++)
-        {
-            Column desiredColumn = desiredTable.getColumn(columnIdx);
-            Column currentColumn = currentTable.findColumn(desiredColumn.getName(),
-                                                           getPlatform().isDelimitedIdentifierModeOn());
-
-            if (null == currentColumn)
-            {
-                if (_log.isInfoEnabled())
-                {
-                    _log.info("Creating column " + desiredTable.getName() + "." + desiredColumn.getName());
-                }
-                writeColumnAlterStmt(desiredTable, desiredColumn, true);
-            }
-            else if (columnsDiffer(currentColumn, desiredColumn))
-            {
-                if (modifyColumns)
-                {
-                    if (_log.isInfoEnabled())
-                    {
-                        _log.info("Altering column " + desiredTable.getName() + "." + desiredColumn.getName());
-                        _log.info("  desired = " + desiredColumn.toVerboseString());
-                        _log.info("  current = " + currentColumn.toVerboseString());
-                    }
-                    writeColumnAlterStmt(desiredTable, desiredColumn, false);
-                }
-                else
-                {
-                    String text = "Column " + currentColumn.getName() + " in table " + currentTable.getName()
+ " differs from current specification";
-
-                    if (_log.isInfoEnabled())
-                    {
-                        _log.info(text);
-                    }
-                    printComment(text);
-                }
-            }
-        }
-
-        // Drop columns
-        for (int columnIdx = 0; columnIdx < currentTable.getColumnCount(); columnIdx++)
-        {
-            Column currentColumn = currentTable.getColumn(columnIdx);
-            Column desiredColumn = desiredTable.findColumn(currentColumn.getName(),
-                                                           getPlatform().isDelimitedIdentifierModeOn());
-
-            if (desiredColumn == null)
-            {
-                if (doDrops)
-                {
-                    if (_log.isInfoEnabled())
-                    {
-                        _log.info("Dropping column " + currentTable.getName() + "." + currentColumn.getName());
-                    }
-                    writeColumnDropStmt(currentTable, currentColumn);
-                }
-                else
-                {
-                    String text = "Column " + currentColumn.getName() + " can be dropped
from table " + currentTable.getName();
-
-                    if (_log.isInfoEnabled())
-                    {
-                        _log.info(text);
-                    }
-                    printComment(text);
-                }
-            }
-        }
-
-        // Add foreign keys
-        for (int fkIdx = 0; fkIdx < desiredTable.getForeignKeyCount(); fkIdx++)
-        {
-            ForeignKey desiredFk = desiredTable.getForeignKey(fkIdx);
-            ForeignKey currentFk = findCorrespondingForeignKey(currentTable, desiredFk);
-
-            if (currentFk == null)
-            {
-                if (_log.isInfoEnabled())
-                {
-                    _log.info("Creating foreign key " + desiredTable.getName() + "." + desiredFk);
-                }
-                writeExternalForeignKeyCreateStmt(desiredModel, desiredTable, desiredFk);
-            }
-        }
-
-        // TODO: we should check the index fields for differences
-        // Add indexes
-        for (int indexIdx = 0; indexIdx < desiredTable.getIndexCount(); indexIdx++)
-        {
-            Index desiredIndex = desiredTable.getIndex(indexIdx);
-            Index currentIndex = currentTable.findIndex(desiredIndex.getName(),
-                                                        getPlatform().isDelimitedIdentifierModeOn());
-
-            if (currentIndex == null)
-            {
-                if (_log.isInfoEnabled())
-                {
-                    _log.info("Creating index " + desiredTable.getName() + "." + desiredIndex.getName());
-                }
-                writeExternalIndexCreateStmt(desiredTable, desiredIndex);
-            }
-        }
-
-    }
-
-    /**
      * 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 in the
      * same order is searched. If the given key has a name, then the a corresponding
@@ -1994,35 +1706,6 @@
             print(" ");
             writeColumnAutoIncrementStmt(table, column);
         }
-    }
-
-    /**
-     * Generates the alter statement to add or modify a single column on a table.
-     *
-     * @param table       The table the index is on
-     * @param column      The column to drop
-     * @param isNewColumn Whether the column should be added
-     */
-    public void writeColumnAlterStmt(Table table, Column column, boolean isNewColumn) throws
IOException
-    {
-        writeTableAlterStmt(table);
-        print(isNewColumn ? "ADD " : "MODIFY ");
-        writeColumn(table, column);
-        printEndOfStatement();
-    }
-
-    /**
-     * Generates the statement to drop an column from a table.
-     *
-     * @param table  The table the index is on
-     * @param column The column to drop
-     */
-    public void writeColumnDropStmt(Table table, Column column) throws IOException
-    {
-        writeTableAlterStmt(table);
-        print("DROP COLUMN ");
-        printIdentifier(getColumnName(column));
-        printEndOfStatement();
     }
 
     /**

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?rev=426396&r1=426395&r2=426396&view=diff
==============================================================================
--- 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 Thu Jul
27 23:12:15 2006
@@ -17,8 +17,6 @@
  */
 
 import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
 import java.sql.Types;
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -76,31 +74,6 @@
     /**
      * {@inheritDoc}
      */
-    protected void alterTable(Database currentModel, Table currentTable, Database desiredModel,
Table desiredTable, boolean doDrops, boolean modifyColumns) throws IOException
-    {
-    	// we only want to generate the quotation start statement if there is something to write
-    	// thus we write the alteration commands into a temporary writer
-    	// and only if something was written, write the quotation start statement and the
-    	// alteration commands to the original writer
-    	Writer       originalWriter = getWriter();
-    	StringWriter tempWriter     = new StringWriter();
-
-    	setWriter(tempWriter);
-        super.alterTable(currentModel, currentTable, desiredModel, desiredTable, doDrops,
modifyColumns);
-        setWriter(originalWriter);
-
-        String alterationCommands = tempWriter.toString();
-
-        if (alterationCommands.trim().length() > 0)
-        {
-        	writeQuotationOnStatement();
-        	getWriter().write(alterationCommands);
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
     public void dropTable(Table table) throws IOException
     {
         String tableName         = getTableName(table);
@@ -176,17 +149,6 @@
         printIdentifier(getTableName(table));
         print(".");
         printIdentifier(getIndexName(index));
-        printEndOfStatement();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void writeColumnAlterStmt(Table table, Column column, boolean isNewColumn) throws
IOException
-    {
-        writeTableAlterStmt(table);
-        print(isNewColumn ? "ADD " : "ALTER COLUMN ");
-        writeColumn(table, column);
         printEndOfStatement();
     }
 

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?rev=426396&r1=426395&r2=426396&view=diff
==============================================================================
--- 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 Thu
Jul 27 23:12:15 2006
@@ -17,8 +17,6 @@
  */
 
 import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
 import java.sql.Types;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -117,31 +115,6 @@
         else
         {
             return super.getNativeDefaultValue(column);
-        }
-    }
-
-	/**
-     * {@inheritDoc}
-     */
-    protected void alterTable(Database currentModel, Table currentTable, Database desiredModel,
Table desiredTable, boolean doDrops, boolean modifyColumns) throws IOException
-    {
-    	// we only want to generate the quotation start statement if there is something to write
-    	// thus we write the alteration commands into a temporary writer
-    	// and only if something was written, write the quotation start statement and the
-    	// alteration commands to the original writer
-    	Writer       originalWriter = getWriter();
-    	StringWriter tempWriter     = new StringWriter();
-
-    	setWriter(tempWriter);
-        super.alterTable(currentModel, currentTable, desiredModel, desiredTable, doDrops,
modifyColumns);
-        setWriter(originalWriter);
-
-        String alterationCommands = tempWriter.toString();
-
-        if (alterationCommands.trim().length() > 0)
-        {
-        	writeQuotationOnStatement();
-        	getWriter().write(alterationCommands);
         }
     }
 

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java?rev=426396&r1=426395&r2=426396&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java Thu
Jul 27 23:12:15 2006
@@ -158,7 +158,7 @@
                                              platform.readModelFromDatabase(null, getCatalogPattern(),
getSchemaPattern(), null) :
                                              platform.readModelFromDatabase(null);
 
-                platform.getSqlBuilder().alterDatabase(currentModel, model, params, _doDrops,
true);
+                platform.getSqlBuilder().alterDatabase(currentModel, model, params);
             }
             else
             {

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestAlterationAlgorithm.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestAlterationAlgorithm.java?rev=426396&r1=426395&r2=426396&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestAlterationAlgorithm.java
(original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestAlterationAlgorithm.java
Thu Jul 27 23:12:15 2006
@@ -69,7 +69,7 @@
         Database currentModel = parseDatabaseFromString(currentSchema);
         Database desiredModel = parseDatabaseFromString(desiredSchema);
 
-        _platform.getSqlBuilder().alterDatabase2(currentModel, desiredModel, null);
+        _platform.getSqlBuilder().alterDatabase(currentModel, desiredModel, null);
 
         return _writer.toString();
     }



Mime
View raw message