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:airport.database.dispatcher.airplane.RunawayDaoImpl.java

@Override
public void liberateRunaway(int runawayId) {
    MapSqlParameterSource parameterSource = new MapSqlParameterSource(SQL_PARAMETER_RUNAWAY_ID, runawayId);

    jdbcTemplate.update(SQL_QUERY_LIBERATE, parameterSource);

    if (LOG.isInfoEnabled()) {
        LOG.info("occupay runaway. RunawayId : " + runawayId);
    }/*from w  ww  .j av a2 s . c  o  m*/
}

From source file:alfio.manager.FileUploadManager.java

public void outputFile(String id, OutputStream out) {
    byte[] res = cache.get(id, identifier -> {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        SqlParameterSource param = new MapSqlParameterSource("id", id);
        jdbc.query(repository.fileContent(id), param, rs -> {
            try (InputStream is = rs.getBinaryStream("content")) {
                StreamUtils.copy(is, baos);
            } catch (IOException e) {
                throw new IllegalStateException("Error while copying data", e);
            }//from   ww  w  . java  2s  .c o  m
        });
        return baos.toByteArray();
    });
    try {
        StreamUtils.copy(res, out);
    } catch (IOException e) {
        throw new IllegalStateException("Error while copying data", e);
    }
}

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

private static SqlParameterSource prepareUserParameterSource(User user) {
    return new MapSqlParameterSource("provider", trimToNull(user.getProvider()))
            .addValue("userName", trimToNull(user.getUsername())).addValue("email", trimToNull(user.getEmail()))
            .addValue("displayName", trimToNull(user.getDisplayName())).addValue("enabled", user.isEnabled())
            .addValue("emailNotification", user.isEmailNotification())
            .addValue("memberSince", ObjectUtils.firstNonNull(user.getMemberSince(), new Date()))
            .addValue("skipOwnNotifications", user.isSkipOwnNotifications());
}

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

private static SqlParameterSource prepareForCardEvent(int cardId, Integer previousColumnId, int columnId,
        int userId, EventType event, Date time, String name) {
    return new MapSqlParameterSource("cardId", cardId).addValue("previousColumnId", previousColumnId)
            .addValue("columnId", columnId).addValue("time", time).addValue("userId", userId)
            .addValue("event", event.toString()).addValue("valueString", name);
}

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

private static List<SqlParameterSource> prepareOrderParameter(List<Integer> dataIds, int cardId,
        Integer referenceId) {//from   w  w  w.ja v a 2 s.  c o  m
    LOG.debug("prepareOrderParameter: {card: {}, data count: {}, reference {}}", cardId, dataIds.size(),
            referenceId);
    List<SqlParameterSource> params = new ArrayList<>(dataIds.size());
    for (int i = 0; i < dataIds.size(); i++) {
        LOG.debug("prepareOrderParameter FOR: {data: {}, order: {}}", dataIds.get(i), i + 1);
        SqlParameterSource p = new MapSqlParameterSource("order", i + 1).addValue("id", dataIds.get(i))
                .addValue("cardId", cardId).addValue("referenceId", referenceId);
        params.add(p);
    }
    return params;
}

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

public List<FieldDictionary> findByInstanceType(int instanceType) {
    String jpql = "select t from FieldDictionary t where t.objectDictionary.instanceType = :instanceType";
    MapSqlParameterSource params = new MapSqlParameterSource("instanceType", instanceType);
    return this.query(jpql, params);
}

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

@Override
public Collection<Post> findByUserName(String userName) {
    return getNamedParameterJdbcTemplate().query(
            "select * from posts where user_name = :user_name order by submit_date desc",
            new MapSqlParameterSource("user_name", userName), postMapper);
}

From source file:ar.com.springbasic.dao.AdminDaoImpl.java

@Override
public boolean delete(int idAd) {
    return jdbcTemplate.update("delete from springbd.admin where idAd=:idAd",
            new MapSqlParameterSource("idAd", idAd)) == 1;
}

From source file:eu.europa.esig.dss.web.dao.PreferencesJdbcDao.java

@Override
public Preference get(PreferenceKey id) {
    final String query = "select * from " + TABLE_NAME + " where " + COLUMN_KEY + " = :key";
    final SqlParameterSource namedParameters = new MapSqlParameterSource("key", id);
    return namedParameterJdbcTemplate.queryForObject(query, namedParameters, new PreferenceRowMapper());
}

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

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

    final String SQL = "(SELECT" + "   S._fk_Strand AS contentLevel, \n" + "   S.minItems, \n"
            + "   S.maxItems, \n" + "   S.isStrictMax, \n" + "   S.bpweight, \n" + "   S.adaptiveCut, \n"
            + "   S.StartAbility, \n" + "   S.StartInfo, \n" + "   S.Scalar, \n"
            + "   CASE WHEN S.StartAbility IS NOT NULL THEN 'true' ELSE 'false' END AS isReportingCategory, \n"
            + "   S.abilityWeight, \n" + "   S.precisionTarget, \n" + "   S.precisionTargetMetWeight, \n"
            + "   S.precisionTargetNotMetWeight, \n"
            + "   CASE WHEN SS._fk_Parent IS NULL THEN 0 ELSE 1 END AS elementType \n"
            + "FROM tbladminstrand S  \n " + "JOIN tblstrand SS ON SS._Key = S._fk_Strand \n"
            + "WHERE S._fk_AdminSubject = :segmentKey ) \n" + "UNION ALL \n" + "(SELECT \n"
            + "   GroupID AS contentLevel, \n" + "   minitems, \n" + "   maxitems, \n" + "   isStrictmax, \n"
            + "   weight AS bpweight, \n" + "   NULL AS adaptiveCut, \n" + "   StartAbility, \n"
            + "   StartInfo, \n" + "   NULL AS Scalar, \n"
            + "   CASE WHEN StartAbility IS NOT NULL THEN 'true' ELSE 'false' END AS isReportingCategory, \n"
            + "   abilityWeight, \n" + "   precisionTarget, \n" + "   precisionTargetMetWeight, \n"
            + "   precisionTargetNotMetWeight, \n" + "   2 AS elementType \n" + "FROM affinitygroup G \n"
            + "WHERE G._fk_AdminSubject = :segmentKey ) \n" + "ORDER BY isReportingCategory DESC, \n"
            + "contentLevel ";

    return new ArrayList<>(jdbcTemplate.query(SQL, parameters,
            (rs, row) -> new ContentLevelSpecification.Builder()
                    .withReportingCategory(rs.getBoolean("isReportingCategory"))
                    .withElementType(rs.getInt("elementType")).withContentLevel(rs.getString("contentLevel"))
                    .withMinItems(rs.getInt("minitems")).withMaxItems(rs.getInt("maxitems"))
                    .withAdaptiveCut((Float) rs.getObject("adaptivecut"))
                    .withStrictMax(rs.getBoolean("isstrictmax")).withBpWeight(rs.getFloat("bpweight"))
                    .withStartInfo((Float) rs.getObject("startInfo")).withScalar((Float) rs.getObject("scalar"))
                    .withPrecisionTarget((Float) rs.getObject("precisionTarget"))
                    .withPrecisionTargetMetWeight((Float) rs.getObject("precisionTargetMetWeight"))
                    .withPrecisionTargetNotMetWeight((Float) rs.getObject("precisionTargetNotMetWeight"))
                    .build()));/*from ww  w.j  a v  a2  s  .c o  m*/
}