Author: tomdz Date: Wed Aug 24 12:24:26 2005 New Revision: 239736 URL: http://svn.apache.org/viewcvs?rev=239736&view=rev Log: Added ability to specify whether to drop tables first, to the writeSchemaToDatabase and writeSchemaSqlToFile subtasks as proposed by Christoffer Hammarström (DDLUTILS-5)
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java?rev=239736&r1=239735&r2=239736&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 Wed Aug 24 12:24:26 2005 @@ -37,6 +37,8 @@ private File _outputFile; /** Whether to alter or re-set the database if it already exists */ private boolean _alterDb = true; + /** Whether to drop tables and the associated constraints first */ + private boolean _dropTablesFirst = true; /** * Sets the file to output the sql to. @@ -68,6 +70,26 @@ _alterDb = alterTheDb; } + /** + * Determines whether to drop tables and the associated constraints first. + * + * @return <code>true</code> if a drop shall be performed first + */ + protected boolean isDropTablesFirst() + { + return _dropTablesFirst; + } + + /** + * Specifies whether to drop tables and the associated constraints first. + * + * @param doDrops <code>true</code> if a drop shall be performed first + */ + public void setDropTablesFirst(boolean doDrops) + { + _dropTablesFirst = doDrops; + } + /* (non-Javadoc) * @see org.apache.ddlutils.task.Command#execute(org.apache.tools.ant.Task, org.apache.ddlutils.model.Database) */ @@ -100,11 +122,11 @@ Database currentModel = new JdbcModelReader(connection).getDatabase(); - platform.getSqlBuilder().alterDatabase(currentModel, model, true, true); + platform.getSqlBuilder().alterDatabase(currentModel, model, _dropTablesFirst, true); } else { - platform.getSqlBuilder().createTables(model); + platform.getSqlBuilder().createTables(model, _dropTablesFirst); } writer.close(); task.log("Written SQL to "+_outputFile.getAbsolutePath(), Project.MSG_INFO); Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java?rev=239736&r1=239735&r2=239736&view=diff ============================================================================== --- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java (original) +++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToDatabaseCommand.java Wed Aug 24 12:24:26 2005 @@ -29,6 +29,8 @@ { /** Whether to alter or re-set the database if it already exists */ private boolean _alterDb = true; + /** Whether to drop tables and the associated constraints first */ + private boolean _dropTablesFirst = true; /** * Determines whether to alter the database if it already exists, or re-set it. @@ -50,6 +52,26 @@ _alterDb = alterTheDb; } + /** + * Determines whether to drop tables and the associated constraints first. + * + * @return <code>true</code> if a drop shall be performed first + */ + protected boolean isDropTablesFirst() + { + return _dropTablesFirst; + } + + /** + * Specifies whether to drop tables and the associated constraints first. + * + * @param doDrops <code>true</code> if a drop shall be performed first + */ + public void setDropTablesFirst(boolean doDrops) + { + _dropTablesFirst = doDrops; + } + /* (non-Javadoc) * @see org.apache.ddlutils.task.Command#execute(org.apache.tools.ant.Task, org.apache.ddlutils.model.Database) */ @@ -66,11 +88,11 @@ { if (isAlterDatabase()) { - platform.alterTables(model, true, true, true); + platform.alterTables(model, _dropTablesFirst, true, true); } else { - platform.createTables(model, true, true); + platform.createTables(model, _dropTablesFirst, true); } task.log("Written schema to database", Project.MSG_INFO);