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, } else { returnsResultSet = false; ResultWithGeneratedKeys result = command.executeUpdate( conn.scopeGeneratedKeys() ? false : generatedKeysRequest); updateCount = result.getUpdateCount(); command.close();
/** * 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); } }
/** * INTERNAL. * Set the statement that is currently running. * * @param c the command */ protected void setExecutingStatement(CommandInterface c) { if (c == null) { conn.setExecutingStatement(null); } else { conn.setExecutingStatement(this); lastExecutedCommandType = c.getCommandType(); } executingCommand = c; }
/** * Read the serializer name from the persistent database settings. * * @return the serializer */ private String readSerializationSettings() { String javaObjectSerializerFQN = null; CommandInterface ci = prepareCommand( "SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS "+ " WHERE NAME='JAVA_OBJECT_SERIALIZER'", Integer.MAX_VALUE); try { ResultInterface result = ci.executeQuery(0, false); if (result.next()) { Value[] row = result.currentRow(); javaObjectSerializerFQN = row[0].getString(); } } finally { ci.close(); } return javaObjectSerializerFQN; }
/** * INTERNAL */ public void setQueryTimeout(int seconds) throws SQLException { try { debugCodeCall("setQueryTimeout", seconds); checkClosed(); setQueryTimeout = prepareCommand("SET QUERY_TIMEOUT ?", setQueryTimeout); setQueryTimeout.getParameters().get(0) .setValue(ValueInt.get(seconds * 1000), false); setQueryTimeout.executeUpdate(false); queryTimeoutCache = seconds; } catch (Exception e) { throw logAndConvert(e); } }
try { setExecutingStatement(command); 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, } else { returnsResultSet = false; ResultWithGeneratedKeys result = command.executeUpdate(generatedKeysRequest); updateCount = result.getUpdateCount(); ResultInterface gk = result.getGeneratedKeys();
private void switchOffCluster() { CommandInterface ci = prepareCommand("SET CLUSTER ''", Integer.MAX_VALUE); ci.executeUpdate(false); }
JdbcParameterMetaData(Trace trace, JdbcPreparedStatement prep, CommandInterface command, int id) { setTrace(trace, TraceObject.PARAMETER_META_DATA, id); this.prep = prep; this.parameters = command.getParameters(); this.paramCount = parameters.size(); }
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(); } }
/** * INTERNAL */ ResultSet getGeneratedKeys(JdbcStatement stat, int id) { getGeneratedKeys = prepareCommand( "SELECT SCOPE_IDENTITY() " + "WHERE SCOPE_IDENTITY() IS NOT NULL", getGeneratedKeys); ResultInterface result = getGeneratedKeys.executeQuery(0, false); return new JdbcResultSet(this, stat, getGeneratedKeys, result, id, false, true, false); }
private static CommandInterface closeAndSetNull(CommandInterface command) { if (command != null) { command.close(); } return null; }
/** * INTERNAL */ int getQueryTimeout() throws SQLException { try { if (queryTimeoutCache == -1) { checkClosed(); getQueryTimeout = prepareCommand( "SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS " + "WHERE NAME=?", getQueryTimeout); getQueryTimeout.getParameters().get(0) .setValue(ValueString.get("QUERY_TIMEOUT"), false); ResultInterface result = getQueryTimeout.executeQuery(0, false); result.next(); int queryTimeout = result.currentRow()[0].getInt(); result.close(); if (queryTimeout != 0) { // round to the next second, otherwise 999 millis would // return 0 seconds queryTimeout = (queryTimeout + 999) / 1000; } queryTimeoutCache = queryTimeout; } return queryTimeoutCache; } catch (Exception e) { throw logAndConvert(e); } }
/** * 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); } }
/** * Executes a statement (insert, update, delete, create, drop) * and returns the update count. * If another result set exists for this statement, this will be closed * (even if this statement fails). * * If auto commit is on, this statement will be committed. * If the statement is a DDL statement (create, drop, alter) and does not * throw an exception, the current transaction (if any) is committed after * executing the statement. * * @return the update count (number of row affected by an insert, update or * delete, or 0 if no rows or the statement was a create, drop, * commit or rollback) * @throws SQLException if this object is closed or invalid */ @Override public long executeLargeUpdate() throws SQLException { try { checkClosed(); if (command.isQuery()) { super.executeQuery(); return 0; } return super.executeLargeUpdate(); } catch (Exception e) { throw logAndConvert(e); } }
try { setExecutingStatement(command); if (command.isQuery()) { returnsResultSet = true; boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY; ResultInterface result = command.executeQuery(maxRows, scrollable); resultSet = new JdbcResultSet(session, conn, this, result, id, closedByResultSet, scrollable); } else { returnsResultSet = false; updateCount = command.executeUpdate();
/** * Gets the current catalog name. * * @return the catalog name * @throws SQLException if the connection is closed */ @Override public String getCatalog() throws SQLException { try { debugCodeCall("getCatalog"); checkClosed(); if (catalog == null) { CommandInterface cat = prepareCommand("CALL DATABASE()", Integer.MAX_VALUE); ResultInterface result = cat.executeQuery(0, false); result.next(); catalog = result.currentRow()[0].getString(); cat.close(); } return catalog; } catch (Exception e) { throw logAndConvert(e); } }
private void rollbackInternal() { rollback = prepareCommand("ROLLBACK", rollback); rollback.executeUpdate(false); }
setLockMode.getParameters().get(0).setValue(ValueInt.get(lockMode), false); setLockMode.executeUpdate(false); } catch (Exception e) { throw logAndConvert(e);
private void setParameter(int parameterIndex, Value value) { checkClosed(); parameterIndex--; ArrayList<? extends ParameterInterface> parameters = command.getParameters(); if (parameterIndex < 0 || parameterIndex >= parameters.size()) { throw DbException.getInvalidValueException("parameterIndex", parameterIndex + 1); } ParameterInterface param = parameters.get(parameterIndex); // can only delete old temp files if they are not in the batch param.setValue(value, batchParameters == null); }