Java Code Examples for org.apache.commons.dbutils.DbUtils#commitAndCloseQuietly()

The following examples show how to use org.apache.commons.dbutils.DbUtils#commitAndCloseQuietly() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpliceGrantWatcher.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void starting(Description description) {
	LOG.trace("Starting");
	Connection connection = null;
	Statement statement = null;
	ResultSet rs = null;
	try {
		connection = userName == null?SpliceNetConnection.getConnection():SpliceNetConnection.getConnectionAs(userName,password);
		statement = connection.createStatement();
		statement.execute(createString);
		connection.commit();
	} catch (Exception e) {
		LOG.error("Grant statement is invalid ");
		e.printStackTrace();
		throw new RuntimeException(e);
	} finally {
		DbUtils.closeQuietly(rs);
		DbUtils.closeQuietly(statement);
		DbUtils.commitAndCloseQuietly(connection);
	}
	super.starting(description);
}
 
Example 2
Source File: SpliceViewWatcher.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void executeDrop(String schemaName,String viewName) {
    LOG.trace("executeDrop");
    Connection connection = null;
    Statement statement = null;
    try {
        connection = SpliceNetConnection.getConnection();
        statement = connection.createStatement();
        statement.execute("drop view " + schemaName.toUpperCase() + "." + viewName.toUpperCase());
        connection.commit();
    } catch (Exception e) {
        LOG.error("error Dropping " + e.getMessage());
        e.printStackTrace(System.err);
        throw new RuntimeException(e);
    } finally {
        DbUtils.closeQuietly(statement);
        DbUtils.commitAndCloseQuietly(connection);
    }
}
 
Example 3
Source File: SpliceFunctionWatcher.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void executeDrop(String schemaName,String functionName) {
	LOG.trace("executeDrop");
	Connection connection = null;
	Statement statement = null;
	try {
		connection = SpliceNetConnection.getConnection();
		statement = connection.createStatement();
		statement.execute("drop function " + schemaName.toUpperCase() + "." + functionName.toUpperCase());
		connection.commit();
	} catch (Exception e) {
		LOG.error("error Dropping " + e.getMessage());
		e.printStackTrace();
		throw new RuntimeException(e);
	} finally {
		DbUtils.closeQuietly(statement);
		DbUtils.commitAndCloseQuietly(connection);
	}
}
 
Example 4
Source File: SpliceUserWatcher.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void starting(Description description) {
    Connection connection = null;
    Statement statement = null;
    ResultSet rs = null;
    try {
        dropAndCreateUser(userName, password);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(statement);
        DbUtils.commitAndCloseQuietly(connection);
    }
    super.starting(description);
}
 
Example 5
Source File: SpliceUserWatcher.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
public void createUser(String userName, String password) {

        Connection connection = null;
        PreparedStatement statement = null;
        try {
            connection = SpliceNetConnection.getConnection();
            statement = connection.prepareStatement("call syscs_util.syscs_create_user(?,?)");
            statement.setString(1, userName);
            statement.setString(2, password);
            statement.execute();
        } catch (Exception e) {
            LOG.error("error Creating " + e.getMessage());
            e.printStackTrace();
            throw new RuntimeException(e);
        } finally {
            DbUtils.closeQuietly(statement);
            DbUtils.commitAndCloseQuietly(connection);
        }
    }
 
Example 6
Source File: SpliceUserWatcher.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
public void dropUser(String userName) {
    Connection connection = null;
    PreparedStatement statement = null;
    try {
        connection = SpliceNetConnection.getConnection();
        statement = connection.prepareStatement("select username from sys.sysusers where username = ?");
        statement.setString(1, userName.toUpperCase());
        ResultSet rs = statement.executeQuery();
        if (rs.next()) {
            statement = connection.prepareStatement("call syscs_util.syscs_drop_user(?)");
            statement.setString(1, userName);
            statement.execute();
        }
    } catch (Exception e) {
        LOG.error("error Creating " + e.getMessage());
        e.printStackTrace();
        throw new RuntimeException(e);
    } finally {
        DbUtils.closeQuietly(statement);
        DbUtils.commitAndCloseQuietly(connection);
    }
}
 
Example 7
Source File: SpliceRoleWatcher.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void starting(Description description) {
	LOG.trace("Starting");
	executeDrop(roleName.toUpperCase());
	Connection connection = null;
	Statement statement = null;
	ResultSet rs = null;
	try {
		connection = SpliceNetConnection.getConnection();
		statement = connection.createStatement();
		statement.execute(String.format("create role %s",roleName));
		connection.commit();
	} catch (Exception e) {
		LOG.error("Role statement is invalid ");
		e.printStackTrace();
		throw new RuntimeException(e);
	} finally {
		DbUtils.closeQuietly(rs);
		DbUtils.closeQuietly(statement);
		DbUtils.commitAndCloseQuietly(connection);
	}
	super.starting(description);
}
 
Example 8
Source File: SpliceRoleWatcher.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void executeDrop(String roleName) {
	LOG.trace("ExecuteDrop");
	Connection connection = null;
	PreparedStatement statement = null;
	try {
		connection = SpliceNetConnection.getConnection();
		statement = connection.prepareStatement("select roleid from sys.sysroles where roleid = ?");
		statement.setString(1, roleName);
		ResultSet rs = statement.executeQuery();
		if (rs.next())
			connection.createStatement().execute(String.format("drop role %s",roleName));
		connection.commit();
	} catch (Exception e) {
		LOG.error("error Dropping " + e.getMessage());
		e.printStackTrace();
		throw new RuntimeException(e);
	} finally {
		DbUtils.closeQuietly(statement);
		DbUtils.commitAndCloseQuietly(connection);
	}
}
 
