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

@Override
public Truck assignTruck(long callId, long truckId) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("truckId", truckId);
    params.addValue("callId", callId);
    String sql = "update calls set truck_id = :truckId where call_id = :callId";
    namedParameterJdbcTemplate.update(sql, params);
    Truck truck = truckDaoService.getByIds(Arrays.asList(truckId)).get(0);
    return truck;

}

From source file:com.perry.infrastructure.call.CallDaoServiceImpl.java

@Override
public Call getTruckActive(long truckId) {
    String sql = "select * from calls where truck_id = :truckId";
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("truckId", truckId);
    List<Call> callList = namedParameterJdbcTemplate.query(sql, params, new CallRowMapper());
    if (!callList.isEmpty()) {
        return callList.get(0);
    }/*from  w  ww  . jav a2s .com*/
    return null;
}

From source file:org.inbio.modeling.core.dao.impl.ConfigDAOImpl.java

@Override
public void updateParameter(String parameterName, String value) {
    String createStatement = null;
    MapSqlParameterSource args = null;

    createStatement = "UPDATE " + this.table + " " + " SET value = :value " + " WHERE name = :parameter_name";

    args = new MapSqlParameterSource();
    args.addValue("parameter_name", parameterName);
    args.addValue("value", value);

    getSimpleJdbcTemplate().update(createStatement, args);
}

From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaIdentityDao.java

/**
 * For the given list of new drops, find those that the identity hash
 * already exists in the db and update the drop entry with the existing id.
 * Also remove the hash from the new identity index.
 * // ww  w  .  j  av a2  s  .co  m
 * @param newIdentityIndex
 * @param drops
 */
private void updateNewIdentityIndex(Map<String, List<Integer>> newIdentityIndex, List<Drop> drops) {
    // First find and update existing drops with their ids.
    String sql = "SELECT id, hash FROM identities WHERE hash IN (:hashes)";

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("hashes", newIdentityIndex.keySet());

    List<Map<String, Object>> results = this.namedJdbcTemplate.queryForList(sql, params);

    // Update id for the drops that were found
    for (Map<String, Object> result : results) {
        String hash = (String) result.get("hash");
        Long id = ((BigInteger) result.get("id")).longValue();

        List<Integer> indexes = newIdentityIndex.get(hash);
        for (Integer index : indexes) {
            drops.get(index).getIdentity().setId(id);
        }

        // Hash is not for a new drop so remove it
        newIdentityIndex.remove(hash);
    }
}

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

/**
 * ????/*w w  w. j  a  va2s . c  o  m*/
 *
 * @param ev
 * @param instanceID ??ID
 * @return
 */
private Long countDown(UpAndDownEvlauateItemHistory ev, AccessSystem accessSystem, String instanceID) {
    //??or.self = or.parent = ?
    ObjectRelation or = objectRelationDAO.findByParent(ev.getDownEntity().getInstanceClass(),
            ev.getObjectDictionary().getInstanceClass());
    if (or == null) {
        throw new RuntimeException(
                "?? = "
                        + ev.getDownEntity().getDisplayname() + " ;  = "
                        + ev.getObjectDictionary().getDisplayname() + "?");
    }

    //sql?
    String jpql = "select count(*) from {0} t where t.evaluateVersion.id = :evid and t.position = :position and exists (select 1 from {1} p where p.evaluateVersion.id = t.evaluateVersion.id and p.position = t.position and p.id = :id and p.id = t.{2}";
    if (or.isSimpleProperty()) {//??p.id = t.field?
        jpql += ")";
    } else {//???p.id = t.field.id?
        jpql += ".id)";
    }
    jpql = MessageFormat.format(jpql,
            new Object[] { or.getSelfClass(), or.getRelationClass(), or.getPropertyName() });
    MapSqlParameterSource params = new MapSqlParameterSource("id", instanceID);
    params.addValue("evid", ev.getEvaluateVersion().getId());
    params.addValue("position", accessSystem.getCode());
    return defaultDAO.findOnylFirst(jpql, params);
}

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

