Author: tomdz
Date: Mon Jul 17 23:00:24 2006
New Revision: 422981
URL: http://svn.apache.org/viewvc?rev=422981&view=rev
Log:
Fix for DDLUTILS-92
Modified:
db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaSqlToFileCommand.java
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=422981&r1=422980&r2=422981&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
Mon Jul 17 23:00:24 2006
@@ -110,7 +110,6 @@
Platform platform = getPlatform();
boolean isCaseSensitive =
platform.isDelimitedIdentifierModeOn();
CreationParameters params = getFilteredParameters(model,
platform.getName(), isCaseSensitive);
- Connection connection = null;
try
{
@@ -122,7 +121,37 @@
platform.setSqlCommentsOn(true);
}
platform.getSqlBuilder().setWriter(writer);
- if (isAlterDatabase() && (getDataSource() != null))
+
+ boolean shouldAlter = isAlterDatabase();
+
+ if (shouldAlter)
+ {
+ if (getDataSource() == null)
+ {
+ shouldAlter = false;
+ task.log("Cannot alter the database because no database
connection was specified." +
+ " SQL for database creation will be generated
instead.",
+ Project.MSG_WARN);
+ }
+ else
+ {
+ try
+ {
+ Connection connection =
getDataSource().getConnection();
+
+ connection.close();
+ }
+ catch (SQLException ex)
+ {
+ shouldAlter = false;
+ task.log("Could not establish a connection to the
specified database, " +
+ "so SQL for database creation will be
generated instead. The error was: " +
+ ex.getMessage(),
+ Project.MSG_WARN);
+ }
+ }
+ }
+ if (shouldAlter)
{
Database currentModel = (getCatalogPattern() != null) ||
(getSchemaPattern() != null) ?
platform.readModelFromDatabase(null, getCatalogPattern(), getSchemaPattern(),
null) :
@@ -146,18 +175,6 @@
else
{
task.log(ex.getMessage() == null ? ex.toString() :
ex.getMessage(), Project.MSG_ERR);
- }
- }
- finally
- {
- if (connection != null)
- {
- try
- {
- connection.close();
- }
- catch (SQLException ex)
- {}
}
}
}