Search in sources :

Example 6 with SqlScript

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);
    }
}
Also used : Table(org.jumpmind.db.model.Table) Database(org.jumpmind.db.model.Database) SqlScript(org.jumpmind.db.sql.SqlScript)

Example 7 with SqlScript

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());
}
Also used : SqlScript(org.jumpmind.db.sql.SqlScript)

Example 8 with SqlScript

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());
}
Also used : SqlScript(org.jumpmind.db.sql.SqlScript)

Aggregations

SqlScript (org.jumpmind.db.sql.SqlScript)8 Database (org.jumpmind.db.model.Database)4 IDdlBuilder (org.jumpmind.db.platform.IDdlBuilder)4 Table (org.jumpmind.db.model.Table)2 LogSqlResultsListener (org.jumpmind.db.sql.LogSqlResultsListener)2 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Column (org.jumpmind.db.model.Column)1 AbstractJdbcDatabasePlatform (org.jumpmind.db.platform.AbstractJdbcDatabasePlatform)1 IAlterDatabaseInterceptor (org.jumpmind.db.platform.IAlterDatabaseInterceptor)1 ISqlResultsListener (org.jumpmind.db.sql.ISqlResultsListener)1 SqlException (org.jumpmind.db.sql.SqlException)1 IoException (org.jumpmind.exception.IoException)1 ISymmetricDialect (org.jumpmind.symmetric.db.ISymmetricDialect)1 IDatabaseUpgradeListener (org.jumpmind.symmetric.ext.IDatabaseUpgradeListener)1 Test (org.junit.Test)1