Example usage for java.sql ResultSet HOLD_CURSORS_OVER_COMMIT

List of usage examples for java.sql ResultSet HOLD_CURSORS_OVER_COMMIT

Introduction

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

Prototype

int HOLD_CURSORS_OVER_COMMIT

To view the source code for java.sql ResultSet HOLD_CURSORS_OVER_COMMIT.

Click Source Link

Document

The constant indicating that open ResultSet objects with this holdability will remain open when the current transaction is committed.

Usage

From source file:org.xenei.jdbc4sparql.J4SDatabaseMetaData.java

@Override
public int getResultSetHoldability() throws SQLException {
    return ResultSet.HOLD_CURSORS_OVER_COMMIT;
}

From source file:org.xenei.jdbc4sparql.J4SConnection.java

@Override
public void setHoldability(final int holdability) throws SQLException {
    // don't support ResultSet.CLOSE_CURSORS_AT_COMMIT
    if (holdability != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
        throw new SQLFeatureNotSupportedException("Invalid holdability value");
    }//w ww .  j a  v  a  2s  .c  o m
    this.holdability = holdability;
}

From source file:ro.nextreports.engine.queryexec.QueryExecutor.java

private PreparedStatement createStatement(String queryString) throws QueryException {
    // create the prepared statement
    PreparedStatement pstmt;//from w  w  w.j  av a 2  s .  co  m
    try {

        boolean hasScrollType = false;
        try {
            hasScrollType = DialectUtil.isSupportedResultSetType(conn, ResultSet.TYPE_SCROLL_INSENSITIVE);
        } catch (Exception ex) {
            ex.printStackTrace();
            LOG.error(ex.getMessage(), ex);
        }
        int resultSetType = hasScrollType ? ResultSet.TYPE_SCROLL_INSENSITIVE : ResultSet.TYPE_FORWARD_ONLY;

        if (QueryUtil.isProcedureCall(queryString)) {
            pstmt = conn.prepareCall("{" + queryString + "}", resultSetType, ResultSet.CONCUR_READ_ONLY);
        } else {
            if (isCsv) {
                pstmt = conn.prepareStatement(queryString);
            } else {
                boolean keepCursorsOverCommit = false;
                try {
                    Dialect dialect = DialectUtil.getDialect(conn);
                    keepCursorsOverCommit = dialect.needsHoldCursorsForPreparedStatement();
                } catch (DialectException e) {
                    e.printStackTrace();
                    LOG.error(e.getMessage(), e);
                }
                if (keepCursorsOverCommit) {
                    pstmt = conn.prepareStatement(queryString, resultSetType, ResultSet.CONCUR_READ_ONLY,
                            ResultSet.HOLD_CURSORS_OVER_COMMIT);
                } else {
                    pstmt = conn.prepareStatement(queryString, resultSetType, ResultSet.CONCUR_READ_ONLY);
                }
            }
        }
        // ignore queryTimeout and maxRows (some drivers - derby - not implement
        // these feature yet)
        try {
            // set timeout
            pstmt.setQueryTimeout(timeout);

            // set max rows
            pstmt.setMaxRows(maxRows);
        } catch (SQLException e) {
            LOG.warn(e);
        }
    } catch (SQLException e) {
        throw new QueryException(e);
    }

    return pstmt;
}

From source file:com.alibaba.wasp.jdbc.JdbcConnection.java

private void checkHoldability(int resultSetHoldability) {
    if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT
            && resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) {
        throw JdbcException.getInvalidValueException("resultSetHoldability", resultSetHoldability);
    }//  ww w . j a v a2 s.  co  m
}

From source file:com.alibaba.wasp.jdbc.JdbcStatement.java

/**
 * Gets the result set holdability./*from   w  ww.  j a v a 2 s.  c  o m*/
 * 
 * @return the holdability
 */
