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:Implement.DAO.CommonDAOImpl.java

@Override
public AdvancedSearchForm searchPackageBelongtoSub(String searchText, String location, int subID,
        int pageNumber, int pageSize) {
    simpleJdbcCall = new SimpleJdbcCall(dataSource).withProcedureName("searchPackagesBelongsToSub");
    simpleJdbcCall.returningResultSet("rs1", PackagesViewMapper.getInstance())
            .returningResultSet("rs2", new RowMapper<String>() {

                @Override/* w  w  w  . j  a  v a  2  s.c o  m*/
                public String mapRow(ResultSet rs, int i) throws SQLException {
                    return rs.getString("Keyword");
                }
            }).returningResultSet("rs3", PopularPackageMapper.getInstance())
            .returningResultSet("rs4", LocationDTOMapper.getInstance());
    SqlParameterSource in = new MapSqlParameterSource().addValue("searchText", searchText)
            .addValue("location", location).addValue("subID", subID).addValue("PageNumber", pageNumber)
            .addValue("RowspPage", pageSize);
    Map<String, Object> record = simpleJdbcCall.execute(in);
    List<PackagesViewDTO> packages = (List<PackagesViewDTO>) record.get("rs1");
    List<String> keywords = (List<String>) record.get("rs2");
    List<LocationDTO> locations = (List<LocationDTO>) record.get("rs4");
    List<PopularPackageDTO> popularPackages = (List<PopularPackageDTO>) record.get("rs3");
    return new AdvancedSearchForm(packages, keywords, locations, popularPackages);
}

From source file:com.ushahidi.swiftriver.core.api.dao.impl.AbstractJpaContextDropDao.java

/**
 * Populates the buckets for each of the {@link Drop} in <code>drops</code>
 * /*  ww w . j ava2  s. c o  m*/
 * @param drops
 * @param queryingAccount
 * @param dropSource
 */
public void populateBuckets(List<Drop> drops, Account queryingAccount) {
    Map<Long, Integer> dropsIndex = new HashMap<Long, Integer>();
    int i = 0;
    for (Drop drop : drops) {
        dropsIndex.put(drop.getId(), i);
        i++;
    }

    // Query to fetch the buckets
    String sql = "SELECT `buckets_droplets`.`droplet_id` AS `id`, `buckets`.`id` AS `bucket_id`, `buckets`.`bucket_name` ";
    sql += "FROM `buckets` ";
    sql += "INNER JOIN `buckets_droplets` ON (`buckets`.`id` = `buckets_droplets`.`bucket_id`) ";
    sql += "WHERE `buckets_droplets`.`droplet_id` IN (:dropletIds) ";
    sql += "AND `buckets`.`bucket_publish` = 1 ";
    sql += "UNION ALL ";
    sql += "SELECT `buckets_droplets`.`droplet_id` AS `id`, `buckets`.`id` AS `bucket_id`, `buckets`.`bucket_name` ";
    sql += "FROM `buckets` ";
    sql += "INNER JOIN `buckets_droplets` ON (`buckets`.`id` = `buckets_droplets`.`bucket_id`) ";
    sql += "LEFT JOIN `accounts` ON (`buckets`.`account_id` = `accounts`.`id` AND `buckets`.`account_id` = :accountId) ";
    sql += "LEFT JOIN `bucket_collaborators` ON (`bucket_collaborators`.`bucket_id` = `buckets`.`id` AND `bucket_collaborators`.`account_id` = :accountId) ";
    sql += "WHERE `buckets_droplets`.`droplet_id` IN (:dropletIds) ";
    sql += "AND `buckets`.`bucket_publish` = 0 ";

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("dropletIds", dropsIndex.keySet());
    params.addValue("accountId", (Long) queryingAccount.getId());
    List<Map<String, Object>> results = this.namedJdbcTemplate.queryForList(sql, params);

    // Group the buckets per drop 
    Map<Long, List<Bucket>> dropBucketsMap = new HashMap<Long, List<Bucket>>();
    for (Map<String, Object> row : results) {

        Long bucketDropId = ((Number) row.get("id")).longValue();
        List<Bucket> dropBuckets = dropBucketsMap.get(bucketDropId);
        if (dropBuckets == null) {
            dropBuckets = new ArrayList<Bucket>();
        }

        // Create the bucket
        Bucket bucket = new Bucket();
        bucket.setId(((Number) row.get("bucket_id")).longValue());
        bucket.setName((String) row.get("bucket_name"));

        // Add to the list of buckets for the current drop
        dropBuckets.add(bucket);
        dropBucketsMap.put(bucketDropId, dropBuckets);
    }

    // Populate the buckets for the submitted drops
    for (Map.Entry<Long, List<Bucket>> entry : dropBucketsMap.entrySet()) {
        Long dropId = entry.getKey();

        // Retrieve the drop
        Drop drop = drops.get(dropsIndex.get(dropId));
        drop.setBuckets(entry.getValue());
    }
}

