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.eu.evaluation.server.dao.eva.history.SimpleStatisticsDAO.java

/**
 * ???// w  ww . j  av  a 2 s  .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.eu.evaluation.server.dao.dictionary.FieldDictionaryDAO.java

public FieldDictionary findByObjectAndProperty(String objectID, String property) {
    String jpql = "select t from FieldDictionary t where t.objectDictionary.id = :oid and t.propertyName = :property";
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("oid", objectID);
    params.addValue("property", property);
    try {//from   www  .ja  v a 2  s.c  o  m
        return (FieldDictionary) this.createQuery(jpql, params).getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

From source file:com.manning.siia.batch.PaymentWriter.java

@Override
public void write(List<? extends Payment> payments) throws Exception {
    for (Payment payment : payments) {
        MapSqlParameterSource parameterSource = new MapSqlParameterSource();
        parameterSource.addValue("RECIPIENT", payment.getDestinationAccountNo())
                .addValue("PAYEE", payment.getSourceAccountNo()).addValue("AMOUNT", payment.getAmount())
                .addValue("DATE", payment.getDate());
        accountUpdate.update("UPDATE ACCOUNTS SET BALANCE = BALANCE + ? WHERE ID = ?", payment.getAmount(),
                payment.getDestinationAccountNo());
        accountUpdate.update("UPDATE ACCOUNTS SET BALANCE = BALANCE - ? WHERE ID = ?", payment.getAmount(),
                payment.getSourceAccountNo());
        paymentInsert.execute(parameterSource);
        System.out.println("Executing the step " + payment.getDate());
    }/*from  w  w w .  j av  a 2  s  . c om*/
}

From source file:org.impotch.calcul.impot.cantonal.ge.param.dao.ParametreCommunalJdbcRTaxPPDao.java

/**************************************************/

//-------- Implmentation de l'interface ParametreCommunalDao

@Override//from  w w  w  .  j a v  a2  s. c o m
public BigDecimal getPartPrivilegiee(int annee, int noOFSCommune) {
    String sql = "SELECT PPC.PIC_N_PART_PRIVILEGIEE / 100 " + FROM;
    MapSqlParameterSource param = new MapSqlParameterSource();
    param.addValue("periode", annee);
    param.addValue("noOFS", noOFSCommune);
    return this.getSimpleJdbcTemplate().queryForObject(sql, BigDecimal.class, param);
}

From source file:com.eu.evaluation.server.dao.dictionary.FieldDictionaryDAO.java

public FieldDictionary findByObjectNameAndProperty(String objectDisplayname, String propertyDisplayname) {
    String jpql = "select t from FieldDictionary t where t.objectDictionary.displayname = :displayname and t.displayname = :property and t.valid = :valid";
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("displayname", objectDisplayname);
    params.addValue("property", propertyDisplayname);
    params.addValue("valid", true);
    List<FieldDictionary> result = this.query(jpql, params);
    if (result.isEmpty()) {
        return null;
    } else if (result.size() == 1) {
        return result.get(0);
    } else {// w w  w. jav  a  2 s . c  o m
        throw new RuntimeException("? " + objectDisplayname
                + "  " + propertyDisplayname + " ?");
    }
}

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

@Override
public boolean parameterExists(Metadata metadata) {
    MapSqlParameterSource namedParameters = new MapSqlParameterSource();
    namedParameters.addValue("domain", metadata.getDomain());
    namedParameters.addValue("parameter", metadata.getFullParameterName());
    return (namedParameterJdbcTemplate.queryForInt(this.countQuery, namedParameters) > 0);
}

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:com.eu.evaluation.server.dao.eva.EvaluateItemTemplateDAO.java

public EvaluateItemTemplate findTheMatching(EvaluateTypeEnum type, ObjectDictionary od, FieldDictionary fd) {
    String jpql = "select t from EvaluateItemTemplate t where t.evaluateTypeEnum = :evaluateTypeEnum ";
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("evaluateTypeEnum", type);
    List<EvaluateItemTemplate> result = this.query(jpql, params);
    if (result.isEmpty()) {
        throw new RuntimeException("" + type.getName() + " ??");
    } else if (result.size() == 1) {
        return result.get(0);
    } else {/*from   w  ww  . j  a  v a2s .com*/
        jpql += "and t.objectDictionary.id = :odID ";
        params.addValue("odID", od.getId());
        result = this.query(jpql, params);
        if (result.size() == 1) {
            return result.get(0);
        } else {
            jpql += "and t.fieldDictionary.id = :fdID ";
            params.addValue("fdID", fd.getId());
            result = this.query(jpql, params);
            if (result.size() == 1) {
                return result.get(0);
            } else if (result.isEmpty()) {
                throw new RuntimeException("" + type.getName()
                        + " ?" + od.getDisplayname() + "?"
                        + fd.getDisplayname() + "??");
            } else {
                throw new RuntimeException(
                        "" + type.getName() + " ?"
                                + od.getDisplayname() + "?" + fd.getDisplayname()
                                + "???");
            }
        }
    }

}

From source file:com.eu.evaluation.server.dao.dictionary.ObjectRelationDAO.java

/**
 * // w w w  . ja va2 s.c  o  m
 * @param selfClassID
 * @param parentClassID
 * @return 
 */
public ObjectRelation findByParent(String selfClass, String relationClass) {
    String jpql = "select t from ObjectRelation t where t.selfClass = :selfClass and t.relationClass = :relationClass";
    MapSqlParameterSource params = new MapSqlParameterSource("selfClass", selfClass);
    params.addValue("relationClass", relationClass);
    List<ObjectRelation> result = this.query(jpql, params);
    if (result.isEmpty()) {
        return null;
    } else if (result.size() == 1) {
        return result.get(0);
    } else {
        throw new RuntimeException("?? = " + selfClass + " ;  = "
                + selfClass + "?????");
    }
}

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;
}