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(String paramName, @Nullable Object value) 

Source Link

Document

Create a new MapSqlParameterSource, with one value comprised of the supplied arguments.

Usage

From source file:tds.assessment.repositories.impl.ItemControlParametersQueryRepositoryImpl.java

@Override
public List<ItemControlParameter> findControlParametersForSegment(final String segmentKey) {
    final SqlParameterSource parameters = new MapSqlParameterSource("segmentKey", segmentKey);

    final String SQL = "SELECT \n" + "   bpElementID, \n" + "   name, \n" + "   value \n" + "FROM \n "
            + "   tblitemselectionparm " + "WHERE _fk_AdminSubject = :segmentKey \n " + "UNION \n" + "SELECT \n"
            + "   p.bpElementID, \n" + "   'proficientTheta' AS NAME, \n " + "   pl.ThetaLo AS VALUE \n" + // TODO: cast(cast(pl.ThetaLo as decimal(38, 18)) as varchar(200))"
            "FROM tblitemselectionparm p \n" + "INNER JOIN performancelevels pl \n"
            + "   ON pl._fk_content = p._fk_AdminSubject \n" + "   AND cast(pl.PLevel AS CHAR(5)) = p.value \n"
            + "WHERE p._fk_AdminSubject = :segmentKey AND p.name = 'proficientPLevel'";

    return jdbcTemplate.query(SQL, parameters,
            (rs, rowNum) -> new ItemControlParameter(rs.getString("bpElementID"), rs.getString("name"),
                    rs.getString("value")));
}

From source file:tds.assessment.repositories.impl.ItemMeasurementQueryRepositoryImpl.java

@Override
public List<ItemMeasurement> findItemMeasurements(final String segmentKey, final String assessmentKey) {
    SqlParameterSource parameters = new MapSqlParameterSource("segmentKey", segmentKey)
            .addValue("assessmentKey", assessmentKey);

    String SQL = "SELECT \n" + "   coalesce(S.TestPosition, 1) as segmentPosition, \n"
            + "   AI._fk_Item as itemkey, \n" + "   D.Dimension as dimension, \n "
            + "   upper(m.ModelName) as irtModel, \n" + "   p.parmnum as parameterNumber, \n"
            + "   p.parmname as parameterName, \n" + "   p.parmdescription as parameterDesc, \n"
            + "   ip.parmvalue as parameterValue \n" + "FROM \n" + "   tblsetofadminitems AI \n"
            + "INNER JOIN \n" + "   tblsetofadminsubjects S ON S._Key = AI._fk_AdminSubject \n"
            + "INNER JOIN \n" + "   itemscoredimension as D ON D._fk_AdminSubject = AI._fk_AdminSubject \n"
            + "       AND D._fk_Item = AI._fk_Item \n" + "INNER JOIN \n"
            + "   measurementmodel m ON m.ModelNumber = D._fk_MeasurementModel \n" + "INNER JOIN \n"
            + "   measurementparameter p ON p._fk_measurementModel = m.ModelNumber \n" + "INNER JOIN \n"
            + "   itemmeasurementparameter ip ON ip._fk_ItemScoreDimension = D._Key \n"
            + "       AND ip._fk_MeasurementParameter = p.parmnum \n" + "WHERE \n"
            + "   S._Key = :segmentKey OR S.VirtualTest = :assessmentKey";

    return jdbcTemplate.query(SQL, parameters,
            (rs, rowNum) -> new ItemMeasurement.Builder().withDimension(rs.getString("dimension"))
                    .withSegmentPosition(rs.getInt("segmentPosition")).withItemKey(rs.getString("itemKey"))
                    .withItemResponseTheoryModel(rs.getString("irtModel"))
                    .withParameterName(rs.getString("parameterName"))
                    .withParameterValue((Float) rs.getObject("parameterValue"))
                    .withParameterDescription(rs.getString("parameterDesc"))
                    .withParameterNumber(rs.getInt("parameterNumber")).build());
}

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

/**
 * ?//from  w w w . j  a  v  a  2s . co  m
 * @param selfClassID
 * @return 
 */
public List<ObjectRelation> findChild(String selfClass) {
    String jpql = "select t from ObjectRelation t where t.relationClass = :relationClass";
    MapSqlParameterSource params = new MapSqlParameterSource("relationClass", selfClass);
    return this.query(jpql, params);
}

From source file:com.exploringspatial.dao.impl.CodeCategoryDaoImpl.java

