Java Code Examples for org.apache.commons.dbutils.QueryRunner#execute()

The following examples show how to use org.apache.commons.dbutils.QueryRunner#execute() . 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: FastJdbc.java    From litchi with Apache License 2.0 5 votes vote down vote up
public <T extends Table<Long>> void execute(Class<T> clazz, String sql) {
    try {
        QueryRunner runner = getJdbcTemplate(clazz);
        runner.execute(sql); // .execute(sql);
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
 
Example 2
Source File: FastJdbc.java    From litchi with Apache License 2.0 5 votes vote down vote up
public <T> List<T> query(Class<? extends Table> clazz, String sql, LinkedHashMap<String, Object> condition, ResultSetHandler<T> handler) {
    try {
        QueryRunner runner = getJdbcTemplate(clazz);
        //return runner.query(sql, condition.values().toArray(), rowMapper);
        return runner.execute(sql, handler, condition.values().toArray());
    } catch (Exception e) {
        LOGGER.error("", e);
    }
    return null;
}
 
Example 3
Source File: SQLQueueComponent.java    From litchi with Apache License 2.0 5 votes vote down vote up
private void executeQueue(String tableName) {

        try {
            ConcurrentLinkedQueue<DbQueueModel> queue = TABLE_QUEUE.get(tableName);

            final TableInfo tableInfo = TABLE_INFO.get(tableName);
            String sql = null;

            for (int i = 0; i < this.tableSubmitNum; i++) {
            	DbQueueModel model = queue.poll();
                Object[] values = model.getArgs();
                if (values == null) {
                    continue;
                }
                if (model.getModelType() == ModelType.UPDATE) {
					sql = FastJdbc.replaceSql.toSqlString(tableInfo.annotation().tableName(), tableInfo.buildDbColumns());
				} else if (model.getModelType() == ModelType.DELETE) {
                	String[] keys = new String[1];
                    keys[0] = tableInfo.pkName();
                    sql = FastJdbc.delSql.toSqlString(tableInfo.pkName(), tableInfo.annotation().tableName(), keys);
				}

                try {
                    QueryRunner runner = defaultJdbc.getJdbcTemplate(tableInfo.clazz());
                    runner.execute(sql, values);
                } catch (Exception ex) {
                    LOGGER.error("submit table error. {}", ex);
                    LOGGER.error("sql :{}", sql);
                    LOGGER.error("sql value:{}", values);
                }
            }
        } finally {
            TABLE_SUBMIT_FLAG.put(tableName, false);
        }
    }
 
Example 4
Source File: DatabaseHandler.java    From xyz-hub with Apache License 2.0 5 votes vote down vote up
public void onAcquire(Connection c, String pdsIdt) {
    String schema = getSchema(pdsIdt);  // config.schema();
    QueryRunner runner = new QueryRunner();
    try {
        runner.execute(c, "SET enable_seqscan = off;");
        runner.execute(c, "SET statement_timeout = " + (STATEMENT_TIMEOUT_SECONDS * 1000) + " ;");
        runner.execute(c, "SET search_path=" + schema + ",h3,public,topology;");
    } catch (SQLException e) {
        logger.error("Failed to initialize connection " + c + " [" + pdsIdt + "] : {}", e);
    }
}