public <T> List<T> findEvaluatedEntity(EvaluateItemHistory itemHistory, AccessSystem system) {
    itemHistory = evaluateItemHistoryDAO.get(itemHistory.getId());

    String jpql = "select t from {0} t " + "where t.evaluateVersion.id = :evid " + "and t.position = :position "
            + "and not exists " + " (select 1 from Result r " + " where r.itemHistory.id = :hid "
            + " and r.evaluateVersion.id = :evid " + " and r.instanceId = t.id"
            + " and r.position = :position)";

    jpql = MessageFormat.format(jpql, new Object[] { itemHistory.getObjectDictionary().getInstanceClass() });
    MapSqlParameterSource params = new MapSqlParameterSource("evid", itemHistory.getEvaluateVersion().getId());
    params.addValue("hid", itemHistory.getId());
    params.addValue("position", system.getCode());

    return defaultDAO.find(jpql, params);
}

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

/**
 * ??//from   www  .jav  a 2  s  . c o  m
 *
 * @param ev
 * @param instanceID ??ID
 * @return
 */
private Long countUp(UpAndDownEvlauateItemHistory ev, AccessSystem accessSystem, String instanceID) {
    //??or.self = ?or.parent = 
    ObjectRelation or = objectRelationDAO.findByParent(ev.getObjectDictionary().getInstanceClass(),
            ev.getUpEntity().getInstanceClass());

    if (or == null) {
        throw new RuntimeException(
                "?? = "
                        + ev.getObjectDictionary().getDisplayname() + " ;  = "
                        + ev.getUpEntity().getDisplayname() + "?");
    }

    //sql?
    String jpql = "select count(*) from {0} t where t.id = :id and t.evaluateVersion.id = :evid and t.position = :position and exists (select 1 from {1} p where p.evaluateVersion.id = t.evaluateVersion.id and p.position = t.position and p.id = t.{2}";
    if (or.isSimpleProperty()) {//??p.id = t.field?
        jpql += ")";
    } else {//???p.id = t.field.id?
        jpql += ".id)";
    }
    jpql = MessageFormat.format(jpql,
            new Object[] { or.getSelfClass(), or.getRelationClass(), or.getPropertyName() });
    MapSqlParameterSource params = new MapSqlParameterSource("id", instanceID);
    params.addValue("evid", ev.getEvaluateVersion().getId());
    params.addValue("position", accessSystem.getCode());

    logger.debug("sql" + jpql + "\n; ? = " + instanceID);
    return defaultDAO.executeCount(jpql, params);
}

From source file:fr.acxio.tools.agia.alfresco.HibernateNodeReader.java

/**
 * Retrieves nodes' IDs/*from ww  w  .ja v  a2 s .co  m*/
 * 
 * @return a collection of IDs
 */
private List<Long> retrieveKeys() {

    synchronized (lock) {
        MapSqlParameterSource aParams = new MapSqlParameterSource();
        aParams.addValue(JOBSTEP_PARAM, currentStep);
        return jdbcTemplate.query(sqlQuery, aParams, new ParameterizedRowMapper<Long>() {
            public Long mapRow(ResultSet rs, int rowNum) throws SQLException {
                return rs.getLong(1);
            }
        });
    }

}

From source file:org.sakuli.services.receiver.database.dao.impl.DaoTestSuiteImpl.java

private MapSqlParameterSource getCompleteParameters() {
    MapSqlParameterSource tcParameters = getInitialDataParameters();
    tcParameters.addValues(getGuidParameter().getValues());
    tcParameters.addValue("stop", testSuite.getStopDateAsUnixTimestamp());
    tcParameters.addValue("warning", testSuite.getWarningTime());
    tcParameters.addValue("critical", testSuite.getCriticalTime());
    tcParameters.addValue("duration", testSuite.getDuration());
    //try to save the screenshot
    try {/*from  w  w  w .  j a v a 2 s . com*/
        if (testSuite.getScreenShotPath() != null) {
            final InputStream blobIs = Files.newInputStream(testSuite.getScreenShotPath());
            final int length = (int) testSuite.getScreenShotPath().toFile().length();
            tcParameters.addValue("screenshot", new SqlLobValue(blobIs, length, lobHandler), Types.BLOB);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    tcParameters.addValue("msg", testSuite.getExceptionMessages());
    return tcParameters;
}

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  . j  a va2s.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);
}