Search in sources :

Example 6 with Activation

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

the class GenericLanguageConnectionContext method endTransactionActivationHandling.

// 
// class implementation
// 
/**
 *        If we are called as part of rollback code path, then we will reset all
 *        the activations that have resultset returning rows associated with
 *        them. DERBY-3304 Resultsets that do not return rows should be left
 *        alone when the rollback is through the JDBC Connection object. If the
 *        rollback is caused by an exception, then at that time, all kinds of
 *        resultsets should be closed.
 *
 *        If we are called as part of commit code path, then we will do one of
 *        the following if the activation has resultset assoicated with it. Also,
 *        we will clear the conglomerate used while scanning for update/delete
 *        1)Close result sets that return rows and are not held across commit.
 *        2)Clear the current row of the resultsets that return rows and are
 *        held across commit.
 *        3)Leave the result sets untouched if they do not return rows
 *
 *        Additionally, clean up (close()) activations that have been
 *        marked as unused during statement finalization.
 *
 *        @exception StandardException thrown on failure
 */
private void endTransactionActivationHandling(boolean forRollback) throws StandardException {
    // itself from the list, thus invalidating the Enumeration
    for (int i = acts.size() - 1; i >= 0; i--) {
        // the end of the array
        if (i >= acts.size())
            continue;
        Activation a = acts.get(i);
        /*
            ** Look for stale activations.  Activations are
            ** marked as unused during statement finalization.
            ** Here, we sweep and remove this inactive ones.
            */
        if (!a.isInUse()) {
            a.close();
            continue;
        }
        // Determine if the activation has a resultset and if that resultset
        // returns rows. For such an activation, we need to take special
        // actions during commit and rollback as explained in the comments
        // below.
        ResultSet activationResultSet = a.getResultSet();
        boolean resultsetReturnsRows = activationResultSet != null && activationResultSet.returnsRows();
        if (forRollback) {
            if (resultsetReturnsRows)
                // Since we are dealing with rollback, we need to reset
                // the activation no matter what the holdability might
                // be provided that resultset returns rows. An example
                // where we do not want to close a resultset that does
                // not return rows would be a java procedure which has
                // user invoked rollback inside of it. That rollback
                // should not reset the activation associated with
                // the call to java procedure because that activation
                // is still being used.
                a.reset();
            // Only invalidate statements if we performed DDL.
            if (dataDictionaryInWriteMode()) {
                ExecPreparedStatement ps = a.getPreparedStatement();
                if (ps != null) {
                    ps.makeInvalid(DependencyManager.ROLLBACK, this);
                }
            }
        } else {
            // We are dealing with commit here.
            if (resultsetReturnsRows) {
                if (a.getResultSetHoldability() == false)
                    // Close result sets that return rows and are not held
                    // across commit. This is to implement closing JDBC
                    // result sets that are CLOSE_CURSOR_ON_COMMIT at commit
                    // time.
                    activationResultSet.close();
                else
                    // Clear the current row of the result sets that return
                    // rows and are held across commit. This is to implement
                    // keeping JDBC result sets open that are
                    // HOLD_CURSORS_OVER_COMMIT at commit time and marking
                    // the resultset to be not on a valid row position. The
                    // user will need to reposition within the resultset
                    // before doing any row operations.
                    activationResultSet.clearCurrentRow();
            }
            a.clearHeapConglomerateController();
        }
    }
}
Also used : ExecPreparedStatement(org.apache.derby.iapi.sql.execute.ExecPreparedStatement) ResultSet(org.apache.derby.iapi.sql.ResultSet) Activation(org.apache.derby.iapi.sql.Activation) CursorActivation(org.apache.derby.iapi.sql.execute.CursorActivation)

Example 7 with Activation

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

the class GenericLanguageConnectionContext method getCurrentSQLSessionContext.

/**
 * Return the current SQL session context of the activation
 *
 * @param activation the activation
 */
public SQLSessionContext getCurrentSQLSessionContext(Activation activation) {
    SQLSessionContext curr;
    Activation parent = activation.getParentActivation();
    if (parent == null) {
        // top level
        curr = getTopLevelSQLSessionContext();
    } else {
        // inside a nested connection (stored procedure/function), or when
        // executing a substatement the SQL session context is maintained
        // in the activation of the parent
        curr = parent.getSQLSessionContextForChildren();
    }
    return curr;
}
Also used : SQLSessionContext(org.apache.derby.iapi.sql.conn.SQLSessionContext) Activation(org.apache.derby.iapi.sql.Activation) CursorActivation(org.apache.derby.iapi.sql.execute.CursorActivation)

Example 8 with Activation

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

the class GenericLanguageConnectionContext method cleanupOnError.

// 
// Context interface
// 
/**
 *        If worse than a transaction error, everything goes; we
 *        rely on other contexts to kill the context manager
 *        for this session.
 *        <p>
 *        If a transaction error, act like we saw a rollback.
 *        <p>
 *        If more severe or a java error, the outer cleanup
 *        will shutdown the connection, so we don't have to clean up.
 *        <p>
 *        REMIND: connection should throw out all contexts and start
 *        over when the connection is closed... perhaps by throwing
 *        out the context manager?
 *        <p>
 *        REVISIT: If statement error, should we do anything?
 *        <P>
 *        Since the access manager's own context takes care of its own
 *        resources on errors, there is nothing that this context has
 *        to do with the transaction controller.
 *
 *        @exception StandardException thrown on error. REVISIT: don't want
 *        cleanupOnError's to throw exceptions.
 */
