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:com.epam.catgenome.dao.DaoHelper.java

/**
 * Clears all records from a temporary list identified by the given ID.
 *
 * @param listId {@code Long} represents unique ID of a temporary list that has to be cleared
 * @return int represents the number of affected (deleted) rows
 *//*from w w w .j  a  v  a 2s.c  om*/
@Transactional(propagation = Propagation.MANDATORY)
public int clearTempList(final Long listId) {
    Assert.notNull(listId);
    return getNamedParameterJdbcTemplate().update(clearTemporaryListQuery,
            new MapSqlParameterSource(HelperParameters.LIST_ID.name(), listId));
}

From source file:com.epam.catgenome.dao.reference.ReferenceGenomeDao.java

@Transactional(propagation = Propagation.MANDATORY)
public Chromosome loadChromosome(final Long chromosomeId) {
    final List<Chromosome> list = getNamedParameterJdbcTemplate().query(loadChromosomeByIdQuery,
            new MapSqlParameterSource(GenomeParameters.CHROMOSOME_ID.name(), chromosomeId),
            GenomeParameters.getChromosomeMapper());
    return CollectionUtils.isNotEmpty(list) ? list.get(0) : null;
}

From source file:com.epam.catgenome.dao.DaoHelper.java

@Transactional(propagation = Propagation.MANDATORY)
public int clearTempStringList(final Long listId) {
    Assert.notNull(listId);//  ww w.j  a v a  2s . co  m
    return getNamedParameterJdbcTemplate().update(clearTemporaryStringListQuery,
            new MapSqlParameterSource(HelperParameters.LIST_ID.name(), listId));
}

From source file:alfio.manager.system.DataMigrator.java

private void migratePrices(final int eventId) {
    final Map<String, Integer> eventIdParam = Collections.singletonMap("eventId", eventId);
    final String srcPriceCtsParam = "srcPriceCts";
    Map<String, List<MapSqlParameterSource>> migrationData = jdbc.queryForList(
            "select * from event where type = :type and id = :eventId and regular_price_cts > 0",
            new MapSqlParameterSource("type", Event.EventType.INTERNAL.name()).addValue("eventId", eventId))
            .stream().flatMap(event -> {
                //fill the event prices
                boolean eventVatIncluded = (boolean) event.get("vat_included");
                BigDecimal vatPercentage = Optional.ofNullable((BigDecimal) event.get("vat"))
                        .orElse(BigDecimal.ZERO);
                int price = (int) event.get("regular_price_cts");
                String currencyCode = (String) event.get("currency");
                int eventSrcPrice = eventVatIncluded ? MonetaryUtil.addVAT(price, vatPercentage) : price;

                List<Pair<String, MapSqlParameterSource>> modifications = new ArrayList<>();

                if (((int) event.get("src_price_cts")) == 0) {
                    modifications/*from   ww  w .  ja  v a  2  s.  c o m*/
                            .add(Pair
                                    .of("event",
                                            new MapSqlParameterSource(srcPriceCtsParam, eventSrcPrice)
                                                    .addValue("vatStatus",
                                                            eventVatIncluded ? INCLUDED.name()
                                                                    : NOT_INCLUDED.name())
                                                    .addValue("eventId", eventId)));
                }

                //ticket categories
                modifications.addAll(collectTicketCategoryMigrationData(srcPriceCtsParam, eventVatIncluded,
                        vatPercentage, eventIdParam));

                //tickets
                modifications.addAll(collectTicketMigrationData(srcPriceCtsParam, eventVatIncluded,
                        vatPercentage, currencyCode, eventId, eventIdParam));

                //additional_service
                modifications.addAll(collectASMigrationData(srcPriceCtsParam, eventVatIncluded, vatPercentage,
                        eventIdParam));

                //additional_service_item
                modifications.addAll(collectASItemMigrationData(srcPriceCtsParam, eventVatIncluded,
                        vatPercentage, currencyCode, eventIdParam));

                log.debug("Price migration: got {} modifications for event {}", modifications.size(),
                        event.get("short_name"));
                return modifications.stream();
            }).collect(groupingBy(Pair::getKey, mapping(Pair::getValue, toList())));

    if (migrationData.size() > 0) {
        log.debug("Price migration: got modifications for: {}", migrationData.keySet());
        PRICE_UPDATE_BY_KEY.entrySet().stream().filter(e -> migrationData.containsKey(e.getKey()))
                .map(e -> Pair.of(e, migrationData.get(e.getKey()))).forEach(p -> {
                    Map.Entry<String, String> entry = p.getLeft();
                    log.debug("migrating {} prices...", entry.getKey());
                    performPriceMigration(entry.getValue(), p.getRight(), jdbc);
                });
    }
}

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