@Override
public CodeCategory find(final String category) {
    final String sql = selectSQL.concat("WHERE CATEGORY = :category");
    final MapSqlParameterSource params = new MapSqlParameterSource("category", category);
    final List<CodeCategory> results = jdbcTemplate.query(sql, params, new CodeCategoryRowMapper());
    if (results != null && !results.isEmpty()) {
        return results.get(0);
    }//  w w w  .j a  v  a2s . c om
    return null;
}

From source file:io.lavagna.service.CardRepository.java

private static List<SqlParameterSource> prepareOrderParameter(List<Integer> cardIds, int columnId) {
    List<SqlParameterSource> params = new ArrayList<>(cardIds.size());
    for (int i = 0; i < cardIds.size(); i++) {
        SqlParameterSource p = new MapSqlParameterSource("cardOrder", i + 1)//
                .addValue("cardId", cardIds.get(i))//
                .addValue("columnId", columnId);
        params.add(p);/*from w ww .  j a  v  a2s. c  om*/
    }
    return params;
}

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

@Override
public User findByUserName(String userName) {
    return getNamedParameterJdbcTemplate().queryForObject("select * from users where user_name = :user_name",
            new MapSqlParameterSource("user_name", userName), userMapper);
}

From source file:dao.BankDao.java

public List<Bank> getBankForName(String name) {

    logger.info("run");

    SqlParameterSource parameterSource = new MapSqlParameterSource("name", "%" + name.toUpperCase() + "%");
    return jdbc.query("SELECT * FROM banktable WHERE name LIKE :name", parameterSource, new RowMapper<Bank>() {

        @Override/*from  ww w .j  a va  2 s  .  c o m*/
        public Bank mapRow(ResultSet rs, int rowNum) throws SQLException {
            return readOneBank(rs);
        }
    });
}

From source file:tds.assessment.repositories.impl.StrandQueryRepositoryImpl.java

@Override
public Set<Strand> findStrands(final String assessmentKey) {
    SqlParameterSource parameters = new MapSqlParameterSource("key", assessmentKey);
    final String SQL = "SELECT \n" + "   strand._fk_strand AS name,\n" + "   strand._key, \n"
            + "   strand.minitems, \n" + "   strand.maxitems,\n" + "   strand.adaptivecut,\n"
            + "   strand._fk_adminsubject AS segmentKey, \n" + "   strand.isstrictmax,\n"
            + "   strand.bpweight,\n" + "   strand.startInfo,\n" + "   strand.scalar,\n"
            + "   strand.precisionTarget,\n" + "   strand.precisionTargetMetWeight,\n"
            + "   strand.precisionTargetNotMetWeight\n" + "FROM \n" + "   itembank.tbladminstrand strand\n"
            + "LEFT JOIN \n" + "   itembank.tblsetofadminsubjects segments \n"
            + "    ON segments._key = strand._fk_adminsubject \n" + "WHERE \n"
            + "   segments.virtualtest = :key OR \n" + "   segments._key = :key";

    return new HashSet<>(jdbcTemplate.query(SQL, parameters, (rs, row) -> buildStrandFromResultSet(rs)));
}

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

public ClusterConfiguration getActive() {
    List<ClusterConfiguration> configuration = jdbcTemplate.query(
            queriesProperties.getProperty("clusterconfig.select.star.wa"),
            new MapSqlParameterSource("active", true), new ClusterConfigurationMapper());

    //tutaj zrobic inaczej
    //jesli defaultConn nie jest pusty to dodaj config nadpisujac
    if (CollectionUtils.isEmpty(configuration)) {
        this.createDefaultConfiguration();
        return this.getActive();
    }/*from   ww w.  java 2 s.  c  o m*/

    return configuration.get(0);
}

From source file:com.exploringspatial.dao.impl.CodeDefinitionDaoImpl.java

@Override
public CodeDefinition find(final Long codeCategoryPk, final Integer code) {
    final String sql = selectSQL.concat("WHERE CODE_CATEGORY_PK = :codeCategoryPk AND CODE = :code");
    final MapSqlParameterSource params = new MapSqlParameterSource("codeCategoryPk", codeCategoryPk)
            .addValue("code", code);
    final List<CodeDefinition> results = jdbcTemplate.query(sql, params, new CodeDefinitionRowMapper());
    if (results != null && !results.isEmpty()) {
        return results.get(0);
    }/*w ww .j av  a2 s. com*/
    return null;
}