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.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:org.runway.users.repository.JdbcUserDaoImpl.java

public List<User> getUsersById(List<String> ids) {
    MapSqlParameterSource mapSql = new MapSqlParameterSource();
    mapSql.addValue("IDS", ids);

    String sql = "SELECT * from EM_USERS where ID in ( :IDS )";
    List<User> users = jdbcTemplate.query(sql, new UserMapper(), mapSql);
    return users;
}

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

public User getUserById(String id) {

    MapSqlParameterSource mapSql = new MapSqlParameterSource();
    mapSql.addValue("id", id);

    User user = jdbcTemplate.queryForObject("SELECT * from EM_USERS where ID=:id", new UserMapper(), mapSql);

    return user;//from   ww  w  .  java  2  s.  c om
}

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

private int addRegistration(int customerId, int productId, int providerId, LicenceType licenceType,
        double price) {
    String sql = "INSERT INTO registration (date, customer_id, product_id, provider_id, licence_type, price)"
            + " VALUES (NOW(), :customer_id, :product_id, :provider_id, :licence_type, :price)";

    MapSqlParameterSource args = new MapSqlParameterSource();
    args.addValue("customer_id", customerId);
    args.addValue("product_id", productId);
    args.addValue("provider_id", providerId);
    args.addValue("licence_type", licenceType.getLicenceType());
    args.addValue("price", price);
    KeyHolder keyHolder = new GeneratedKeyHolder();

    jdbcTemplate.update(sql, args, keyHolder);

    return keyHolder.getKey().intValue();
}

From source file:com.eu.evaluation.server.dao.DefaultDAO.java

/**
 * ?//from w  ww.  jav a  2s.  com
 * @param <T>
 * @param className ???
 * @param id ?ID
 * @param evaluateVersionID ?
 * @return 
 */
public <T> T findEvaluateData(String className, String id, String evaluateVersionID,
        AccessSystem accessSystem) {
    String jpql = "select t from {0} t where t.id = :id and t.evaluateVersion.id = :evID and t.position = :position";
    jpql = MessageFormat.format(jpql, new Object[] { className });
    MapSqlParameterSource params = new MapSqlParameterSource("id", id);
    params.addValue("evID", evaluateVersionID);
    params.addValue("position", accessSystem.getCode());
    List<T> result = find(jpql, params);
    if (result.isEmpty()) {
        String msg = "??{0}  ?ID {1}  ? {2} , ? {3}";
        throw new RuntimeException(MessageFormat.format(msg,
                new Object[] { className, id, evaluateVersionID, accessSystem.getName() }));
    } else if (result.size() == 1) {
        return result.get(0);
    } else {
        String msg = "????{0}  ?ID {1}  ? {2} , ? {3}";
        throw new RuntimeException(MessageFormat.format(msg,
                new Object[] { className, id, evaluateVersionID, accessSystem.getName() }));
    }
}

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

public void collate(EvaluateVersion ev) {

    List<AccessSystem> systems = accessSystemDAO.findByEvaluateVersion(ev.getId());
    for (AccessSystem system : systems) {
        //?SimpleStatistics
        simpleStatisticsDAO.delete(ev, system);

        //?ResultSimpleStatistics??????
        List<SimpleStatistics> statisticses = resultDAO.groupToSimpleStatistics(ev, system);

        //???????
        List<SimpleStatistics> list = unPassedEvaluatedDataDAO.countToSimpleStatistics(ev, system);

        //SimpleStatistics??????
        for (SimpleStatistics simpleStatistics : statisticses) {
            //??/*w w w . j  av  a 2  s. c  o  m*/
            String jpql = "select count(*) from {0} t where t.evaluateVersion.id = :evid and t.position = :position";
            jpql = MessageFormat.format(jpql, new Object[] { simpleStatistics.getInstanceClass() });
            MapSqlParameterSource params = new MapSqlParameterSource();
            params.addValue("evid", ev.getId());
            params.addValue("position", system.getCode());
            Long total = defaultDAO.executeCount(jpql, params);
            simpleStatistics.setTotal(total);

            //?
            for (SimpleStatistics ss : list) {
                if (ss.getInstanceType() == simpleStatistics.getInstanceType()
                        && ss.getEvaluateTypeEnum() == simpleStatistics.getEvaluateTypeEnum()) {
                    simpleStatistics.setFailCount(ss.getFailCount());
                    break;
                }
            }

            //?
            simpleStatistics.setSuccessCount(simpleStatistics.getTotal() - simpleStatistics.getFailCount());

            //?
            simpleStatistics.setEvaluateVersion(ev);
            simpleStatistics.setPosition(system.getCode());
        }

        this.simpleStatisticsDAO.save(statisticses);

    }

}

