Example usage for org.springframework.jdbc.core ResultSetExtractor ResultSetExtractor

List of usage examples for org.springframework.jdbc.core ResultSetExtractor ResultSetExtractor

Introduction

In this page you can find the example usage for org.springframework.jdbc.core ResultSetExtractor ResultSetExtractor.

Prototype

ResultSetExtractor

Source Link

Usage

From source file:com.lixiaocong.social.MyJdbcUsersConnection.java

public Set<String> findUserIdsConnectedTo(String providerId, Set<String> providerUserIds) {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("providerId", providerId);
    parameters.addValue("providerUserIds", providerUserIds);
    final Set<String> localUserIds = new HashSet<String>();
    return new NamedParameterJdbcTemplate(jdbcTemplate).query(
            "select userId from " + tablePrefix
                    + "UserConnection where providerId = :providerId and providerUserId in (:providerUserIds)",
            parameters, new ResultSetExtractor<Set<String>>() {
                public Set<String> extractData(ResultSet rs) throws SQLException, DataAccessException {
                    while (rs.next()) {
                        localUserIds.add(rs.getString("userId"));
                    }//w  w w.j  a v a 2s .com
                    return localUserIds;
                }
            });
}

From source file:com.havoc.hotel.admin.dao.impl.CustomerDAOImpl.java

@Override
public Customer authenticate(String username, String password) {
    return (Customer) jdbcTemplate.query(SQLConstant.CUSTOMER_AUTHENTICATE, new Object[] { username, password },
            new ResultSetExtractor<Customer>() {

                @Override// ww w  .ja  v a  2s  .c  om
                public Customer extractData(ResultSet rs) throws SQLException, DataAccessException {
                    Customer c = null;
                    if (rs.next()) {
                        c = new Customer();
                        c.setCustomerId(rs.getInt("customer_id"));
                        c.setFirstName(rs.getString("first_name"));
                        c.setLastName(rs.getString("last_name"));
                        c.setEmail(rs.getString("email"));
                        c.setContactNo(rs.getString("contact_no"));
                        c.setUsername(rs.getString("username"));
                        c.setPassword(rs.getString("password"));
                        c.setAddedDate(rs.getDate("added_date"));
                        c.setStatus(rs.getBoolean("status"));

                    }
                    return c;
                }
            });
}

From source file:com.ebay.pulsar.analytics.dao.RDBMS.java

public <T> List<T> query(String sql, Map<String, ?> parameters, final int maxrows, final RowMapper<T> mapper) {
    return this.namedParameterJdbcTemplate.query(sql, parameters, new ResultSetExtractor<List<T>>() {
        @Override/*from w w  w  .j  a v a 2 s . co  m*/
        public List<T> extractData(ResultSet rs) throws SQLException, DataAccessException {
            List<T> data = new ArrayList<T>();
            if (rs == null)
                return data;
            int rowNum = 0;
            while ((maxrows > 0 && rowNum < maxrows || maxrows < 0) && rs.next()) {
                data.add(mapper.mapRow(rs, rowNum++));
            }
            return data;
        }
    });
}

From source file:org.obiba.onyx.jade.instrument.reichert.OraInstrumentRunner.java