public void cleanupOnError(Throwable error) throws StandardException {
    /*
        ** If it isn't a StandardException, then assume
        ** session severity. It is probably an unexpected
        ** java error somewhere in the language.
        ** Store layer treats JVM error as session severity, 
        ** hence to be consistent and to avoid getting rawstore
        ** protocol violation errors, we treat java errors here
        ** to be of session severity.
        */
    int severity = (error instanceof StandardException) ? ((StandardException) error).getSeverity() : ExceptionSeverity.SESSION_SEVERITY;
    if (statementContexts[0] != null) {
        statementContexts[0].clearInUse();
        // and no hanging refrences in the ContextManager.
        if (severity >= ExceptionSeverity.SESSION_SEVERITY)
            statementContexts[0].popMe();
    }
    if (statementContexts[1] != null) {
        statementContexts[1].clearInUse();
    }
    // cursors.
    if (severity >= ExceptionSeverity.SESSION_SEVERITY) {
        for (int i = acts.size() - 1; i >= 0; i--) {
            // the end of the array
            if (i >= acts.size())
                continue;
            Activation a = acts.get(i);
            a.reset();
            a.close();
        }
        popMe();
        InterruptStatus.saveInfoFromLcc(this);
    } else /*
        ** We have some global state that we need
        ** to clean up no matter what.  Be sure
        ** to do so.
        */
    if (severity >= ExceptionSeverity.TRANSACTION_SEVERITY) {
        internalRollback();
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) Activation(org.apache.derby.iapi.sql.Activation) CursorActivation(org.apache.derby.iapi.sql.execute.CursorActivation)

Example 9 with Activation

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

the class GenericLanguageConnectionContext method lookupCursorActivation.

/**
 * See if a given cursor is available for use.
 * if so return its activation. Returns null if not found.
 * For use in execution.
 *
 * @return the activation for the given cursor, null
 *  if none was found.
 */
public CursorActivation lookupCursorActivation(String cursorName) {
    int size = acts.size();
    if (size > 0) {
        int cursorHash = cursorName.hashCode();
        for (int i = 0; i < size; i++) {
            Activation a = acts.get(i);
            if (!a.isInUse()) {
                continue;
            }
            String executingCursorName = a.getCursorName();
            // two names actually are equal.
            if (executingCursorName == null || executingCursorName.hashCode() != cursorHash) {
                continue;
            }
            if (cursorName.equals(executingCursorName)) {
                ResultSet rs = a.getResultSet();
                if (rs == null)
                    continue;
                // if the result set is closed, the the cursor doesn't exist
                if (rs.isClosed()) {
                    continue;
                }
                return (CursorActivation) a;
            }
        }
    }
    return null;
}
Also used : CursorActivation(org.apache.derby.iapi.sql.execute.CursorActivation) ResultSet(org.apache.derby.iapi.sql.ResultSet) Activation(org.apache.derby.iapi.sql.Activation) CursorActivation(org.apache.derby.iapi.sql.execute.CursorActivation)

Example 10 with Activation

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

the class GenericLanguageConnectionContext method verifyAllHeldResultSetsAreClosed.

/**
 * Verify that there are no activations with open held result sets.
 *
 * @return boolean  Found no open (held) resultsets.
 *
 * @exception StandardException thrown on failure
 */
/* This gets used in case of hold cursors. If there are any hold cursors open
     * then user can't change the isolation level without closing them. At the
     * execution time, set transaction isolation level calls this method before
     * changing the isolation level.
     */
public boolean verifyAllHeldResultSetsAreClosed() throws StandardException {
    boolean seenOpenResultSets = false;
    /* For every activation */
    for (int i = acts.size() - 1; i >= 0; i--) {
        Activation a = acts.get(i);
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(a instanceof CursorActivation, "a is not a CursorActivation");
        }
        if (!a.isInUse()) {
            continue;
        }
        if (!a.getResultSetHoldability()) {
            continue;
        }
        ResultSet rs = ((CursorActivation) a).getResultSet();
        /* is there an open result set? */
        if ((rs != null) && !rs.isClosed() && rs.returnsRows()) {
            seenOpenResultSets = true;
            break;
        }
    }
    if (!seenOpenResultSets)
        return (true);
    // There may be open ResultSet's that are yet to be garbage collected
    // let's try and force these out rather than throw an error
    System.gc();
    System.runFinalization();
    /* For every activation */
    for (int i = acts.size() - 1; i >= 0; i--) {
        Activation a = acts.get(i);
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(a instanceof CursorActivation, "a is not a CursorActivation");
        }
        if (!a.isInUse()) {
            continue;
        }
        if (!a.getResultSetHoldability()) {
            continue;
        }
        ResultSet rs = ((CursorActivation) a).getResultSet();
        /* is there an open held result set? */
        if ((rs != null) && !rs.isClosed() && rs.returnsRows()) {
            return (false);
        }
    }
    return (true);
}
Also used : CursorActivation(org.apache.derby.iapi.sql.execute.CursorActivation) ResultSet(org.apache.derby.iapi.sql.ResultSet) Activation(org.apache.derby.iapi.sql.Activation) CursorActivation(org.apache.derby.iapi.sql.execute.CursorActivation)

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