private static CommandInterface closeAndSetNull(CommandInterface command) { if (command != null) { command.close(); } return null; }
/** * 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); ResultSet rs = new JdbcResultSet(this, stat, result, id, false, true, false); return rs; }
private void rollbackInternal() { rollback = prepareCommand("ROLLBACK", rollback); rollback.executeUpdate(); }
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); resultSet = new JdbcResultSet(conn, this, result, id, closedByResultSet, scrollable, updatable); } else { returnsResultSet = false; updateCount = command.executeUpdate(); command.close(); return returnsResultSet; } finally {
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); resultSet = new JdbcResultSet(conn, this, result, id, closedByResultSet, scrollable, } else { returnsResultSet = false; updateCount = command.executeUpdate();
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) throws SQLException { checkClosed(); try { closeOldResultSet(); sql = JdbcConnection.translateSQL(sql, escapeProcessing); CommandInterface command = conn.prepareCommand(sql, fetchSize); synchronized (session) { setExecutingStatement(command); try { updateCount = command.executeUpdate(); } finally { setExecutingStatement(null); } } command.close(); return updateCount; } finally { afterWriting(); } }
setExecutingStatement(command); try { result = command.executeQuery(maxRows, scrollable); } finally { setExecutingStatement(null); command.close(); resultSet = new JdbcResultSet(conn, this, result, id, closedByResultSet, scrollable, updatable);
/** * 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; }
/** * 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); } }
/** * 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). * <p> * 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 int executeUpdate() throws SQLException { try { checkClosed(); if (command.isQuery()) { super.executeQuery(); return 0; } return super.executeUpdate(); } 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(); JdbcResultSetMetaData meta = new JdbcResultSetMetaData( null, this, result, catalog, session.getTrace(), id); return meta; } 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); }
private int executeUpdateInternal() throws SQLException { closeOldResultSet(); synchronized (session) { try { setExecutingStatement(command); updateCount = command.executeUpdate(); } finally { setExecutingStatement(null); } } return updateCount; }
@Override protected boolean checkClosed() { if (super.checkClosed()) { // if the session was re-connected, re-prepare the statement ArrayList<? extends ParameterInterface> oldParams = command.getParameters(); command = conn.prepareCommand(sqlStatement, fetchSize); ArrayList<? extends ParameterInterface> newParams = command.getParameters(); for (int i = 0, size = oldParams.size(); i < size; i++) { ParameterInterface old = oldParams.get(i); Value value = old.getParamValue(); if (value != null) { ParameterInterface n = newParams.get(i); n.setValue(value, false); } } return true; } return false; }
try { setExecutingStatement(command); result = command.executeQuery(maxRows, scrollable); } finally { setExecutingStatement(null);
/** * Closes this statement. * All result sets that where created by this statement * become invalid after calling this method. */ @Override public void close() throws SQLException { try { super.close(); batchParameters = null; if (command != null) { command.close(); command = null; } } catch (Exception e) { throw logAndConvert(e); } }
/** * Release this savepoint. This method only set the connection to null and * does not execute a statement. */ void release() { checkValid(); conn.prepareCommand( "RELEASE TO SAVEPOINT " + getName(name, savepointId), Integer.MAX_VALUE).executeUpdate(); this.conn = null; }
/** * Clears all parameters. * * @throws SQLException if this object is closed or invalid */ @Override public void clearParameters() throws SQLException { try { debugCodeCall("clearParameters"); checkClosed(); ArrayList<? extends ParameterInterface> parameters = command.getParameters(); for (int i = 0, size = parameters.size(); i < size; i++) { ParameterInterface param = parameters.get(i); // can only delete old temp files if they are not in the batch param.setValue(null, batchParameters == null); } } catch (Exception e) { throw logAndConvert(e); } }
/** * Roll back to this savepoint. */ void rollback() { checkValid(); conn.prepareCommand( "ROLLBACK TO SAVEPOINT " + getName(name, savepointId), Integer.MAX_VALUE).executeUpdate(); }