Example usage for java.sql CallableStatement setFetchSize

List of usage examples for java.sql CallableStatement setFetchSize

Introduction

In this page you can find the example usage for java.sql CallableStatement 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 ResultSet objects generated by this Statement.

Usage

From source file:com.toxind.benchmark.thrid.ibatis.sqlmap.engine.execution.SqlExecutor.java

/**
 * Execute a stored procedure/*from ww  w  .  ja v a 2s .c om*/
 * 
 * @param statementScope
 *            - the request scope
 * @param conn
 *            - the database connection
 * @param sql
 *            - the sql to call the procedure
 * @param parameters
 *            - the parameters for the procedure
 * @param skipResults
 *            - the number of results to skip
 * @param maxResults
 *            - the maximum number of results to return
 * @param callback
 *            - a row handler for processing the results
 * @throws SQLException
 *             - if the procedure fails
 */
public void executeQueryProcedure(StatementScope statementScope, Connection conn, String sql,
        Object[] parameters, int skipResults, int maxResults, RowHandlerCallback callback) throws SQLException {
    ErrorContext errorContext = statementScope.getErrorContext();
    errorContext.setActivity("executing query procedure");
    errorContext.setObjectId(sql);
    CallableStatement cs = null;
    ResultSet rs = null;
    setupResultObjectFactory(statementScope);
    try {
        errorContext.setMoreInfo("Check the SQL Statement (preparation failed).");
        Integer rsType = statementScope.getStatement().getResultSetType();
        if (rsType != null) {
            cs = prepareCall(statementScope.getSession(), conn, sql, rsType);
        } else {
            cs = prepareCall(statementScope.getSession(), conn, sql);
        }
        setStatementTimeout(statementScope.getStatement(), cs);
        Integer fetchSize = statementScope.getStatement().getFetchSize();
        if (fetchSize != null) {
            cs.setFetchSize(fetchSize.intValue());
        }
        ParameterMap parameterMap = statementScope.getParameterMap();
        ParameterMapping[] mappings = parameterMap.getParameterMappings();
        errorContext.setMoreInfo("Check the output parameters (register output parameters failed).");
        registerOutputParameters(cs, mappings);
        errorContext.setMoreInfo("Check the parameters (set parameters failed).");
        parameterMap.setParameters(statementScope, cs, parameters);
        errorContext.setMoreInfo("Check the statement (update procedure failed).");
        cs.execute();
        errorContext.setMoreInfo("Check the results (failed to retrieve results).");

        // Begin ResultSet Handling
        rs = handleMultipleResults(cs, statementScope, skipResults, maxResults, callback);
        // End ResultSet Handling
        errorContext.setMoreInfo("Check the output parameters (retrieval of output parameters failed).");
        retrieveOutputParameters(statementScope, cs, mappings, parameters, callback);

    } finally {
        try {
            closeResultSet(rs);
        } finally {
            closeStatement(statementScope.getSession(), cs);
        }
    }
}

From source file:org.apache.openjpa.jdbc.sql.SQLBuffer.java

/**
 * Create and populate the parameters of a prepred statement using the
 * SQL in this buffer and the given fetch configuration.
 *///from  w w  w. ja v a 2  s . c  o m
public CallableStatement prepareCall(Connection conn, JDBCFetchConfiguration fetch, int rsType, int rsConcur)
        throws SQLException {
    if (rsType == -1 && fetch == null)
        rsType = ResultSet.TYPE_FORWARD_ONLY;
    else if (rsType == -1)
        rsType = fetch.getResultSetType();
    if (rsConcur == -1)
        rsConcur = ResultSet.CONCUR_READ_ONLY;

    CallableStatement stmnt;
    if (rsType == ResultSet.TYPE_FORWARD_ONLY && rsConcur == ResultSet.CONCUR_READ_ONLY)
        stmnt = conn.prepareCall(getSQL());
    else
        stmnt = conn.prepareCall(getSQL(), rsType, rsConcur);
    try {
        setParameters(stmnt);
        if (fetch != null) {
            if (fetch.getFetchBatchSize() > 0)
                stmnt.setFetchSize(_dict.getBatchFetchSize(fetch.getFetchBatchSize()));
            if (rsType != ResultSet.TYPE_FORWARD_ONLY && fetch.getFetchDirection() != ResultSet.FETCH_FORWARD)
                stmnt.setFetchDirection(fetch.getFetchDirection());
        }
        return stmnt;
    } catch (SQLException se) {
        try {
            stmnt.close();
        } catch (SQLException se2) {
        }
        throw se;
    }
}

From source file:org.s23m.cell.repository.RelationalDatabaseRepository.java

private CallableStatement execueteUUIDQuery(final String queryName, final String uuid) throws SQLException {
    final Connection connection = DriverManager
            .getConnection("jdbc:apache:commons:dbcp:" + REPOSITORY_CONNECTION_POOL_ID); //$NON-NLS-1$
    connection.setAutoCommit(false);/*  w ww .j a  v a 2s.  c o  m*/
    final CallableStatement stmt = connection.prepareCall("{ call " + queryName + "(?) }", //$NON-NLS-1$
            ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    stmt.setString(1, uuid);
    stmt.setFetchSize(Integer.MIN_VALUE);
    stmt.execute();
    returnConnectionToPool(connection);
    return stmt;
}

From source file:org.s23m.cell.repository.RelationalDatabaseRepository.java

@SuppressWarnings("unchecked")
protected Map<String, String> getContainmentTree(final String uuid, final int depth)
        throws IllegalStateException {
    CallableStatement fetchContainedInstanceProc = null;
    final PreparedStatement preStmt = null;
    Connection connection = null;
    try {/*from w  ww  .j  ava2s . c  om*/
        connection = DriverManager.getConnection("jdbc:apache:commons:dbcp:" + REPOSITORY_CONNECTION_POOL_ID); //$NON-NLS-1$
        connection.setAutoCommit(false);
        fetchContainedInstanceProc = connection.prepareCall("{ call getContainedInstances(?) }", //$NON-NLS-1$
                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        fetchContainedInstanceProc.setString(1, uuid);
        fetchContainedInstanceProc.setFetchSize(Integer.MIN_VALUE);
        final Map uuidsToFetch = getContainmentTreeUUIDs(uuid);
        System.err.println(uuidsToFetch.size());

        final String fetchXmlString = "select urr, contentAsXml from instance where urr = ?";
        final StatementBatchManager fetchXmlStatementMan = new StatementBatchManager(
                connection.prepareStatement(fetchXmlString), "instance", "", "", UPDATE_BATCH_SIZE,
                READ_BATCH_SIZE);

        final ListOrderedMap fetchedArtifacts = fetchArtifacts(uuidsToFetch, fetchXmlStatementMan);
        fetchXmlStatementMan.getStatement().close();
        return fetchedArtifacts;
    } catch (final SQLException ex) {
        throw new IllegalStateException("SQL exception", ex); //$NON-NLS-1$
    } finally {
        returnConnectionToPool(connection);
    }
}