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:org.smigo.comment.JdbcCommentDao.java

@Override
public int addComment(Comment comment, int submitter) {
    MapSqlParameterSource parameterSource = new MapSqlParameterSource();
    parameterSource.addValue("TEXT", comment.getText());
    parameterSource.addValue("SUBMITTER_USER_ID", submitter);
    parameterSource.addValue("RECEIVER_USER_ID", comment.getReceiverUserId());
    parameterSource.addValue("YEAR", comment.getYear());
    parameterSource.addValue("UNREAD", comment.isUnread());
    return insert.executeAndReturnKey(parameterSource).intValue();
}

From source file:org.impotch.calcul.impot.cantonal.ge.param.dao.ParametreCommunalJdbcRTaxPPDao.java

@Override
public BigDecimal getTauxCentimes(int annee, int noOFSCommune) {
    String sql = "SELECT PPC.PIC_N_TAUX / 100 " + FROM;
    MapSqlParameterSource param = new MapSqlParameterSource();
    param.addValue("periode", annee);
    param.addValue("noOFS", noOFSCommune);
    return this.getSimpleJdbcTemplate().queryForObject(sql, BigDecimal.class, param);
}

From source file:com.eu.evaluation.server.dao.eva.history.ResultDAO.java

/**
 * ?????SimpleStatistics//from w  ww.  ja va  2 s. c om
 * @param ev
 * @param system
 * @return 
 */
public List<SimpleStatistics> groupToSimpleStatistics(EvaluateVersion ev, AccessSystem system) {
    String jpql = "select new SimpleStatistics(t.instanceType , t.instanceClass , h.evaluateTypeEnum)"
            + " from Result t , EvaluateItemHistory h "
            + "where t.itemHistory.id = h.id and t.evaluateVersion.id = :evid and t.position = :position "
            + "group by t.instanceType , t.instanceClass , h.evaluateTypeEnum";
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("evid", ev.getId());
    params.addValue("position", system.getCode());
    return this.createQuery(jpql, params).getResultList();
}

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

