Search in sources :

Example 1 with RowSetNavigator

use of org.hsqldb_voltpatches.navigator.RowSetNavigator in project voltdb by VoltDB.

the class LobManager method getLobHeader.

private Object[] getLobHeader(Session session, long lobID) {
    ResultMetaData meta = getLob.getParametersMetaData();
    Object[] params = new Object[meta.getColumnCount()];
    params[0] = Long.valueOf(lobID);
    session.sessionContext.pushDynamicArguments(params);
    Result result = getLob.execute(session);
    session.sessionContext.popDynamicArguments();
    if (result.isError()) {
        return null;
    }
    RowSetNavigator navigator = result.getNavigator();
    boolean next = navigator.next();
    if (!next) {
        navigator.close();
        return null;
    }
    Object[] data = navigator.getCurrent();
    return data;
}
Also used : RowSetNavigator(org.hsqldb_voltpatches.navigator.RowSetNavigator) ResultMetaData(org.hsqldb_voltpatches.result.ResultMetaData) Result(org.hsqldb_voltpatches.result.Result)

Example 2 with RowSetNavigator

use of org.hsqldb_voltpatches.navigator.RowSetNavigator in project voltdb by VoltDB.

the class LobManager method getBlockAddresses.

int[][] getBlockAddresses(Session session, long lobID, int offset, int limit) {
    ResultMetaData meta = getLobPart.getParametersMetaData();
    Object[] params = new Object[meta.getColumnCount()];
    params[0] = Long.valueOf(lobID);
    params[1] = Integer.valueOf(offset);
    params[2] = Integer.valueOf(limit);
    session.sessionContext.pushDynamicArguments(params);
    Result result = getLobPart.execute(session);
    session.sessionContext.popDynamicArguments();
    RowSetNavigator navigator = result.getNavigator();
    int size = navigator.getSize();
    int[][] blocks = new int[size][3];
    for (int i = 0; i < size; i++) {
        navigator.absolute(i);
        Object[] data = navigator.getCurrent();
        blocks[i][0] = ((Integer) data[LOBS.BLOCK_ADDR]).intValue();
        blocks[i][1] = ((Integer) data[LOBS.BLOCK_COUNT]).intValue();
        blocks[i][2] = ((Integer) data[LOBS.BLOCK_OFFSET]).intValue();
    }
    navigator.close();
    return blocks;
}
Also used : RowSetNavigator(org.hsqldb_voltpatches.navigator.RowSetNavigator) ResultMetaData(org.hsqldb_voltpatches.result.ResultMetaData) Result(org.hsqldb_voltpatches.result.Result)

Example 3 with RowSetNavigator

use of org.hsqldb_voltpatches.navigator.RowSetNavigator in project voltdb by VoltDB.

the class Table method insertResult.

/**
     * Used for subquery inserts. No checks. No identity
     * columns.
     */
void insertResult(PersistentStore store, Result ins) {
    RowSetNavigator nav = ins.initialiseNavigator();
    while (nav.hasNext()) {
        Object[] data = nav.getNext();
        Object[] newData = (Object[]) ArrayUtil.resizeArrayIfDifferent(data, getColumnCount());
        insertData(store, newData);
    }
}
Also used : RowSetNavigator(org.hsqldb_voltpatches.navigator.RowSetNavigator) CachedObject(org.hsqldb_voltpatches.persist.CachedObject)

Example 4 with RowSetNavigator

use of org.hsqldb_voltpatches.navigator.RowSetNavigator in project voltdb by VoltDB.

the class JDBCPreparedStatement method executeBatch.

//------------------------- JDBC 2.0 - overriden methods -------------------
/**
     * <!-- start generic documentation -->
     * Submits a batch of commands to the database for execution and
     * if all commands execute successfully, returns an array of update counts.
     * The <code>int</code> elements of the array that is returned are ordered
     * to correspond to the commands in the batch, which are ordered
     * according to the order in which they were added to the batch.
     * The elements in the array returned by the method <code>executeBatch</code>
     * may be one of the following:
     * <OL>
     * <LI>A number greater than or equal to zero -- indicates that the
     * command was processed successfully and is an update count giving the
     * number of rows in the database that were affected by the command's
     * execution
     * <LI>A value of <code>SUCCESS_NO_INFO</code> -- indicates that the command was
     * processed successfully but that the number of rows affected is
     * unknown
     * <P>
     * If one of the commands in a batch update fails to execute properly,
     * this method throws a <code>BatchUpdateException</code>, and a JDBC
     * driver may or may not continue to process the remaining commands in
     * the batch.  However, the driver's behavior must be consistent with a
     * particular DBMS, either always continuing to process commands or never
     * continuing to process commands.  If the driver continues processing
     * after a failure, the array returned by the method
     * <code>BatchUpdateException.getUpdateCounts</code>
     * will contain as many elements as there are commands in the batch, and
     * at least one of the elements will be the following:
     * <P>
     * <LI>A value of <code>EXECUTE_FAILED</code> -- indicates that the command failed
     * to execute successfully and occurs only if a driver continues to
     * process commands after a command fails
     * </OL>
     * <P>
     * A driver is not required to implement this method.
     * The possible implementations and return values have been modified in
     * the Java 2 SDK, Standard Edition, version 1.3 to
     * accommodate the option of continuing to proccess commands in a batch
     * update after a <code>BatchUpdateException</code> obejct has been thrown. <p>
     * <!-- end generic documentation -->
     *
     * <!-- start release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * Starting with HSQLDB 1.7.2, this feature is supported. <p>
     *
     * HSQLDB stops execution of commands in a batch when one of the commands
     * results in an exception. The size of the returned array equals the
     * number of commands that were executed successfully.<p>
     *
     * When the product is built under the JAVA1 target, an exception
     * is never thrown and it is the responsibility of the client software to
     * check the size of the  returned update count array to determine if any
     * batch items failed.  To build and run under the JAVA2 target, JDK/JRE
     * 1.3 or higher must be used.
     * </div>
     * <!-- end release-specific documentation -->
     *
     * @return an array of update counts containing one element for each
     * command in the batch.  The elements of the array are ordered according
     * to the order in which commands were added to the batch.
     * @exception SQLException if a database access error occurs,
     * this method is called on a closed <code>Statement</code> or the
     * driver does not support batch statements. Throws {@link BatchUpdateException}
     * (a subclass of <code>SQLException</code>) if one of the commands sent to the
     * database fails to execute properly or attempts to return a result set.
     *
     *
     * @see #addBatch
     * @see java.sql.DatabaseMetaData#supportsBatchUpdates()
     * @since JDK 1.3 (JDK 1.1.x developers: read the overview for
     * JDBCStatement)
     */