@Override
public int getResultSetHoldability() throws SQLException {
    try {
        checkClosed();
        return ResultSet.HOLD_CURSORS_OVER_COMMIT;
    } catch (Exception e) {
        throw Logger.logAndConvert(log, e);
    }
}

From source file:org.kawanfw.sql.jdbc.ConnectionHttp.java

/**
 * Creates a <code>Statement</code> object that will generate
 * <code>ResultSet</code> objects with the given type, concurrency, and
 * holdability. This method is the same as the <code>createStatement</code>
 * method above, but it allows the default result set type, concurrency, and
 * holdability to be overridden.//from  www  . j  a v  a 2  s.  c  o m
 * 
 * @param resultSetType
 *            one of the following <code>ResultSet</code> constants:
 *            <code>ResultSet.TYPE_FORWARD_ONLY</code>,
 *            <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
 *            <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
 * @param resultSetConcurrency
 *            one of the following <code>ResultSet</code> constants:
 *            <code>ResultSet.CONCUR_READ_ONLY</code> or
 *            <code>ResultSet.CONCUR_UPDATABLE</code>
 * @param resultSetHoldability
 *            one of the following <code>ResultSet</code> constants:
 *            <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
 *            <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
 * @return a new <code>Statement</code> object that will generate
 *         <code>ResultSet</code> objects with the given type, concurrency,
 *         and holdability
 * @exception SQLException
 *                if a database access error occurs, this method is called
 *                on a closed connection or the given parameters are not
 *                <code>ResultSet</code> constants indicating type,
 *                concurrency, and holdability
 * @exception SQLFeatureNotSupportedException
 *                if the JDBC driver does not support this method or this
 *                method is not supported for the specified result set type,
 *                result set holdability and result set concurrency.
 * @see ResultSet
 * @since 1.4
 */
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
        throws SQLException {
    testIfClosed();

    // We support only ResultSet.CONCUR_READ_ONLY
    if (resultSetConcurrency == ResultSet.CONCUR_UPDATABLE) {
        throw new SQLFeatureNotSupportedException("Concurrency ResultSet.CONCUR_UPDATABLE is not supported.");
    }

    // We support only ResultSet.CLOSE_CURSORS_AT_COMMIT
    if (resultSetHoldability == ResultSet.HOLD_CURSORS_OVER_COMMIT) {
        throw new SQLFeatureNotSupportedException(
                "Concurrency ResultSet.HOLD_CURSORS_OVER_COMMIT is not supported.");
    }

    return new StatementHttp(this, resultSetType, resultSetConcurrency, resultSetHoldability);
}

From source file:net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.java

protected static int getHoldability(String holdability, Connection connection) throws SQLException {
    if (HOLD_CURSORS_OVER_COMMIT.equals(holdability)) {
        return ResultSet.HOLD_CURSORS_OVER_COMMIT;
    } else if (CLOSE_CURSORS_AT_COMMIT.equals(holdability)) {
        return ResultSet.CLOSE_CURSORS_AT_COMMIT;
    }//from  w  w w  . jav  a 2  s .c o  m

    return connection.getHoldability();
}

From source file:org.kawanfw.sql.jdbc.ConnectionHttp.java

