Search in sources :

Example 16 with SqlException

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

the class AbstractDatabasePlatform method getDropSymTablePermission.

protected PermissionResult getDropSymTablePermission() {
    Table table = getPermissionTableDefinition();
    PermissionResult result = new PermissionResult(PermissionType.DROP_TABLE, Status.FAIL);
    try {
        if (getTableFromCache(table.getName(), true) != null) {
            dropTables(false, table);
            result.setStatus(Status.PASS);
        } else {
            result.setStatus(Status.NOT_APPLICABLE);
        }
    } catch (SqlException e) {
        result.setException(e);
        result.setSolution("Grant DROP permission");
    }
    return result;
}
Also used : Table(org.jumpmind.db.model.Table) SqlException(org.jumpmind.db.sql.SqlException)

Example 17 with SqlException

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

the class HsqlDbDatabasePlatform method getCreateSymTriggerPermission.

@Override
public PermissionResult getCreateSymTriggerPermission() {
    String delimiter = getDatabaseInfo().getDelimiterToken();
    delimiter = delimiter != null ? delimiter : "";
    String triggerSql = "CREATE TRIGGER TEST_TRIGGER AFTER UPDATE ON " + delimiter + PERMISSION_TEST_TABLE_NAME + delimiter + " FOR EACH ROW INSERT INTO " + delimiter + PERMISSION_TEST_TABLE_NAME + delimiter + " VALUES(NULL,NULL)";
    PermissionResult result = new PermissionResult(PermissionType.CREATE_TRIGGER, Status.FAIL);
    try {
        getSqlTemplate().update(triggerSql);
        result.setStatus(Status.PASS);
    } catch (SqlException e) {
        result.setException(e);
        result.setSolution("Grant CREATE TRIGGER permission or TRIGGER permission");
    }
    return result;
}
Also used : PermissionResult(org.jumpmind.db.platform.PermissionResult) SqlException(org.jumpmind.db.sql.SqlException)

Example 18 with SqlException

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

the class InformixDatabasePlatform method getCreateSymTriggerPermission.

@Override
public PermissionResult getCreateSymTriggerPermission() {
    String delimiter = getDatabaseInfo().getDelimiterToken();
    delimiter = delimiter != null ? delimiter : "";
    String triggerSql = "CREATE TRIGGER TEST_TRIGGER DELETE ON " + delimiter + PERMISSION_TEST_TABLE_NAME + delimiter + " FOR EACH ROW(DELETE FROM " + delimiter + PERMISSION_TEST_TABLE_NAME + delimiter + " WHERE TEST_ID IS NULL)";
    PermissionResult result = new PermissionResult(PermissionType.CREATE_TRIGGER, Status.FAIL);
    try {
        getSqlTemplate().update(triggerSql);
        result.setStatus(Status.PASS);
    } catch (SqlException e) {
        result.setException(e);
        result.setSolution("Grant CREATE TRIGGER permission or TRIGGER permission");
    }
    return result;
}
Also used : PermissionResult(org.jumpmind.db.platform.PermissionResult) SqlException(org.jumpmind.db.sql.SqlException)

Example 19 with SqlException

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

the class AbstractJdbcDdlReader method readTable.

public Table readTable(final String catalog, final String schema, final String table) {
    try {
        log.debug("reading table: " + table);
        JdbcSqlTemplate sqlTemplate = (JdbcSqlTemplate) platform.getSqlTemplate();
        return postprocessTableFromDatabase(sqlTemplate.execute(new IConnectionCallback<Table>() {

            public Table execute(Connection connection) throws SQLException {
                DatabaseMetaDataWrapper metaData = new DatabaseMetaDataWrapper();
                metaData.setMetaData(connection.getMetaData());
                metaData.setCatalog(catalog);
                metaData.setSchemaPattern(schema);
                metaData.setTableTypes(null);
                ResultSet tableData = null;
                try {
                    log.debug("getting table metadata for " + table);
                    tableData = metaData.getTables(getTableNamePattern(table));
                    log.debug("done getting table metadata for " + table);
                    if (tableData != null && tableData.next()) {
                        Map<String, Object> values = readMetaData(tableData, initColumnsForTable());
                        return readTable(connection, metaData, values);
                    } else {
                        return null;
                    }
                } finally {
                    close(tableData);
                }
            }
        }));
    } catch (SqlException e) {
        if (e.getMessage() != null && StringUtils.containsIgnoreCase(e.getMessage(), "does not exist")) {
            return null;
        } else {
            throw e;
        }
    }
}
Also used : JdbcSqlTemplate(org.jumpmind.db.sql.JdbcSqlTemplate) IConnectionCallback(org.jumpmind.db.sql.IConnectionCallback) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) SqlException(org.jumpmind.db.sql.SqlException)

Example 20 with SqlException

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

the class AbstractJdbcDdlReader method initWildcardString.

protected void initWildcardString(IDatabasePlatform platform) {
    DataSource ds = platform.getDataSource();
    Connection c = null;
    try {
        c = ds.getConnection();
        wildcardEscapeString = c.getMetaData().getSearchStringEscape();
    } catch (SQLException ex) {
        throw new SqlException(ex);
    } finally {
        JdbcSqlTemplate.close(c);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) SqlException(org.jumpmind.db.sql.SqlException) DataSource(javax.sql.DataSource)

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