Search in sources :

Example 6 with ResultWithGeneratedKeys

use of org.h2.result.ResultWithGeneratedKeys 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)4 ResultWithGeneratedKeys (org.h2.result.ResultWithGeneratedKeys)4 CommandInterface (org.h2.command.CommandInterface)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 Database (org.h2.engine.Database)1 Session (org.h2.engine.Session)1 DbException (org.h2.message.DbException)1 ResultRemote (org.h2.result.ResultRemote)1 Transfer (org.h2.value.Transfer)1