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.inbio.modeling.core.dao.impl.SystemUserDAOImpl.java

@Override
public void createUser(SystemUser newUser) {
    String createStatement = null;
    MapSqlParameterSource args = null;/*w w w. j  a v  a 2 s.c  o m*/

    try {
        createStatement = "INSERT INTO " + this.table + " ( fullname, username, \"password\", enabled, roles)"
                + "VALUES (:fullname, :username, :passwd, :enabled, :roles) ";

        args = new MapSqlParameterSource();
        args.addValue("fullname", newUser.getFullname());
        args.addValue("username", newUser.getUsername());
        args.addValue("passwd", newUser.getPassword());
        args.addValue("enabled", newUser.isEnabled());
        args.addValue("roles", newUser.getRoles());

        getSimpleJdbcTemplate().update(createStatement, args);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.smigo.species.JdbcSpeciesDao.java

@Override
public int addSpecies(int userId) {
    MapSqlParameterSource s = new MapSqlParameterSource();
    s.addValue("creator", userId, Types.INTEGER);
    return insertSpecies.executeAndReturnKey(s).intValue();
}

From source file:com.joliciel.jochre.security.SecurityDaoJdbc.java

@Override
public User loadUser(int userId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_USER + " FROM ocr_user WHERE user_id=:user_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("user_id", userId);

    LOG.info(sql);//from w  w w.  j  av  a 2 s.  co  m
    logParameters(paramSource);
    User user = null;
    try {
        user = (User) jt.queryForObject(sql, paramSource, new UserMapper(this.getSecurityServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return user;
}

From source file:tomekkup.helenos.dao.ClusterConfigDao.java

public List<ClusterConfiguration> loadAll() {
    return jdbcTemplate.query(queriesProperties.getProperty("clusterconfig.select.star"),
            new MapSqlParameterSource(), new ClusterConfigurationMapper());
}

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: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:net.mindengine.oculus.frontend.db.jdbc.MySimpleJdbcDaoSupport.java

/**
 * Executes a sql query and converts the JDBC ResultSet to a list of java
 * bean objects.//from  w ww  . ja  v a 2s.c om
 * 
 * @param sql
 *            The SQL command string
 * @param mapperClass
 *            The end-point class of a java bean
 * @param args
 *            An array of pairs of name and value for the
 *            {@link MapSqlParameterSource}
 * @return A list of mapped java bean objects.
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public <T> List<T> query(String sql, Class<T> mapperClass, Object... args) throws Exception {
    logQuery(sql, args);
    if (args == null)
        return (List<T>) getSimpleJdbcTemplate().query(sql, beanMappingFactory.getBeanMapper(mapperClass));
    MapSqlParameterSource map = new MapSqlParameterSource();
    for (int i = 0; i < args.length; i += 2) {
        map.addValue((String) args[i], args[i + 1]);
    }
    return (List<T>) getSimpleJdbcTemplate().query(sql, beanMappingFactory.getBeanMapper(mapperClass), map);
}

From source file:com.github.dbourdette.glass.log.execution.jdbc.JdbcJobExecutions.java

@Override
public JobExecution jobStarts(JobExecutionContext context) {
    JobExecution execution = new JobExecution();

    execution.fillWithContext(context);/*from  w w w  . j a  v  a 2  s.c  o m*/
    execution.setId(nextId());

    String sql = "insert into " + getTableName()
            + " (id, startDate, ended, jobGroup, jobName, triggerGroup, triggerName, jobClass, dataMap, result)"
            + " values (:id, :startDate, :ended, :jobGroup, :jobName, :triggerGroup, :triggerName, :jobClass, :dataMap, :result)";

    SqlParameterSource params = new MapSqlParameterSource().addValue("id", execution.getId())
            .addValue("startDate", execution.getStartDate()).addValue("ended", execution.isEnded())
            .addValue("jobGroup", execution.getJobGroup()).addValue("jobName", execution.getJobName())
            .addValue("triggerGroup", execution.getTriggerGroup())
            .addValue("triggerName", execution.getTriggerName()).addValue("jobClass", execution.getJobClass())
            .addValue("dataMap", execution.getDataMap()).addValue("result", JobExecutionResult.SUCCESS.name());

    jdbcTemplate.update(sql, params);

    return execution;
}

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

/**
 * ???/*from w  w w.j  av a2s. c  om*/
 * @param evaulateVersionID
 * @param position
 * @param evaluateTypeEnum
 * @return 
 */
public List<SimpleStatistics> find(String evaulateVersionID, String position,
        EvaluateTypeEnum evaluateTypeEnum) {
    String jpql = "select t from SimpleStatistics t where t.evaluateVersion.id = :evid and t.position = :position and t.evaluateTypeEnum = :evaluateTypeEnum";
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("evid", evaulateVersionID);
    params.addValue("position", position);
    params.addValue("evaluateTypeEnum", evaluateTypeEnum);
    return this.query(jpql, params);
}

From source file:com.mesut.daopattern.OffersDAO.java

public boolean deleteById(int id) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("id", id);
    return jdbc.update("delete from offers where id= :id", params) == 1;
}