validate();
Class.forName(driver);
QueryExecuter queryExecuter = new QueryExecuter(url, userid, password);
DatabaseSchemaVersionManager databaseSchemaVersionManager =
new DatabaseSchemaVersionManager(queryExecuter, changeLogTableName);
ChangeScriptRepository changeScriptRepository =
new ChangeScriptRepository(new DirectoryScanner(encoding).getChangeScriptsForDirectory(scriptdirectory));
ChangeScriptApplier doScriptApplier;
if (outputfile != null) {
doScriptApplier = new TemplateBasedApplier(
new PrintWriter(outputfile, encoding), dbms,
changeLogTableName, delimiter, delimiterType, getTemplatedir());
} else {
QueryStatementSplitter splitter = new QueryStatementSplitter();
splitter.setDelimiter(getDelimiter());
splitter.setDelimiterType(getDelimiterType());
splitter.setOutputLineEnding(lineEnding);
doScriptApplier = new DirectToDbApplier(queryExecuter, databaseSchemaVersionManager, splitter);
}
ChangeScriptApplier undoScriptApplier = null;
if (undoOutputfile != null) {
undoScriptApplier = new UndoTemplateBasedApplier(
new PrintWriter(undoOutputfile), dbms, changeLogTableName, delimiter, delimiterType, templatedir);
}
Controller controller = new Controller(changeScriptRepository, databaseSchemaVersionManager, doScriptApplier, undoScriptApplier);
controller.processChangeScripts(lastChangeToApply);
queryExecuter.close();
}