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.jochre.graphics.GraphicsDaoJdbc.java

@Override
public Shape loadShape(int shapeId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_SHAPE + " FROM ocr_shape WHERE shape_id=:shape_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("shape_id", shapeId);

    LOG.debug(sql);/*from  w  w  w.j a v  a 2 s  .  c  o m*/
    logParameters(paramSource);
    Shape shape = null;
    try {
        shape = (Shape) jt.queryForObject(sql, paramSource, new ShapeMapper(this.getGraphicsServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return shape;
}

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

@Override
public void deleteTemp(int productId) {
    // remove temp since it is read-only for only one time.
    String sql = "UPDATE product SET temp = NULL WHERE id = :id";
    SqlParameterSource args = new MapSqlParameterSource().addValue("id", productId);
    jdbcTemplate.update(sql, args);/*from   w  ww  . j a v a2s. c o  m*/
}

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:tomekkup.helenos.dao.AccountDao.java

public List<QxAccount> loadAll() {
    return jdbcTemplate.query(queriesProperties.getProperty("user.select.star"), new MapSqlParameterSource(),
            new UserMapper());
}

From source file:net.mindengine.oculus.frontend.db.jdbc.MySimpleJdbcDaoSupport.java

/**
 * Executes the SQL command and returns the long value of counts of entities
 * //from w  w  w. jav  a 2  s  . c  o  m
 * @param sql
 *            SQL command string
 * @param args
 *            An array of pairs of name and value for the
 *            {@link MapSqlParameterSource}
 * @return
 * @throws Exception
 */
public Long count(String sql, Object... args) throws Exception {
    MapSqlParameterSource map = new MapSqlParameterSource();
    for (int i = 0; i < args.length; i += 2) {
        map.addValue((String) args[i], args[i + 1]);
    }
    return getSimpleJdbcTemplate().queryForLong(sql, map);
}

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:org.inbio.modeling.core.dao.impl.LayerDAOImpl.java

@Override
public void deleteById(Long id) {
    String deleteStatement = null;
    MapSqlParameterSource args = null;//from   w  ww . jav  a  2 s. c  o  m

    deleteStatement = "DELETE FROM " + this.table + " WHERE id = :identification ";

    args = new MapSqlParameterSource();
    args.addValue("identification", id);

    getSimpleJdbcTemplate().update(deleteStatement, args);

}

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

public Attribute loadAttribute(String attributeCode, String attributeValue) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());

    String sql = "SELECT " + SELECT_ATTRIBUTE + " FROM lef_attribute" + " WHERE attribute_code=:attribute_code"
            + " AND attribute_value=:attribute_value";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("attribute_code", attributeCode);
    paramSource.addValue("attribute_value", attributeValue);

    LOG.info(sql);//from   w w  w . ja  v a 2s  .co  m
    LefffDaoImpl.LogParameters(paramSource);
    Attribute attribute = null;
    try {
        attribute = (Attribute) jt.queryForObject(sql, paramSource,
                new AttributeMapper(this.getLefffServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return attribute;
}

From source file:ru.org.linux.user.UserTagDao.java

/**
 *  ?? ?  ? ?.//from   w w w . j  a va 2  s  .co m
 *
 * @param userId       ?
 * @param isFavorite    (true)   (false)
 * @return ??  ?
 */
public ImmutableList<String> getTags(int userId, boolean isFavorite) {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("user_id", userId);
    parameters.addValue("is_favorite", isFavorite);

    final ImmutableList.Builder<String> tags = ImmutableList.builder();

    jdbcTemplate.query("SELECT tags_values.value FROM user_tags, tags_values WHERE "
            + "user_tags.user_id=:user_id AND tags_values.id=user_tags.tag_id AND user_tags.is_favorite=:is_favorite "
            + "ORDER BY value", parameters, new RowCallbackHandler() {
                @Override
                public void processRow(ResultSet rs) throws SQLException {
                    tags.add(rs.getString("value"));
                }
            });

    return tags.build();
}

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

@Override
public Page<JobExecution> find(String jobGroup, String jobName, Query query) {
    String sql = "from " + getTableName() + " where jobGroup = :jobGroup and jobName = :jobName";

    SqlParameterSource source = new MapSqlParameterSource().addValue("jobGroup", jobGroup).addValue("jobName",
            jobName);/*  www  .j a  v a  2 s  . co m*/

    return getLogs(sql, source, query);
}