public synchronized int[] executeBatch() throws SQLException {
    checkClosed();
    connection.clearWarningsNoCheck();
    checkStatementType(StatementTypes.RETURN_COUNT);
    if (!isBatch) {
        throw Util.sqlExceptionSQL(ErrorCode.X_07506);
    }
    generatedResult = null;
    int batchCount = resultOut.getNavigator().getSize();
    resultIn = null;
    try {
        resultIn = connection.sessionProxy.execute(resultOut);
    } catch (HsqlException e) {
        throw Util.sqlException(e);
    } finally {
        performPostExecute();
        resultOut.getNavigator().clear();
        isBatch = false;
    }
    if (resultIn.isError()) {
        throw Util.sqlException(resultIn);
    }
    RowSetNavigator navigator = resultIn.getNavigator();
    int[] updateCounts = new int[navigator.getSize()];
    for (int i = 0; i < updateCounts.length; i++) {
        Object[] data = (Object[]) navigator.getNext();
        updateCounts[i] = ((Integer) data[0]).intValue();
    }
    if (updateCounts.length != batchCount) {
        if (errorResult == null) {
            throw new BatchUpdateException(updateCounts);
        } else {
            errorResult.getMainString();
            throw new BatchUpdateException(errorResult.getMainString(), errorResult.getSubString(), errorResult.getErrorCode(), updateCounts);
        }
    }
    return updateCounts;
}
Also used : RowSetNavigator(org.hsqldb_voltpatches.navigator.RowSetNavigator) SchemaObject(org.hsqldb_voltpatches.SchemaObject) HsqlException(org.hsqldb_voltpatches.HsqlException) BatchUpdateException(java.sql.BatchUpdateException)

Example 5 with RowSetNavigator

use of org.hsqldb_voltpatches.navigator.RowSetNavigator in project voltdb by VoltDB.

the class JDBCResultSet method getCurrent.

//-------------------------- Private Methods -------------------------------
/**
     * Fetches the current row of the result set.
     *
     * @throws SQLException when result set is closed; result set is empty;
     *   result set is before first; result set is alfter last; no row data is
     *   available.
     * @return Object[]
     */
private Object[] getCurrent() throws SQLException {
    final RowSetNavigator lnavigator = this.navigator;
    if (lnavigator == null) {
        throw Util.sqlException(ErrorCode.X_24501);
    } else if (lnavigator.isEmpty()) {
        throw Util.sqlException(ErrorCode.X_24504, ErrorCode.M_RS_EMPTY);
    } else if (lnavigator.isBeforeFirst()) {
        throw Util.sqlException(ErrorCode.X_24504, ErrorCode.M_RS_BEFORE_FIRST);
    } else if (lnavigator.isAfterLast()) {
        throw Util.sqlException(ErrorCode.X_24504, ErrorCode.M_RS_AFTER_LAST);
    }
    Object[] data = lnavigator.getCurrent();
    if (data == null) {
        throw Util.sqlException(ErrorCode.X_24501);
    }
    return data;
}
Also used : RowSetNavigator(org.hsqldb_voltpatches.navigator.RowSetNavigator)

Aggregations

RowSetNavigator (org.hsqldb_voltpatches.navigator.RowSetNavigator)20 Result (org.hsqldb_voltpatches.result.Result)10 RowSetNavigatorClient (org.hsqldb_voltpatches.navigator.RowSetNavigatorClient)4 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)4 BatchUpdateException (java.sql.BatchUpdateException)2 HsqlException (org.hsqldb_voltpatches.HsqlException)2 SchemaObject (org.hsqldb_voltpatches.SchemaObject)2 HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)2 CachedObject (org.hsqldb_voltpatches.persist.CachedObject)2 ResultMetaData (org.hsqldb_voltpatches.result.ResultMetaData)2 RangeIteratorBase (org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase)1 RangeIterator (org.hsqldb_voltpatches.navigator.RangeIterator)1 RowSetNavigatorLinkedList (org.hsqldb_voltpatches.navigator.RowSetNavigatorLinkedList)1 BlobData (org.hsqldb_voltpatches.types.BlobData)1 ClobData (org.hsqldb_voltpatches.types.ClobData)1 Type (org.hsqldb_voltpatches.types.Type)1