List of usage examples for org.apache.commons.dbutils QueryRunner query
public <T> T query(String sql, ResultSetHandler<T> rsh) throws SQLException
From source file:org.mule.module.db.integration.DbTestUtil.java
public static List<Map<String, String>> selectData(String query, DataSource dataSource) throws SQLException { QueryRunner qr = new QueryRunner(dataSource); @SuppressWarnings({ "unchecked" }) List<Map<String, String>> result = (List<Map<String, String>>) qr.query(query, new MapListHandler()); return result; }
From source file:org.rti.zcore.dar.utils.DatabaseUtils.java
/** * Get a single value/*from w w w .j av a2 s .c o m*/ * String idSql = "SELECT LAST_INSERT_ID() AS id;"; * unused * * @param sql * @return * @throws ServletException * @throws SQLException */ public static Object getScalar(String sql) throws ServletException, SQLException { ResultSetHandler h = new ScalarHandler(); DataSource dataSource = null; dataSource = DatabaseUtils.getZEPRSDataSource(); QueryRunner run = new QueryRunner(dataSource); Object result = run.query(sql, h); return result; }
From source file:ttf.persistence.sql.SQLStore.java
@Override public Collection<Topic> loadTopics(Query query) throws PersistenceException { QueryRunner run = new QueryRunner(dataSource); String sql = "SELECT id, title FROM Topics"; ResultSetHandler<Collection<Topic>> rsh = new TopicListRSH(dataSource, topicFactory); Collection<Topic> topics; try {//w ww. j av a 2s . c o m topics = run.query(sql, rsh); } catch (SQLException e) { throw new PersistenceException(e); } return topics; }
From source file:ttf.persistence.sql.SQLStore.java
@Override public double loadNrOfArticles() throws PersistenceException, SQLException { QueryRunner run = new QueryRunner(dataSource); double NrOfArticles = 0; String queryInterval = "SELECT count(*) FROM articles"; Long count = (Long) run.query(queryInterval, new ScalarHandler()); if (count != null) NrOfArticles = ((double) count); return NrOfArticles; }
From source file:ttf.persistence.sql.SQLStore.java
@Override public PropertyGroup<String, NumericalValue> loadAppearancy() throws PersistenceException, SQLException { QueryRunner run = new QueryRunner(dataSource); String sql = "SELECT name, count(articleId) FROM articlefeatures where type='term' group by name"; PropertyGroup<String, NumericalValue> Appearancy = new HashMapPropertyGroup<String, NumericalValue>(); List<Object[]> features = run.query(sql, new ArrayListHandler()); // parse features for (Object[] o : features) { String name = (String) o[0]; Long count = (Long) o[1]; Appearancy.put(name, new NumericalValue(count)); }/* w ww . j a v a 2s .co m*/ return Appearancy; }
From source file:ttf.tools.AdvancedApp.java
public void run() throws IllegalArgumentException, FeedException, IOException, SQLException { // set up parameters double minSimilarity = configuration.getDouble("analysis.minSimilarity"); // set up commands List<Command> commands = new LinkedList<Command>(); commands.add(new EntityDetectionCommand()); commands.add(new TfIdfHelperCommand()); commands.add(new TfIdfDetectionCommand()); commands.add(new TopicLoadingCommand()); commands.add(new TopicSelectionCommand(minSimilarity)); commands.add(new TopicUpdateCommand()); commands.add(new ModelPersistenceCommand()); QueryRunner run = new QueryRunner(dataSource); String queryInterval = "SELECT min(retrievalInterval) FROM " + SOURCES; String queryArticles = "SELECT title, author, publishedAt, discoveredAt, address, content FROM " + INCOMINGARTICLES + " WHERE processed = 0"; String updateArticle = "UPDATE " + INCOMINGARTICLES + " SET processed = 1 WHERE address = ?"; // Read update interval long updateInterval = 0; Integer interval = (Integer) run.query(queryInterval, new ScalarHandler()); if (interval != null) updateInterval = ((Integer) interval) * FeedInfo.MINUTE; while (updateInterval > 0) { // Get unprocessed incoming articles InternalProvider provider = new InternalProvider(); List<IncomingArticle> incomingArticles = run.query(queryArticles, new IncomingArticleListRSH()); for (IncomingArticle incomingArticle : incomingArticles) { Article article = transformer.transform(incomingArticle); provider.add(article);/*from www .j a v a 2 s . c o m*/ } process(commands, provider); // Mark processed for (IncomingArticle incomingArticle : incomingArticles) { run.update(updateArticle, incomingArticle.getAddress()); } try { Thread.sleep(updateInterval); } catch (InterruptedException e) { } } }