Search in sources :

Example 11 with CommandInterface

use of org.h2.command.CommandInterface in project h2database by h2database.

the class SessionWithState method readSessionState.

/**
 * Read the session state if necessary.
 */
public void readSessionState() {
    if (!sessionStateChanged || sessionStateUpdating) {
        return;
    }
    sessionStateChanged = false;
    sessionState = New.arrayList();
    CommandInterface ci = prepareCommand("SELECT * FROM INFORMATION_SCHEMA.SESSION_STATE", Integer.MAX_VALUE);
    ResultInterface result = ci.executeQuery(0, false);
    while (result.next()) {
        Value[] row = result.currentRow();
        sessionState.add(row[1].getString());
    }
}
Also used : ResultInterface(org.h2.result.ResultInterface) Value(org.h2.value.Value) CommandInterface(org.h2.command.CommandInterface)

Example 12 with CommandInterface

use of org.h2.command.CommandInterface in project h2database by h2database.

the class JdbcConnection method setSavepoint.

/**
 * Creates a new named savepoint.
 *
 * @param name the savepoint name
 * @return the new savepoint
 */
@Override
public Savepoint setSavepoint(String name) throws SQLException {
    try {
        int id = getNextId(TraceObject.SAVEPOINT);
        if (isDebugEnabled()) {
            debugCodeAssign("Savepoint", TraceObject.SAVEPOINT, id, "setSavepoint(" + quote(name) + ")");
        }
        checkClosed();
        CommandInterface set = prepareCommand("SAVEPOINT " + JdbcSavepoint.getName(name, 0), Integer.MAX_VALUE);
        set.executeUpdate(false);
        return new JdbcSavepoint(this, 0, name, trace, id);
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : CommandInterface(org.h2.command.CommandInterface) Savepoint(java.sql.Savepoint) DbException(org.h2.message.DbException) SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException)

Example 13 with CommandInterface

use of org.h2.command.CommandInterface in project h2database by h2database.

the class JdbcStatement method executeInternal.

private boolean executeInternal(String sql, Object generatedKeysRequest) throws SQLException {
    int id = getNextId(TraceObject.RESULT_SET);
    checkClosedForWrite();
    try {
        closeOldResultSet();
        sql = JdbcConnection.translateSQL(sql, escapeProcessing);
        CommandInterface command = conn.prepareCommand(sql, fetchSize);
        boolean lazy = false;
        boolean returnsResultSet;
        synchronized (session) {
            setExecutingStatement(command);
            try {
                if (command.isQuery()) {
                    returnsResultSet = true;
                    boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
                    boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
                    ResultInterface result = command.executeQuery(maxRows, scrollable);
                    lazy = result.isLazy();
                    resultSet = new JdbcResultSet(conn, this, command, result, id, closedByResultSet, scrollable, updatable);
                } else {
                    returnsResultSet = false;
                    ResultWithGeneratedKeys result = command.executeUpdate(conn.scopeGeneratedKeys() ? false : generatedKeysRequest);
                    updateCount = result.getUpdateCount();
                    ResultInterface gk = result.getGeneratedKeys();
                    if (gk != null) {
                        generatedKeys = new JdbcResultSet(conn, this, command, gk, id, false, true, false);
                    }
                }
            } finally {
                if (!lazy) {
                    setExecutingStatement(null);
                }
            }
        }
        if (!lazy) {
            command.close();
        }
        return returnsResultSet;
    } finally {
        afterWriting();
    }
}
Also used : ResultInterface(org.h2.result.ResultInterface) CommandInterface(org.h2.command.CommandInterface) ResultWithGeneratedKeys(org.h2.result.ResultWithGeneratedKeys)

Example 14 with CommandInterface

use of org.h2.command.CommandInterface in project h2database by h2database.

the class JdbcStatement method cancel.

/**
 * Cancels a currently running statement.
 * This method must be called from within another
 * thread than the execute method.
 * Operations on large objects are not interrupted,
 * only operations that process many rows.
 *
 * @throws SQLException if this object is closed
 */
@Override
public void cancel() throws SQLException {
    try {
        debugCodeCall("cancel");
        checkClosed();
        // executingCommand can be reset  by another thread
        CommandInterface c = executingCommand;
        try {
            if (c != null) {
                c.cancel();
                cancelled = true;
            }
        } finally {
            setExecutingStatement(null);
        }
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : CommandInterface(org.h2.command.CommandInterface) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Aggregations

CommandInterface (org.h2.command.CommandInterface)14 ResultInterface (org.h2.result.ResultInterface)7 DbException (org.h2.message.DbException)6 SQLException (java.sql.SQLException)5 SQLClientInfoException (java.sql.SQLClientInfoException)3 Savepoint (java.sql.Savepoint)2 ResultWithGeneratedKeys (org.h2.result.ResultWithGeneratedKeys)2 Value (org.h2.value.Value)2 SessionInterface (org.h2.engine.SessionInterface)1 SessionRemote (org.h2.engine.SessionRemote)1