Search in sources :

Example 26 with SqlException

use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.

the class AbstractSymmetricDialect method truncateTable.

public void truncateTable(String tableName) {
    String quote = platform.getDdlBuilder().isDelimitedIdentifierModeOn() ? platform.getDatabaseInfo().getDelimiterToken() : "";
    boolean success = false;
    int tryCount = 5;
    while (!success && tryCount > 0) {
        try {
            Table table = platform.getTableFromCache(tableName, false);
            if (table != null) {
                platform.getSqlTemplate().update(String.format("truncate table %s%s%s", quote, table.getName(), quote));
                success = true;
            } else {
                throw new RuntimeException(String.format("Could not find %s to trunate", tableName));
            }
        } catch (SqlException ex) {
            log.warn("", ex);
            AppUtils.sleep(5000);
            tryCount--;
        }
    }
}
Also used : Table(org.jumpmind.db.model.Table) SqlException(org.jumpmind.db.sql.SqlException)

Example 27 with SqlException

use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.

the class DbFill method updateRandomRecord.

private void updateRandomRecord(Table table) {
    DmlStatement updStatement = createUpdateDmlStatement(table);
    Row row = createRandomUpdateValues(updStatement, table);
    try {
        platform.getSqlTemplate().update(updStatement.getSql(), row.toArray(table.getColumnNames()));
        if (verbose) {
            log.info("Successful update in " + table.getName());
        }
    } catch (SqlException ex) {
        log.info("Failed to process {} with values of {}", updStatement.getSql(), ArrayUtils.toString(row.toArray(table.getColumnNames())));
        if (continueOnError) {
            if (debug) {
                log.info("", ex);
            }
        } else {
            throw ex;
        }
    }
}
Also used : SqlException(org.jumpmind.db.sql.SqlException) DmlStatement(org.jumpmind.db.sql.DmlStatement) Row(org.jumpmind.db.sql.Row)

Example 28 with SqlException

use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.

the class MySqlSymmetricDialect method switchCatalogForTriggerInstall.

@Override
protected String switchCatalogForTriggerInstall(String catalog, ISqlTransaction transaction) {
    if (catalog != null) {
        Connection c = ((JdbcSqlTransaction) transaction).getConnection();
        String previousCatalog;
        try {
            previousCatalog = c.getCatalog();
            c.setCatalog(catalog);
            return previousCatalog;
        } catch (SQLException e) {
            throw new SqlException(e);
        }
    } else {
        return null;
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) SqlException(org.jumpmind.db.sql.SqlException) JdbcSqlTransaction(org.jumpmind.db.sql.JdbcSqlTransaction)

Example 29 with SqlException

use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.

the class MsSqlSymmetricDialect method switchCatalogForTriggerInstall.

@Override
protected String switchCatalogForTriggerInstall(String catalog, ISqlTransaction transaction) {
    if (catalog != null) {
        Connection c = ((JdbcSqlTransaction) transaction).getConnection();
        String previousCatalog = null;
        try {
            previousCatalog = c.getCatalog();
            c.setCatalog(catalog);
            return previousCatalog;
        } catch (SQLException e) {
            if (catalog != null) {
                try {
                    c.setCatalog(previousCatalog);
                } catch (SQLException ex) {
                }
            }
            throw new SqlException(e);
        }
    } else {
        return null;
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) SqlException(org.jumpmind.db.sql.SqlException) JdbcSqlTransaction(org.jumpmind.db.sql.JdbcSqlTransaction)

Example 30 with SqlException

use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.

the class AbstractDatabasePlatform method getAlterSymTablePermission.

protected PermissionResult getAlterSymTablePermission(Database database) {
    String delimiter = getDatabaseInfo().getDelimiterToken();
    delimiter = delimiter != null ? delimiter : "";
    Column idColumn = new Column("TEST_ID");
    idColumn.setMappedType("INTEGER");
    Column valueColumn = new Column("TEST_VALUE");
    valueColumn.setMappedType("INTEGER");
    Column alterColumn = new Column("TEST_ALTER");
    alterColumn.setMappedType("INTEGER");
    Table table = new Table(PERMISSION_TEST_TABLE_NAME, idColumn, valueColumn);
    Table alterTable = new Table(PERMISSION_TEST_TABLE_NAME, idColumn, valueColumn, alterColumn);
    PermissionResult result = new PermissionResult(PermissionType.ALTER_TABLE, Status.FAIL);
    try {
        database.removeAllTablesExcept();
        database.addTable(alterTable);
        alterDatabase(database, false);
        database.removeAllTablesExcept();
        database.addTable(table);
        alterDatabase(database, false);
        result.setStatus(Status.PASS);
    } catch (SqlException e) {
        result.setException(e);
        result.setSolution("Grant ALTER permission");
    }
    return result;
}
Also used : Table(org.jumpmind.db.model.Table) Column(org.jumpmind.db.model.Column) IndexColumn(org.jumpmind.db.model.IndexColumn) SqlException(org.jumpmind.db.sql.SqlException)

Aggregations

SqlException (org.jumpmind.db.sql.SqlException)50 PermissionResult (org.jumpmind.db.platform.PermissionResult)18 SQLException (java.sql.SQLException)11 Connection (java.sql.Connection)10 Table (org.jumpmind.db.model.Table)8 DmlStatement (org.jumpmind.db.sql.DmlStatement)6 Row (org.jumpmind.db.sql.Row)6 Column (org.jumpmind.db.model.Column)5 DatabaseMetaData (java.sql.DatabaseMetaData)4 JdbcSqlTransaction (org.jumpmind.db.sql.JdbcSqlTransaction)4 DetectConflict (org.jumpmind.symmetric.io.data.writer.Conflict.DetectConflict)3 ArrayList (java.util.ArrayList)2 IndexColumn (org.jumpmind.db.model.IndexColumn)2 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)2 DbImport (org.jumpmind.symmetric.io.data.DbImport)2 AbstractServiceTest (org.jumpmind.symmetric.service.impl.AbstractServiceTest)2 Test (org.junit.Test)2 ResultSet (java.sql.ResultSet)1 DataSource (javax.sql.DataSource)1 Database (org.jumpmind.db.model.Database)1