Search in sources :

Example 21 with Activation

use of org.apache.derby.iapi.sql.Activation in project derby by apache.

the class GenericResultSetFactory method getUpdateVTIResultSet.

/**
 *		@see ResultSetFactory#getUpdateVTIResultSet
 *		@exception StandardException thrown on error
 */
public ResultSet getUpdateVTIResultSet(NoPutResultSet source) throws StandardException {
    Activation activation = source.getActivation();
    getAuthorizer(activation).authorize(activation, Authorizer.SQL_WRITE_OP);
    return new UpdateVTIResultSet(source, activation);
}
Also used : Activation(org.apache.derby.iapi.sql.Activation)

Example 22 with Activation

use of org.apache.derby.iapi.sql.Activation in project derby by apache.

the class GenericResultSetFactory method getDeleteVTIResultSet.

/**
 *		@see ResultSetFactory#getDeleteVTIResultSet
 *		@exception StandardException thrown on error
 */
public ResultSet getDeleteVTIResultSet(NoPutResultSet source) throws StandardException {
    Activation activation = source.getActivation();
    getAuthorizer(activation).authorize(activation, Authorizer.SQL_WRITE_OP);
    return new DeleteVTIResultSet(source, activation);
}
Also used : Activation(org.apache.derby.iapi.sql.Activation)

Example 23 with Activation

use of org.apache.derby.iapi.sql.Activation in project derby by apache.

the class TabInfoImpl method getRowChanger.

/**
 *	Gets a row changer for this catalog.
 *
 *	@param	tc	transaction controller
 *	@param	changedCols	the columns to change (1 based), may be null
 * @param  baseRow used to detemine column types at creation time
 *         only. The row changer does ***Not*** keep a referance to
 *         this row or change it in any way.
 *
 *	@return	a row changer for this catalog.
 * @exception StandardException		Thrown on failure
 */
private RowChanger getRowChanger(TransactionController tc, int[] changedCols, ExecRow baseRow) throws StandardException {
    RowChanger rc;
    int indexCount = crf.getNumIndexes();
    IndexRowGenerator[] irgs = new IndexRowGenerator[indexCount];
    long[] cids = new long[indexCount];
    if (SanityManager.DEBUG) {
        if (changedCols != null) {
            for (int i = changedCols.length - 1; i >= 0; i--) {
                SanityManager.ASSERT(changedCols[i] != 0, "Column id is 0, but should be 1 based");
            }
        }
    }
    for (int ictr = 0; ictr < indexCount; ictr++) {
        irgs[ictr] = getIndexRowGenerator(ictr);
        cids[ictr] = getIndexConglomerate(ictr);
    }
    rc = crf.getExecutionFactory().getRowChanger(getHeapConglomerate(), (StaticCompiledOpenConglomInfo) null, (DynamicCompiledOpenConglomInfo) null, irgs, cids, (StaticCompiledOpenConglomInfo[]) null, (DynamicCompiledOpenConglomInfo[]) null, crf.getHeapColumnCount(), tc, changedCols, getStreamStorableHeapColIds(baseRow), (Activation) null);
    return rc;
}
Also used : IndexRowGenerator(org.apache.derby.iapi.sql.dictionary.IndexRowGenerator) RowChanger(org.apache.derby.iapi.sql.execute.RowChanger) DynamicCompiledOpenConglomInfo(org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo) Activation(org.apache.derby.iapi.sql.Activation) StaticCompiledOpenConglomInfo(org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo)

Example 24 with Activation

use of org.apache.derby.iapi.sql.Activation in project derby by apache.

the class MatchingClauseConstantAction method executeConstantAction.

public void executeConstantAction(Activation activation, TemporaryRowHolderImpl thenRows) throws StandardException {
    // nothing to do if no rows qualified
    if (thenRows == null) {
        return;
    }
    CursorResultSet sourceRS = thenRows.getResultSet();
    GeneratedMethod actionGM = ((BaseActivation) activation).getMethod(_actionMethodName);
    // 
    try {
        activation.pushConstantAction(_thenAction);
        try {
            // 
            // Poke the temporary table into the variable which will be pushed as
            // an argument to the INSERT/UPDATE/DELETE action.
            // 
            Field resultSetField = activation.getClass().getField(_resultSetFieldName);
            resultSetField.set(activation, sourceRS);
            Activation cursorActivation = sourceRS.getActivation();
            // 
            // Now execute the generated method which creates an InsertResultSet,
            // UpdateResultSet, or DeleteResultSet.
            // 
            Method actionMethod = activation.getClass().getMethod(_actionMethodName);
            _actionRS = (ResultSet) actionMethod.invoke(activation, null);
        } catch (Exception e) {
            throw StandardException.plainWrapException(e);
        }
        // this is where the INSERT/UPDATE/DELETE is processed
        _actionRS.open();
    } finally {
        activation.popConstantAction();
    }
}
Also used : Field(java.lang.reflect.Field) CursorResultSet(org.apache.derby.iapi.sql.execute.CursorResultSet) Activation(org.apache.derby.iapi.sql.Activation) GeneratedMethod(org.apache.derby.iapi.services.loader.GeneratedMethod) Method(java.lang.reflect.Method) GeneratedMethod(org.apache.derby.iapi.services.loader.GeneratedMethod) StandardException(org.apache.derby.shared.common.error.StandardException) IOException(java.io.IOException)

