List of usage examples for org.apache.commons.dbutils QueryRunner QueryRunner
public QueryRunner()
From source file:hermes.store.schema.DefaultJDBCAdapter.java
public QueueBrowser getMessages(Connection connection, String storeId, Destination destination, MessageFactory messageFactory, MessageStore.HeaderPolicy headerPolicy) throws SQLException, JMSException { final QueryRunner runner = new QueryRunner(); final PreparedStatement stmt = createPreparedStatement(connection, "select stores.destination, stores.domain, messages.message, messages.messageid from stores, messages where stores.storeId=? and destination=? and stores.messageid = messages.messageid order by messages.messageid", new Object[] { storeId, messageFactory.getDestinationName(destination) }); return new MessageResultSetHandler(connection, stmt, messageFactory, headerPolicy); }
From source file:azkaban.migration.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 {// www. j a v a2 s .co m runner.update(connection, UPDATE_NEXT_EXEC_TIME, s.getNextExecTime(), s.getProjectId(), s.getFlowName()); } 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:dbutils.DbUtilsTemplate.java
/** * ??Map?Map?List/*from w w w. j a va2 s .c o m*/ * * @param sql sql? * @param params ? * @return */ public List<Map<String, Object>> find(String sql, Object[] params) { queryRunner = new QueryRunner(); List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Connection conn = null; try { conn = dataSource.getConnection(); if (params == null) { list = queryRunner.query(conn, sql, new MapListHandler()); } else { list = queryRunner.query(conn, sql, new MapListHandler(), params); } } catch (SQLException e) { LOG.error("Error occured while attempting to query data", e); } finally { if (conn != null) { DbUtils.closeQuietly(conn); } } return list; }
From source file:com.netflix.metacat.usermetadata.mysql.MySqlLookupService.java
private Lookup findOrCreateLookupByName(final String name, final Connection conn) throws SQLException { Lookup lookup = get(name);//from w ww . j av a 2 s . c o m if (lookup == null) { final Object[] params = { name, STRING_TYPE, config.getLookupServiceUserAdmin(), config.getLookupServiceUserAdmin(), }; final Long lookupId = new QueryRunner().insert(conn, SQL_INSERT_LOOKUP, new ScalarHandler<>(1), params); lookup = new Lookup(); lookup.setName(name); lookup.setId(lookupId); } return lookup; }
From source file:com.netflix.metacat.usermetadata.mysql.MysqlUserMetadataService.java
@SuppressWarnings("checkstyle:methodname") private Void _softDeleteDataMetadatas(final Connection conn, final String userId, final List<String> uris) throws SQLException { if (uris != null && !uris.isEmpty()) { final List<String> paramVariables = uris.stream().map(s -> "?").collect(Collectors.toList()); final String[] aUris = uris.stream().toArray(String[]::new); final String paramString = Joiner.on(",").skipNulls().join(paramVariables); final ColumnListHandler<Long> handler = new ColumnListHandler<>("id"); final List<Long> ids = new QueryRunner().query(conn, String.format(SQL.GET_DATA_METADATA_IDS, paramString), handler, (Object[]) aUris); if (!ids.isEmpty()) { final List<String> idParamVariables = ids.stream().map(s -> "?").collect(Collectors.toList()); final Long[] aIds = ids.stream().toArray(Long[]::new); final String idParamString = Joiner.on(",").skipNulls().join(idParamVariables); final List<Long> dupIds = new QueryRunner().query(conn, String.format(SQL.GET_DATA_METADATA_DELETE_BY_IDS, idParamString), handler, (Object[]) aIds); if (!dupIds.isEmpty()) { ids.removeAll(dupIds);//from w ww . j ava2 s. c o m } final List<Object[]> deleteDataMetadatas = Lists.newArrayList(); ids.forEach(id -> deleteDataMetadatas.add(new Object[] { id, userId })); new QueryRunner().batch(conn, SQL.SOFT_DELETE_DATA_METADATA, deleteDataMetadatas.toArray(new Object[deleteDataMetadatas.size()][2])); } } return null; }
From source file:com.aw.core.dao.DAOSql.java
/** * Executes a simple SQL update (INSERT/DETELE/UPDATE) operation. * Implemtantion uses JdbcTemplate/*w w w. j ava2s. co m*/ * * @param sql SQL expresion, params with ? * @param sqlParams array of parameters to replace ? in order that appear * @return the numer of rows affected by the SQL operation */ public int execSqlUpdate(String sql, Object[] sqlParams) { try { if (logger.isDebugEnabled()) { logger.debug("Executing:" + AWQueryRunner.buildSQLLog(sql, sqlParams)); } return new QueryRunner().update(getHibernateConnection(), sql, sqlParams); } catch (SQLException e) { try { logger.error("SQL:" + buildSQL(sql, sqlParams)); } catch (Throwable e2) { logger.error("SQL:" + sql + "-" + sqlParams); } throw AWBusinessException.wrapUnhandledException(logger, e); } }
From source file:com.netflix.metacat.usermetadata.mysql.MySqlTagService.java
@Override public Void delete(final QualifiedName name, final boolean updateUserMetadata) { try {//from ww w .j a v a 2 s . c o m final Connection conn = getDataSource().getConnection(); try { new QueryRunner().update(conn, SQL_DELETE_TAG_ITEM_TAGS_BY_NAME, name.toString()); new QueryRunner().update(conn, SQL_DELETE_TAG_ITEM, name.toString()); if (updateUserMetadata) { // Set the tags in user metadata final Map<String, Set<String>> data = Maps.newHashMap(); data.put(NAME_TAGS, Sets.newHashSet()); userMetadataService.saveDefinitionMetadata(name, "admin", Optional.of(metacatJson.toJsonObject(data)), true); } conn.commit(); } catch (SQLException e) { conn.rollback(); throw e; } finally { conn.close(); } } catch (SQLException e) { final String message = String.format("Failed to delete all tags for name %s", name); log.error(message, e); throw new UserMetadataServiceException(message, e); } return null; }
From source file:com.bjond.Main.java
public static String findPersonPersonByID(final Connection connection, final String ID) throws SQLException { PersonStub stub = personMap.get(ID); if (stub != null) { return stub.toString().replace(',', '|'); }/* www . j ava 2s. co m*/ val run = new QueryRunner(); stub = run.query(connection, "SELECT p.id, p.first_name, p.middle_name, p.last_name FROM person_person p WHERE p.id = ?", new BeanHandler<>(PersonStub.class), ID); if (stub != null) { personMap.put(ID, stub); return stub.toString().replace(',', '|'); } else { return ID; } }