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() 

Source Link

Document

Create an empty MapSqlParameterSource, with values to be added via addValue .

Usage

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

@Transactional(propagation = Propagation.MANDATORY)
public Long createTempList(final Long listId, final Collection<? extends BaseEntity> list) {
    Assert.notNull(listId);//from w  w w .j  ava2s  .c o  m
    Assert.isTrue(CollectionUtils.isNotEmpty(list));
    // creates a new local temporary table if it doesn't exists to handle temporary lists
    getJdbcTemplate().update(createTemporaryListQuery);
    // fills in a temporary list by given values
    int i = 0;
    final Iterator<? extends BaseEntity> iterator = list.iterator();
    final MapSqlParameterSource[] batchArgs = new MapSqlParameterSource[list.size()];
    while (iterator.hasNext()) {
        MapSqlParameterSource params = new MapSqlParameterSource();
        params.addValue(HelperParameters.LIST_ID.name(), listId);
        params.addValue(HelperParameters.LIST_VALUE.name(), iterator.next().getId());
        batchArgs[i] = params;
        i++;
    }
    getNamedParameterJdbcTemplate().batchUpdate(insertTemporaryListItemQuery, batchArgs);
    return listId;
}

From source file:org.owasp.proxy.http.dao.JdbcMessageDAO.java

public Conversation getConversation(int id) throws DataAccessException {
    try {/*from  w  ww .  jav  a  2s.  c  om*/
        MapSqlParameterSource params = new MapSqlParameterSource();
        params.addValue(ID, id, Types.INTEGER);
        SimpleJdbcTemplate template = new SimpleJdbcTemplate(getNamedParameterJdbcTemplate());
        return template.queryForObject(SELECT_SUMMARY, CONVERSATION_MAPPER, params);
    } catch (EmptyResultDataAccessException erdae) {
        return null;
    }
}

From source file:org.aksw.gerbil.database.ExperimentDAOImpl.java

@Override
protected void setRunningExperimentsToError() {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("unfinishedState", TASK_STARTED_BUT_NOT_FINISHED_YET);
    parameters.addValue("state", ErrorTypes.SERVER_STOPPED_WHILE_PROCESSING.getErrorCode());
    java.util.Date today = new java.util.Date();
    parameters.addValue("lastChanged", new java.sql.Timestamp(today.getTime()));
    this.template.update(SET_UNFINISHED_TASK_STATE, parameters);
}

From source file:com.gst.portfolio.search.service.SearchReadPlatformServiceImpl.java

@Override
public Collection<AdHocSearchQueryData> retrieveAdHocQueryMatchingData(
        final AdHocQuerySearchConditions searchConditions) {

    this.context.authenticatedUser();

    final AdHocQuerySearchMapper rm = new AdHocQuerySearchMapper();
    final MapSqlParameterSource params = new MapSqlParameterSource();

    return this.namedParameterjdbcTemplate.query(rm.schema(searchConditions, params), params, rm);
}

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

/**
 * Saves {@code List} of {@code Chromosome} entities with a specified ID in the database
 * as one reference/*from  w ww . j  a  v  a  2 s  .com*/
 * @param referenceId for the chromosomes
 * @param chromosomes {@code List} of {@code Chromosome} entities to store int the database
 * @return an array containing the numbers of rows affected by each update in the batch
 */
@Transactional(propagation = Propagation.MANDATORY)
public int[] saveChromosomes(final Long referenceId, final List<Chromosome> chromosomes) {
    final int count = chromosomes.size();
    final List<Long> chromosomeIds = daoHelper.createIds(chromosomeSequenceName, count);
    final MapSqlParameterSource[] batchArgs = new MapSqlParameterSource[count];
    for (int i = 0; i < count; i++) {
        final Chromosome chromosome = chromosomes.get(i);
        chromosome.setId(chromosomeIds.get(i));
        chromosome.setReferenceId(referenceId);
        MapSqlParameterSource params = new MapSqlParameterSource();
        params.addValue(GenomeParameters.NAME.name(), chromosome.getName());
        params.addValue(GenomeParameters.SIZE.name(), chromosome.getSize());
        params.addValue(GenomeParameters.PATH.name(), chromosome.getPath());
        params.addValue(GenomeParameters.HEADER.name(), chromosome.getHeader());
        params.addValue(GenomeParameters.CHROMOSOME_ID.name(), chromosome.getId());
        params.addValue(GenomeParameters.REFERENCE_GENOME_ID.name(), chromosome.getReferenceId());
        batchArgs[i] = params;
    }
    return getNamedParameterJdbcTemplate().batchUpdate(createChromosomeQuery, batchArgs);
}

