List of usage examples for org.springframework.jdbc.core.namedparam MapSqlParameterSource MapSqlParameterSource
public MapSqlParameterSource()
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
public Category loadCategory(String categoryCode) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_CATEGORY + " FROM ftb_category WHERE cat_code=:cat_code"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("cat_code", categoryCode); LOG.info(sql);/*w w w.j av a2 s . c om*/ TreebankDaoImpl.LogParameters(paramSource); Category category = null; try { category = (Category) jt.queryForObject(sql, paramSource, new CategoryMapper()); } catch (EmptyResultDataAccessException ex) { ex.hashCode(); } return category; }
From source file:alfio.datamapper.QueryType.java
private static SqlParameterSource extractParameters(Method m, Object[] args) { Annotation[][] parameterAnnotations = m.getParameterAnnotations(); if (parameterAnnotations == null || parameterAnnotations.length == 0) { return new EmptySqlParameterSource(); }/*from www . j a va2 s . c o m*/ MapSqlParameterSource ps = new MapSqlParameterSource(); Class<?>[] parameterTypes = m.getParameterTypes(); for (int i = 0; i < args.length; i++) { String name = parameterName(parameterAnnotations[i]); if (name != null) { if (args[i] != null && ZonedDateTime.class.isAssignableFrom(parameterTypes[i])) { ZonedDateTime dateTime = ZonedDateTime.class.cast(args[i]); final ZonedDateTime utc = dateTime.withZoneSameInstant(ZoneId.of("UTC")); Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone("UTC")); c.setTimeInMillis(utc.toInstant().toEpochMilli()); ps.addValue(name, c, Types.TIMESTAMP); } else { ps.addValue(name, args[i], StatementCreatorUtils.javaTypeToSqlParameterType(parameterTypes[i])); } } } return ps; }
From source file:org.aksw.gerbil.database.ExperimentDAOImpl.java
@Override public List<ExperimentTaskResult> getResultsOfExperiment(String experimentId) { MapSqlParameterSource parameters = new MapSqlParameterSource(); parameters.addValue("id", experimentId); List<ExperimentTaskResult> result = this.template.query(GET_EXPERIMENT_RESULTS, parameters, new ExperimentTaskResultRowMapper()); return result; }
From source file:com.team3637.service.TeamServiceMySQLImpl.java
@Override public void update(Team team) { Team oldTeam = getTeamByNumber(team.getTeam()); int diff = oldTeam.getTags().size() - team.getTags().size(); String valuesSting = "team=?, avgscore=?, matches=?", SQL; List<Object> values = new ArrayList<>(); values.add(team.getTeam());//from w ww . j a va 2s. c o m values.add(team.getAvgscore()); values.add(team.getMatches()); if (diff <= 0) { for (int i = 0; i < team.getTags().size(); i++) { valuesSting += ", tag" + i + "=?"; values.add(team.getTags().get(i)); } } else { for (int i = 0; i < oldTeam.getTags().size(); i++) { valuesSting += ", tag" + i + "=?"; if (team.getTags().size() > i) values.add(team.getTags().get(i)); else values.add(null); } } SQL = "UPDATE teams SET " + valuesSting + " WHERE team=" + team.getTeam() + ";"; SqlParameterSource in = new MapSqlParameterSource().addValue("ignoreCols", 4).addValue("tableName", "teams") .addValue("newCols", team.getTags().size()); addCols.execute(in); jdbcTemplateObject.update(SQL, values.toArray()); for (String tagName : team.getTags()) { SqlParameterSource addTagArg = new MapSqlParameterSource().addValue("tableName", "teams") .addValue("tagName", tagName); addTag.execute(addTagArg); } }
From source file:airport.database.services.users.UsersDaoOnlineImpl.java
@Override public List<User> getUsersSour(Date timeDifference, int secondsLimit) { MapSqlParameterSource parametrQuery = new MapSqlParameterSource(); parametrQuery.addValue("difference", new Timestamp(timeDifference.getTime())); parametrQuery.addValue("limit", secondsLimit); List<User> resultUsers; try {//from ww w . j a v a 2 s.c om resultUsers = jdbcTemplate.query(SQL_QUERY_SELECT_SOUR_USER, parametrQuery, new UserSourMapper()); } catch (EmptyResultDataAccessException e) { if (LOG.isInfoEnabled()) { LOG.info("Users aren't exist which not online"); } return new ArrayList<>(); } if (LOG.isInfoEnabled()) { LOG.info("get users which not online. Users not online: " + resultUsers); } return resultUsers; }
From source file:com.joliciel.jochre.boundaries.BoundaryDaoJdbc.java
@Override public void deleteSplit(Split split) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("split_id", split.getId()); String sql = null;//from w w w . j a v a2 s.com sql = "delete from ocr_split where split_id = :split_id"; LOG.debug(sql); logParameters(paramSource); jt.update(sql, paramSource); }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaPlaceDao.java
/** * For the given list of new drops, find those that the place hash already * exists in the db and update the drop entry with the existing id. Also * remove the hash from the new place index for those that already exist. * /*from ww w. j ava 2 s .c o m*/ * @param newPlaceIndex * @param drops */ private void updateNewPlaceIndex(Map<String, List<int[]>> newPlaceIndex, List<Drop> drops) { // First find and update existing drops with their ids. String sql = "SELECT id, hash FROM places WHERE hash IN (:hashes)"; MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("hashes", newPlaceIndex.keySet()); List<Map<String, Object>> results = this.namedJdbcTemplate.queryForList(sql, params); // Update id for the drops that were found for (Map<String, Object> result : results) { String hash = (String) result.get("hash"); Long id = ((Number) result.get("id")).longValue(); List<int[]> indexes = newPlaceIndex.get(hash); for (int[] index : indexes) { drops.get(index[0]).getPlaces().get(index[1]).setId(id); } // Hash is not for a new drop so remove it newPlaceIndex.remove(hash); } }
From source file:com.epam.catgenome.dao.reference.ReferenceGenomeDao.java
/** * Persists a {@code Reference} entity in database with a specified ID * @param reference to persist//from w w w . ja v a2 s . c o m * @param referenceId ID for the reference * @return saved {@code Reference} instance */ @Transactional(propagation = Propagation.MANDATORY) public Reference createReferenceGenome(final Reference reference, final long referenceId) { reference.setBioDataItemId(reference.getId()); reference.setId(referenceId); final MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(GenomeParameters.REFERENCE_GENOME_ID.name(), reference.getId()); params.addValue(GenomeParameters.BIO_DATA_ITEM_ID.name(), reference.getBioDataItemId()); params.addValue(GenomeParameters.SIZE.name(), reference.getSize()); params.addValue(GenomeParameters.INDEX_ID.name(), reference.getIndex().getId()); params.addValue(GenomeParameters.GENE_ITEM_ID.name(), reference.getGeneFile() != null ? reference.getGeneFile().getId() : null); getNamedParameterJdbcTemplate().update(createReferenceGenomeQuery, params); return reference; }
From source file:com.joliciel.jochre.doc.DocumentDaoJdbc.java
@Override public void deleteJochrePage(JochrePage page) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("page_id", page.getId()); String sql = null;//from www. j a v a 2 s . com sql = "delete from ocr_page" + " WHERE page_id = :page_id"; LOG.info(sql); logParameters(paramSource); jt.update(sql, paramSource); }
From source file:com.team3637.service.MatchServiceMySQLImpl.java
@Override public void update(Match match) { Match oldMatch = getForMatchAndTeam(match.getMatchNum(), match.getTeam()); int diff = oldMatch.getTags().size() - match.getTags().size(); String valuesSting = "matchNum=?, team=?, score=?", SQL; SQL = "SELECT `score` FROM matches WHERE `matchNum` = ? AND `team` = ?"; Integer oldScore = jdbcTemplateObject.queryForObject(SQL, Integer.class, match.getMatchNum(), match.getTeam());// w ww .ja va 2s .c o m List<Object> values = new ArrayList<>(); values.add(match.getMatchNum()); values.add(match.getTeam()); values.add(match.getScore()); if (diff <= 0) { for (int i = 0; i < match.getTags().size(); i++) { valuesSting += ", tag" + i + "=?"; values.add(match.getTags().get(i)); } } else { for (int i = 0; i < oldMatch.getTags().size(); i++) { valuesSting += ", tag" + i + "=?"; if (match.getTags().size() > i) values.add(match.getTags().get(i)); else values.add(null); } } SQL = "UPDATE matches SET " + valuesSting + " WHERE matchNum = " + match.getMatchNum() + " AND team = " + match.getTeam() + ";"; SqlParameterSource in = new MapSqlParameterSource().addValue("ignoreCols", 4) .addValue("tableName", "matches").addValue("newCols", match.getTags().size()); addCols.execute(in); jdbcTemplateObject.update(SQL, values.toArray()); for (String tagName : match.getTags()) { SQL = "SELECT count(*) FROM tags WHERE tag = ? AND type = ?"; Integer count = jdbcTemplateObject.queryForObject(SQL, Integer.class, tagName, "matches"); if (count <= 0) { SQL = "INSERT INTO tags (tag, type) VALUES (?, ?)"; jdbcTemplateObject.update(SQL, tagName, "matches"); } } SQL = "UPDATE teams SET `avgscore` = IF(`matches` > 1, (`avgscore` * `matches` - ? + ?) / `matches`, 0) " + "WHERE `team` = ?"; jdbcTemplateObject.update(SQL, match.getScore(), oldScore, match.getTeam()); }