Search in sources :

Example 31 with Result

use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.

the class QuerySpecification method buildResult.

private Result buildResult(Session session, int limitcount) {
    RowSetNavigatorData navigator = new RowSetNavigatorData(session, this);
    Result result = Result.newResult(navigator);
    result.metaData = resultMetaData;
    result.setDataResultConcurrency(isUpdatable);
    // Test for early return case added by VoltDB to support LIMIT 0 in "HSQL backend".
    if (limitcount == 0) {
        return result;
    }
    // End of VoltDB extension
    int fullJoinIndex = 0;
    RangeIterator[] rangeIterators = new RangeIterator[rangeVariables.length];
    for (int i = 0; i < rangeVariables.length; i++) {
        rangeIterators[i] = rangeVariables[i].getIterator(session);
    }
    for (int currentIndex = 0; ; ) {
        if (currentIndex < fullJoinIndex) {
            boolean end = true;
            for (int i = fullJoinIndex + 1; i < rangeVariables.length; i++) {
                if (rangeVariables[i].isRightJoin) {
                    rangeIterators[i] = rangeVariables[i].getFullIterator(session, (RangeIteratorMain) rangeIterators[i]);
                    fullJoinIndex = i;
                    currentIndex = i;
                    end = false;
                    break;
                }
            }
            if (end) {
                break;
            }
        }
        RangeIterator it = rangeIterators[currentIndex];
        if (it.next()) {
            if (currentIndex < rangeVariables.length - 1) {
                currentIndex++;
                continue;
            }
        } else {
            it.reset();
            currentIndex--;
            continue;
        }
        session.sessionData.startRowProcessing();
        Object[] data = new Object[indexLimitData];
        for (int i = 0; i < indexStartAggregates; i++) {
            if (isAggregated && aggregateCheck[i]) {
                continue;
            } else {
                data[i] = exprColumns[i].getValue(session);
            }
        }
        for (int i = indexLimitVisible; i < indexLimitRowId; i++) {
            data[i] = it.getRowidObject();
        }
        Object[] groupData = null;
        if (isAggregated || isGrouped) {
            groupData = navigator.getGroupData(data);
            if (groupData != null) {
                data = groupData;
            }
        }
        for (int i = indexStartAggregates; i < indexLimitExpressions; i++) {
            data[i] = ((ExpressionAggregate) exprColumns[i]).updateAggregatingValue(session, data[i]);
        }
        if (groupData == null) {
            navigator.add(data);
        }
        if (isAggregated || isGrouped) {
            continue;
        }
        if (navigator.getSize() >= limitcount) {
            break;
        }
    }
    navigator.reset();
    if (!isGrouped && !isAggregated) {
        return result;
    }
    if (isAggregated) {
        if (!isGrouped && navigator.getSize() == 0) {
            Object[] data = new Object[exprColumns.length];
            navigator.add(data);
        }
        RangeIteratorBase it = new RangeIteratorBase(session, navigator.store, navigator.table, resultRangePosition);
        session.sessionContext.setRangeIterator(it);
        while (it.next()) {
            for (int i = indexStartAggregates; i < indexLimitExpressions; i++) {
                ExpressionAggregate aggregate = (ExpressionAggregate) exprColumns[i];
                it.currentData[i] = aggregate.getAggregatedValue(session, it.currentData[i]);
            }
            for (int i = 0; i < indexStartAggregates; i++) {
                if (aggregateCheck[i]) {
                    it.currentData[i] = exprColumns[i].getValue(session);
                }
            }
        }
    }
    navigator.reset();
    if (havingCondition != null) {
        while (navigator.hasNext()) {
            Object[] data = navigator.getNext();
            if (!Boolean.TRUE.equals(data[indexLimitVisible + groupByColumnCount])) {
                navigator.remove();
            }
        }
        navigator.reset();
    }
    return result;
}
Also used : RowSetNavigatorData(org.hsqldb_voltpatches.navigator.RowSetNavigatorData) RangeIterator(org.hsqldb_voltpatches.navigator.RangeIterator) RangeIteratorBase(org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase) RangeIteratorMain(org.hsqldb_voltpatches.RangeVariable.RangeIteratorMain) Result(org.hsqldb_voltpatches.result.Result)

Example 32 with Result

use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.

the class JDBCConnection method releaseSavepoint.

