Search in sources :

Example 36 with ResultInterface

use of org.h2.result.ResultInterface in project h2database by h2database.

the class CommandRemote method executeQuery.

@Override
public ResultInterface executeQuery(int maxRows, boolean scrollable) {
    checkParameters();
    synchronized (session) {
        int objectId = session.getNextId();
        ResultRemote result = null;
        for (int i = 0, count = 0; i < transferList.size(); i++) {
            prepareIfRequired();
            Transfer transfer = transferList.get(i);
            try {
                session.traceOperation("COMMAND_EXECUTE_QUERY", id);
                transfer.writeInt(SessionRemote.COMMAND_EXECUTE_QUERY).writeInt(id).writeInt(objectId).writeInt(maxRows);
                int fetch;
                if (session.isClustered() || scrollable) {
                    fetch = Integer.MAX_VALUE;
                } else {
                    fetch = fetchSize;
                }
                transfer.writeInt(fetch);
                sendParameters(transfer);
                session.done(transfer);
                int columnCount = transfer.readInt();
                if (result != null) {
                    result.close();
                    result = null;
                }
                result = new ResultRemote(session, transfer, objectId, columnCount, fetch);
                if (readonly) {
                    break;
                }
            } catch (IOException e) {
                session.removeServer(e, i--, ++count);
            }
        }
        session.autoCommitIfCluster();
        session.readSessionState();
        return result;
    }
}
Also used : ResultRemote(org.h2.result.ResultRemote) Transfer(org.h2.value.Transfer) IOException(java.io.IOException)

Example 37 with ResultInterface

use of org.h2.result.ResultInterface in project h2database by h2database.

the class CommandRemote method getMetaData.

@Override
public ResultInterface getMetaData() {
    synchronized (session) {
        if (!isQuery) {
            return null;
        }
        int objectId = session.getNextId();
        ResultRemote result = null;
        for (int i = 0, count = 0; i < transferList.size(); i++) {
            prepareIfRequired();
            Transfer transfer = transferList.get(i);
            try {
                session.traceOperation("COMMAND_GET_META_DATA", id);
                transfer.writeInt(SessionRemote.COMMAND_GET_META_DATA).writeInt(id).writeInt(objectId);
                session.done(transfer);
                int columnCount = transfer.readInt();
                result = new ResultRemote(session, transfer, objectId, columnCount, Integer.MAX_VALUE);
                break;
            } catch (IOException e) {
                session.removeServer(e, i--, ++count);
            }
        }
        session.autoCommitIfCluster();
        return result;
    }
}
Also used : ResultRemote(org.h2.result.ResultRemote) Transfer(org.h2.value.Transfer) IOException(java.io.IOException)

Example 38 with ResultInterface

use of org.h2.result.ResultInterface in project h2database by h2database.

the class Command method executeQuery.

/**
 * Execute a query and return the result.
 * This method prepares everything and calls {@link #query(int)} finally.
 *
 * @param maxrows the maximum number of rows to return
 * @param scrollable if the result set must be scrollable (ignored)
 * @return the result set
 */
@Override
public ResultInterface executeQuery(int maxrows, boolean scrollable) {
    startTimeNanos = 0;
    long start = 0;
    Database database = session.getDatabase();
    Object sync = database.isMultiThreaded() ? (Object) session : (Object) database;
    session.waitIfExclusiveModeEnabled();
    boolean callStop = true;
    boolean writing = !isReadOnly();
    if (writing) {
        while (!database.beforeWriting()) {
        // wait
        }
    }
    synchronized (sync) {
        session.setCurrentCommand(this, false);
        try {
            while (true) {
                database.checkPowerOff();
                try {
                    ResultInterface result = query(maxrows);
                    callStop = !result.isLazy();
                    return result;
                } catch (DbException e) {
                    start = filterConcurrentUpdate(e, start);
                } catch (OutOfMemoryError e) {
                    callStop = false;
                    // there is a serious problem:
                    // the transaction may be applied partially
                    // in this case we need to panic:
                    // close the database
                    database.shutdownImmediately();
                    throw DbException.convert(e);
                } catch (Throwable e) {
                    throw DbException.convert(e);
                }
            }
        } catch (DbException e) {
            e = e.addSQL(sql);
            SQLException s = e.getSQLException();
            database.exceptionThrown(s, sql);
            if (s.getErrorCode() == ErrorCode.OUT_OF_MEMORY) {
                callStop = false;
                database.shutdownImmediately();
                throw e;
            }
            database.checkPowerOff();
            throw e;
        } finally {
            if (callStop) {
                stop();
            }
            if (writing) {
                database.afterWriting();
            }
        }
    }
}
Also used : ResultInterface(org.h2.result.ResultInterface) SQLException(java.sql.SQLException) Database(org.h2.engine.Database) DbException(org.h2.message.DbException)