/**
 * Creates a <code>CallableStatement</code> object that will generate
 * <code>ResultSet</code> objects with the given type and concurrency. This
 * method is the same as the <code>prepareCall</code> method above, but it
 * allows the default result set type, result set concurrency type and
 * holdability to be overridden./*  w ww . ja  va2s  .  c  o m*/
 * 
 * @param sql
 *            a <code>String</code> object that is the SQL statement to be
 *            sent to the database; may contain on or more ? parameters
 * @param resultSetType
 *            one of the following <code>ResultSet</code> constants:
 *            <code>ResultSet.TYPE_FORWARD_ONLY</code>,
 *            <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
 *            <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
 * @param resultSetConcurrency
 *            one of the following <code>ResultSet</code> constants:
 *            <code>ResultSet.CONCUR_READ_ONLY</code> or
 *            <code>ResultSet.CONCUR_UPDATABLE</code>
 * @param resultSetHoldability
 *            one of the following <code>ResultSet</code> constants:
 *            <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
 *            <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
 * @return a new <code>CallableStatement</code> object, containing the
 *         pre-compiled SQL statement, that will generate
 *         <code>ResultSet</code> objects with the given type, concurrency,
 *         and holdability
 * @exception SQLException
 *                if a database access error occurs or the given parameters
 *                are not <code>ResultSet</code> constants indicating type,
 *                concurrency, and holdability
 * @see ResultSet
 * @since 1.4
 */
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
        int resultSetHoldability) throws SQLException {
    testIfClosed();

    // We support only ResultSet.CONCUR_READ_ONLY
    if (resultSetConcurrency == ResultSet.CONCUR_UPDATABLE) {
        throw new SQLFeatureNotSupportedException("Concurrency ResultSet.CONCUR_UPDATABLE is not supported.");
    }

    // We support only ResultSet.CLOSE_CURSORS_AT_COMMIT
    if (resultSetHoldability == ResultSet.HOLD_CURSORS_OVER_COMMIT) {
        throw new SQLFeatureNotSupportedException(
                "Concurrency ResultSet.HOLD_CURSORS_OVER_COMMIT is not supported.");
    }

    return new CallableStatementHttp(this, sql, resultSetType, resultSetConcurrency, resultSetHoldability);

}

From source file:org.xenei.jdbc4sparql.J4SDatabaseMetaData.java

@Override
public boolean supportsResultSetType(final int arg0) throws SQLException {
    switch (arg0) {
    case ResultSet.TYPE_FORWARD_ONLY:
    case ResultSet.CONCUR_READ_ONLY:
    case ResultSet.TYPE_SCROLL_INSENSITIVE:
    case ResultSet.HOLD_CURSORS_OVER_COMMIT:
        return true;

    case ResultSet.CLOSE_CURSORS_AT_COMMIT:
    case ResultSet.CONCUR_UPDATABLE:
    case ResultSet.TYPE_SCROLL_SENSITIVE:
    default://from  w ww . j a  v a2 s. co  m
        return false;
    }
}

From source file:net.antidot.semantic.rdf.rdb2rdf.r2rml.core.R2RMLEngine.java

/**
 * Construct logical table. Note : Run SQL Query against database calling
 * the method Connection.commit can close the ResultSet objects that have
 * been created during the current transaction. In some cases, however, this
 * may not be the desired behavior. The ResultSet property holdability gives
 * the application control over whether ResultSet objects (cursors) are
 * closed when commit is called./*ww  w .  j a v a  2 s . c om*/
 * 
 * @param triplesMap
 * @throws SQLException
 */
private ResultSet constructLogicalTable(TriplesMap triplesMap) throws SQLException {
    log.debug("[R2RMLEngine:constructLogicalTable] Run effective SQL Query : "
            + triplesMap.getLogicalTable().getEffectiveSQLQuery());
    ResultSet rs = null;
    java.sql.Statement s = conn.createStatement(ResultSet.HOLD_CURSORS_OVER_COMMIT, ResultSet.CONCUR_READ_ONLY);
    if (triplesMap.getLogicalTable().getEffectiveSQLQuery() != null) {

        s.executeQuery(triplesMap.getLogicalTable().getEffectiveSQLQuery());
        rs = s.getResultSet();
        if (rs == null)
            throw new IllegalStateException("[R2RMLEngine:constructLogicalTable] SQL request "
                    + "failed : result of effective SQL query is null.");

    } else {
        throw new IllegalStateException(
                "[R2RMLEngine:constructLogicalTable] No effective SQL query has been found.");
    }
    // Commit to held logical table (read-only)
    conn.setAutoCommit(false);
    conn.commit();
    return rs;
}