Example 25 with Activation

use of org.apache.derby.iapi.sql.Activation in project derby by apache.

the class EmbedStatement method execute.

/**
 * Execute a SQL statement that may return multiple results.
 * Under some (uncommon) situations a single SQL statement may return
 * multiple result sets and/or update counts.  Normally you can ignore
 * this, unless you're executing a stored procedure that you know may
 * return multiple results, or unless you're dynamically executing an
 * unknown SQL string.  The "execute", "getMoreResults", "getResultSet"
 * and "getUpdateCount" methods let you navigate through multiple results.
 *
 * The "execute" method executes a SQL statement and indicates the
 * form of the first result.  You can then use getResultSet or
 * getUpdateCount to retrieve the result, and getMoreResults to
 * move to any subsequent result(s).
 *
 * @param sql					any SQL statement
 * @param executeQuery			caller is executeQuery()
 * @param executeUpdate			caller is executeUpdate()
 * @param autoGeneratedKeys
 * @param columnIndexes
 * @param columnNames
 *
 * @return true if the first result is a ResultSet; false if it is an integer
 * @see #getResultSet
 * @see #getUpdateCount
 * @see #getMoreResults
 * @exception SQLException thrown on failure
 */
private boolean execute(String sql, boolean executeQuery, boolean executeUpdate, int autoGeneratedKeys, int[] columnIndexes, String[] columnNames) throws SQLException {
    synchronized (getConnectionSynchronization()) {
        checkExecStatus();
        if (sql == null) {
            throw newSQLException(SQLState.NULL_SQL_TEXT);
        }
        checkIfInMiddleOfBatch();
        // release the last statement executed, if any.
        clearResultSets();
        // make sure there's context
        setupContextStack();
        // try to remember the SQL statement in case anybody asks for it
        SQLText = sql;
        try {
            Activation activation;
            try {
                PreparedStatement preparedStatement = lcc.prepareInternalStatement(lcc.getDefaultSchema(), sql, resultSetConcurrency == java.sql.ResultSet.CONCUR_READ_ONLY, false);
                activation = preparedStatement.getActivation(lcc, resultSetType == java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE);
                checkRequiresCallableStatement(activation);
                InterruptStatus.restoreIntrFlagIfSeen(lcc);
            } catch (Throwable t) {
                throw handleException(t);
            }
            // this is for a Statement execution
            activation.setSingleExecution();
            // information in lcc will not work work it can be tampered by a nested trasaction
            if (autoGeneratedKeys == Statement.RETURN_GENERATED_KEYS) {
                activation.setAutoGeneratedKeysResultsetInfo(columnIndexes, columnNames);
            }
            return executeStatement(activation, executeQuery, executeUpdate);
        } finally {
            restoreContextStack();
        }
    }
}
Also used : Activation(org.apache.derby.iapi.sql.Activation) PreparedStatement(org.apache.derby.iapi.sql.PreparedStatement)

Aggregations

Activation (org.apache.derby.iapi.sql.Activation)25 CursorActivation (org.apache.derby.iapi.sql.execute.CursorActivation)10 ResultSet (org.apache.derby.iapi.sql.ResultSet)8 StatementContext (org.apache.derby.iapi.sql.conn.StatementContext)5 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)3 StandardException (org.apache.derby.shared.common.error.StandardException)3 SQLWarning (java.sql.SQLWarning)2 ResultDescription (org.apache.derby.iapi.sql.ResultDescription)2 SQLSessionContext (org.apache.derby.iapi.sql.conn.SQLSessionContext)2 CursorResultSet (org.apache.derby.iapi.sql.execute.CursorResultSet)2 ExecCursorTableReference (org.apache.derby.iapi.sql.execute.ExecCursorTableReference)2 ExecPreparedStatement (org.apache.derby.iapi.sql.execute.ExecPreparedStatement)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 GeneratedClass (org.apache.derby.iapi.services.loader.GeneratedClass)1 GeneratedMethod (org.apache.derby.iapi.services.loader.GeneratedMethod)1 PreparedStatement (org.apache.derby.iapi.sql.PreparedStatement)1 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)1 IndexRowGenerator (org.apache.derby.iapi.sql.dictionary.IndexRowGenerator)1