Example 39 with ResultInterface

use of org.h2.result.ResultInterface in project h2database by h2database.

the class JdbcConnection method getTransactionIsolation.

/**
 * Returns the current transaction isolation level.
 *
 * @return the isolation level.
 * @throws SQLException if the connection is closed
 */
@Override
public int getTransactionIsolation() throws SQLException {
    try {
        debugCodeCall("getTransactionIsolation");
        checkClosed();
        getLockMode = prepareCommand("CALL LOCK_MODE()", getLockMode);
        ResultInterface result = getLockMode.executeQuery(0, false);
        result.next();
        int lockMode = result.currentRow()[0].getInt();
        result.close();
        int transactionIsolationLevel;
        switch(lockMode) {
            case Constants.LOCK_MODE_OFF:
                transactionIsolationLevel = Connection.TRANSACTION_READ_UNCOMMITTED;
                break;
            case Constants.LOCK_MODE_READ_COMMITTED:
                transactionIsolationLevel = Connection.TRANSACTION_READ_COMMITTED;
                break;
            case Constants.LOCK_MODE_TABLE:
            case Constants.LOCK_MODE_TABLE_GC:
                transactionIsolationLevel = Connection.TRANSACTION_SERIALIZABLE;
                break;
            default:
                throw DbException.throwInternalError("lockMode:" + lockMode);
        }
        return transactionIsolationLevel;
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ResultInterface(org.h2.result.ResultInterface) Savepoint(java.sql.Savepoint) DbException(org.h2.message.DbException) SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException)

Example 40 with ResultInterface

use of org.h2.result.ResultInterface in project h2database by h2database.

the class JdbcPreparedStatement method getMetaData.

/**
 * Gets the result set metadata of the query returned when the statement is
 * executed. If this is not a query, this method returns null.
 *
 * @return the meta data or null if this is not a query
 * @throws SQLException if this object is closed
 */
@Override
public ResultSetMetaData getMetaData() throws SQLException {
    try {
        debugCodeCall("getMetaData");
        checkClosed();
        ResultInterface result = command.getMetaData();
        if (result == null) {
            return null;
        }
        int id = getNextId(TraceObject.RESULT_SET_META_DATA);
        if (isDebugEnabled()) {
            debugCodeAssign("ResultSetMetaData", TraceObject.RESULT_SET_META_DATA, id, "getMetaData()");
        }
        String catalog = conn.getCatalog();
        return new JdbcResultSetMetaData(null, this, result, catalog, session.getTrace(), id);
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ResultInterface(org.h2.result.ResultInterface) ValueString(org.h2.value.ValueString) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Aggregations

ResultInterface (org.h2.result.ResultInterface)34 Value (org.h2.value.Value)15 DbException (org.h2.message.DbException)11 LocalResult (org.h2.result.LocalResult)9 SQLException (java.sql.SQLException)8 CommandInterface (org.h2.command.CommandInterface)7 Expression (org.h2.expression.Expression)5 Column (org.h2.table.Column)5 SQLClientInfoException (java.sql.SQLClientInfoException)4 Prepared (org.h2.command.Prepared)4 Database (org.h2.engine.Database)4 ResultWithGeneratedKeys (org.h2.result.ResultWithGeneratedKeys)4 Row (org.h2.result.Row)4 IOException (java.io.IOException)3 ValueString (org.h2.value.ValueString)3 Savepoint (java.sql.Savepoint)2 GeneratedKeys (org.h2.engine.GeneratedKeys)2 ExpressionColumn (org.h2.expression.ExpressionColumn)2 SequenceValue (org.h2.expression.SequenceValue)2 ResultRemote (org.h2.result.ResultRemote)2