From source file:alfio.manager.WaitingQueueManager.java

private void preReserveTickets(Event event, int ticketsNeeded, int eventId, int alreadyReserved) {
    final int toBeGenerated = Math.abs(alreadyReserved - ticketsNeeded);
    EventStatisticView eventStatisticView = eventRepository.findStatisticsFor(eventId);
    Map<Integer, TicketCategoryStatisticView> ticketCategoriesStats = ticketCategoryRepository
            .findStatisticsForEventIdByCategoryId(eventId);
    List<Pair<Integer, TicketCategoryStatisticView>> collectedTickets = ticketCategoryRepository
            .findAllTicketCategories(eventId).stream().filter(tc -> !tc.isAccessRestricted())
            .sorted(Comparator.comparing(t -> t.getExpiration(event.getZoneId())))
            .map(tc -> Pair.of(//w w w .j  a va  2  s  .com
                    determineAvailableSeats(ticketCategoriesStats.get(tc.getId()), eventStatisticView),
                    ticketCategoriesStats.get(tc.getId())))
            .collect(new PreReservedTicketDistributor(toBeGenerated));
    MapSqlParameterSource[] candidates = collectedTickets.stream()
            .flatMap(p -> selectTicketsForPreReservation(eventId, p).stream())
            .map(id -> new MapSqlParameterSource().addValue("id", id)).toArray(MapSqlParameterSource[]::new);
    jdbc.batchUpdate(ticketRepository.preReserveTicket(), candidates);
}

From source file:com.joliciel.jochre.doc.DocumentDaoJdbc.java

