List of usage examples for org.springframework.jdbc.core.namedparam MapSqlParameterSource MapSqlParameterSource
public MapSqlParameterSource(String paramName, @Nullable Object value)
From source file:org.string_db.jdbc.ProteinRepositoryJdbc.java
@Override public Map<Integer, String> loadProteinSequences(Integer speciesId) { return queryProcessor.selectTwoColumns("protein_id", /**/"\"sequence\"", "items.proteins_sequences", TwoColumnRowMapper.<Integer, String>uniqueValMapper(), " protein_id IN (select protein_id from items.proteins where species_id = :species_id );", new MapSqlParameterSource("species_id", speciesId)); }
From source file:orz.neptune.prospring3.ch8.JdbcContactDao.java
public String findLastNameByIdUsingNamedParameter(Long id) { String sql = "select last_name from contact where id = :contactId"; SqlParameterSource namedParameters = new MapSqlParameterSource("contactId", id); return namedParameterJdbcTemplate.queryForObject(sql, namedParameters, String.class); }
From source file:fi.luontola.cqrshotel.framework.PsqlEventStore.java
@Override public List<Event> getAllEvents(long sincePosition) { return jdbcTemplate.query( "SELECT e.data, e.metadata " + "FROM event e " + "JOIN event_sequence s USING (stream_id, version) " + "WHERE s.position > :position " + "ORDER BY s.position", new MapSqlParameterSource("position", sincePosition), this::eventMapping); }
From source file:com.eu.evaluation.server.service.impl.EvaluateServiceImpl.java
public <T> List<T> findEvaluatedEntity(EvaluateItemHistory itemHistory, AccessSystem system) { itemHistory = evaluateItemHistoryDAO.get(itemHistory.getId()); String jpql = "select t from {0} t " + "where t.evaluateVersion.id = :evid " + "and t.position = :position " + "and not exists " + " (select 1 from Result r " + " where r.itemHistory.id = :hid " + " and r.evaluateVersion.id = :evid " + " and r.instanceId = t.id" + " and r.position = :position)"; jpql = MessageFormat.format(jpql, new Object[] { itemHistory.getObjectDictionary().getInstanceClass() }); MapSqlParameterSource params = new MapSqlParameterSource("evid", itemHistory.getEvaluateVersion().getId()); params.addValue("hid", itemHistory.getId()); params.addValue("position", system.getCode()); return defaultDAO.find(jpql, params); }
From source file:io.lavagna.service.NotificationService.java
/** * Return a list of user id to notify./*from www .j a v a 2 s .co m*/ * * @param upTo * @return */ public Set<Integer> check(Date upTo) { final List<Integer> userWithChanges = new ArrayList<>(); List<SqlParameterSource> res = jdbc.query(queries.countNewForUsersId(), new RowMapper<SqlParameterSource>() { @Override public SqlParameterSource mapRow(ResultSet rs, int rowNum) throws SQLException { int userId = rs.getInt("USER_ID"); userWithChanges.add(userId); return new MapSqlParameterSource("count", rs.getInt("COUNT_EVENT_ID")).addValue("userId", userId); } }); if (!res.isEmpty()) { jdbc.batchUpdate(queries.updateCount(), res.toArray(new SqlParameterSource[res.size()])); } queries.updateCheckDate(upTo); // select users that have pending notifications that were not present in this check round MapSqlParameterSource userWithChangesParam = new MapSqlParameterSource("userWithChanges", userWithChanges); // List<Integer> usersToNotify = jdbc.queryForList( queries.usersToNotify() + " " + (userWithChanges.isEmpty() ? "" : queries.notIn()), userWithChangesParam, Integer.class); // jdbc.update(queries.reset() + " " + (userWithChanges.isEmpty() ? "" : queries.notIn()), userWithChangesParam); // return new TreeSet<>(usersToNotify); }
From source file:io.lavagna.service.BoardColumnRepository.java
/** * update column order in a given board/location. The column ids are filtered. * /* ww w .j ava 2 s . c o m*/ * @param columns * @param boardId * @param location */ @Transactional(readOnly = false) public void updateColumnOrder(List<Integer> columns, int boardId, BoardColumnLocation location) { Objects.requireNonNull(columns); Objects.requireNonNull(location); // keep only the columns that are inside the boardId and have location=board List<Integer> filteredColumns = Utils.filter(columns, queries.findColumnIdsInBoard(columns, location.toString(), boardId)); // SqlParameterSource[] params = new SqlParameterSource[filteredColumns.size()]; for (int i = 0; i < filteredColumns.size(); i++) { params[i] = new MapSqlParameterSource("order", i + 1).addValue("columnId", filteredColumns.get(i)) .addValue("boardId", boardId).addValue("location", location.toString()); } jdbc.batchUpdate(queries.updateColumnOrder(), params); }
From source file:org.string_db.jdbc.ProteinRepositoryJdbc.java
@Override public Map<Integer, UniprotAC> loadUniqueUniProtIds(Integer speciesId) { return queryProcessor.selectTwoColumns("protein_id", "protein_name", "items.proteins_names", uniprotAcMapper, "linkout = 'UniProt' AND species_id = :species_id", new MapSqlParameterSource("species_id", speciesId)); }
From source file:fi.luontola.cqrshotel.framework.PsqlEventStore.java
@Override public int getCurrentVersion(UUID streamId) { List<Integer> version = jdbcTemplate.queryForList("SELECT version FROM stream WHERE stream_id = :stream_id", new MapSqlParameterSource("stream_id", streamId), Integer.class); return version.isEmpty() ? BEGINNING : version.get(0); }
From source file:alfio.manager.UploadedResourceManager.java
public void outputResource(int organizationId, String name, OutputStream out) { SqlParameterSource param = new MapSqlParameterSource("name", name).addValue("organizationId", organizationId);/*from w ww . j a va2 s.c om*/ jdbc.query(uploadedResourceRepository.fileContentTemplate(organizationId, name), param, rs -> { try (InputStream is = rs.getBinaryStream("content")) { StreamUtils.copy(is, out); } catch (IOException e) { throw new IllegalStateException("Error while copying data", e); } }); }
From source file:com.exploringspatial.dao.impl.ConflictDaoImpl.java
@Override public Conflict get(Long eventPk) { final String sql = selectSql.concat(" WHERE EVENT_ID_NO_CNTY = :eventPk"); final MapSqlParameterSource params = new MapSqlParameterSource("eventPk", eventPk); List<Conflict> conflicts = namedParameterJdbcTemplate.query(sql, params, new ConflictRowMapper()); if (conflicts.isEmpty()) { return null; }/*w w w.j a va 2s .c om*/ return conflicts.get(0); }