Search in sources :

Example 1 with CommandInterface

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

the class SessionRemote method checkClusterDisableAutoCommit.

private void checkClusterDisableAutoCommit(String serverList) {
    if (autoCommit && transferList.size() > 1) {
        setAutoCommitSend(false);
        CommandInterface c = prepareCommand("SET CLUSTER " + serverList, Integer.MAX_VALUE);
        // this will set autoCommit to false
        c.executeUpdate(false);
        // so we need to switch it on
        autoCommit = true;
        cluster = true;
    }
}
Also used : CommandInterface(org.h2.command.CommandInterface)

Example 2 with CommandInterface

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

the class SessionWithState method recreateSessionState.

/**
 * Re-create the session state using the stored sessionState list.
 */
protected void recreateSessionState() {
    if (sessionState != null && !sessionState.isEmpty()) {
        sessionStateUpdating = true;
        try {
            for (String sql : sessionState) {
                CommandInterface ci = prepareCommand(sql, Integer.MAX_VALUE);
                ci.executeUpdate(false);
            }
        } finally {
            sessionStateUpdating = false;
            sessionStateChanged = false;
        }
    }
}
Also used : CommandInterface(org.h2.command.CommandInterface)

Example 3 with CommandInterface

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

the class JdbcDatabaseMetaData method hasSynonyms.

private boolean hasSynonyms() {
    Boolean hasSynonyms = this.hasSynonyms;
    if (hasSynonyms == null) {
        SessionInterface si = conn.getSession();
        if (si instanceof SessionRemote) {
            SessionRemote sr = (SessionRemote) si;
            int clientVersion = sr.getClientVersion();
            if (clientVersion >= Constants.TCP_PROTOCOL_VERSION_17) {
                hasSynonyms = true;
            } else if (clientVersion <= Constants.TCP_PROTOCOL_VERSION_15) {
                hasSynonyms = false;
            } else {
                // 1.4.194-1.4.196
                CommandInterface c = sr.prepareCommand("CALL H2VERSION()", Integer.MAX_VALUE);
                ResultInterface result = c.executeQuery(0, false);
                result.next();
                String s = result.currentRow()[0].getString();
                result.close();
                hasSynonyms = "1.4.196".equals(s);
            }
        } else {
            hasSynonyms = true;
        }
        this.hasSynonyms = hasSynonyms;
    }
    return hasSynonyms;
}
Also used : SessionRemote(org.h2.engine.SessionRemote) ResultInterface(org.h2.result.ResultInterface) SessionInterface(org.h2.engine.SessionInterface) CommandInterface(org.h2.command.CommandInterface)

Example 4 with CommandInterface

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

the class JdbcStatement method executeUpdateInternal.

private int executeUpdateInternal(String sql, Object generatedKeysRequest) throws SQLException {
    checkClosedForWrite();
    try {
        closeOldResultSet();
        sql = JdbcConnection.translateSQL(sql, escapeProcessing);
        CommandInterface command = conn.prepareCommand(sql, fetchSize);
        synchronized (session) {
            setExecutingStatement(command);
            try {
                ResultWithGeneratedKeys result = command.executeUpdate(conn.scopeGeneratedKeys() ? false : generatedKeysRequest);
                updateCount = result.getUpdateCount();
                ResultInterface gk = result.getGeneratedKeys();
                if (gk != null) {
                    int id = getNextId(TraceObject.RESULT_SET);
                    generatedKeys = new JdbcResultSet(conn, this, command, gk, id, false, true, false);
                }
            } finally {
                setExecutingStatement(null);
            }
        }
        command.close();
        return updateCount;
    } finally {
        afterWriting();
    }
}
Also used : ResultInterface(org.h2.result.ResultInterface) CommandInterface(org.h2.command.CommandInterface) ResultWithGeneratedKeys(org.h2.result.ResultWithGeneratedKeys)

Example 5 with CommandInterface

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

the class JdbcStatement method executeQuery.

/**
 * Executes a query (select statement) and returns the result set.
 * If another result set exists for this statement, this will be closed
 * (even if this statement fails).
 *
 * @param sql the SQL statement to execute
 * @return the result set
 */
@Override
public ResultSet executeQuery(String sql) throws SQLException {
    try {
        int id = getNextId(TraceObject.RESULT_SET);
        if (isDebugEnabled()) {
            debugCodeAssign("ResultSet", TraceObject.RESULT_SET, id, "executeQuery(" + quote(sql) + ")");
        }
        synchronized (session) {
            checkClosed();
            closeOldResultSet();
            sql = JdbcConnection.translateSQL(sql, escapeProcessing);
            CommandInterface command = conn.prepareCommand(sql, fetchSize);
            ResultInterface result;
            boolean lazy = false;
            boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
            boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
            setExecutingStatement(command);
            try {
                result = command.executeQuery(maxRows, scrollable);
                lazy = result.isLazy();
            } finally {
                if (!lazy) {
                    setExecutingStatement(null);
                }
            }
            if (!lazy) {
                command.close();
            }
            resultSet = new JdbcResultSet(conn, this, command, result, id, closedByResultSet, scrollable, updatable);
        }
        return resultSet;
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ResultInterface(org.h2.result.ResultInterface) 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