private Map<String, Data> extractData(final String eyeSide) {
    return jdbc.query("select * from Measures where PatientId = ? and Eye = ? order by MeasureDate desc",
            new PreparedStatementSetter() {

                @Override//from ww  w .  jav  a 2s. co m
                public void setValues(PreparedStatement ps) throws SQLException {
                    ps.setInt(1, extractPatientId());
                    ps.setString(2, eyeSide);
                }

            }, new ResultSetExtractor<Map<String, Data>>() {

                @Override
                public Map<String, Data> extractData(ResultSet rs) throws SQLException, DataAccessException {

                    // how to avoid while() ? last() on Access DB can not be called
                    log.info("Retrieve measures");
                    if (rs.next()) {
                        Putter data = new Putter(rs);
                        data.putInt("MeasureID");
                        data.putInt("MeasureNumber");
                        data.putDate("MeasureDate");
                        data.putDate("SessionDate");
                        data.putString("Eye");
                        data.putString("ORASerialNumber");
                        data.putString("ORASoftware");
                        data.putString("PCSoftware");
                        data.putDecimal("IOPG");
                        data.putDecimal("IOPCC");
                        data.putDecimal("CRF");
                        data.putDecimal("CCTAvg");
                        data.putDecimal("CCTLowest");
                        data.putDecimal("CCTSD");
                        data.putDecimal("CH");
                        data.putDecimal("TearFilmValue");
                        data.putString("Pressure");
                        data.putString("Applanation");
                        data.putDecimal("TimeIn");
                        data.putDecimal("TimeOut");
                        data.putString("Meds");
                        data.putString("Conditions");
                        data.putString("Notes1");
                        data.putString("Notes2");
                        data.putString("Notes3");
                        data.putDecimal("m_G2");
                        data.putDecimal("b_G2");
                        data.putDecimal("m_G3");
                        data.putDecimal("b_G3");
                        data.putDecimal("iop_cc_coef");
                        data.putDecimal("crf_coef");
                        data.putDecimal("m_ABC");
                        data.putDecimal("b_ABC");
                        data.putDecimal("b_PP");
                        data.putBoolean("BestWeighted");
                        data.putDecimal("QualityIndex");
                        data.putString("Indexes");
                        return data.getData();
                    }
                    return Collections.emptyMap();
                }
            });
}

From source file:de.whs.poodle.repositories.CourseStatisticsRepository.java

public Map<LocalDate, TotalCourseTermStatistics> getStatisticsForCourse(int courseId) {
    return jdbc.query("SELECT * FROM get_course_term_statistics(?)", new Object[] { courseId },

            new ResultSetExtractor<Map<LocalDate, TotalCourseTermStatistics>>() {

                @Override/* w  w  w.  j  a v  a  2 s .c om*/
                public Map<LocalDate, TotalCourseTermStatistics> extractData(ResultSet rs) throws SQLException {
                    Map<LocalDate, TotalCourseTermStatistics> map = new LinkedHashMap<>();
                    CourseTermStatisticsRowMapper rowMapper = new CourseTermStatisticsRowMapper();

                    while (rs.next()) {
                        TotalCourseTermStatistics ct = rowMapper.mapRow(rs, 0);
                        LocalDate day = rs.getDate("day").toLocalDate();
                        map.put(day, ct);
                    }

                    return map;
                }

            });
}

From source file:gov.nih.nci.ncicb.cadsr.bulkloader.util.BulkLoaderUnclassifier.java

private Double getLatestCSIVersion(UnloadProperties unloadProperties) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String csName = unloadProperties.getClassificationSchemeName();
    String csiName = unloadProperties.getClassificationSchemeItemName();

    Double latestVersion = (Double) jdbcTemplate.query(csiLatestVersionQry, new Object[] { csiName, csName },
            new ResultSetExtractor() {

                @Override//w w w .j  a  va  2  s .c  o  m
                public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
                    if (rs.next()) {
                        return new Double(rs.getDouble(1));
                    }
                    return new Double(0.0);
                }
            });

    return latestVersion;
}

From source file:de.whs.poodle.repositories.McWorksheetRepository.java

