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.perry.infrastructure.call.CallDaoServiceImpl.java

@Override
public Call create(Call call) {
    String sql = "INSERT INTO calls(\r\n" + //
            "            customer_first_name, customer_last_name, pick_up_location, \r\n" + //
            "            drop_off_location, customer_vehicle_year, customer_vehicle_make, \r\n" + //
            "            customer_vehicle_model, customer_vehicle_color, customer_vehicle_license_plate_number, \r\n"
            + ////from  w w  w . j  a v a2 s . co  m
            "            customer_phone_number, customer_vehicle_key_location, customer_call_type, \r\n" + //
            "            customer_payment_information, insert_by, update_by, truck_id, \r\n" + //
            "            insert_time, update_time)\r\n" + //
            "    VALUES (:customerFirstName, :customerLastName, :pickUpLocation, \r\n" + //
            "            :dropOffLocation, :customerVehicleYear, :customerVehicleMake, \r\n" + //
            "            :customerVehicleModel, :customerVehicleColor, :customerVehicleLiscensePlateNumber, \r\n"
            + //
            "            :customerPhoneNumber, :customerVehicleKeyLocation, :customerCallType, \r\n" + //
            "            :customerPaymentInformation , :insertBy, :updateBy, :truckId, \r\n" + //
            "            :insertTime, :updateTime)";

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("customerFirstName", call.getCustomer().getFirstName());
    params.addValue("customerLastName", call.getCustomer().getLastName());
    params.addValue("pickUpLocation", call.getPickUpLocation());
    params.addValue("dropOffLocation", call.getDropOffLocation());
    params.addValue("customerVehicleYear", call.getCustomer().getVehicle().getYear());
    params.addValue("customerVehicleMake", call.getCustomer().getVehicle().getMake());
    params.addValue("customerVehicleModel", call.getCustomer().getVehicle().getMake());
    params.addValue("customerVehicleColor", call.getCustomer().getVehicle().getColor());
    params.addValue("customerVehicleLiscensePlateNumber",
            call.getCustomer().getVehicle().getLicensePlateNumber());
    params.addValue("customerPhoneNumber", call.getCustomer().getPhoneNumber());
    params.addValue("customerVehicleKeyLocation",
            call.getCustomer().getVehicle().getKeyLocationType().getValue());
    params.addValue("customerCallType", call.getCallType().getValue());
    params.addValue("customerPaymentInformation", call.getCustomer().getVehicle().getMake());
    params.addValue("insertBy", 1);
    params.addValue("updateBy", 1);
    params.addValue("truckId", 0);
    params.addValue("insertTime", Instant.now().getEpochSecond());
    params.addValue("updateTime", Instant.now().getEpochSecond());

    GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
    namedParameterJdbcTemplate.update(sql, params, keyHolder);

    // update call with primary key returned from DB
    call.setId((Long) keyHolder.getKeys().get("call_id"));
    return call;
}

From source file:org.ext4spring.parameter.dao.JdbcParameterRepository.java

@Override
public String getValue(Metadata metadata) {
    MapSqlParameterSource namedParameters = new MapSqlParameterSource();
    namedParameters.addValue("domain", metadata.getDomain());
    namedParameters.addValue("parameter", metadata.getFullParameterName());
    return namedParameterJdbcTemplate.queryForObject(this.selectQuery, namedParameters, String.class);
}

From source file:org.springmodules.samples.cache.guava.repository.jdbc.JdbcPostRepository.java

@Override
public void delete(String userName, int id) {
    getNamedParameterJdbcTemplate().update("delete from posts where user_name = :user_name and id = :id",
            new MapSqlParameterSource().addValue("user_name", userName).addValue("id", id));
}

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

public UserProfile getUserProfile(String userid, String key) {

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

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

    UserProfile profile = jdbcTemplate.queryForObject(querySql, new UserProfileMapper(), mapSql);

    return profile;
}

From source file:com.devicehive.dao.rdbms.DeviceDaoRdbmsImpl.java

/**
 * Method change statuses for devices with guids that consists in the list
 *
 * @param status new status//from  w  w w  . jav  a2s . c  o  m
 * @param guids  list of guids
 */
public void changeStatusForDevices(String status, List<String> guids) {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("status", status);
    parameters.addValue("guids", guids);
    jdbcTemplate.update(UPDATE_DEVICES_STATUSES, parameters);
}

From source file:org.terasoluna.gfw.functionaltest.app.DBLogProvider.java

public long countContainsByRegexExceptionMessage(String xTrack, String loggerNamePattern, String messagePattern,
        String exceptionMessagePattern) {

    StringBuilder sql = new StringBuilder();
    StringBuilder where = new StringBuilder();
    sql.append("SELECT COUNT(e.*) FROM logging_event e");
    where.append(" WHERE e.formatted_message REGEXP :message");

    sql.append(" JOIN logging_event_exception ee ON ee.event_id = e.event_id");
    where.append(" AND ee.I = '0' AND ee.TRACE_LINE REGEXP :exceptionMessage");

    if (StringUtils.hasText(xTrack)) {
        sql.append(" JOIN logging_event_property ep ON ep.event_id = e.event_id");
        where.append(" AND ep.mapped_key = 'X-Track' AND ep.mapped_value = :xTrack");
    }/*from ww  w  . j a  va 2  s .c  om*/
    if (StringUtils.hasText(loggerNamePattern)) {
        where.append(" AND e.logger_name REGEXP :loggerName");
    }
    sql.append(where);

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("xTrack", xTrack);
    params.addValue("loggerName", loggerNamePattern);
    params.addValue("message", messagePattern);
    params.addValue("exceptionMessage", exceptionMessagePattern);
    Long count = jdbcOperations.queryForObject(sql.toString(), params, Long.class);
    return count;
}

From source file:com.joliciel.jochre.boundaries.BoundaryDaoJdbc.java

@Override
public Split loadSplit(int splitId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_SPLIT + " FROM ocr_split WHERE split_id=:split_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("split_id", splitId);

    LOG.debug(sql);/*  w  w  w. j ava2 s .  co  m*/
    logParameters(paramSource);
    Split split = null;
    try {
        split = (Split) jt.queryForObject(sql, paramSource, new SplitMapper(this.getBoundaryServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return split;
}

From source file:com.branded.holdings.qpc.repository.jdbc.JdbcVisitRepositoryImpl.java

/**
 * Creates a {@link MapSqlParameterSource} based on data values from the supplied {@link Visit} instance.
 *//*from   w  w w. j a v  a 2s  .co m*/
private MapSqlParameterSource createVisitParameterSource(Visit visit) {
    return new MapSqlParameterSource().addValue("id", visit.getId())
            .addValue("visit_date", visit.getDate().toDate()).addValue("description", visit.getDescription())
            .addValue("pet_id", visit.getPet().getId());
}

From source file:com.opengamma.elsql.ElSqlBundleTest.java

public void test_getSql() {
    ElSqlBundle test = ElSqlBundle.of(ElSqlConfig.DEFAULT, ElSql.class);
    assertEquals("SELECT * FROM foo ", test.getSql("TestFoo"));
    assertEquals("SELECT * FROM foo ", test.getSql("TestFoo", new MapSqlParameterSource()));
}

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) {
            //??/*from  w ww. ja  v  a2  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);

    }

}