@Override
public void create(Team team) {
    String fieldsSting = "team, avgscore, matches", valuesSting = "?, ?, ?", SQL;
    List<Object> values = new ArrayList<>();
    values.add(team.getTeam());/* w  w  w  .  ja v a2 s  .c  o m*/
    values.add(team.getAvgscore());
    values.add(team.getMatches());
    for (int i = 0; i < team.getTags().size(); i++) {
        fieldsSting += ", tag" + i;
        valuesSting += ", ?";
        values.add(team.getTags().get(i));
    }
    SqlParameterSource addColsArg = new MapSqlParameterSource().addValue("tableName", "teams")
            .addValue("ignoreCols", 4).addValue("newCols", team.getTags().size());
    addCols.execute(addColsArg);
    SQL = "INSERT INTO teams (" + fieldsSting + ") VALUES (" + valuesSting + ");";
    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:org.runway.users.repository.JdbcUserDaoImpl.java

public List<User> getUsersByEmail(String email) {
    MapSqlParameterSource args = new MapSqlParameterSource();
    args.addValue("EMAIL", email);

    String querySql = "select * from EM_USERS where EMAIL = :EMAIL ";

    List<User> users = jdbcTemplate.query(querySql, new UserMapper(), args);
    return users;
}

From source file:com.joliciel.jochre.doc.DocumentDaoJdbc.java

@Override
public JochrePage loadJochrePage(int jochrePageId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_PAGE + " FROM ocr_page WHERE page_id=:page_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("page_id", jochrePageId);

    LOG.info(sql);/*from  w  ww  . ja  v a 2  s  .  c  om*/
    logParameters(paramSource);
    JochrePage jochrePage = null;
    try {
        jochrePage = (JochrePage) jt.queryForObject(sql, paramSource,
                new JochrePageMapper(this.getDocumentServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return jochrePage;
}

From source file:com.xinferin.dao.DAOLicenceImpl.java

@Override
public LicenceReply get(KeyRequest keyRequest) {

    LicenceReply lr = null;/*  ww w  .j av a 2  s  .  c o  m*/
    String sql = "SELECT licence_id FROM xlicenser.licence_registration"
            + " WHERE registration_id = (SELECT id FROM xlicenser.registration"
            + "                        WHERE customer_id = (SELECT id FROM xlicenser.customer WHERE email = :email)"
            + ")";
    MapSqlParameterSource args = new MapSqlParameterSource();
    args.addValue("email", keyRequest.getEmail());
    int licence_id_one = jdbcTemplate.queryForObject(sql, args, Integer.class);

    sql = "SELECT id FROM xlicenser.licence WHERE customer_key = :key";
    args = new MapSqlParameterSource();
    args.addValue("key", keyRequest.getKey());
    int licence_id_two = jdbcTemplate.queryForObject(sql, args, Integer.class);

    if (licence_id_one == licence_id_two) {
        sql = "SELECT key_info, generated_key FROM xlicenser.licence WHERE customer_key = :key";
        args = new MapSqlParameterSource();
        args.addValue("key", keyRequest.getKey());

        lr = jdbcTemplate.query(sql, args, new ResultSetExtractor<LicenceReply>() {

            @Override
            public LicenceReply extractData(ResultSet rs) throws SQLException, DataAccessException {

                if (rs.next()) {
                    LicenceReply lr = new LicenceReply();
                    lr.setKey_info(rs.getString("key_info"));
                    lr.setGenerated_key(rs.getString("generated_key"));

                    return lr;
                }
                return null;
            }
        });
    }
    return lr;
}

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

@Override
public void create(Match match) {
    String fieldsSting = "matchNum, team, score", valuesSting = "?, ?, ?", SQL;
    List<Object> values = new ArrayList<>();
    values.add(match.getMatchNum());//  w w w  .j  a va 2 s  .c  o  m
    values.add(match.getTeam());
    values.add(match.getScore());
    for (int i = 0; i < match.getTags().size(); i++) {
        fieldsSting += ", tag" + i;
        valuesSting += ", ?";
        values.add(match.getTags().get(i));
    }
    SqlParameterSource addColsArg = new MapSqlParameterSource().addValue("ignoreCols", 4)
            .addValue("tableName", "matches").addValue("newCols", match.getTags().size());
    addCols.execute(addColsArg);
    SQL = "INSERT INTO matches (" + fieldsSting + ") VALUES (" + valuesSting + ");";
    jdbcTemplateObject.update(SQL, values.toArray());
    for (String tagName : match.getTags()) {
        SqlParameterSource addTagArg = new MapSqlParameterSource().addValue("tableName", "matches")
                .addValue("tagName", tagName);
        addTag.execute(addTagArg);
    }
    SQL = "UPDATE teams SET `avgscore` = (`avgscore` * `matches` + ?) / (`matches` + 1) WHERE `team` = ?";
    jdbcTemplateObject.update(SQL, match.getScore(), match.getTeam());
    SQL = "UPDATE teams SET `matches` = `matches` + 1 WHERE `team` = ?";
    jdbcTemplateObject.update(SQL, match.getTeam());
}

From source file:com.ebay.pulsar.analytics.dao.service.BaseDBService.java

public List<T> getAllByColumnIn(String column, List<?> in, int maxSize) {
    Set<?> unique = Sets.newHashSet(in);
    if (unique.size() == 0)
        return Lists.newArrayList();
    String sql = "select * from " + QUTOA + getTableName() + QUTOA + " where " + QUTOA + column + QUTOA
            + " in (:INPARAMETER)";
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("INPARAMETER", unique);
    return this.getDB().query(sql, parameters, maxSize, mapper());
}

From source file:org.smart.migrate.dao.impl.DefaultImportDao.java

@Override
public List<Map<String, Object>> findSourceByPrimaryKeys(TableSetting tableSetting, List<String> primaryKeys) {

    String sql = "SELECT " + SettingUtils.getSourceFields(tableSetting) + " FROM "
            + tableSetting.getSourceTable();
    sql += " WHERE " + tableSetting.getSourcePK() + " in (:ids) ";

    NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(sourceJdbcTemplate);
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("ids", primaryKeys);
    return namedParameterJdbcTemplate.queryForList(sql, parameters);

}