List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
From source file:org.zenoss.zep.dao.impl.EventIndexQueueDaoImpl.java
@Override @TransactionalRollbackAllExceptions/* w w w . j a v a2 s.com*/ 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:om.edu.squ.squportal.portlet.dps.registration.postpone.db.PostponeDBImpl.java
/** * /* ww w . ja v a2s . c o m*/ * method name : getPostponeReasons * @param locale * @return * PostponeDBImpl * return type : List<PostponeReason> * * purpose : Get list of default reasons for postpone * * Date : May 25, 2017 4:15:05 PM */ public List<PostponeReason> getPostponeReasons(Locale locale) { String SQL_POSTPONE_REASONS = queryPostpone.getProperty(Constants.CONST_SQL_POSTPONE_REASONS); RowMapper<PostponeReason> rowMapper = new RowMapper<PostponeReason>() { @Override public PostponeReason mapRow(ResultSet rs, int rowNum) throws SQLException { PostponeReason postponeReason = new PostponeReason(); postponeReason.setSiscodecd(rs.getString(Constants.CONST_COLMN_SISCODECD)); postponeReason.setReasonName(rs.getString(Constants.CONST_COLMN_POSTPONE_REASON_NAME)); return postponeReason; } }; Map<String, String> namedParameterMap = new HashMap<String, String>(); namedParameterMap.put("paramLocale", locale.getLanguage()); return nPJdbcTemplDpsPostpone.query(SQL_POSTPONE_REASONS, namedParameterMap, rowMapper); }
From source file:com.jd.survey.dao.survey.QuestionStatisticDAOImp.java
/** * Returns frequency statistics for a choice question' answers (Value, Count) * @param question// w ww.j av a2 s. co m * @return */ private List<QuestionStatistic> getFrequencyStatistics(Question question, final Long totalRecordCount) { Long surveyDefinitionId = question.getPage().getSurveyDefinition().getId(); Short pageOrder = question.getPage().getOrder(); Short questionOrder = question.getOrder(); final String columnName = "p" + pageOrder + "q" + questionOrder; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("select d." + columnName + " as col, count(*) as total "); stringBuilder.append(" from survey_data_" + surveyDefinitionId + " d inner join survey s on (s.id=d.survey_id and s.status='S')"); stringBuilder.append(" group by d." + columnName); String selectSQLStatement = stringBuilder.toString(); List<QuestionStatistic> questionStatistics = this.jdbcTemplate.query(selectSQLStatement, new RowMapper<QuestionStatistic>() { public QuestionStatistic mapRow(ResultSet rs, int rowNum) throws SQLException { QuestionStatistic questionStatistic = new QuestionStatistic(); questionStatistic.setEntry(rs.getString("col")); questionStatistic.setCount(rs.getLong("total")); questionStatistic.setTotalCount(totalRecordCount); return questionStatistic; } }); return questionStatistics; }
From source file:dao.CircleDAO.java
public List<Integer> getCustomerId(int circleId) { String query = "SELECT * FROM circlemembership" + " WHERE CircleID=" + circleId + ";"; List<Integer> custIds = this.jdbcTemplate.query(query, new RowMapper<Integer>() { @Override//from w w w. j a va 2 s. co m public Integer mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getInt("UserID"); } }); return custIds; }
From source file:nl.surfnet.coin.teams.service.impl.TeamExternalGroupDaoImpl.java
@Override public TeamExternalGroup getByTeamIdentifierAndExternalGroupIdentifier(String teamId, String externalGroupIdentifier) { Object[] args = { teamId, externalGroupIdentifier }; String s = "SELECT teg.id AS teg_id, teg.grouper_team_id, eg.id AS eg_id, eg.identifier, eg.name, eg.description, eg.group_provider " + " FROM team_external_groups AS teg " + " INNER JOIN external_groups AS eg " + " ON teg.external_groups_id = eg.id " + " WHERE teg.grouper_team_id = ? AND eg.identifier = ?"; try {//from w w w.java2s. co m return this.jdbcTemplate.queryForObject(s, args, new RowMapper<TeamExternalGroup>() { @Override public TeamExternalGroup mapRow(ResultSet rs, int rowNum) throws SQLException { return mapRowToTeamExternalGroup(rs); } }); } catch (EmptyResultDataAccessException er) { return null; } }
From source file:com.arcane.dao.Impl.PatternDaoImpl.java
@Override public List<Pattern> getAllPatternList() { //select all patterns from specified category LOG.info("Selecting all patterns from specific category"); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); List<String> patternNameList = getPatternNames(); String sql = ""; List<Pattern> listPattern = new ArrayList<Pattern>(); for (String pattern : patternNameList) { sql = "SELECT * from " + pattern; List<Pattern> templistPattern = jdbcTemplate.query(sql, new RowMapper<Pattern>() { @Override// w w w. j av a 2 s .com public Pattern mapRow(ResultSet rs, int rowNumber) throws SQLException { Pattern pattern1 = new Pattern(); pattern1.setId(rs.getInt("id")); pattern1.setStock(rs.getString("stock")); pattern1.setTimeStamp(rs.getString("breakPoint")); pattern1.setName(rs.getMetaData().getTableName(1)); return pattern1; } }); listPattern.addAll(templistPattern); } Collections.sort(listPattern, comparator); return listPattern; }
From source file:org.pegadi.server.sources.SourceServerImpl.java
public List<Source> getSourcesBySearchTerm(SearchTerm term) { return template.query(term.getQuery("Source_person.ID"), new RowMapper<Source>() { @Override//from w w w. jav a2 s. c o m public Source mapRow(ResultSet rs, int rowNum) throws SQLException { return getSourceByID(rs.getInt(1)); } }); }
From source file:ru.org.linux.spring.SameIPController.java
private List<TopicItem> getComments(String ip) { return jdbcTemplate.query( "SELECT sections.name as ptitle, groups.title as gtitle, topics.title, topics.id as topicid, comments.id as msgid, comments.postdate, comments.deleted " + "FROM sections, groups, topics, comments " + "WHERE sections.id=groups.section " + "AND groups.id=topics.groupid " + "AND comments.topic=topics.id " + "AND comments.postip=?::inet " + "AND comments.postdate>CURRENT_TIMESTAMP-'24 hour'::interval " + "ORDER BY postdate DESC", new RowMapper<TopicItem>() { @Override/* ww w . j a v a 2 s .c o m*/ public TopicItem mapRow(ResultSet rs, int rowNum) throws SQLException { return new TopicItem(rs, true); } }, ip); }
From source file:com.sfs.whichdoctor.dao.AddressDAOImpl.java
/** * Get a collection of AddressBeans for a specified GUID. * * @param guid the guid/*ww w. ja va 2 s .c o m*/ * @param allAddresses the all addresses * @param addressClass the address class * @param addressType the address type * * @return the collection< address bean> * * @throws com.sfs.whichdoctor.dao.WhichDoctorDaoException * @throws * WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public final Collection<AddressBean> load(final int guid, final boolean allAddresses, final String addressClass, final String addressType) throws WhichDoctorDaoException { dataLogger.info("Addresses for GUID: " + guid + " requested"); boolean specificAddress = false; String sql = getSQL().getValue("address/load") + " WHERE address.Active = true AND address.ReferenceGUID = ?"; Collection<Object> variables = new ArrayList<Object>(); /* The GUID value is the first variable */ variables.add(guid); if (addressClass != null) { if (addressClass.compareTo("") != 0 && addressClass.compareTo("Preferred") != 0) { sql += " AND addresstype.Class = ?"; variables.add(addressClass); specificAddress = true; } } if (addressType != null) { if (addressType.compareTo("") != 0 && addressType.compareTo("Preferred") != 0) { sql += " AND addresstype.Name = ?"; variables.add(addressType); specificAddress = true; } } sql += " ORDER BY PrimaryAddress DESC"; if (!allAddresses) { sql += " LIMIT 1"; } Collection<AddressBean> addresses = new ArrayList<AddressBean>(); try { addresses = this.getJdbcTemplateReader().query(sql, variables.toArray(), new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadAddress(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for search: " + ie.getMessage()); } if (specificAddress && addresses.size() == 0) { /** * Specific address type defined but no result found Try getting a * more generic address */ if (addressType != null) { if (addressType.compareTo("") != 0) { addresses = load(guid, allAddresses, addressClass, null); } } if (addresses.size() == 0) { if (addressClass != null) { if (addressClass.compareTo("") != 0) { addresses = load(guid, allAddresses, null, null); } } } } return addresses; }