public McStudentCourseTermStatistics getMcStudentStatistics(int studentId, int courseTermId) {
    return jdbc.query(
            "SELECT SUM(CASE WHEN has_student_answered_mc_question(?,root_id) THEN 1 END)::INT AS answered, "
                    + "COUNT(*) AS total " + "FROM v_mc_question " + "WHERE visibility != 'PRIVATE'"
                    + "AND is_latest_revision " + "AND is_course_linked_with("
                    + "  (SELECT course_id FROM course_term sm WHERE sm.id = ?)," + "  course_id" + ")",
            new Object[] { studentId, courseTermId },

            new ResultSetExtractor<McStudentCourseTermStatistics>() {

                @Override/*w  w  w.jav  a  2  s .co m*/
                public McStudentCourseTermStatistics extractData(ResultSet rs)
                        throws SQLException, DataAccessException {
                    if (!rs.next())
                        return null;

                    McStudentCourseTermStatistics mcs = new McStudentCourseTermStatistics();

                    mcs.setAnsweredCount(rs.getInt("answered"));
                    mcs.setTotalCount(rs.getInt("total"));

                    return mcs;
                }
            });
}

From source file:com.ebay.pulsar.analytics.dao.RDBMS.java

public <T> List<T> query(String sql, AbstractSqlParameterSource parameters, final int maxrows,
        final RowMapper<T> mapper) {
    return this.namedParameterJdbcTemplate.query(sql, parameters, new ResultSetExtractor<List<T>>() {
        @Override/*from  w w w .j ava2 s .  c om*/
        public List<T> extractData(ResultSet rs) throws SQLException, DataAccessException {
            List<T> data = new ArrayList<T>();
            if (rs == null)
                return data;
            int rowNum = 0;
            while ((maxrows > 0 && rowNum < maxrows || maxrows < 0) && rs.next()) {
                data.add(mapper.mapRow(rs, rowNum++));
            }
            return data;
        }
    });
}

From source file:org.ohmage.query.impl.CampaignImageQueries.java

@Override
public Collection<UUID> getImageIdsFromCampaign(String campaignId) throws DataAccessException {

    try {// w  ww.  j ava2  s  .  c  om
        return getJdbcTemplate().query(SQL_GET_IDS_FOR_ALL_IMAGE_RESPONSES_FOR_CAMPAIGN,
                new Object[] { campaignId }, new ResultSetExtractor<Collection<UUID>>() {

                    /**
                     * Retrieves all of the UUIDs only from the query and
                     * ignores the skipped, not displayed, etc. responses.
                     * 
                     * @param rs The result set from the database.
                     * 
                     * @return A collection of the UUIDs only from the
                     *          corresponding survey responses.
                     * 
                     * @throws SQLException Thrown if there is an error.
                     * 
                     * @throws org.springframework.dao.DataAccessException
                     *          Thrown if there is an error.
                     */
                    @Override
                    public Collection<UUID> extractData(ResultSet rs)
                            throws SQLException, org.springframework.dao.DataAccessException {

                        Collection<UUID> result = new HashSet<UUID>();
                        while (rs.next()) {
                            try {
                                result.add(UUID.fromString(rs.getString("uuid")));
                            } catch (IllegalArgumentException e) {
                                // This is fine. The row should be ignored
                                // because this indicates that it was 
                                // skipped, not displayed, etc.
                            }
                        }
                        return result;
                    }

                });

    } catch (org.springframework.dao.DataAccessException e) {
        throw new DataAccessException("Error executing SQL '" + SQL_GET_IDS_FOR_ALL_IMAGE_RESPONSES_FOR_CAMPAIGN
                + "' with parameter: " + campaignId, e);
    }
}

From source file:net.solarnetwork.node.dao.jdbc.reactor.JdbcInstructionDao.java

@Override
@Transactional(readOnly = true, propagation = Propagation.REQUIRED)
public Instruction getInstruction(Long instructionId) {
    return getJdbcTemplate().query(getSqlResource(RESOURCE_SQL_SELECT_INSTRUCTION_FOR_ID),
            new Object[] { instructionId }, new ResultSetExtractor<Instruction>() {

                @Override/* ww  w  .  j  a  v a 2 s  . c  om*/
                public Instruction extractData(ResultSet rs) throws SQLException, DataAccessException {
                    List<Instruction> results = extractInstructions(rs);
                    if (results.size() > 0) {
                        return results.get(0);
                    }
                    return null;
                }
            });
}