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

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

Introduction

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

Prototype

public MapSqlParameterSource addValue(String paramName, @Nullable Object value) 

Source Link

Document

Add a parameter to this parameter source.

Usage

From source file:org.voltdb.example.springjdbc.ContestantDao.java

public List<ContestantData> findContestant(String code) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("code", new SqlParameterValue(Types.VARCHAR, code));
    return query(selectSql, params, new ContestantRowMapper());
}

From source file:org.voltdb.example.springjdbc.ContestantDao.java

public int deleteContestant(String code) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("code", new SqlParameterValue(Types.VARCHAR, code));
    return update(deleteByCode, params);
}

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:com.mesut.daopattern.OffersDAO.java

public Offer findById(int id) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("id", id);
    return jdbc.queryForObject("select * from offers where id= :id", params, new RowMapper<Offer>() {

        public Offer mapRow(ResultSet rs, int i) throws SQLException {
            Offer offer = new Offer();
            offer.setId(rs.getInt("id"));
            offer.setName(rs.getString("name"));
            offer.setEmail(rs.getString("email"));
            offer.setText(rs.getString("text"));
            return offer;
        }//from   w  ww . ja  v  a  2  s  .  co m
    });
}

From source file:org.voltdb.example.springjdbc.ContestantDao.java

public int insertContestant(String firstName, String lastName, String code) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("firstName", new SqlParameterValue(Types.VARCHAR, firstName));
    params.addValue("lastName", new SqlParameterValue(Types.VARCHAR, lastName));
    params.addValue("code", new SqlParameterValue(Types.VARCHAR, code));

    return update(insertContestant, params);
}

From source file:org.voltdb.example.springjdbc.ContestantDao.java

public int updateContestant(String firstName, String lastName, String code) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("firstName", new SqlParameterValue(Types.VARCHAR, firstName));
    params.addValue("lastName", new SqlParameterValue(Types.VARCHAR, lastName));
    params.addValue("code", new SqlParameterValue(Types.VARCHAR, code));

    return update(updateContestantByCode, params);
}

From source file:com.himanshu.poc.springbootsec.dao.UsersDao.java

public UserDO getUserByUserName(String username) {
    Map<String, UserDO> usersMap = new HashMap<String, UserDO>();
    MapSqlParameterSource sqlParams = new MapSqlParameterSource();
    sqlParams.addValue("username", username);
    namedParameterJdbcTemplate.query(specificUserSql, sqlParams, new UserRowMapper(usersMap));
    logger.info("Total records found : " + usersMap.size());
    return usersMap.get(username);
}

From source file:com.eu.evaluation.server.service.impl.DataServiceImpl.java

public void copyData(EvaluateVersion ev, AccessSystem system) {
    List<ObjectDictionary> ods = objectDictionaryDAO.findAndOrder();

    String sqlTemp = "insert into {0} ( {1} ) select {2} , ''{3}'' from {4} o "
            + "where o.position = :position "
            + "and not exists (select 1 from {5} t where t.id = o.id and t.evaluateVersion_id = :evid and t.position = :position)";
    for (ObjectDictionary od : ods) {
        List<String> fds = fieldDictionaryDAO.findByObject(od.getId());
        String orgFieldStr = StringUtils.arrayToCommaDelimitedString(fds.toArray(new String[] {}));

        fds.add("evaluateVersion_id");
        String feildStr = StringUtils.arrayToCommaDelimitedString(fds.toArray(new String[] {}));

        String tableName = od.getTableName();
        String orgTableName = tableName + "_org";

        String sql = MessageFormat.format(sqlTemp,
                new Object[] { tableName, feildStr, orgFieldStr, ev.getId(), orgTableName, tableName });
        logger.debug("??sql" + sql);

        MapSqlParameterSource params = new MapSqlParameterSource("evid", ev.getId());
        params.addValue("position", system.getCode());
        defaultDAO.executeNativeInsert(sql, params);
    }// www .j  a v  a 2 s.com
}

From source file:org.runway.users.repository.JdbcUserProfileDaoImpl.java

public List<UserProfile> getUserProfile(String userid) {
    MapSqlParameterSource mapSql = new MapSqlParameterSource();
    mapSql.addValue("id", userid);

    String querySql = "SELECT id, key1, value, em_time from EM_USER_PROFILE where id=:id";

    List<UserProfile> profiles = jdbcTemplate.query(querySql, new UserProfileMapper(), mapSql);
    return profiles;
}

From source file:org.sakuli.services.forwarder.database.dao.impl.DaoTestCaseStepImpl.java

@Override
public void saveTestCaseSteps(SortedSet<TestCaseStep> steps, int primaryKeyOfTestCase) {
    for (TestCaseStep step : steps) {
        LOGGER.info("============== save STEP \"" + step.getName() + "\" ==============");
        MapSqlParameterSource stepParameters = new MapSqlParameterSource();
        stepParameters.addValue("sakuli_cases_id", primaryKeyOfTestCase);
        stepParameters.addValue("result", step.getState().getErrorCode());
        stepParameters.addValue("result_desc", step.getState());
        stepParameters.addValue("name", step.getName());
        stepParameters.addValue("start", step.getStartDateAsUnixTimestamp());
        stepParameters.addValue("stop", step.getStopDateAsUnixTimestamp());
        int warningTime = step.getWarningTime();
        stepParameters.addValue("warning", (warningTime != 0) ? warningTime : null);
        stepParameters.addValue("duration", step.getDuration());

        LOGGER.debug("write the following values to 'sakuli_steps': " + stepParameters.getValues()
                + "\n now execute ....");

        //generate the sql-statement
        SimpleJdbcInsert insertStepResults = new SimpleJdbcInsert(getDataSource()).withTableName("sakuli_steps")
                .usingGeneratedKeyColumns("id");

        //execute the sql-statement and save the primary key
        int dbPrimaryKey = insertStepResults.executeAndReturnKey(stepParameters).intValue();
        LOGGER.info("test case step '" + step.getName()
                + "' has been written to 'sakuli_steps' with  primaryKey=" + dbPrimaryKey);
        step.setDbPrimaryKey(dbPrimaryKey);
    }//from w ww  .ja  v  a  2  s .c  o  m
}