From source file:com.neeti.neg.dao.impl.RegisterUserDaoImpl.java

@Override
public int getGameId(String gameRefId, String pass) {
    MapSqlParameterSource namedParameters = new MapSqlParameterSource();
    namedParameters.addValue("gamereqid", gameRefId);
    namedParameters.addValue("gamepassword", pass);

    int temp = 0;
    try {//from   w w w. j ava2  s  . c  o  m
        temp = this.namedParameterJdbcTemplate.queryForInt(SQL_GETGAMEREF, namedParameters);
    } catch (Exception e) {
        e.printStackTrace();
        temp = 0;
    } finally {
        //status=(boolean) temp;
        return temp;

    }
}

From source file:com.lixiaocong.social.MyJdbcUsersConnection.java

public Set<String> findUserIdsConnectedTo(String providerId, Set<String> providerUserIds) {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("providerId", providerId);
    parameters.addValue("providerUserIds", providerUserIds);
    final Set<String> localUserIds = new HashSet<String>();
    return new NamedParameterJdbcTemplate(jdbcTemplate).query(
            "select userId from " + tablePrefix
                    + "UserConnection where providerId = :providerId and providerUserId in (:providerUserIds)",
            parameters, new ResultSetExtractor<Set<String>>() {
                public Set<String> extractData(ResultSet rs) throws SQLException, DataAccessException {
                    while (rs.next()) {
                        localUserIds.add(rs.getString("userId"));
                    }//from  w  ww  . j  a v a  2  s . c  o  m
                    return localUserIds;
                }
            });
}

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

@Override
public LicenceReply get(KeyRequest keyRequest) {

    LicenceReply lr = null;//from  w  ww  . j  a  v  a2  s .co 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:airport.database.services.setting.SettingFrontEndDaoImpl.java

@Override
public void setSettingFrontEnd(User user, SettingFrontEnd settingFrontEnd) {
    MapSqlParameterSource mapSqlParameterSource = new MapSqlParameterSource();

    mapSqlParameterSource.addValue("checkSettingMusicAirplane", settingFrontEnd.getCheckSettingMusicAirplane());
    mapSqlParameterSource.addValue("checkSettingMusicChat", settingFrontEnd.getCheckSettingMusicChat());
    mapSqlParameterSource.addValue("checkSettingMusicService", settingFrontEnd.getCheckSettingMusicService());
    mapSqlParameterSource.addValue("checkSettingShowClock", settingFrontEnd.getCheckSettingShowClock());
    mapSqlParameterSource.addValue("checkSettingShowDispatcherOnline",
            settingFrontEnd.getCheckSettingShowDispatcherOnline());
    mapSqlParameterSource.addValue("checkSettingShowNewMessage",
            settingFrontEnd.getCheckSettingShowNewMessage());
    mapSqlParameterSource.addValue("checkSettingShowProfile", settingFrontEnd.getCheckSettingShowProfile());
    mapSqlParameterSource.addValue("checkSettingShowWeather", settingFrontEnd.getCheckSettingShowWeather());
    mapSqlParameterSource.addValue("id", user.getId());

    jdbcOperations.update(SQL_QUERY_UPDATE_SETTING, mapSqlParameterSource);

    if (LOG.isInfoEnabled()) {
        LOG.info("set setting front end of user. User : " + user + ". SettingFrontEnd " + settingFrontEnd);
    }/*  ww  w .j  a  v  a  2s  . c o m*/
}