Example usage for org.springframework.jdbc.core.namedparam MapSqlParameterSource MapSqlParameterSource

List of usage examples for org.springframework.jdbc.core.namedparam MapSqlParameterSource MapSqlParameterSource

Introduction

In this page you can find the example usage for org.springframework.jdbc.core.namedparam MapSqlParameterSource MapSqlParameterSource.

Prototype

public MapSqlParameterSource() 

Source Link

Document

Create an empty MapSqlParameterSource, with values to be added via addValue .

Usage

From source file:com.joliciel.lefff.LefffDaoImpl.java

public void savePredicate(PredicateInternal predicate) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("predicate_text", predicate.getText());
    if (predicate.isNew()) {
        String sql = "SELECT nextval('seq_predicate_id')";
        LOG.info(sql);//w  w w  . j a va  2s  .c  o  m
        int predicateId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("predicate_id", predicateId);

        sql = "INSERT INTO lef_predicate (predicate_id, predicate_text) VALUES (:predicate_id, :predicate_text)";

        LOG.info(sql);
        LefffDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);
        predicate.setId(predicateId);
    } else {
        String sql = "UPDATE lef_predicate" + " SET predicate_text = :predicate_text"
                + " WHERE predicate_id = :predicate_id";

        paramSource.addValue("predicate_id", predicate.getId());
        LOG.info(sql);
        LefffDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);
    }
}

From source file:com.team3637.service.TagServiceMySQLImpl.java

@Override
public void mergeTags(Tag oldTag, Tag newTag) {
    if (!oldTag.getType().equals(newTag.getType()))
        return;//from w w w  . j a  v  a  2s  .c o  m
    SqlParameterSource args = new MapSqlParameterSource().addValue("tableName", oldTag.getType())
            .addValue("noTagCols", 4).addValue("oldTag", oldTag.getTag()).addValue("newTag", newTag.getTag());
    mergeTags.execute(args);
    delete(oldTag.getTag());
}

From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaRiverDao.java

public List<RiverTagTrend> getTrendingTags(Long riverId, TrendFilter trendFilter) {
    int count = trendFilter.getCount();
    int page = trendFilter.getPage();

    String sql = "SELECT a.tag, a.tag_type, SUM(a.count) AS tag_count, " + "a.date_pub AS trend_date "
            + "FROM river_tag_trends a " + "WHERE a.tag_type <> 'place' " + "AND a.river_id = :riverId ";

    if (trendFilter.getDateFrom() != null) {
        sql += "AND a.date_pub > :dateFrom ";
    }/*from   w w  w  .j a  va  2s.  c  om*/

    if (trendFilter.getDateTo() != null) {
        sql += "AND a.date_pub <= :dateTo ";
    }

    sql += "GROUP BY a.tag, a.tag_type, trend_date ORDER BY `trend_date` ASC " + "LIMIT " + count + " OFFSET "
            + count * (page - 1);

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("riverId", riverId);

    if (trendFilter.getDateFrom() != null) {
        params.addValue("dateFrom", trendFilter.getDateFrom());
    }

    if (trendFilter.getDateTo() != null) {
        params.addValue("dateTo", trendFilter.getDateTo());
    }

    List<RiverTagTrend> tagTrends = new ArrayList<RiverTagTrend>();
    for (Map<String, Object> row : jdbcTemplate.queryForList(sql, params)) {
        RiverTagTrend tagTrend = new RiverTagTrend();

        tagTrend.setTag((String) row.get("tag"));
        tagTrend.setTagType((String) row.get("tag_type"));
        tagTrend.setCount(((Number) row.get("tag_count")).longValue());
        tagTrend.setDatePublished((Date) row.get("trend_date"));

        tagTrends.add(tagTrend);
    }

    return tagTrends;
}

From source file:org.owasp.proxy.http.dao.JdbcMessageDAO.java

public MutableResponseHeader loadResponseHeader(int id) throws DataAccessException {
    try {//from   ww w  . ja va  2  s. c o m
        MapSqlParameterSource params = new MapSqlParameterSource();
        params.addValue(ID, id, Types.INTEGER);
        SimpleJdbcTemplate template = new SimpleJdbcTemplate(getNamedParameterJdbcTemplate());
        return template.queryForObject(SELECT_RESPONSE, RESPONSE_MAPPER, params);
    } catch (EmptyResultDataAccessException erdae) {
        return null;
    }
}