Example usage for java.sql ResultSet setFetchSize

List of usage examples for java.sql ResultSet setFetchSize

Introduction

In this page you can find the example usage for java.sql ResultSet setFetchSize.

Prototype

void setFetchSize(int rows) throws SQLException;

Source Link

Document

Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed for this ResultSet object.

Usage

From source file:org.ensembl.healthcheck.testcase.eg_compara.AbstractControlledRows.java

/**
 * For every row of the table controlledTableToTest in the database 
 * testDbre this checks, if this row also exists in the table 
 * masterTable of masterDbRe.//from   w  w  w  .ja v a 2 s  .com
 * 
 */
protected boolean checkRangeOfRowsInTable(final String controlledTableToTest, final String masterTable,
        DatabaseRegistryEntry testDbre, DatabaseRegistryEntry masterDbRe, String whereClause, int limit,
        int offset) {

    final Connection testDbConn = testDbre.getConnection();
    final Connection masterconn = masterDbRe.getConnection();

    final SqlTemplate sqlTemplateTestDb = getSqlTemplate(testDbConn);
    final SqlTemplate sqlTemplateComparaMaster = getSqlTemplate(masterconn);

    String fetchAllRowsFromTableSql = generateFetchAllRowsFromTableSql(testDbConn, controlledTableToTest,
            whereClause, limit, offset);

    final EnsTestCase thisTest = this;
    final List<String> testTableColumns = getColumnsOfTable(testDbConn, controlledTableToTest);

    boolean result = sqlTemplateTestDb.execute(fetchAllRowsFromTableSql, new ResultSetCallback<Boolean>() {

        @Override
        public Boolean process(ResultSet rs) throws SQLException {

            rs.setFetchSize(batchSize);

            boolean allRowsPresentInMasterDb = true;

            while (rs.next() && !numReportedRowsExceedsMaximum()) {

                boolean currentRowPresentInMasterDb = isCurrentRowInMaster(rs, sqlTemplateComparaMaster,
                        masterTable, testTableColumns);

                allRowsPresentInMasterDb &= currentRowPresentInMasterDb;

                if (!currentRowPresentInMasterDb) {

                    numReportedRows++;

                    if (numReportedRowsExceedsMaximum()) {
                        ReportManager.problem(thisTest, testDbConn,
                                "The maximum of " + getMaxReportedMismatches()
                                        + " reported rows has been reached, no further rows will be tested.");
                    } else {
                        ReportManager.problem(thisTest, testDbConn,
                                "Row not found in master: " + resultSetRowAsString(rs));
                    }
                }
            }
            return allRowsPresentInMasterDb;
        }
    },
            // No bound parameters
            //
            new Object[0]);
    return result;
}

From source file:org.hyperic.hq.measurement.server.session.AvailabilityDataDAO.java

protected Map<Integer, Long> executeAvailQuery(Connection conn, final String sql, final int batchSize,
        IAvailExtractionStrategy extractStrtg) throws SQLException {
    Statement stmt = null;/*  ww w .  j a  va2s  .  c o  m*/
    ResultSet rs = null;
    Map<Integer, Long> rtn = new HashMap<Integer, Long>();
    try {
        stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        rs = stmt.executeQuery(sql);
        rs.setFetchSize(batchSize);
        Long accumulatedTime;
        int availId;
        while (rs.next()) {
            availId = rs.getInt(1);
            accumulatedTime = rtn.get(Integer.valueOf(availId));
            rtn.put(availId, Long.valueOf(
                    extractStrtg.extract(rs) + (accumulatedTime != null ? accumulatedTime.longValue() : 0)));
        }
    } finally {
        DBUtil.closeResultSet(logCtx, rs);
        DBUtil.closeStatement(logCtx, stmt);
    }
    return rtn;
}