From source file:com.joliciel.talismane.terminology.postgres.PostGresTerminologyBase.java

@Override
public List<Term> getMarkedTerms() {
    MONITOR.startTask("getMarkedTerms");
    try {//from w  w w.  j  a v a2  s . co m
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_TERM + " FROM term" + " INNER JOIN text ON term_text_id=text_id"
                + " WHERE term_marked = :term_marked" + " AND term_project_id = :term_project_id"
                + " ORDER BY text_text";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("term_marked", true);
        paramSource.addValue("term_project_id", this.getCurrentProjectId());

        LOG.trace(sql);
        LogParameters(paramSource);
        @SuppressWarnings("unchecked")
        List<Term> terms = jt.query(sql, paramSource, new TermMapper());

        return terms;

    } finally {
        MONITOR.endTask("getMarkedTerms");
    }
}

From source file:com.joliciel.lefff.LefffDaoImpl.java

public void deleteCategory(int categoryId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    String sql = "DELETE FROM lef_category WHERE category_id = :category_id";
    paramSource.addValue("category_id", categoryId);
    LOG.info(sql);/* ww  w.j  a  va  2  s .  c  om*/
    LefffDaoImpl.LogParameters(paramSource);
    jt.update(sql, paramSource);
}

From source file:com.joliciel.jochre.graphics.GraphicsDaoJdbc.java

@Override
public void saveOriginalImage(JochreImage jochreImage) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("image_id", jochreImage.getId());

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {/*from www . j  a va 2s  . c o  m*/
        ImageIO.write(jochreImage.getOriginalImage(), "png", os);
        os.flush();
        paramSource.addValue("image_image", os.toByteArray());
        os.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    String sql = "UPDATE ocr_image SET image_image = :image_image" + " WHERE image_id = :image_id";

    LOG.debug(sql);
    logParameters(paramSource);
    jt.update(sql, paramSource);
}

From source file:org.aksw.gerbil.database.ExperimentDAOImpl.java

@Deprecated
@Override/* w  w  w. j a v a 2s .  c om*/
protected List<String[]> getAnnotatorDatasetCombinations(String experimentType, String matching) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("experimentType", experimentType);
    params.addValue("matching", matching);
    return this.template.query(GET_LATEST_EXPERIMENT_TASKS, params,
            new StringArrayRowMapper(new int[] { 1, 2 }));
}

From source file:org.cloudfoundry.workers.stocks.batch.BatchConfiguration.java

/***
 * The Spring Batch {@link org.springframework.batch.item.ItemWriter item
 * writer} persists the {@link StockSymbolLookup} lookup results into a
 * table (<CODE>STOCKS_DATA</CODE>).
 * /*from   ww  w . j av  a  2s . com*/
 * @param dateOfAnalysis
 */
@Bean(name = "writer")
@Scope("step")
public JdbcBatchItemWriter<StockSymbolLookup> writer(
        final @Value("#{jobParameters['date']}") Date dateOfAnalysis) {
    JdbcBatchItemWriter<StockSymbolLookup> jdbcBatchItemWriter = new JdbcBatchItemWriter<StockSymbolLookup>();
    jdbcBatchItemWriter.setSql(
            "INSERT INTO STOCKS_DATA( DATE_ANALYSED, HIGH_PRICE, LOW_PRICE,  CLOSING_PRICE, SYMBOL) VALUES ( :da, :hp, :lp,  :cp, :s ) ");
    jdbcBatchItemWriter.setDataSource(dsConfig.dataSource());
    jdbcBatchItemWriter
            .setItemSqlParameterSourceProvider(new ItemSqlParameterSourceProvider<StockSymbolLookup>() {
                @Override
                public SqlParameterSource createSqlParameterSource(StockSymbolLookup item) {
                    return new MapSqlParameterSource()
                            .addValue("da", new java.sql.Date(dateOfAnalysis.getTime()), Types.DATE)
                            .addValue("hp", item.getHighPrice(), Types.DOUBLE)
                            .addValue("lp", item.getLowPrice(), Types.DOUBLE).addValue("s", item.getTicker())
                            .addValue("si", item.getId(), Types.BIGINT)
                            .addValue("cp", item.getLastValueWhileOpen(), Types.DOUBLE);

                }
            });
    return jdbcBatchItemWriter;
}