//#endif JAVA4
/**
     * <!-- start generic documentation -->
     *
     * Removes the specified <code>Savepoint</code> (JDBC4 Clarification:) and subsequent <code>Savepoint</code> objects from the current
     * transaction. Any reference to the savepoint after it have been removed
     * will cause an <code>SQLException</code> to be thrown.
     *
     * <!-- end generic documentation -->
     *
     *
     * <b>HSLQDB Note:</b><p>
     *
     * Previous to JDBC 4, <tt>JDBCSavepoint</tt> objects are valid for the life of
     * the originating <tt>Connection</tt> object and hence can be used
     * interchangably, as long as they have equal savepoint names. <p>
     *
     * When built for JDBC 4, <tt>JDBCConnection</tt> objects invalidate
     * <tt>JDBCSavepoint</tt> objects when auto-commit mode is entered as well
     * as when they are used to successfully release or roll back to a named SQL
     * savepoint.  As per the JDBC 4 standard, when built for JDBC 4, this
     * method throws an <tt>SQLException</tt> when this <tt>Connection</tt>
     * object is currently in auto-commit mode and when an invalidated
     * <tt>JDBCSavepoint</tt> is specified. <p>
     *
     * @param savepoint the <code>Savepoint</code> object to be removed
     * @exception SQLException if a database access error occurs, this
     *  (JDBC4 Clarification:)
     *  method is called on a closed connection or
     *            the given <code>Savepoint</code> object is not a valid
     *            savepoint in the current transaction
     * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
     * this method
     * @see JDBCSavepoint
     * @see java.sql.Savepoint
     * @since JDK 1.4, HSQLDB 1.7.2
     */
//#ifdef JAVA4
public synchronized void releaseSavepoint(Savepoint savepoint) throws SQLException {
    JDBCSavepoint sp;
    Result req;
    checkClosed();
    if (savepoint == null) {
        throw Util.nullArgument();
    }
    if (!(savepoint instanceof JDBCSavepoint)) {
        String msg = Error.getMessage(ErrorCode.X_3B001);
        throw Util.invalidArgument(msg);
    }
    sp = (JDBCSavepoint) savepoint;
    if (JDBCDatabaseMetaData.JDBC_MAJOR >= 4 && sp.name == null) {
        String msg = Error.getMessage(ErrorCode.X_3B001);
        throw Util.invalidArgument(msg);
    }
    if (this != sp.connection) {
        String msg = Error.getMessage(ErrorCode.X_3B001);
        throw Util.invalidArgument(msg);
    }
    if (JDBCDatabaseMetaData.JDBC_MAJOR >= 4 && getAutoCommit()) {
        sp.name = null;
        sp.connection = null;
        throw Util.sqlException(ErrorCode.X_3B001);
    }
    try {
        sessionProxy.releaseSavepoint(sp.name);
        if (JDBCDatabaseMetaData.JDBC_MAJOR >= 4) {
            sp.connection = null;
            sp.name = null;
        }
    } catch (HsqlException e) {
        throw Util.sqlException(e);
    }
}
Also used : HsqlException(org.hsqldb_voltpatches.HsqlException) Result(org.hsqldb_voltpatches.result.Result)

Example 33 with Result

use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.

the class BlobDataID method length.

public long length(SessionInterface session) {
    ResultLob resultOut = ResultLob.newLobGetLengthRequest(id);
    Result resultIn = session.execute(resultOut);
    if (resultIn.isError()) {
        throw resultIn.getException();
    }
    return ((ResultLob) resultIn).getBlockLength();
}
Also used : ResultLob(org.hsqldb_voltpatches.result.ResultLob) Result(org.hsqldb_voltpatches.result.Result)

Example 34 with Result

use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.

the class BlobDataID method getBlob.

public BlobData getBlob(SessionInterface session, long pos, long length) {
    ResultLob resultOut = ResultLob.newLobGetRequest(id, pos, length);
    Result resultIn = session.execute(resultOut);
    if (resultIn.isError()) {
        throw Error.error(resultIn);
    }
    long lobID = ((ResultLob) resultIn).getLobID();
    return new BlobDataID(lobID);
}
Also used : ResultLob(org.hsqldb_voltpatches.result.ResultLob) Result(org.hsqldb_voltpatches.result.Result)

Example 35 with Result

use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.

the class BlobDataID method truncate.

public void truncate(SessionInterface session, long len) {
    ResultLob resultOut = ResultLob.newLobTruncateRequest(id, len);
    Result resultIn = session.execute(resultOut);
    if (resultIn.isError()) {
        throw resultIn.getException();
    }
}
Also used : ResultLob(org.hsqldb_voltpatches.result.ResultLob) Result(org.hsqldb_voltpatches.result.Result)

Aggregations

Result (org.hsqldb_voltpatches.result.Result)83 Session (org.hsqldb_voltpatches.Session)18 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)16 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)15 Table (org.hsqldb_voltpatches.Table)14 ResultLob (org.hsqldb_voltpatches.result.ResultLob)13 TextTable (org.hsqldb_voltpatches.TextTable)12 ResultMetaData (org.hsqldb_voltpatches.result.ResultMetaData)11 RowSetNavigator (org.hsqldb_voltpatches.navigator.RowSetNavigator)10 HsqlException (org.hsqldb_voltpatches.HsqlException)5 RowSetNavigatorData (org.hsqldb_voltpatches.navigator.RowSetNavigatorData)4 EOFException (java.io.EOFException)3 RowSetNavigatorClient (org.hsqldb_voltpatches.navigator.RowSetNavigatorClient)3 IOException (java.io.IOException)2 RangeIteratorBase (org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase)2 Statement (org.hsqldb_voltpatches.Statement)2 HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)2 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)2 HsqlByteArrayInputStream (org.hsqldb_voltpatches.lib.HsqlByteArrayInputStream)2 Iterator (org.hsqldb_voltpatches.lib.Iterator)2