List of usage examples for java.sql ResultSet getLong
long getLong(String columnLabel) throws SQLException;
ResultSet
object as a long
in the Java programming language. From source file:com.grayfox.server.dao.jdbc.UserJdbcDao.java
@Override public User findCompactByAccessToken(String accessToken) { List<User> users = getJdbcTemplate().query(getQuery("User.findByAccessToken"), (ResultSet rs, int i) -> { User user = new User(); int columnIndex = 1; user.setId(rs.getLong(columnIndex++)); user.setName(rs.getString(columnIndex++)); user.setLastName(rs.getString(columnIndex++)); user.setPhotoUrl(rs.getString(columnIndex++)); user.setFoursquareId(rs.getString(columnIndex++)); return user; }, accessToken);/*from w w w. j a v a 2 s . c o m*/ if (users.size() > 1) { throw new DaoException.Builder().messageKey("data.integrity.error").build(); } return users.isEmpty() ? null : users.get(0); }
From source file:jobimtext.thesaurus.distributional.DatabaseThesaurusDatastructure.java
public Long getKeyCount(String key) { Long count = 0L;//from w ww . j a v a 2 s.c o m String sql = "SELECT count FROM " + tableKey + " WHERE word = ?"; PreparedStatement ps; try { ps = getDatabaseConnection().getConnection().prepareStatement(sql); ps.setString(1, key); ResultSet set = ps.executeQuery(); if (set.next()) { count = set.getLong("count"); } ps.close(); } catch (SQLException e) { e.printStackTrace(); } return count; }
From source file:org.ohmage.query.impl.UserSurveyResponseQueries.java
/** * Retrieves the milliseconds since epoch of the time that the most recent * survey was completed.//from w ww. ja v a 2 s.com * * @param requestersUsername The username of the user that is requesting * this information. * * @param usersUsername The username of the user to which the data belongs. * * @return A Long representing the milliseconds since epoch when the most * recently completed survey was completed or null if the user has * not yet uploaded any surveys. */ public Long getLastUploadForUser(String requestersUsername, String usersUsername) throws DataAccessException { try { List<Long> epochMillis = getJdbcTemplate().query(SQL_GET_SURVEY_RESPONSES_FOR_USER_FOR_REQUESTER, new Object[] { usersUsername, requestersUsername }, new RowMapper<Long>() { @Override public Long mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getLong("epoch_millis"); } }); if (epochMillis.size() == 0) { return null; } else { Collections.sort(epochMillis); return epochMillis.get(epochMillis.size() - 1); } } catch (org.springframework.dao.DataAccessException e) { throw new DataAccessException("Error executing SQL '" + SQL_GET_SURVEY_RESPONSES_FOR_USER_FOR_REQUESTER + "' with parameters: " + usersUsername + ", " + requestersUsername, e); } }
From source file:com.fileanalyzer.dao.impl.FilesDAOImpl.java
@Override public Long getMaxId() { Connection con = null;/* www.j a va2 s . co m*/ PreparedStatement statement = null; String sql = "select max(id) from " + Files.FilesFieldsKey.TABLE; Long maxId = null; try { con = DBConnector.getConnection(); con.setAutoCommit(false); statement = con.prepareStatement(sql); ResultSet rs = statement.executeQuery(); if (rs.next()) maxId = rs.getLong(1); con.commit(); } catch (SQLException e) { handleException(e, con); } finally { doFinal(con, statement); } return maxId; }
From source file:com.bt.aloha.batchtest.PerformanceMeasurmentDao.java
@SuppressWarnings("unchecked") public List<Long> findLastXRunId(int x, String testType) { List<Long> runIds = jdbcTemplate.query( "select distinct(runId) as r from performance where testType='" + testType + "'", new RowMapper() { public Object mapRow(ResultSet rs, int row) throws SQLException { long runId = rs.getLong("r"); return runId; }/*from www .jav a2s . c o m*/ }); int s = runIds.size(); if (s > x) { int remNr = s - x; for (int j = 0; j < remNr; j++) runIds.remove(0); } return runIds; }
From source file:org.zenoss.zep.dao.impl.EventIndexQueueDaoImpl.java
@Override @TransactionalRollbackAllExceptions/*from w ww . ja va 2 s . c o m*/ public List<Long> indexEvents(final EventIndexHandler handler, final int limit, final long maxUpdateTime) throws ZepException { final Map<String, Object> selectFields = new HashMap<String, Object>(); selectFields.put("_limit", limit); final String sql; // Used for partition pruning final String queryJoinLastSeen = (this.isArchive) ? "AND iq.last_seen=es.last_seen " : ""; if (maxUpdateTime > 0L) { selectFields.put("_max_update_time", timestampConverter.toDatabaseType(maxUpdateTime)); sql = "SELECT iq.id AS iq_id, iq.uuid AS iq_uuid, iq.update_time AS iq_update_time," + "es.* FROM " + this.queueTableName + " AS iq " + "LEFT JOIN " + this.tableName + " es ON iq.uuid=es.uuid " + queryJoinLastSeen + "WHERE iq.update_time <= :_max_update_time " + "ORDER BY iq_id LIMIT :_limit"; } else { sql = "SELECT iq.id AS iq_id, iq.uuid AS iq_uuid, iq.update_time AS iq_update_time," + "es.* FROM " + this.queueTableName + " AS iq " + "LEFT JOIN " + this.tableName + " es ON iq.uuid=es.uuid " + queryJoinLastSeen + "ORDER BY iq_id LIMIT :_limit"; } final Set<String> eventUuids = new HashSet<String>(); final List<Long> indexQueueIds = this.template.query(sql, new RowMapper<Long>() { @Override public Long mapRow(ResultSet rs, int rowNum) throws SQLException { final long iqId = rs.getLong("iq_id"); final String iqUuid = uuidConverter.fromDatabaseType(rs, "iq_uuid"); // Don't process the same event multiple times. if (eventUuids.add(iqUuid)) { final Object uuid = rs.getObject("uuid"); if (uuid != null) { EventSummary summary = rowMapper.mapRow(rs, rowNum); try { handler.handle(summary); } catch (Exception e) { throw new RuntimeException(e.getLocalizedMessage(), e); } } else { try { handler.handleDeleted(iqUuid); } catch (Exception e) { throw new RuntimeException(e.getLocalizedMessage(), e); } } } return iqId; } }, selectFields); if (!indexQueueIds.isEmpty()) { try { handler.handleComplete(); } catch (Exception e) { throw new ZepException(e.getLocalizedMessage(), e); } } // publish current size of event_*_index_queue table this.lastQueueSize = this.template.queryForInt("SELECT COUNT(1) FROM " + this.queueTableName); this.applicationEventPublisher .publishEvent(new EventIndexQueueSizeEvent(this, tableName, this.lastQueueSize, limit)); return indexQueueIds; }
From source file:com.dsf.dbxtract.cdc.AppJournalDeleteTest.java
/** * Rigourous Test :-)//from w ww . j a v a2s. co m * * @throws Exception * in case of any error */ @Test(timeOut = 120000) public void testAppWithJournalDelete() throws Exception { final Config config = new Config(configFile); BasicDataSource ds = new BasicDataSource(); Source source = config.getDataSources().getSources().get(0); ds.setDriverClassName(source.getDriver()); ds.setUsername(source.getUser()); ds.setPassword(source.getPassword()); ds.setUrl(source.getConnection()); // prepara os dados Connection conn = ds.getConnection(); conn.createStatement().execute("truncate table test"); conn.createStatement().execute("truncate table j$test"); // Carrega os dados de origem PreparedStatement ps = conn.prepareStatement("insert into test (key1,key2,data) values (?,?,?)"); for (int i = 0; i < TEST_SIZE; i++) { if ((i % 100) == 0) { ps.executeBatch(); } ps.setInt(1, i); ps.setInt(2, i); ps.setInt(3, (int) Math.random() * 500); ps.addBatch(); } ps.executeBatch(); ps.close(); app = new App(config); app.start(); Assert.assertEquals(config.getHandlers().iterator().next().getStrategy(), JournalStrategy.DELETE); // Popula as tabelas de journal ps = conn.prepareStatement("insert into j$test (key1,key2) values (?,?)"); for (int i = 0; i < TEST_SIZE; i++) { if ((i % 500) == 0) { ps.executeBatch(); } ps.setInt(1, i); ps.setInt(2, i); ps.addBatch(); } ps.executeBatch(); ps.close(); while (true) { TimeUnit.MILLISECONDS.sleep(500); ResultSet rs = conn.createStatement().executeQuery("select count(*) from j$test"); if (rs.next()) { long count = rs.getLong(1); System.out.println("remaining journal rows: " + count); rs.close(); if (count == 0L) break; } } conn.close(); ds.close(); }
From source file:io.apiman.manager.api.jdbc.handlers.UsagePerClientHandler.java
/** * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet) *///w w w.j a va 2s . co m @Override public UsagePerClientBean handle(ResultSet rs) throws SQLException { UsagePerClientBean rval = new UsagePerClientBean(); while (rs.next()) { String clientId = rs.getString(1); if (clientId == null) { continue; } long count = rs.getLong(2); rval.getData().put(clientId, count); } return rval; }
From source file:com.github.dbourdette.glass.log.execution.jdbc.JdbcJobExecutions.java
private Page<JobExecution> getLogs(String sqlBase, SqlParameterSource params, Query query) { String sql = query.applySqlLimit("select * " + sqlBase + " order by startDate desc"); List<JobExecution> executions = jdbcTemplate.query(sql, params, new RowMapper<JobExecution>() { @Override/* w w w . j a va2 s . co m*/ public JobExecution mapRow(ResultSet rs, int rowNum) throws SQLException { JobExecution execution = new JobExecution(); execution.setId(rs.getLong("id")); execution.setStartDate(rs.getTimestamp("startDate")); execution.setEndDate(rs.getTimestamp("endDate")); execution.setEnded(rs.getBoolean("ended")); execution.setJobGroup(rs.getString("jobGroup")); execution.setJobName(rs.getString("jobName")); execution.setTriggerGroup(rs.getString("triggerGroup")); execution.setTriggerName(rs.getString("triggerName")); execution.setJobClass(rs.getString("jobClass")); execution.setDataMap(rs.getString("dataMap")); execution.setResult(JobExecutionResult.valueOf(rs.getString("result"))); return execution; } }); String countSql = "select count(*) " + sqlBase; Page<JobExecution> page = Page.fromQuery(query); page.setItems(executions); page.setTotalCount(jdbcTemplate.queryForInt(countSql, params)); return page; }
From source file:net.mindengine.oculus.frontend.service.customization.JdbcCustomizationDAO.java
@Override public Long addCustomization(Customization customization) throws Exception { PreparedStatement ps = getConnection() .prepareStatement("insert into customizations " + "(unit, " + "project_id, " + "name, " + "description, " + "type, " + "subtype, " + "group_name) values (?,?,?,?,?,?,?)"); ps.setString(1, customization.getUnit()); ps.setLong(2, customization.getProjectId()); ps.setString(3, customization.getName()); ps.setString(4, customization.getDescription()); ps.setString(5, customization.getType()); ps.setString(6, customization.getSubtype()); ps.setString(7, customization.getGroupName()); logger.info(ps);//from w w w . j a v a 2s. c o m ps.execute(); ResultSet rs = ps.getGeneratedKeys(); if (rs.next()) { return rs.getLong(1); } return null; }