public List<String> get(String sourceType, String source, String targetType) { return jdbc.query("select "+COL_TARGET+" from "+TABLE+" where "+ COL_ID_TYPE+"=? and "+COL_ID+"=? and "+COL_TARGET_TYPE+"=?", STRING_MAPPER, sourceType, source, targetType); }
@Override public FlowCollection getFlows(CriteriaAdapter criteria) { FlowCollection flowCollection = new FlowCollection(); final String whereClause = criteria.getWhereClause(); final String countQuery = dialect.getCountQuery().replaceAll(DatabaseDialect.SUBSTITUTION_STRING, (whereClause != null && whereClause.length() > 0) ? " AND " + whereClause : ""); int rowCount = getSimpleJdbcTemplate().queryForInt(countQuery, criteria); int offset = Integer.parseInt(criteria.getValue("offset").toString()); int limit = Integer.parseInt(criteria.getValue("limit").toString()); List<Flow> flows = null; if (offset < rowCount) { String dataQuery = dialect.getDataQuery(criteria); if ((rowCount - offset) < limit) limit = rowCount - offset; String soffset = String.valueOf(offset); String slimit = String.valueOf(limit); dataQuery = dataQuery.replaceAll(SUBSTITUTION_STRING_LIMIT, slimit).replaceAll(SUBSTITUTION_STRING_OFFSET, soffset); flows = getSimpleJdbcTemplate().query(dataQuery, flowMapper, criteria); } if(flows == null) flows = new ArrayList<Flow>(); flowCollection.setFlows(flows); flowCollection.setCount(rowCount); return flowCollection; }
@Deprecated public <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, SqlParameterSource args) throws DataAccessException { return query(sql, (RowMapper<T>) rm, args); }
@Deprecated public <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Map<String, ?> args) throws DataAccessException { return query(sql, (RowMapper<T>) rm, args); }
@Deprecated public <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Object... args) throws DataAccessException { return query(sql, (RowMapper<T>) rm, args); }
final SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(datasource); final List<String> data = jdbcTemplate.query("SELECT column1 FROM MyTable ORDER BY column1 ASC", new ParameterizedSingleColumnRowMapper<String>());
SimpleJdbcTemplate template = new SimpleJdbcTemplate(dataSource); List<String> result = template.query("SELECT name FROM people WHERE id > ?", new RowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getString("name"); } }, 666 );
/** * {@inheritDoc} */ @Override public List<Task> getTaskList(String userId) { List<Task> tasks = simpleJdbcTemplate.query(SQL_GET_TASK, getTaskRowMapper(), userId); return tasks; }
@Override public List<FlowEvent> getFlowDetails(String flowID) { return getSimpleJdbcTemplate().query(SELECT_FLOW_QUERY, flowEventMapper, Collections.singletonMap("flowID", flowID)); }
@Override public FlowEvent getEventDetails(Integer eventID) { List<FlowEvent> list = getSimpleJdbcTemplate().query(SELECT_EVENT_QUERY, eventMapper, Collections.singletonMap("eventID", eventID)); if (list.isEmpty()) { return null; } else { return list.get(0); } }
public Map getSession(String sessionId,int timeoutSeconds) { List<Map> results = getSimpleJdbcTemplate().query(GET,new ParameterizedRowMapper<Map>(){ public Map mapRow(ResultSet rs, int row) throws SQLException { String sessionData = rs.getString(1); return decode(sessionData); } },sessionId,System.currentTimeMillis()); return results.size() > 0 ? results.get(0) : new HashMap(); }
public List<Spittle> getRecentSpittle() { DateTime dt = new DateTime().minusDays(1); return getSimpleJdbcTemplate().query(SQL_SELECT_RECENT_SPITTLE, new ParameterizedRowMapper<Spittle>() { public Spittle mapRow(ResultSet rs, int rowNum) throws SQLException { Spittle spittle = new Spittle(); spittle.setId(rs.getLong(1)); spittle.setSpitter(getSpitterById(rs.getLong(2))); spittle.setText(rs.getString(3)); spittle.setWhen(rs.getDate(4)); return spittle; } }, dt.toDate()); }
@Override protected List<IPersonAttributes> getPeopleForQuery(PartialWhereClause queryBuilder, String queryUserName) { //Execute the query final ParameterizedRowMapper<R> rowMapper = this.getRowMapper(); final List<R> results; if (queryBuilder != null) { //Merge the generated SQL with the base query template final StringBuilder partialSqlWhere = queryBuilder.sql; final Matcher queryMatcher = WHERE_PLACEHOLDER.matcher(this.queryTemplate); final String querySQL = queryMatcher.replaceAll(partialSqlWhere.toString()); results = this.simpleJdbcTemplate.query(querySQL, rowMapper, queryBuilder.arguments.toArray()); if (this.logger.isDebugEnabled()) { this.logger.debug("Executed '" + this.queryTemplate + "' with arguments " + queryBuilder.arguments + " and got results " + results); } } else { results = this.simpleJdbcTemplate.query(this.queryTemplate, rowMapper); if (this.logger.isDebugEnabled()) { this.logger.debug("Executed '" + this.queryTemplate + "' and got results " + results); } } return this.parseAttributeMapFromResults(results, queryUserName); }
return this.getSimpleJdbcTemplate().query(sqlString, mapper, positionNumber);
private List<StoredEvent<E>> loadEventsUptoTimestamp(EventStream stream, long timestamp) { List<StoredEvent<E>> storedEvents = jdbcTemplate.query( "select version, timestamp, data from event where event_stream_id = ? and timestamp <= ? order by sequence_number", new StoredEventRowMapper(), stream.getId().toString(), new Date(timestamp)); if (storedEvents.isEmpty()) { throw new EmptyResultDataAccessException("no events found for stream " + stream.getId() + " for timestamp " + timestamp, 1); } return storedEvents; }
public Credential findCredentialByResourceType(ResourceType resourceType) throws Exception { List<Credential> credentials = this.getSimpleJdbcTemplate() .query(CREDENTIAL_SELECT_BY_RESOURCE_TYPE, new ParameterizedRowMapper<Credential>() { public Credential mapRow(ResultSet rs, int rowNum) throws SQLException { String username = rs.getString(usernameCol); String password = rs.getString(passwordCol); return new Credential(username, password); } }, resourceType.toString()); if (credentials.size() == 0) { throw new Exception("Table is empty: '" + tablename + "'"); } if (credentials.size() != 1) { throw new Exception(tablename + " contains more than one entry for resourceType: " + resourceType.toString()); } return credentials.get(0); }
public String findPasswordByResourceTypeAndUsername(ResourceType resourceType, String username) throws Exception { List<String> passwords = this.getSimpleJdbcTemplate() .query(PASSWORD_SELECT_BY_RESOURCE_TYPE_AND_USERNAME, new ParameterizedRowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getString(passwordCol); } }, resourceType.toString(), username); if (passwords.size() == 0) { throw new Exception("Table is empty: '" + tablename + "'"); } if (passwords.size() != 1) { throw new Exception(tablename + " contains more than one entry for resourceType and username : [" + resourceType.toString() + "|" + username + "]"); } return passwords.get(0); }
private List<StoredEvent<E>> loadEventsUptoVersion(EventStream stream, long version) { List<StoredEvent<E>> storedEvents = jdbcTemplate.query( "select version, timestamp, data from event where event_stream_id = ? and version <= ? order by sequence_number", new StoredEventRowMapper(), stream.getId().toString(), version); if (storedEvents.isEmpty()) { throw new EmptyResultDataAccessException("no events found for stream " + stream.getId() + " for version " + version, 1); } return storedEvents; }
public Collection<Integer> listConversationsSince(int id) throws DataAccessException { MapSqlParameterSource params = new MapSqlParameterSource(); try { params.addValue(ID, id, Types.INTEGER); SimpleJdbcTemplate template = new SimpleJdbcTemplate( getNamedParameterJdbcTemplate()); return template.query(SELECT_CONVERSATIONS, ID_MAPPER, params); } catch (EmptyResultDataAccessException erdae) { return Collections.emptyList(); } }
public Collection<Book> getBooks() { return this.jdbcTemplate.query("SELECT * FROM books", new BookRowMapper()); }