You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ddlutils-dev@db.apache.org by to...@apache.org on 2007/12/10 09:21:39 UTC
svn commit: r602807 [1/15] - in /db/ddlutils/trunk: ./
src/java/org/apache/ddlutils/ src/java/org/apache/ddlutils/alteration/
src/java/org/apache/ddlutils/model/ src/java/org/apache/ddlutils/platform/
src/java/org/apache/ddlutils/platform/axion/ src/ja...
Author: tomdz
Date: Mon Dec 10 00:20:47 2007
New Revision: 602807
URL: http://svn.apache.org/viewvc?rev=602807&view=rev
Log:
Implemented new model comparison algorithm and database alteration workflow
Started to add tests to cover database alteration in more detail
Added:
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDefinitionChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/Pair.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RecreateTableChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/TableDefinitionChangesPredicate.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/CloneHelper.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexImplBase.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/DefaultTableDefinitionChangesPredicate.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlModelComparator.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlModelComparator.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/util/StringUtils.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestComparisonBase.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestForeignKeyComparison.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestIndexComparison.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestModelComparison.java
- copied, changed from r581500, db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestModelComparator.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestPrimaryKeyComparison.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestTableComparison.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAddColumn.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDropColumn.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestInsertColumn.java
Removed:
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnAutoIncrementChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDataTypeChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDefaultValueChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnRequiredChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnSizeChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexImpBase.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestModelComparator.java
Modified:
db/ddlutils/trunk/.classpath
db/ddlutils/trunk/build.xml
db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddColumnChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddForeignKeyChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddIndexChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddPrimaryKeyChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddTableChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnChangeImplBase.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnOrderChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ForeignKeyChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ForeignKeyChangeImplBase.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/IndexChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/IndexChangeImplBase.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ModelComparator.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/PrimaryKeyChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveColumnChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveForeignKeyChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveIndexChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemovePrimaryKeyChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/RemoveTableChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/TableChange.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/TableChangeImplBase.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/CascadeActionEnum.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java
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/NonUniqueIndex.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Reference.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/UniqueIndex.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/JdbcModelReader.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/axion/AxionBuilder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/cloudscape/CloudscapePlatform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Builder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2ModelReader.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Platform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2v8Builder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyBuilder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyPlatform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdBuilder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdModelReader.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdPlatform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbBuilder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbPlatform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbasePlatform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/maxdb/MaxDbBuilder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mckoi/MckoiBuilder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mckoi/MckoiPlatform.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/mysql/MySqlPlatform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Platform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlPlatform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbPlatform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseBuilder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybasePlatform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/RunAllTests.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestAlterationAlgorithm.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java
Modified: db/ddlutils/trunk/.classpath
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/.classpath?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/.classpath (original)
+++ db/ddlutils/trunk/.classpath Mon Dec 10 00:20:47 2007
@@ -1,26 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
<classpath>
<classpathentry kind="src" path="src/java"/>
<classpathentry kind="src" output="target/test" path="src/test"/>
- <classpathentry kind="var" path="JRE_LIB" sourcepath="JRE_SRC"/>
<classpathentry exported="true" kind="lib" path="lib/commons-logging-1.0.4.jar"/>
<classpathentry exported="true" kind="lib" path="lib/dom4j-1.4.jar"/>
<classpathentry exported="true" kind="lib" path="lib/commons-collections-3.1.jar"/>
@@ -34,5 +15,6 @@
<classpathentry kind="lib" path="lib/build-only/junit-3.8.2.jar"/>
<classpathentry kind="lib" path="lib/stax-api-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/log4j-1.2.8.jar"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Modified: db/ddlutils/trunk/build.xml
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/build.xml?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/build.xml (original)
+++ db/ddlutils/trunk/build.xml Mon Dec 10 00:20:47 2007
@@ -179,6 +179,10 @@
author="false"
version="true"
packagenames="org.*">
+ <tag name="ant.type" scope="types" description="Marks an ant type"/>
+ <tag name="ant.task" scope="types" description="Marks an ant task"/>
+ <tag name="ant.required" scope="methods" description="Marks a required task property"/>
+ <tag name="ant.not-required" scope="methods" description="Marks an optional task property"/>
<link href="http://java.sun.com/j2se/1.4.2/docs/api/"/>
<link href="http://jakarta.apache.org/commons/lang/apidocs/"/>
<link href="http://jakarta.apache.org/commons/beanutils/apidocs/"/>
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java Mon Dec 10 00:20:47 2007
@@ -292,6 +292,7 @@
* @param model The database model
* @param dropTablesFirst Whether to drop the tables prior to creating them (anew)
* @param continueOnError Whether to continue executing the sql commands when an error occurred
+ * @deprecated Use {@link #createModel(Database, boolean, boolean)} instead.
*/
public void createTables(Database model, boolean dropTablesFirst, boolean continueOnError) throws DatabaseOperationException;
@@ -302,20 +303,76 @@
* @param model The database model
* @param dropTablesFirst Whether to drop the tables prior to creating them (anew)
* @param continueOnError Whether to continue executing the sql commands when an error occurred
+ * @deprecated Use {@link #createModel(Connection, Database, boolean, boolean)} instead.
*/
public void createTables(Connection connection, Database model, boolean dropTablesFirst, boolean continueOnError) throws DatabaseOperationException;
/**
+ * Creates the tables defined in the database model.
+ *
+ * @param model The database model
+ * @param params The parameters used in the creation
+ * @param dropTablesFirst Whether to drop the tables prior to creating them (anew)
+ * @param continueOnError Whether to continue executing the sql commands when an error occurred
+ * @deprecated Use {@link #createModel(Database, CreationParameters, boolean, boolean)} instead.
+ */
+ public void createTables(Database model, CreationParameters params, boolean dropTablesFirst, boolean continueOnError) throws DatabaseOperationException;
+
+ /**
+ * Creates the tables defined in the database model.
+ *
+ * @param connection The connection to the database
+ * @param model The database model
+ * @param params The parameters used in the creation
+ * @param dropTablesFirst Whether to drop the tables prior to creating them (anew)
+ * @param continueOnError Whether to continue executing the sql commands when an error occurred
+ * @deprecated Use {@link #createModel(Connection, Database, CreationParameters, boolean, boolean)} instead.
+ */
+ public void createTables(Connection connection, Database model, CreationParameters params, boolean dropTablesFirst, boolean continueOnError) throws DatabaseOperationException;
+
+ /**
* Returns the SQL for creating the tables defined in the database model.
*
* @param model The database model
* @param dropTablesFirst Whether to drop the tables prior to creating them (anew)
* @param continueOnError Whether to continue executing the sql commands when an error occurred
* @return The SQL statements
+ * @deprecated Use {@link #getCreateModelSql(Database, boolean, boolean)} instead.
*/
public String getCreateTablesSql(Database model, boolean dropTablesFirst, boolean continueOnError);
/**
+ * Returns the SQL for creating the tables defined in the database model.
+ *
+ * @param model The database model
+ * @param params The parameters used in the creation
+ * @param dropTablesFirst Whether to drop the tables prior to creating them (anew)
+ * @param continueOnError Whether to continue executing the sql commands when an error occurred
+ * @return The SQL statements
+ * @deprecated Use {@link #getCreateModelSql(Database, CreationParameters, boolean, boolean)} instead.
+ */
+ public String getCreateTablesSql(Database model, CreationParameters params, boolean dropTablesFirst, boolean continueOnError);
+
+ /**
+ * Creates the tables defined in the database model.
+ *
+ * @param model The database model
+ * @param dropTablesFirst Whether to drop the tables prior to creating them (anew)
+ * @param continueOnError Whether to continue executing the sql commands when an error occurred
+ */
+ public void createModel(Database model, boolean dropTablesFirst, boolean continueOnError) throws DatabaseOperationException;
+
+ /**
+ * Creates the tables defined in the database model.
+ *
+ * @param connection The connection to the database
+ * @param model The database model
+ * @param dropTablesFirst Whether to drop the tables prior to creating them (anew)
+ * @param continueOnError Whether to continue executing the sql commands when an error occurred
+ */
+ public void createModel(Connection connection, Database model, boolean dropTablesFirst, boolean continueOnError) throws DatabaseOperationException;
+
+ /**
* Creates the tables defined in the database model.
*
* @param model The database model
@@ -323,7 +380,7 @@
* @param dropTablesFirst Whether to drop the tables prior to creating them (anew)
* @param continueOnError Whether to continue executing the sql commands when an error occurred
*/
- public void createTables(Database model, CreationParameters params, boolean dropTablesFirst, boolean continueOnError) throws DatabaseOperationException;
+ public void createModel(Database model, CreationParameters params, boolean dropTablesFirst, boolean continueOnError) throws DatabaseOperationException;
/**
* Creates the tables defined in the database model.
@@ -334,7 +391,17 @@
* @param dropTablesFirst Whether to drop the tables prior to creating them (anew)
* @param continueOnError Whether to continue executing the sql commands when an error occurred
*/
- public void createTables(Connection connection, Database model, CreationParameters params, boolean dropTablesFirst, boolean continueOnError) throws DatabaseOperationException;
+ public void createModel(Connection connection, Database model, CreationParameters params, boolean dropTablesFirst, boolean continueOnError) throws DatabaseOperationException;
+
+ /**
+ * Returns the SQL for creating the tables defined in the database model.
+ *
+ * @param model The database model
+ * @param dropTablesFirst Whether to drop the tables prior to creating them (anew)
+ * @param continueOnError Whether to continue executing the sql commands when an error occurred
+ * @return The SQL statements
+ */
+ public String getCreateModelSql(Database model, boolean dropTablesFirst, boolean continueOnError);
/**
* Returns the SQL for creating the tables defined in the database model.
@@ -345,41 +412,54 @@
* @param continueOnError Whether to continue executing the sql commands when an error occurred
* @return The SQL statements
*/
- public String getCreateTablesSql(Database model, CreationParameters params, boolean dropTablesFirst, boolean continueOnError);
+ public String getCreateModelSql(Database model, CreationParameters params, boolean dropTablesFirst, boolean continueOnError);
+
+ /**
+ * Returns the necessary changes to apply to the current database to make it the desired one.
+ * These changes are in the correct order and have been adjusted for the current platform.
+ *
+ * @param currentModel The current model
+ * @param desiredModel The desired model
+ * @return The list of changes, adjusted to the platform and sorted for execution
+ */
+ public List getChanges(Database currentModel, Database desiredModel);
/**
* Alters the database schema so that it match the given model.
*
* @param desiredDb The desired database schema
* @param continueOnError Whether to continue with the next sql statement when an error occurred
+ * @deprecated Use {@link #alterModel(Database, Database, boolean)} together with
+ * {@link #readModelFromDatabase(String)} instead.
*/
public void alterTables(Database desiredDb, boolean continueOnError) throws DatabaseOperationException;
/**
- * Returns the SQL for altering the database schema so that it match the given model.
- *
- * @param desiredDb The desired database schema
- * @return The SQL statements
- */
- public String getAlterTablesSql(Database desiredDb) throws DatabaseOperationException;
-
- /**
* Alters the database schema so that it match the given model.
*
* @param desiredDb The desired database schema
* @param params The parameters used in the creation
* @param continueOnError Whether to continue with the next sql statement when an error occurred
+ * @deprecated Use {@link #alterModel(Database, Database, CreationParameters, boolean)} together with
+ * {@link #readModelFromDatabase(String)} instead.
*/
public void alterTables(Database desiredDb, CreationParameters params, boolean continueOnError) throws DatabaseOperationException;
/**
- * Returns the SQL for altering the database schema so that it match the given model.
+ * Alters the database schema so that it match the given model.
*
- * @param desiredDb The desired database schema
- * @param params The parameters used in the creation
- * @return The SQL statements
+ * @param catalog The catalog in the existing database to read (can be a pattern);
+ * use <code>null</code> for the platform-specific default value
+ * @param schema The schema in the existing database to read (can be a pattern);
+ * use <code>null</code> for the platform-specific default value
+ * @param tableTypes The table types to read from the existing database;
+ * use <code>null</code> or an empty array for the platform-specific default value
+ * @param desiredDb The desired database schema
+ * @param continueOnError Whether to continue with the next sql statement when an error occurred
+ * @deprecated Use {@link #alterModel(Database, Database, boolean)} together with
+ * {@link #readModelFromDatabase(String, String, String, String[])} instead.
*/
- public String getAlterTablesSql(Database desiredDb, CreationParameters params) throws DatabaseOperationException;
+ public void alterTables(String catalog, String schema, String[] tableTypes, Database desiredDb, boolean continueOnError) throws DatabaseOperationException;
/**
* Alters the database schema so that it match the given model.
@@ -391,27 +471,57 @@
* @param tableTypes The table types to read from the existing database;
* use <code>null</code> or an empty array for the platform-specific default value
* @param desiredDb The desired database schema
+ * @param params The parameters used in the creation
* @param continueOnError Whether to continue with the next sql statement when an error occurred
+ * @deprecated Use {@link #alterModel(Database, Database, CreationParameters, boolean)} together with
+ * {@link #readModelFromDatabase(String, String, String, String[])} instead.
*/
- public void alterTables(String catalog, String schema, String[] tableTypes, Database desiredDb, boolean continueOnError) throws DatabaseOperationException;
+ public void alterTables(String catalog, String schema, String[] tableTypes, Database desiredDb, CreationParameters params, boolean continueOnError) throws DatabaseOperationException;
/**
- * Returns the SQL for altering the database schema so that it match the given model.
+ * Alters the database schema so that it match the given model.
*
- * @param catalog The catalog in the existing database to read (can be a pattern);
- * use <code>null</code> for the platform-specific default value
- * @param schema The schema in the existing database to read (can be a pattern);
- * use <code>null</code> for the platform-specific default value
- * @param tableTypes The table types to read from the existing database;
- * use <code>null</code> or an empty array for the platform-specific default value
- * @param desiredDb The desired database schema
- * @return The SQL statements
+ * @param connection A connection to the existing database that shall be modified
+ * @param desiredDb The desired database schema
+ * @param continueOnError Whether to continue with the next sql statement when an error occurred
+ * @deprecated Use {@link #alterModel(Connection, Database, Database, boolean)} together with
+ * {@link #readModelFromDatabase(Connection, String)} instead.
*/
- public String getAlterTablesSql(String catalog, String schema, String[] tableTypes, Database desiredDb) throws DatabaseOperationException;
+ public void alterTables(Connection connection, Database desiredDb, boolean continueOnError) throws DatabaseOperationException;
/**
* Alters the database schema so that it match the given model.
*
+ * @param connection A connection to the existing database that shall be modified
+ * @param desiredDb The desired database schema
+ * @param params The parameters used in the creation
+ * @param continueOnError Whether to continue with the next sql statement when an error occurred
+ * @deprecated Use {@link #alterModel(Connection, Database, Database, CreationParameters, boolean)} together with
+ * {@link #readModelFromDatabase(Connection, String)} instead.
+ */
+ public void alterTables(Connection connection, Database desiredDb, CreationParameters params, boolean continueOnError) throws DatabaseOperationException;
+
+ /**
+ * Alters the database schema so that it match the given model.
+ *
+ * @param connection A connection to the existing database that shall be modified
+ * @param catalog The catalog in the existing database to read (can be a pattern);
+ * use <code>null</code> for the platform-specific default value
+ * @param schema The schema in the existing database to read (can be a pattern);
+ * use <code>null</code> for the platform-specific default value
+ * @param tableTypes The table types to read from the existing database;
+ * use <code>null</code> or an empty array for the platform-specific default value
+ * @param desiredDb The desired database schema
+ * @param continueOnError Whether to continue with the next sql statement when an error occurred
+ * @deprecated Use {@link #alterModel(Connection, Database, Database, boolean)} together with
+ * {@link #readModelFromDatabase(Connection, String, String, String, String[])} instead.
+ */
+ public void alterTables(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredDb, boolean continueOnError) throws DatabaseOperationException;
+
+ /**
+ * Alters the database schema so that it match the given model.
+ *
+ * @param connection A connection to the existing database that shall be modified
* @param catalog The catalog in the existing database to read (can be a pattern);
* use <code>null</code> for the platform-specific default value
* @param schema The schema in the existing database to read (can be a pattern);
@@ -421,8 +531,31 @@
* @param desiredDb The desired database schema
* @param params The parameters used in the creation
* @param continueOnError Whether to continue with the next sql statement when an error occurred
+ * @deprecated Use {@link #alterModel(Connection, Database, Database, CreationParameters, boolean)} together with
+ * {@link #readModelFromDatabase(Connection, String, String, String, String[])} instead.
*/
- public void alterTables(String catalog, String schema, String[] tableTypes, Database desiredDb, CreationParameters params, boolean continueOnError) throws DatabaseOperationException;
+ public void alterTables(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredDb, CreationParameters params, boolean continueOnError) throws DatabaseOperationException;
+
+ /**
+ * Returns the SQL for altering the database schema so that it match the given model.
+ *
+ * @param desiredDb The desired database schema
+ * @return The SQL statements
+ * @deprecated Use {@link #getAlterModelSql(Database, Database)} together with
+ * {@link #readModelFromDatabase(String)} instead.
+ */
+ public String getAlterTablesSql(Database desiredDb) throws DatabaseOperationException;
+
+ /**
+ * Returns the SQL for altering the database schema so that it match the given model.
+ *
+ * @param desiredDb The desired database schema
+ * @param params The parameters used in the creation
+ * @return The SQL statements
+ * @deprecated Use {@link #getAlterModelSql(Database, Database, CreationParameters)} together with
+ * {@link #readModelFromDatabase(String)} instead.
+ */
+ public String getAlterTablesSql(Database desiredDb, CreationParameters params) throws DatabaseOperationException;
/**
* Returns the SQL for altering the database schema so that it match the given model.
@@ -434,19 +567,28 @@
* @param tableTypes The table types to read from the existing database;
* use <code>null</code> or an empty array for the platform-specific default value
* @param desiredDb The desired database schema
- * @param params The parameters used in the creation
* @return The SQL statements
+ * @deprecated Use {@link #getAlterModelSql(Database, Database)} together with
+ * {@link #readModelFromDatabase(String, String, String, String[])} instead.
*/
- public String getAlterTablesSql(String catalog, String schema, String[] tableTypes, Database desiredDb, CreationParameters params) throws DatabaseOperationException;
+ public String getAlterTablesSql(String catalog, String schema, String[] tableTypes, Database desiredDb) throws DatabaseOperationException;
/**
- * Alters the database schema so that it match the given model.
+ * Returns the SQL for altering the database schema so that it match the given model.
*
- * @param connection A connection to the existing database that shall be modified
- * @param desiredDb The desired database schema
- * @param continueOnError Whether to continue with the next sql statement when an error occurred
+ * @param catalog The catalog in the existing database to read (can be a pattern);
+ * use <code>null</code> for the platform-specific default value
+ * @param schema The schema in the existing database to read (can be a pattern);
+ * use <code>null</code> for the platform-specific default value
+ * @param tableTypes The table types to read from the existing database;
+ * use <code>null</code> or an empty array for the platform-specific default value
+ * @param desiredDb The desired database schema
+ * @param params The parameters used in the creation
+ * @return The SQL statements
+ * @deprecated Use {@link #getAlterModelSql(Database, Database, CreationParameters)} together with
+ * {@link #readModelFromDatabase(String, String, String, String[])} instead.
*/
- public void alterTables(Connection connection, Database desiredDb, boolean continueOnError) throws DatabaseOperationException;
+ public String getAlterTablesSql(String catalog, String schema, String[] tableTypes, Database desiredDb, CreationParameters params) throws DatabaseOperationException;
/**
* Returns the SQL for altering the database schema so that it match the given model.
@@ -454,45 +596,24 @@
* @param connection A connection to the existing database that shall be modified
* @param desiredDb The desired database schema
* @return The SQL statements
+ * @deprecated Use {@link #getAlterModelSql(Database, Database)} together with
+ * {@link #readModelFromDatabase(Connection, String)} instead.
*/
public String getAlterTablesSql(Connection connection, Database desiredDb) throws DatabaseOperationException;
/**
- * Alters the database schema so that it match the given model.
- *
- * @param connection A connection to the existing database that shall be modified
- * @param desiredDb The desired database schema
- * @param params The parameters used in the creation
- * @param continueOnError Whether to continue with the next sql statement when an error occurred
- */
- public void alterTables(Connection connection, Database desiredDb, CreationParameters params, boolean continueOnError) throws DatabaseOperationException;
-
- /**
* Returns the SQL for altering the database schema so that it match the given model.
*
* @param connection A connection to the existing database that shall be modified
* @param desiredDb The desired database schema
* @param params The parameters used in the creation
* @return The SQL statements
+ * @deprecated Use {@link #getAlterModelSql(Database, Database, CreationParameters)} together with
+ * {@link #readModelFromDatabase(Connection, String)} instead.
*/
public String getAlterTablesSql(Connection connection, Database desiredDb, CreationParameters params) throws DatabaseOperationException;
/**
- * Alters the database schema so that it match the given model.
- *
- * @param connection A connection to the existing database that shall be modified
- * @param catalog The catalog in the existing database to read (can be a pattern);
- * use <code>null</code> for the platform-specific default value
- * @param schema The schema in the existing database to read (can be a pattern);
- * use <code>null</code> for the platform-specific default value
- * @param tableTypes The table types to read from the existing database;
- * use <code>null</code> or an empty array for the platform-specific default value
- * @param desiredDb The desired database schema
- * @param continueOnError Whether to continue with the next sql statement when an error occurred
- */
- public void alterTables(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredDb, boolean continueOnError) throws DatabaseOperationException;
-
- /**
* Returns the SQL for altering the database schema so that it match the given model.
*
* @param connection A connection to the existing database that shall be modified
@@ -504,26 +625,12 @@
* use <code>null</code> or an empty array for the platform-specific default value
* @param desiredDb The desired database schema
* @return The SQL statements
+ * @deprecated Use {@link #getAlterModelSql(Database, Database)} together with
+ * {@link #readModelFromDatabase(Connection, String, String, String, String[])} instead.
*/
public String getAlterTablesSql(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredDb) throws DatabaseOperationException;
/**
- * Alters the database schema so that it match the given model.
- *
- * @param connection A connection to the existing database that shall be modified
- * @param catalog The catalog in the existing database to read (can be a pattern);
- * use <code>null</code> for the platform-specific default value
- * @param schema The schema in the existing database to read (can be a pattern);
- * use <code>null</code> for the platform-specific default value
- * @param tableTypes The table types to read from the existing database;
- * use <code>null</code> or an empty array for the platform-specific default value
- * @param desiredDb The desired database schema
- * @param params The parameters used in the creation
- * @param continueOnError Whether to continue with the next sql statement when an error occurred
- */
- public void alterTables(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredDb, CreationParameters params, boolean continueOnError) throws DatabaseOperationException;
-
- /**
* Returns the SQL for altering the database schema so that it match the given model.
*
* @param connection A connection to the existing database that shall be modified
@@ -536,10 +643,71 @@
* @param desiredDb The desired database schema
* @param params The parameters used in the creation
* @return The SQL statements
+ * @deprecated Use {@link #getAlterModelSql(Database, Database, CreationParameters)} together with
+ * {@link #readModelFromDatabase(Connection, String, String, String, String[])} instead.
*/
public String getAlterTablesSql(Connection connection, String catalog, String schema, String[] tableTypes, Database desiredDb, CreationParameters params) throws DatabaseOperationException;
/**
+ * Alters the given live database model so that it match the desired model, using the default database conneciton.
+ *
+ * @param currentModel The current database model
+ * @param desiredModel The desired database model
+ * @param continueOnError Whether to continue with the next sql statement when an error occurred
+ */
+ public void alterModel(Database currentModel, Database desiredModel, boolean continueOnError) throws DatabaseOperationException;
+
+ /**
+ * Alters the given live database model so that it match the desired model, using the default database conneciton.
+ *
+ * @param currentModel The current database model
+ * @param desiredModel The desired database model
+ * @param params The parameters used in the creation
+ * @param continueOnError Whether to continue with the next sql statement when an error occurred
+ */
+ public void alterModel(Database currentModel, Database desiredModel, CreationParameters params, boolean continueOnError) throws DatabaseOperationException;
+
+ /**
+ * Alters the given live database model so that it match the desired model.
+ *
+ * @param connection A connection to the existing database that shall be modified
+ * @param currentModel The current database model
+ * @param desiredModel The desired database model
+ * @param continueOnError Whether to continue with the next sql statement when an error occurred
+ */
+ public void alterModel(Connection connection, Database currentModel, Database desiredModel, boolean continueOnError) throws DatabaseOperationException;
+
+ /**
+ * Alters the given live database model so that it match the desired model.
+ *
+ * @param connection A connection to the existing database that shall be modified
+ * @param currentModel The current database model
+ * @param desiredModel The desired database model
+ * @param params The parameters used in the creation
+ * @param continueOnError Whether to continue with the next sql statement when an error occurred
+ */
+ public void alterModel(Connection connection, Database currentModel, Database desiredModel, CreationParameters params, boolean continueOnError) throws DatabaseOperationException;
+
+ /**
+ * Returns the SQL for altering the given current model so that it match the desired model.
+ *
+ * @param currentModel The current database model
+ * @param desiredModel The desired database model
+ * @return The SQL statements
+ */
+ public String getAlterModelSql(Database currentModel, Database desiredModel) throws DatabaseOperationException;
+
+ /**
+ * Returns the SQL for altering the given current model so that it match the desired model.
+ *
+ * @param currentModel The current database model
+ * @param desiredModel The desired database model
+ * @param params The parameters used in the creation of tables etc.
+ * @return The SQL statements
+ */
+ public String getAlterModelSql(Database currentModel, Database desiredModel, CreationParameters params) throws DatabaseOperationException;
+
+ /**
* Drops the specified table and all foreign keys pointing to it.
*
* @param model The database model
@@ -569,30 +737,58 @@
public void dropTable(Connection connection, Database model, Table table, boolean continueOnError) throws DatabaseOperationException;
/**
- * Drops the tables defined in the given database.
+ * Returns the SQL for dropping the given model.
*
* @param model The database model
* @param continueOnError Whether to continue executing the sql commands when an error occurred
+ * @return The SQL statements
+ * @deprecated Use {@link #getDropModelSql(Database)} instead.
+ */
+ public String getDropTablesSql(Database model, boolean continueOnError);
+
+ /**
+ * Drops the given model using the default database connection.
+ *
+ * @param model The database model
+ * @param continueOnError Whether to continue executing the sql commands when an error occurred
+ * @deprecated Use {@link #dropModel(Database, boolean)} instead.
*/
public void dropTables(Database model, boolean continueOnError) throws DatabaseOperationException;
/**
- * Returns the SQL for dropping the tables defined in the given database.
+ * Drops the given model.
*
+ * @param connection The connection to the database
* @param model The database model
* @param continueOnError Whether to continue executing the sql commands when an error occurred
+ * @deprecated Use {@link #dropModel(Connection, Database, boolean)} instead.
+ */
+ public void dropTables(Connection connection, Database model, boolean continueOnError) throws DatabaseOperationException;
+
+ /**
+ * Returns the SQL for dropping the given model.
+ *
+ * @param model The database model
* @return The SQL statements
*/
- public String getDropTablesSql(Database model, boolean continueOnError);
+ public String getDropModelSql(Database model);
+
+ /**
+ * Drops the given model using the default database connection.
+ *
+ * @param model The database model
+ * @param continueOnError Whether to continue executing the sql commands when an error occurred
+ */
+ public void dropModel(Database model, boolean continueOnError) throws DatabaseOperationException;
/**
- * Drops the tables defined in the given database.
+ * Drops the given model.
*
* @param connection The connection to the database
* @param model The database model
* @param continueOnError Whether to continue executing the sql commands when an error occurred
*/
- public void dropTables(Connection connection, Database model, boolean continueOnError) throws DatabaseOperationException;
+ public void dropModel(Connection connection, Database model, boolean continueOnError) throws DatabaseOperationException;
/**
* Performs the given SQL query returning an iterator over the results.
@@ -833,7 +1029,7 @@
* @param newDynaBean The bean containing the new values
* @return The update sql
*/
- public String getUpdateSql(Database model, DynaBean oldDynaBean, DynaBean newDynaBan);
+ public String getUpdateSql(Database model, DynaBean oldDynaBean, DynaBean newDynaBean);
/**
* Updates the given bean in the database, assuming the primary key values are specified. Note that this means
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java Mon Dec 10 00:20:47 2007
@@ -69,7 +69,13 @@
private boolean _defaultValueUsedForIdentitySpec = false;
// properties influencing the reading of models from live databases
-
+
+ /** Whether primary key columns are automatically required. */
+ private boolean _primaryKeyColumnAutomaticallyRequired = false;
+
+ /** Whether identity columns are automatically required. */
+ private boolean _identityColumnAutomaticallyRequired = false;
+
/** Whether system indices (database-generated indices for primary and foreign keys) are returned when
reading a model from a database. */
private boolean _systemIndicesReturned = true;
@@ -373,6 +379,48 @@
}
// properties influencing the reading of models from live databases
+
+ /**
+ * Determines whether the database will make a primary key column automatically required.
+ *
+ * @return <code>true</code> if primary key columns are automatically required
+ */
+ public boolean isPrimaryKeyColumnAutomaticallyRequired()
+ {
+ return _primaryKeyColumnAutomaticallyRequired;
+ }
+
+ /**
+ * Specifies whether the database will make a primary key column automatically required.
+ *
+ * @param primaryKeyAutomaticallyRequired <code>true</code> if primary key columns are
+ * automatically required
+ */
+ public void setPrimaryKeyColumnAutomaticallyRequired(boolean primaryKeyAutomaticallyRequired)
+ {
+ _primaryKeyColumnAutomaticallyRequired = primaryKeyAutomaticallyRequired;
+ }
+
+ /**
+ * Determines whether the database will make an idenity column automatically required.
+ *
+ * @return <code>true</code> if identity columns are automatically required
+ */
+ public boolean isIdentityColumnAutomaticallyRequired()
+ {
+ return _identityColumnAutomaticallyRequired;
+ }
+
+ /**
+ * Specifies whether the database will make a primary key column automatically required.
+ *
+ * @param identityAutomaticallyRequired <code>true</code> if identity columns are
+ * automatically required
+ */
+ public void setIdentityColumnAutomaticallyRequired(boolean identityAutomaticallyRequired)
+ {
+ _identityColumnAutomaticallyRequired = identityAutomaticallyRequired;
+ }
/**
* Determines whether database-generated indices for primary and foreign keys are
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddColumnChange.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddColumnChange.java?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddColumnChange.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddColumnChange.java Mon Dec 10 00:20:47 2007
@@ -19,7 +19,7 @@
* under the License.
*/
-import org.apache.ddlutils.DdlUtilsException;
+import org.apache.ddlutils.model.CloneHelper;
import org.apache.ddlutils.model.Column;
import org.apache.ddlutils.model.Database;
import org.apache.ddlutils.model.Table;
@@ -33,27 +33,25 @@
{
/** The new column. */
private Column _newColumn;
- /** The column after which the new column should be added. */
- private Column _previousColumn;
- /** The column before which the new column should be added. */
- private Column _nextColumn;
- /** Whether the column is added at the end. */
- private boolean _atEnd;
+ /** The name of the column after which the new column should be added. */
+ private String _previousColumnName;
+ /** The name of the column before which the new column should be added. */
+ private String _nextColumnName;
/**
* Creates a new change object.
*
- * @param table The table to add the column to
- * @param newColumn The new column
- * @param previousColumn The column after which the new column should be added
- * @param nextColumn The column before which the new column should be added
- */
- public AddColumnChange(Table table, Column newColumn, Column previousColumn, Column nextColumn)
- {
- super(table);
- _newColumn = newColumn;
- _previousColumn = previousColumn;
- _nextColumn = nextColumn;
+ * @param tableName The name of the table to add the column to
+ * @param newColumn The new column
+ * @param previousColumnName The name of the column after which the new column should be added
+ * @param nextColumnName The name of the column before which the new column should be added
+ */
+ public AddColumnChange(String tableName, Column newColumn, String previousColumnName, String nextColumnName)
+ {
+ super(tableName);
+ _newColumn = newColumn;
+ _previousColumnName = previousColumnName;
+ _nextColumnName = nextColumnName;
}
/**
@@ -67,23 +65,23 @@
}
/**
- * Returns the column after which the new column should be added.
+ * Returns the name of the column after which the new column should be added.
*
- * @return The previous column
+ * @return The name of the previous column
*/
- public Column getPreviousColumn()
+ public String getPreviousColumn()
{
- return _previousColumn;
+ return _previousColumnName;
}
/**
- * Returns the column before which the new column should be added.
+ * Returns the name of the column before which the new column should be added.
*
- * @return The next column
+ * @return The name of the next column
*/
- public Column getNextColumn()
+ public String getNextColumn()
{
- return _nextColumn;
+ return _nextColumnName;
}
/**
@@ -94,18 +92,7 @@
*/
public boolean isAtEnd()
{
- return _atEnd;
- }
-
- /**
- * Specifies whether the column is added at the end (when applied in the order
- * of creation of the changes).
- *
- * @param atEnd <code>true</code> if the column is added at the end
- */
- public void setAtEnd(boolean atEnd)
- {
- _atEnd = atEnd;
+ return _nextColumnName == null;
}
/**
@@ -113,26 +100,19 @@
*/
public void apply(Database model, boolean caseSensitive)
{
- Column newColumn = null;
+ Table table = findChangedTable(model, caseSensitive);
+ Column newColumn = new CloneHelper().clone(_newColumn, true);
- try
+ if (_previousColumnName != null)
{
- // TODO: Cloning should not be necessary
- newColumn = (Column)_newColumn.clone();
- }
- catch (CloneNotSupportedException ex)
- {
- throw new DdlUtilsException(ex);
- }
-
- Table table = findChangedTable(model, caseSensitive);
-
- // TODO: change this !
- if ((_previousColumn != null) && (_nextColumn != null))
- {
- int idx = table.getColumnIndex(_previousColumn) + 1;
+ Column prevColumn = table.findColumn(_previousColumnName, caseSensitive);
+ int idx = table.getColumnIndex(prevColumn) + 1;
table.addColumn(idx, newColumn);
+ }
+ else if (_nextColumnName != null)
+ {
+ table.addColumn(0, newColumn);
}
else
{
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddForeignKeyChange.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddForeignKeyChange.java?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddForeignKeyChange.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddForeignKeyChange.java Mon Dec 10 00:20:47 2007
@@ -19,10 +19,8 @@
* under the License.
*/
-import org.apache.ddlutils.DdlUtilsException;
import org.apache.ddlutils.model.Database;
import org.apache.ddlutils.model.ForeignKey;
-import org.apache.ddlutils.model.Table;
/**
* Represents the addition of a foreign key to a table. Note that for
@@ -39,12 +37,12 @@
/**
* Creates a new change object.
*
- * @param table The table to add the foreign key to
+ * @param tableName The name of the table to add the foreign key to
* @param newForeignKey The new foreign key
*/
- public AddForeignKeyChange(Table table, ForeignKey newForeignKey)
+ public AddForeignKeyChange(String tableName, ForeignKey newForeignKey)
{
- super(table);
+ super(tableName);
_newForeignKey = newForeignKey;
}
@@ -63,19 +61,6 @@
*/
public void apply(Database database, boolean caseSensitive)
{
- ForeignKey newFK = null;
-
- try
- {
- // TODO: we should not have to clone here
- newFK = (ForeignKey)_newForeignKey.clone();
- newFK.setForeignTable(database.findTable(_newForeignKey.getForeignTableName(), caseSensitive));
- }
- catch (CloneNotSupportedException ex)
- {
- throw new DdlUtilsException(ex);
- }
- findChangedTable(database, caseSensitive).addForeignKey(newFK);
+ findChangedTable(database, caseSensitive).addForeignKey(_newForeignKey);
}
-
}
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddIndexChange.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddIndexChange.java?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddIndexChange.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddIndexChange.java Mon Dec 10 00:20:47 2007
@@ -22,7 +22,6 @@
import org.apache.ddlutils.DdlUtilsException;
import org.apache.ddlutils.model.Database;
import org.apache.ddlutils.model.Index;
-import org.apache.ddlutils.model.Table;
/**
* Represents the addition of an index to a table.
@@ -37,12 +36,12 @@
/**
* Creates a new change object.
*
- * @param table The table to add the index to
- * @param newIndex The new index
+ * @param tableName The name of the table to add the index to
+ * @param newIndex The new index
*/
- public AddIndexChange(Table table, Index newIndex)
+ public AddIndexChange(String tableName, Index newIndex)
{
- super(table);
+ super(tableName);
_newIndex = newIndex;
}
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddPrimaryKeyChange.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddPrimaryKeyChange.java?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddPrimaryKeyChange.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddPrimaryKeyChange.java Mon Dec 10 00:20:47 2007
@@ -30,27 +30,27 @@
*/
public class AddPrimaryKeyChange extends TableChangeImplBase
{
- /** The columns making up the primary key. */
- private Column[] _primaryKeyColumns;
+ /** The names of the columns making up the primary key. */
+ private String[] _primaryKeyColumns;
/**
* Creates a new change object.
*
- * @param table The table to add the primary key to
- * @param primaryKeyColumns The columns making up the primary key
+ * @param tableName The name of the table to add the primary key to
+ * @param primaryKeyColumns The names of the columns making up the primary key
*/
- public AddPrimaryKeyChange(Table table, Column[] primaryKeyColumns)
+ public AddPrimaryKeyChange(String tableName, String[] primaryKeyColumns)
{
- super(table);
+ super(tableName);
_primaryKeyColumns = primaryKeyColumns;
}
/**
- * Returns the primary key columns making up the new primary key.
+ * Returns the primary key column names making up the new primary key.
*
- * @return The primary key columns
+ * @return The primary key column names
*/
- public Column[] getPrimaryKeyColumns()
+ public String[] getPrimaryKeyColumns()
{
return _primaryKeyColumns;
}
@@ -64,7 +64,7 @@
for (int idx = 0; idx < _primaryKeyColumns.length; idx++)
{
- Column column = table.findColumn(_primaryKeyColumns[idx].getName(), caseSensitive);
+ Column column = table.findColumn(_primaryKeyColumns[idx], caseSensitive);
column.setPrimaryKey(true);
}
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddTableChange.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddTableChange.java?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddTableChange.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/AddTableChange.java Mon Dec 10 00:20:47 2007
@@ -19,7 +19,7 @@
* under the License.
*/
-import org.apache.ddlutils.DdlUtilsException;
+import org.apache.ddlutils.model.CloneHelper;
import org.apache.ddlutils.model.Database;
import org.apache.ddlutils.model.Table;
@@ -37,7 +37,8 @@
/**
* Creates a new change object.
*
- * @param newTable The new table
+ * @param newTable The new table; note that the change object will keep a reference to this table
+ * which means that the table should not be changed after creating this change object
*/
public AddTableChange(Table newTable)
{
@@ -61,15 +62,8 @@
*/
public void apply(Database database, boolean caseSensitive)
{
- try
- {
- // TODO: we shouldn't have to clone here
- database.addTable((Table)_newTable.clone());
- }
- catch (CloneNotSupportedException ex)
- {
- throw new DdlUtilsException(ex);
- }
- }
+ Table table = new CloneHelper().clone(_newTable, true, false, database, caseSensitive);
+ database.addTable(table);
+ }
}
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnChange.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnChange.java?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnChange.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnChange.java Mon Dec 10 00:20:47 2007
@@ -30,11 +30,11 @@
public interface ColumnChange extends TableChange
{
/**
- * Returns the affected column from the original model.
+ * Returns the name of the affected column from the original model.
*
- * @return The affected column
+ * @return The name of the affected column
*/
- public Column getChangedColumn();
+ public String getChangedColumn();
/**
* Finds the column object corresponding to the changed column in the given database model.
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnChangeImplBase.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnChangeImplBase.java?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnChangeImplBase.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnChangeImplBase.java Mon Dec 10 00:20:47 2007
@@ -1,33 +1,57 @@
package org.apache.ddlutils.alteration;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
import org.apache.ddlutils.model.Column;
import org.apache.ddlutils.model.Database;
import org.apache.ddlutils.model.Table;
+/**
+ * Base class for changes to columns.
+ *
+ * @version $Revision: $
+ */
public abstract class ColumnChangeImplBase extends TableChangeImplBase
implements ColumnChange
{
- /** The column. */
- private Column _column;
+ /** The column's name. */
+ private String _columnName;
/**
* Creates a new change object.
*
- * @param table The table to remove the column from
- * @param column The column
+ * @param tableName The name of the table to remove the column from
+ * @param columnName The column's name
*/
- public ColumnChangeImplBase(Table table, Column column)
+ public ColumnChangeImplBase(String tableName, String columnName)
{
- super(table);
- _column = column;
+ super(tableName);
+ _columnName = columnName;
}
/**
* {@inheritDoc}
*/
- public Column getChangedColumn()
+ public String getChangedColumn()
{
- return _column;
+ return _columnName;
}
/**
@@ -37,6 +61,6 @@
{
Table table = findChangedTable(model, caseSensitive);
- return table == null ? null : table.findColumn(_column.getName(), caseSensitive);
+ return table == null ? null : table.findColumn(_columnName, caseSensitive);
}
}
Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDefinitionChange.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDefinitionChange.java?rev=602807&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDefinitionChange.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDefinitionChange.java Mon Dec 10 00:20:47 2007
@@ -0,0 +1,182 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.ddlutils.PlatformInfo;
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Database;
+import org.apache.ddlutils.util.StringUtils;
+
+/**
+ * Represents the change of one or more aspects of the definition of a column, such as
+ * data type or size, whether it is required or not, etc. Note that primary key status
+ * is not part of the definition.
+ *
+ * @version $Revision: $
+ */
+public class ColumnDefinitionChange extends ColumnChangeImplBase
+{
+ /** The target column definition. */
+ private Column _newColumnDef;
+
+ /**
+ * Creates a new change object.
+ *
+ * @param tableName The name of the table owning the changed column
+ * @param columnName The name of the changed column
+ * @param newColumnDef The new column definition
+ */
+ public ColumnDefinitionChange(String tableName, String columnName, Column newColumnDef)
+ {
+ super(tableName, columnName);
+ _newColumnDef = newColumnDef;
+ }
+
+ /**
+ * Returns the new column definition.
+ *
+ * @return The new column
+ */
+ public Column getNewColumn()
+ {
+ return _newColumnDef;
+ }
+
+ /**
+ * Determines whether the definition of the given target column is different from the one of the given source column.
+ *
+ * @param platformInfo The info object for the current platform
+ * @param sourceColumn The source column
+ * @param targetColumn The target column
+ * @return <code>true</code> if the definitions differ
+ */
+ public static boolean isChanged(PlatformInfo platformInfo, Column sourceColumn, Column targetColumn)
+ {
+ return isTypeChanged(platformInfo, sourceColumn, targetColumn) ||
+ isSizeChanged(platformInfo, sourceColumn, targetColumn) ||
+ isDefaultValueChanged(sourceColumn, targetColumn) ||
+ isRequiredStatusChanged(sourceColumn, targetColumn) ||
+ isAutoIncrementChanged(sourceColumn, targetColumn);
+ }
+
+ /**
+ * Determines whether the jdbc type of the given target column is different from the one of the given source column.
+ * This method uses the platform info object to determine the actual jdbc type that the target column would have
+ * in the database, and compares that to the type of he source column.
+ *
+ * @param platformInfo The info object for the current platform
+ * @param sourceColumn The source column
+ * @param targetColumn The target column
+ * @return <code>true</code> if the jdbc types differ
+ */
+ public static boolean isTypeChanged(PlatformInfo platformInfo, Column sourceColumn, Column targetColumn)
+ {
+ int targetTypeCode = platformInfo.getTargetJdbcType(targetColumn.getTypeCode());
+
+ return targetTypeCode != sourceColumn.getTypeCode();
+ }
+
+ /**
+ * Determines whether the size or precision/scale of the given target column is different from that of the given source column.
+ * If size and precision/scale do not matter for the target column's type, then <code>false</code> is returned.
+ *
+ * @param platformInfo The info object for the current platform
+ * @param sourceColumn The source column
+ * @param targetColumn The target column
+ * @return <code>true</code> if the sizes or precisions/scales differ
+ */
+ public static boolean isSizeChanged(PlatformInfo platformInfo, Column sourceColumn, Column targetColumn)
+ {
+ int targetTypeCode = platformInfo.getTargetJdbcType(targetColumn.getTypeCode());
+ boolean sizeMatters = platformInfo.hasSize(targetTypeCode);
+ boolean scaleMatters = platformInfo.hasPrecisionAndScale(targetTypeCode);
+
+ if (sizeMatters && !StringUtils.equals(sourceColumn.getSize(), targetColumn.getSize()))
+ {
+ return true;
+ }
+ else if (scaleMatters &&
+ (sourceColumn.getPrecisionRadix() != targetColumn.getPrecisionRadix()) ||
+ (sourceColumn.getScale() != targetColumn.getScale()))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Determines whether the default value of the given target column is different from the one of the given source column.
+ * This method compares the parsed default values instead of their representations in the columns.
+ *
+ * @param sourceColumn The source column
+ * @param targetColumn The target column
+ * @return <code>true</code> if the default values differ
+ */
+ public static boolean isDefaultValueChanged(Column sourceColumn, Column targetColumn)
+ {
+ Object sourceDefaultValue = sourceColumn.getParsedDefaultValue();
+ Object targetDefaultValue = targetColumn.getParsedDefaultValue();
+
+ return ((sourceDefaultValue == null) && (targetDefaultValue != null)) ||
+ ((sourceDefaultValue != null) && !sourceDefaultValue.equals(targetDefaultValue));
+ }
+
+ /**
+ * Determines whether the required status of the given target column is different from that of the given source column.
+ *
+ * @param sourceColumn The source column
+ * @param targetColumn The target column
+ * @return <code>true</code> if the required status is different in the target column
+ */
+ public static boolean isRequiredStatusChanged(Column sourceColumn, Column targetColumn)
+ {
+ return sourceColumn.isRequired() != targetColumn.isRequired();
+ }
+
+ /**
+ * Determines whether the auto increment status of the given target column is different from that of the given source column.
+ *
+ * @param sourceColumn The source column
+ * @param targetColumn The target column
+ * @return <code>true</code> if the auto increment status is different in the target column
+ */
+ public static boolean isAutoIncrementChanged(Column sourceColumn, Column targetColumn)
+ {
+ return sourceColumn.isAutoIncrement() != targetColumn.isAutoIncrement();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void apply(Database model, boolean caseSensitive)
+ {
+ Column column = findChangedColumn(model, caseSensitive);
+
+ column.setTypeCode(_newColumnDef.getTypeCode());
+ column.setSize(_newColumnDef.getSize());
+ column.setAutoIncrement(_newColumnDef.isAutoIncrement());
+ column.setRequired(_newColumnDef.isRequired());
+ column.setDescription(_newColumnDef.getDescription());
+ column.setDefaultValue(_newColumnDef.getDefaultValue());
+ }
+}
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnOrderChange.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnOrderChange.java?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnOrderChange.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnOrderChange.java Mon Dec 10 00:20:47 2007
@@ -20,6 +20,7 @@
*/
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.Map;
import org.apache.ddlutils.model.Column;
@@ -39,24 +40,43 @@
/**
* Creates a new change object.
*
- * @param table The table whose primary key is to be changed
- * @param newPositions The map containing the new positions keyed by the source columns
+ * @param tableName The name of the table whose primary key is to be changed
+ * @param newPositions The map containing the new positions keyed by the source column names
*/
- public ColumnOrderChange(Table table, Map newPositions)
+ public ColumnOrderChange(String tableName, Map newPositions)
{
- super(table);
+ super(tableName);
_newPositions = newPositions;
}
/**
* Returns the new position of the given source column.
*
- * @param sourceColumn The column
+ * @param sourceColumnName The column's name
+ * @param caseSensitive Whether case of the column name matters
* @return The new position or -1 if no position is marked for the column
*/
- public int getNewPosition(Column sourceColumn)
+ public int getNewPosition(String sourceColumnName, boolean caseSensitive)
{
- Integer newPos = (Integer)_newPositions.get(sourceColumn);
+ Integer newPos = null;
+
+ if (caseSensitive)
+ {
+ newPos = (Integer)_newPositions.get(sourceColumnName);
+ }
+ else
+ {
+ for (Iterator it = _newPositions.entrySet().iterator(); it.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)it.next();
+
+ if (sourceColumnName.equalsIgnoreCase((String)entry.getKey()))
+ {
+ newPos = (Integer)entry.getValue();
+ break;
+ }
+ }
+ }
return newPos == null ? -1 : newPos.intValue();
}
@@ -66,20 +86,24 @@
*/
public void apply(Database database, boolean caseSensitive)
{
- Table table = database.findTable(getChangedTable().getName(), caseSensitive);
- ArrayList newColumns = new ArrayList(table.getColumnCount());
+ Table table = findChangedTable(database, caseSensitive);
+ ArrayList newColumns = new ArrayList();
for (int idx = 0; idx < table.getColumnCount(); idx++)
{
- Column column = table.getColumn(idx);
- int newPos = getNewPosition(column);
-
- newColumns.set(newPos < 0 ? idx : newPos, column);
- }
+ newColumns.add(table.getColumn(idx));
+ }
for (int idx = 0; idx < table.getColumnCount(); idx++)
{
- table.removeColumn(idx);
+ Column column = table.getColumn(idx);
+ int newPos = getNewPosition(column.getName(), caseSensitive);
+
+ if (newPos >= 0)
+ {
+ newColumns.set(newPos, column);
+ }
}
+ table.removeAllColumns();
table.addColumns(newColumns);
}
}
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ForeignKeyChange.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ForeignKeyChange.java?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ForeignKeyChange.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ForeignKeyChange.java Mon Dec 10 00:20:47 2007
@@ -30,13 +30,6 @@
public interface ForeignKeyChange extends TableChange
{
/**
- * Returns the affected foreign key from the original model.
- *
- * @return The affected foreign key
- */
- public ForeignKey getChangedForeignKey();
-
- /**
* Finds the foreign key object corresponding to the changed foreign key in the given database model.
*
* @param model The database model
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ForeignKeyChangeImplBase.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ForeignKeyChangeImplBase.java?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ForeignKeyChangeImplBase.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ForeignKeyChangeImplBase.java Mon Dec 10 00:20:47 2007
@@ -1,33 +1,59 @@
package org.apache.ddlutils.alteration;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.ddlutils.model.Database;
import org.apache.ddlutils.model.ForeignKey;
+import org.apache.ddlutils.model.Reference;
import org.apache.ddlutils.model.Table;
+/**
+ * The base class for changes affecting foreign keys.
+ *
+ * @version $Revision: $
+ */
public abstract class ForeignKeyChangeImplBase extends TableChangeImplBase
implements ForeignKeyChange
{
- /** The foreign key. */
- private ForeignKey _foreignKey;
+ /** List of pairs of local and corresponding foreign column names that make up the foreign key. */
+ private List _referenceColumnNames = new ArrayList();
/**
* Creates a new change object.
*
- * @param table The table
- * @param foreignKey The foreign key
+ * @param tableName The name of the table that owns the foreign key
+ * @param foreignKey The foreign key; note that this change object will not maintain a reference
+ * to the foreign key object
*/
- public ForeignKeyChangeImplBase(Table table, ForeignKey foreignKey)
+ public ForeignKeyChangeImplBase(String tableName, ForeignKey foreignKey)
{
- super(table);
- _foreignKey = foreignKey;
- }
+ super(tableName);
+ for (int refIdx = 0; refIdx < foreignKey.getReferenceCount(); refIdx++)
+ {
+ Reference ref = foreignKey.getReference(refIdx);
- /**
- * {@inheritDoc}
- */
- public ForeignKey getChangedForeignKey()
- {
- return _foreignKey;
+ _referenceColumnNames.add(new Pair(ref.getLocalColumnName(), ref.getForeignColumnName()));
+ }
}
/**
@@ -43,10 +69,30 @@
{
ForeignKey curFk = table.getForeignKey(fkIdx);
- if ((caseSensitive && _foreignKey.equals(curFk)) ||
- (!caseSensitive && _foreignKey.equalsIgnoreCase(curFk)))
+ if (curFk.getReferenceCount() == _referenceColumnNames.size())
{
- return curFk;
+ for (int refIdx = 0; refIdx < curFk.getReferenceCount(); refIdx++)
+ {
+ Reference ref = curFk.getReference(refIdx);
+ Pair colNames = (Pair)_referenceColumnNames.get(refIdx);
+
+ if (caseSensitive)
+ {
+ if (ref.getLocalColumnName().equals((String)colNames.getFirst()) &&
+ ref.getForeignColumnName().equals((String)colNames.getSecond()))
+ {
+ return curFk;
+ }
+ }
+ else
+ {
+ if (ref.getLocalColumnName().equalsIgnoreCase((String)colNames.getFirst()) &&
+ ref.getForeignColumnName().equalsIgnoreCase((String)colNames.getSecond()))
+ {
+ return curFk;
+ }
+ }
+ }
}
}
}
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/IndexChange.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/IndexChange.java?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/IndexChange.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/IndexChange.java Mon Dec 10 00:20:47 2007
@@ -30,13 +30,6 @@
public interface IndexChange extends TableChange
{
/**
- * Returns the affected index from the original model.
- *
- * @return The affected index
- */
- public Index getChangedIndex();
-
- /**
* Finds the index object corresponding to the changed index in the given database model.
*
* @param model The database model
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/IndexChangeImplBase.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/IndexChangeImplBase.java?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/IndexChangeImplBase.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/IndexChangeImplBase.java Mon Dec 10 00:20:47 2007
@@ -1,33 +1,56 @@
package org.apache.ddlutils.alteration;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.ddlutils.model.Database;
import org.apache.ddlutils.model.Index;
import org.apache.ddlutils.model.Table;
+/**
+ * The base class for changes affecting indexes.
+ *
+ * @version $Revision: $
+ */
public abstract class IndexChangeImplBase extends TableChangeImplBase
implements IndexChange
{
- /** The index. */
- private Index _index;
+ /** The names of the columns in the index. */
+ private List _columnNames = new ArrayList();
/**
* Creates a new change object.
*
- * @param table The table
- * @param index The index
- */
- public IndexChangeImplBase(Table table, Index index)
- {
- super(table);
- _index = index;
- }
-
- /**
- * {@inheritDoc}
+ * @param tableName The name of the changed table
+ * @param index The index; note that this change object will not maintain a reference
+ * to the index object
*/
- public Index getChangedIndex()
+ public IndexChangeImplBase(String tableName, Index index)
{
- return _index;
+ super(tableName);
+ for (int colIdx = 0; colIdx < index.getColumnCount(); colIdx++)
+ {
+ _columnNames.add(index.getColumn(colIdx).getName());
+ }
}
/**
@@ -35,21 +58,30 @@
*/
public Index findChangedIndex(Database model, boolean caseSensitive)
{
- Table table = findChangedTable(model, caseSensitive);
+ Table table = findChangedTable(model, caseSensitive);
- if (table != null)
- {
+ if (table != null)
+ {
for (int indexIdx = 0; indexIdx < table.getIndexCount(); indexIdx++)
{
Index curIndex = table.getIndex(indexIdx);
- if ((caseSensitive && _index.equals(curIndex)) ||
- (!caseSensitive && _index.equalsIgnoreCase(curIndex)))
+ if (curIndex.getColumnCount() == _columnNames.size())
{
- return curIndex;
+ for (int colIdx = 0; colIdx < curIndex.getColumnCount(); colIdx++)
+ {
+ String curColName = curIndex.getColumn(colIdx).getName();
+ String expectedColName = (String)_columnNames.get(colIdx);
+
+ if ((caseSensitive && curColName.equals(expectedColName)) ||
+ (!caseSensitive && curColName.equalsIgnoreCase(expectedColName)))
+ {
+ return curIndex;
+ }
+ }
}
}
- }
+ }
return null;
}
}