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)
    public void execute(Task task, Database model) throws BuildException    {        if (_outputFile == null)        {            throw new BuildException("No output file specified");        }        if (_outputFile.exists() && !_outputFile.canWrite())        {            throw new BuildException("Cannot overwrite output file "+_outputFile.getAbsolutePath());        }        Platform           platform        = getPlatform();        boolean            isCaseSensitive = platform.isDelimitedIdentifierModeOn();        CreationParameters params          = getFilteredParameters(model, platform.getName(), isCaseSensitive);        Connection         connection      = null;        try        {            FileWriter writer = new FileWriter(_outputFile);            if (platform.getPlatformInfo().isSqlCommentsSupported())            {                // we're generating SQL comments if possible                platform.setSqlCommentsOn(true);            }            platform.getSqlBuilder().setWriter(writer);            if (isAlterDatabase() && (getDataSource() != null))            {                Database currentModel = (getCatalogPattern() != null) || (getSchemaPattern() != null) ?                                             platform.readModelFromDatabase(null, getCatalogPattern(), getSchemaPattern(), null) :                                             platform.readModelFromDatabase(null);                platform.getSqlBuilder().alterDatabase(currentModel, model, params, _doDrops, true);            }            else            {                platform.getSqlBuilder().createTables(model, params, _doDrops);            }            writer.close();            task.log("Written SQL to "+_outputFile.getAbsolutePath(), Project.MSG_INFO);        }        catch (Exception ex)        {            if (isFailOnError())            {                throw new BuildException(ex);            }            else            {                task.log(ex.getMessage() == null ? ex.toString() : ex.getMessage(), Project.MSG_ERR);            }        }        finally        {            if (connection != null)            {                try                {                    connection.close();                }                catch (SQLException ex)                {}            }        }    }