use of org.jumpmind.db.sql.SqlScript in project symmetric-ds by JumpMind.
the class AbstractDatabasePlatform method alterTables.
public void alterTables(boolean continueOnError, Table... desiredTables) {
Database currentDatabase = new Database();
Database desiredDatabase = new Database();
StringBuilder tablesProcessed = new StringBuilder();
for (Table table : desiredTables) {
tablesProcessed.append(table.getFullyQualifiedTableName());
tablesProcessed.append(", ");
desiredDatabase.addTable(table);
Table currentTable = ddlReader.readTable(table.getCatalog(), table.getSchema(), table.getName());
if (currentTable != null) {
currentDatabase.addTable(currentTable);
}
}
if (tablesProcessed.length() > 1) {
tablesProcessed.replace(tablesProcessed.length() - 2, tablesProcessed.length(), "");
}
String alterSql = ddlBuilder.alterDatabase(currentDatabase, desiredDatabase);
if (StringUtils.isNotBlank(alterSql.trim())) {
log.info("Running alter sql:\n{}", alterSql);
String delimiter = getDdlBuilder().getDatabaseInfo().getSqlCommandDelimiter();
new SqlScript(alterSql, getSqlTemplate(), !continueOnError, false, false, delimiter, null).execute(getDatabaseInfo().isRequiresAutoCommitForDdl());
} else {
log.info("Tables up to date. No alters found for {}", tablesProcessed);
}
}
use of org.jumpmind.db.sql.SqlScript in project symmetric-ds by JumpMind.
the class AbstractDatabasePlatform method createDatabase.
public void createDatabase(Database targetDatabase, boolean dropTablesFirst, boolean continueOnError) {
if (dropTablesFirst) {
dropDatabase(targetDatabase, true);
}
String createSql = ddlBuilder.createTables(targetDatabase, false);
if (log.isDebugEnabled()) {
log.debug("Generated create sql: \n{}", createSql);
}
String delimiter = getDdlBuilder().getDatabaseInfo().getSqlCommandDelimiter();
new SqlScript(createSql, getSqlTemplate(), !continueOnError, false, false, delimiter, null).execute(getDatabaseInfo().isRequiresAutoCommitForDdl());
}
use of org.jumpmind.db.sql.SqlScript in project symmetric-ds by JumpMind.
the class AbstractDatabasePlatform method dropDatabase.
public void dropDatabase(Database database, boolean continueOnError) {
String sql = ddlBuilder.dropTables(database);
new SqlScript(sql, getSqlTemplate(), !continueOnError, null).execute(getDatabaseInfo().isRequiresAutoCommitForDdl());
}
Aggregations