@Override
public Author loadAuthor(int authorId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_AUTHOR + " FROM ocr_author WHERE author_id=:author_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("author_id", authorId);

    LOG.info(sql);/*from   w ww .j  av a2 s.c om*/
    logParameters(paramSource);
    Author author = null;
    try {
        author = (Author) jt.queryForObject(sql, paramSource,
                new AuthorMapper(this.getDocumentServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return author;
}

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

public List<JochreImage> findImages(JochrePage jochrePage) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_IMAGE + " FROM ocr_image WHERE image_page_id=:image_page_id"
            + " ORDER BY image_index";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("image_page_id", jochrePage.getId());

    LOG.debug(sql);/*from w ww . j a  v  a 2 s. c  om*/
    logParameters(paramSource);
    @SuppressWarnings("unchecked")
    List<JochreImage> images = jt.query(sql, paramSource,
            new JochreImageMapper(this.getGraphicsServiceInternal()));

    return images;
}

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

@Test
public void shouldReturnAssessmentWindows() {
    Instant earlier = Instant.now().minus(100000);
    String clientTestModeInsertSQL = "INSERT INTO configs.client_testmode (clientname,testid,mode,algorithm,formtideselectable,issegmented,maxopps,requirertsform,requirertsformwindow,requirertsformifexists,sessiontype,testkey,_key) "
            + "VALUES ('SBAC_PT','SBAC-Mathematics-3','online','virtual',0,1,50,0,0,1,0,'(SBAC_PT)SBAC-Mathematics-11-Spring-2013-2015',UNHEX('0431F6515F2D11E6B2C80243FCF25EAB'));";

    String clientTestWindowInsertSQL = "INSERT INTO configs.client_testwindow (clientname,testid,window,numopps,startdate,enddate,origin,source,windowid,_key,sessiontype,sortorder)"
            + "VALUES ('SBAC_PT','SBAC-Mathematics-3',1,3, NULL ,NULL,NULL,NULL,'ANNUAL',UNHEX('043A37525F2D11E6B2C80243FCF25EAB'),-1,1);";

    jdbcTemplate.update(clientTestModeInsertSQL, new MapSqlParameterSource());
    jdbcTemplate.update(clientTestWindowInsertSQL, new MapSqlParameterSource());

    List<AssessmentWindow> assessmentWindows = repository.findCurrentAssessmentWindows("SBAC_PT", 0, 0,
            "SBAC-Mathematics-3");
    assertThat(assessmentWindows).hasSize(1);

    AssessmentWindow window = assessmentWindows.get(0);
    assertThat(window.getAssessmentKey()).isEqualTo("(SBAC_PT)SBAC-Mathematics-11-Spring-2013-2015");
    assertThat(window.getEndTime().getMillis()).isGreaterThan(earlier.getMillis());
    assertThat(window.getStartTime().getMillis()).isGreaterThan(earlier.getMillis());
    assertThat(window.getFormKey()).isNull();
    assertThat(window.getMode()).isEqualTo("online");
    assertThat(window.getWindowId()).isEqualTo("ANNUAL");
    assertThat(window.getModeMaxAttempts()).isEqualTo(50);
    assertThat(window.getWindowSessionType()).isEqualTo(-1);
    assertThat(window.getModeSessionType()).isEqualTo(0);

}

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

@Override
public List<ExperimentTaskResult> getAllRunningExperimentTasks() {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("unfinishedState", TASK_STARTED_BUT_NOT_FINISHED_YET);
    return this.template.query(GET_RUNNING_EXPERIMENT_TASKS, params, new ExperimentTaskResultRowMapper());
}

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

public byte[] loadMessageContent(int id) throws DataAccessException {
    try {//from w ww.  jav  a 2  s. c om
        MapSqlParameterSource params = new MapSqlParameterSource();
        params.addValue(ID, id, Types.INTEGER);
        SimpleJdbcTemplate template = new SimpleJdbcTemplate(getNamedParameterJdbcTemplate());
        return template.queryForObject(SELECT_CONTENT, CONTENT_MAPPER, params);
    } catch (EmptyResultDataAccessException erdae) {
        return null;
    }
}

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

public Predicate loadPredicate(int predicateId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_PREDICATE + " FROM lef_predicate WHERE predicate_id=:predicate_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("predicate_id", predicateId);

    LOG.info(sql);/*from  ww  w .j  a v  a 2  s  .c  om*/
    LefffDaoImpl.LogParameters(paramSource);
    Predicate predicate = null;
    try {
        predicate = (Predicate) jt.queryForObject(sql, paramSource,
                new PredicateMapper(this.getLefffServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return predicate;
}

From source file:com.joliciel.jochre.doc.DocumentDaoJdbc.java

@Override
public List<Author> findAuthors() {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_AUTHOR + " FROM ocr_author"
            + " ORDER BY author_last_name, author_first_name";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();

    LOG.info(sql);/*from w  ww.  ja v a 2 s  .c o m*/
    logParameters(paramSource);
    @SuppressWarnings("unchecked")
    List<Author> authors = jt.query(sql, paramSource, new AuthorMapper(this.getDocumentServiceInternal()));

    return authors;
}