List of usage examples for org.apache.commons.dbutils QueryRunner QueryRunner
public QueryRunner()
From source file:azkaban.scheduler.JdbcScheduleLoader.java
@Override public void updateNextExecTime(Schedule s) throws ScheduleManagerException { logger.info("Update schedule " + s.getScheduleName() + " into db. "); Connection connection = getConnection(); QueryRunner runner = new QueryRunner(); try {//from w w w .j a va 2 s . c om runner.update(connection, UPDATE_NEXT_EXEC_TIME, s.getNextExecTime(), s.getScheduleId()); } catch (SQLException e) { e.printStackTrace(); logger.error(UPDATE_NEXT_EXEC_TIME + " failed.", e); throw new ScheduleManagerException("Update schedule " + s.getScheduleName() + " into db failed. ", e); } finally { DbUtils.closeQuietly(connection); } }
From source file:com.odap.server.scheduler.JobManager.java
public synchronized static void createWebNotification(String type, String account_id, String message) { logger.info("Entering removeJob"); try {/*from ww w . j a v a 2s .c o m*/ String sql = "INSERT INTO messages (message_type,message_text,account_id,message_timestamp) VALUES('" + type + "','" + message + "'," + account_id + ", UNIX_TIMESTAMP())"; logger.info(sql); new QueryRunner().update(conn, sql); } catch (SQLException e) { logger.error("Error removing job", e); } logger.info("Exiting removeJob"); }
From source file:dbutils.DbUtilsTemplate.java
/** * ?sql?//from ww w . java2s. c om * * @param sql sql? * @param params ? * @return ?? */ public int[] batchUpdate(String sql, Object[][] params) throws SQLException { queryRunner = new QueryRunner(); int[] affectedRows = new int[0]; Connection conn = null; try { conn = dataSource.getConnection(); affectedRows = queryRunner.batch(conn, sql, params); } catch (SQLException e) { LOG.error("Error occured while attempting to batch update data", e); if (conn != null) { conn.rollback(); } throw e; } finally { if (conn != null) { DbUtils.commitAndClose(conn); } } return affectedRows; }
From source file:azkaban.trigger.JdbcTriggerLoader.java
private void updateTrigger(Connection connection, Trigger t, EncodingType encType) throws TriggerLoaderException { String json = JSONUtils.toJSON(t.toJson()); byte[] data = null; try {/* w w w . j a va2 s . c om*/ byte[] stringData = json.getBytes("UTF-8"); data = stringData; if (encType == EncodingType.GZIP) { data = GZIPUtils.gzipBytes(stringData); } logger.debug("NumChars: " + json.length() + " UTF-8:" + stringData.length + " Gzip:" + data.length); } catch (IOException e) { throw new TriggerLoaderException("Error encoding the trigger " + t.toString()); } QueryRunner runner = new QueryRunner(); try { int updates = runner.update(connection, UPDATE_TRIGGER, t.getSource(), t.getLastModifyTime(), encType.getNumVal(), data, t.getTriggerId()); connection.commit(); if (updates == 0) { throw new TriggerLoaderException("No trigger has been updated."); } else { if (logger.isDebugEnabled()) { logger.debug("Updated " + updates + " records."); } } } catch (SQLException e) { logger.error(UPDATE_TRIGGER + " failed."); throw new TriggerLoaderException("Update trigger " + t.toString() + " into db failed. ", e); } }
From source file:com.bjond.Main.java
public static String findTagNameByID(final Connection connection, final String ID) throws SQLException { String name = nameIDMap.get(ID); if (name != null) { return name; }//from w w w.j av a2s. c o m val run = new QueryRunner(); final StringStub stub = run.query(connection, "SELECT p.name FROM tags_fulltext p WHERE p.id = ?", new BeanHandler<>(StringStub.class), ID); if (stub != null) { nameIDMap.put(ID, stub.getName()); return stub.getName(); } else { return ID; } }
From source file:com.gs.obevo.dbmetadata.impl.dialects.MsSqlMetadataDialect.java
@Override public ImmutableCollection<DaRule> searchRules(final DaSchema schema, Connection conn) throws SQLException { QueryRunner query = new QueryRunner(); // using queryRunner so that we can reuse the connection // Do not use ANSI JOIN as it does not work in Sybase 11.x - the SQL below works across all versions ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(query.query(conn, "SELECT rul.name as RULE_NAME\n" + "FROM " + schema.getName() + "..sysobjects rul\n" + "WHERE rul.type = 'R'\n" + "and not exists (\n" + "\t-- Ensure that the entry is not attached to a table; otherwise, it is a regular table constraint, and will already be dropped when the table is dropped\n" + "\tselect 1 from " + schema.getName() + "..sysconstraints c\n" + "\twhere c.constid = rul.id\n" + ")\n", new MapListHandler())).toImmutable(); return maps.collect(new Function<Map<String, Object>, DaRule>() { @Override//from w w w . ja v a 2 s . c o m public DaRule valueOf(Map<String, Object> map) { return new DaRuleImpl((String) map.get("RULE_NAME"), schema); } }); }
From source file:com.aw.core.dao.DAOSql.java
/** * Helper method used to retrieve a COLUMN using standard SQL sintaxis * The query must return a single column * * @param sql SQL query//from w w w.j a v a 2 s .c o m * @param filterKeys key used to restrict the search * @return First Row First column , NULL if no row */ public Object findObjectGetColumn(String sql, Object[] filterKeys) { try { return new QueryRunner().query(getHibernateConnection(), sql, filterKeys, new ScalarHandler()); } catch (SQLException e) { throw AWBusinessException.wrapUnhandledException(logger, e); } }
From source file:com.netflix.metacat.usermetadata.mysql.MySqlTagService.java
private TagItem findOrCreateTagItemByName(final String name, final Connection conn) throws SQLException { TagItem result = get(name);//from w w w .j ava2s.c o m if (result == null) { final Object[] params = { name, config.getTagServiceUserAdmin(), config.getTagServiceUserAdmin() }; final Long id = new QueryRunner().insert(conn, SQL_INSERT_TAG_ITEM, new ScalarHandler<>(1), params); result = new TagItem(); result.setName(name); result.setId(id); } return result; }
From source file:com.bjond.Main.java
public static String findQuestionNameByID(final Connection connection, final String ID) throws SQLException { String name = nameIDMap.get(ID); if (name != null) { return name; }/* w ww . j a v a 2s . c o m*/ val run = new QueryRunner(); final StringStub stub = run.query(connection, "SELECT p.name FROM assessment_questions p WHERE p.id = ?", new BeanHandler<>(StringStub.class), ID); if (stub != null) { nameIDMap.put(ID, stub.getName()); return stub.getName(); } else { return ID; } }
From source file:com.mirth.connect.connectors.jdbc.JdbcMessageDispatcher.java
public UMOMessage receive(UMOEndpointURI endpointUri, long timeout) throws Exception { if (logger.isDebugEnabled()) { logger.debug("Trying to receive a message with a timeout of " + timeout); }/*from w w w . j av a 2 s . co m*/ String[] stmts = this.connector.getReadAndAckStatements(endpointUri, null); String readStmt = stmts[0]; String ackStmt = stmts[1]; List<String> readParams = new ArrayList<String>(); List<String> ackParams = new ArrayList<String>(); readStmt = JdbcUtils.parseStatement(readStmt, readParams); ackStmt = JdbcUtils.parseStatement(ackStmt, ackParams); Connection connection = null; long t0 = System.currentTimeMillis(); try { connection = connector.getConnection(null); if (timeout < 0) { timeout = Long.MAX_VALUE; } Object result = null; do { result = new QueryRunner().query(connection, readStmt, new MapHandler(), JdbcUtils.getParams(endpointUri, readParams, null)); if (result != null) { if (logger.isDebugEnabled()) { logger.debug("Received: " + result); } break; } long sleep = Math.min(this.connector.getPollingFrequency(), timeout - (System.currentTimeMillis() - t0)); if (sleep > 0) { if (logger.isDebugEnabled()) { logger.debug("No results, sleeping for " + sleep); } Thread.sleep(sleep); } else { logger.debug("Timeout"); return null; } } while (true); if (result != null && ackStmt != null) { int numRows = new QueryRunner().update(connection, ackStmt, JdbcUtils.getParams(endpointUri, ackParams, result)); if (numRows != 1) { logger.warn("Row count for ack should be 1 and not " + numRows); } } UMOMessageAdapter msgAdapter = this.connector.getMessageAdapter(result); UMOMessage message = new MuleMessage(msgAdapter); JdbcUtils.commitAndClose(connection); return message; } catch (Exception e) { JdbcUtils.rollbackAndClose(connection); throw e; } }