public void outputFileContent(String digest, final OutputStream out) throws IOException {
    LOG.debug("get file digest : {} ", digest);
    SqlParameterSource param = new MapSqlParameterSource("digest", digest);

    jdbc.query(queries.fileContent(), param, new RowCallbackHandler() {
        @Override//from w  w  w  . j a v a2s  .com
        public void processRow(ResultSet rs) throws SQLException {
            try (InputStream is = rs.getBinaryStream("CONTENT")) {
                StreamUtils.copy(is, out);
            } catch (IOException e) {
                throw new IllegalStateException("Error while copying data", e);
            }
        }
    });
}

From source file:com.epam.catgenome.dao.reference.ReferenceGenomeDao.java

@Transactional(propagation = Propagation.MANDATORY)
public List<Chromosome> loadAllChromosomesByReferenceId(final Long referenceId) {
    return getNamedParameterJdbcTemplate().query(loadAllChromosomesByReferenceIdQuery,
            new MapSqlParameterSource(GenomeParameters.REFERENCE_GENOME_ID.name(), referenceId),
            GenomeParameters.getChromosomeMapper());
}

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

/**
 * Return a mapping//from  www  .j av a 2 s  . com
 *
 * {labelListValue : {labelId : labelListValueId}}
 *
 * @param labelListValues
 * @return
 */
public Map<String, Map<Integer, Integer>> findLabelListValueMapping(List<String> labelListValues) {

    if (labelListValues.isEmpty()) {
        return Collections.emptyMap();
    }

    final Map<String, Map<Integer, Integer>> res = new HashMap<>();
    jdbc.query(queries.findLabelListValueMapping(), new MapSqlParameterSource("values", labelListValues),
            new RowCallbackHandler() {
                @Override
                public void processRow(ResultSet rs) throws SQLException {
                    String name = rs.getString("CARD_LABEL_LIST_VALUE");
                    if (!res.containsKey(name)) {
                        res.put(name, new HashMap<Integer, Integer>());
                    }
                    res.get(name).put(rs.getInt("CARD_LABEL_ID_FK"), rs.getInt("CARD_LABEL_LIST_VALUE_ID"));
                }
            });
    return res;
}

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

private static MapSqlParameterSource[] fromUserIdAndRoleName(Role role, Set<Integer> userIds) {
    List<MapSqlParameterSource> ret = new ArrayList<>(userIds.size());
    for (Integer userId : userIds) {
        ret.add(new MapSqlParameterSource("userId", userId).addValue("roleName", role.getName()));
    }//from   w w w .  j  a  v  a 2s . c o  m

    return ret.toArray(new MapSqlParameterSource[ret.size()]);
}

From source file:com.epam.catgenome.dao.reference.ReferenceGenomeDao.java

@Transactional(propagation = Propagation.MANDATORY)
public List<BaseEntity> loadAllFileByReferenceId(final Long referenceId) {
    return getNamedParameterJdbcTemplate().query(loadBiologicalItemsQuery,
            new MapSqlParameterSource(GenomeParameters.REFERENCE_GENOME_ID.name(), referenceId),
            GenomeParameters.getBioDataMapper());
}

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

private static MapSqlParameterSource[] from(Role role, Set<Permission> l) {
    List<MapSqlParameterSource> ret = new ArrayList<>(l.size());

    for (Permission p : l) {
        ret.add(new MapSqlParameterSource("permission", p.toString()).addValue("roleName", role.getName()));
    }/*from   www.j a  v a 2 s  .  c  o  m*/

    return ret.toArray(new MapSqlParameterSource[ret.size()]);
}