Search in sources :

Example 11 with JdbcResultSet

use of org.h2.jdbc.JdbcResultSet 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)

Aggregations

ResultInterface (org.h2.result.ResultInterface)7 JdbcResultSet (org.h2.jdbc.JdbcResultSet)4 ResultWithGeneratedKeys (org.h2.result.ResultWithGeneratedKeys)4 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)3 GridCacheSqlQuery (org.apache.ignite.internal.processors.cache.query.GridCacheSqlQuery)3 GridH2RetryException (org.apache.ignite.internal.processors.query.h2.opt.GridH2RetryException)3 CommandInterface (org.h2.command.CommandInterface)3 Connection (java.sql.Connection)2 ArrayList (java.util.ArrayList)2 GridReservable (org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable)2 GridH2QueryContext (org.apache.ignite.internal.processors.query.h2.opt.GridH2QueryContext)2 DbException (org.h2.message.DbException)2 PreparedStatement (java.sql.PreparedStatement)1 QueryRetryException (org.apache.ignite.cache.query.QueryRetryException)1 IoStatisticsHolder (org.apache.ignite.internal.metric.IoStatisticsHolder)1 QueryTable (org.apache.ignite.internal.processors.cache.query.QueryTable)1 H2PooledConnection (org.apache.ignite.internal.processors.query.h2.H2PooledConnection)1 MapH2QueryInfo (org.apache.ignite.internal.processors.query.h2.MapH2QueryInfo)1