Example 9
Source File: SpliceTableWatcher.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
public void importData(String filename) {
    Connection connection = null;
    PreparedStatement ps = null;
    try {
        connection = SpliceNetConnection.getConnection();
        ps = connection.prepareStatement("call SYSCS_UTIL.IMPORT_DATA (?, ?, null,?,',',null,null,null,null,1,null,true,'utf-8')");
        ps.setString(1,schemaName);
        ps.setString(2,tableName);
        ps.setString(3,filename);
        try(ResultSet rs = ps.executeQuery()){
            while(rs.next()){

            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        DbUtils.closeQuietly(ps);
        DbUtils.commitAndCloseQuietly(connection);
    }
}
 
Example 10
Source File: SpliceTableWatcher.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
public void importData(String filename, String timestamp) {
    Connection connection = null;
    PreparedStatement ps = null;
    try {
        connection = SpliceNetConnection.getConnection();
        ps = connection.prepareStatement("call SYSCS_UTIL.IMPORT_DATA (?, ?, null,?,',',null,?,null,null,0,null,true,null)");
        ps.setString(1,schemaName);
        ps.setString(2,tableName);
        ps.setString(3,filename);
        ps.setString(4, timestamp);
        ps.executeQuery();
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        DbUtils.closeQuietly(ps);
        DbUtils.commitAndCloseQuietly(connection);
    }
}
 
Example 11
Source File: SqlSelectExecutor.java    From moneta with Apache License 2.0 5 votes vote down vote up
public SearchResult call() {
	SearchResult result = new SearchResult();
	Connection topicConnection = null;
	QueryRunner runner = new QueryRunner();
	
	try {
		topicConnection = MonetaEnvironment.getConfiguration()
				.getConnection(topic.getDataSourceName());
		
		RecordResultSetHandler handler = new RecordResultSetHandler();
		handler.setMaxRows(this.getMaxRows());
		handler.setStartRow(this.getStartRow());
		handler.getAliasMap().putAll(topic.getAliasMap());
		
		result.setResultData(runner.query(topicConnection, sqlStmt.getSqlText(), 
				handler, sqlStmt.getHostVariableValueList().toArray()));
		
		if (topicConnection.getAutoCommit()) {
			DbUtils.closeQuietly(topicConnection);
		}
		else {
			DbUtils.commitAndCloseQuietly(topicConnection);
		}
	}
	catch (Exception e) {			
		result.setErrorCode(500);
		result.setErrorMessage(ExceptionUtils.getStackTrace(e));
		DbUtils.rollbackAndCloseQuietly(topicConnection);
	}
	
	return result;

}
 
Example 12
Source File: SpliceViewWatcher.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void starting(Description description) {
    LOG.trace("Starting");
    Connection connection = null;
    Statement statement = null;
    ResultSet rs = null;
    try {
        connection = userName==null?SpliceNetConnection.getConnection():SpliceNetConnection.getConnectionAs(userName,password);
        rs = connection.getMetaData().getTables(null, schemaName, viewName, null);
        if (rs.next()) {
            executeDrop(schemaName, viewName);
        }
        connection.commit();
        statement = connection.createStatement();
        statement.execute(CREATE_VIEW + schemaName + "." + viewName + " " + createString);
        connection.commit();
    } catch (Exception e) {
        LOG.error("Create view statement is invalid ");
        e.printStackTrace(System.err);
        throw new RuntimeException(e);
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(statement);
        DbUtils.commitAndCloseQuietly(connection);
    }
    super.starting(description);
}
 
Example 13
Source File: SpliceFunctionWatcher.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void starting(Description description) {
	LOG.trace("Starting");
	Connection connection = null;
	Statement statement = null;
	ResultSet rs = null;
	try {
		connection = (userName==null)?SpliceNetConnection.getConnection():SpliceNetConnection.getConnectionAs(userName, password);
		rs = connection.getMetaData().getTables(null, schemaName, functionName, null);
		if (rs.next()) {
			executeDrop(schemaName,functionName);
		}
		connection.commit();
		statement = connection.createStatement();
		statement.execute(CREATE_FUNCTION + schemaName + "." + functionName + " " + createString);
		connection.commit();
	} catch (Exception e) {
		LOG.error("Create function statement is invalid ");
		e.printStackTrace();
		throw new RuntimeException(e);
	} finally {
		DbUtils.closeQuietly(rs);
		DbUtils.closeQuietly(statement);
		DbUtils.commitAndCloseQuietly(connection);
	}
	super.starting(description);
}
 
Example 14
Source File: SpliceIndexWatcher.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void starting(Description description) {
	LOG.trace("Starting");
	Connection connection = null;
	PreparedStatement statement = null;
	Statement statement2 = null;
	ResultSet rs = null;
	try {
		connection = SpliceNetConnection.getConnection();
		statement = connection.prepareStatement(SELECT_SPECIFIC_INDEX);
		statement.setString(1, indexSchemaName);
		statement.setString(2, indexName);			
		rs = statement.executeQuery();
		if (rs.next()) {
			executeDrop(connection,indexSchemaName,indexName);
		}
		connection.commit();
		statement2 = connection.createStatement();
		statement2.execute(String.format("%s index %s.%s on %s.%s %s %s %s",create,indexSchemaName,indexName,tableSchemaName,tableName,createString,
				excludeNulls?EXCLUDE_NULL_KEYS:"",
				excludeDefaults?EXCLUDE_DEFAULT_KEYS:""
				));
		connection.commit();
	} catch (Exception e) {
		LOG.error("Create index statement is invalid ");
		throw new RuntimeException(e);
	} finally {
		DbUtils.closeQuietly(rs);
		DbUtils.closeQuietly(statement);
		DbUtils.closeQuietly(statement2);
		DbUtils.commitAndCloseQuietly(connection);
	}
	super.starting(description);
}