Search in sources :

Example 1 with SQLSessionContext

use of org.apache.derby.iapi.sql.conn.SQLSessionContext in project derby by apache.

the class GenericLanguageConnectionContext method popNestedSessionContext.

/**
 * @param a {@inheritDoc}
 * @throws StandardException {@inheritDoc}
 */
public void popNestedSessionContext(Activation a) throws StandardException {
    SQLSessionContext nested = a.getSQLSessionContextForChildren();
    SQLSessionContext caller = getCurrentSQLSessionContext(a);
    compareConstraintModes(nested, caller);
}
Also used : SQLSessionContext(org.apache.derby.iapi.sql.conn.SQLSessionContext)

Example 2 with SQLSessionContext

use of org.apache.derby.iapi.sql.conn.SQLSessionContext 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 3 with SQLSessionContext

use of org.apache.derby.iapi.sql.conn.SQLSessionContext in project derby by apache.

the class GenericLanguageConnectionContext method resetSchemaUsages.

/**
 * @see LanguageConnectionContext#resetSchemaUsages(Activation activation,
 *      String schemaName)
 */
public void resetSchemaUsages(Activation activation, String schemaName) throws StandardException {
    Activation parent = activation.getParentActivation();
    SchemaDescriptor defaultSchema = getInitialDefaultSchemaDescriptor();
    // walk SQL session context chain
    while (parent != null) {
        SQLSessionContext ssc = parent.getSQLSessionContextForChildren();
        SchemaDescriptor s = ssc.getDefaultSchema();
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(s != null, "s should not be empty here");
        }
        if (schemaName.equals(s.getSchemaName())) {
            ssc.setDefaultSchema(defaultSchema);
        }
        parent = parent.getParentActivation();
    }
    // finally top level
    SQLSessionContext top = getTopLevelSQLSessionContext();
    SchemaDescriptor sd = top.getDefaultSchema();
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(sd != null, "sd should not be empty here");
    }
    if (schemaName.equals(sd.getSchemaName())) {
        top.setDefaultSchema(defaultSchema);
    }
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) Activation(org.apache.derby.iapi.sql.Activation) CursorActivation(org.apache.derby.iapi.sql.execute.CursorActivation) SQLSessionContext(org.apache.derby.iapi.sql.conn.SQLSessionContext)

Example 4 with SQLSessionContext

use of org.apache.derby.iapi.sql.conn.SQLSessionContext in project derby by apache.

the class GenericLanguageConnectionContext method getCurrentSQLSessionContext.

/**
 * Return the current SQL session context based on statement context
 */
private SQLSessionContext getCurrentSQLSessionContext() {
    StatementContext ctx = getStatementContext();
    SQLSessionContext curr;
    if (ctx == null || !ctx.inUse()) {
        curr = getTopLevelSQLSessionContext();
    } else {
        // We are inside a nested connection in a procedure of
        // function.
        curr = ctx.getSQLSessionContext();
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(curr != null, "SQL session context should never be empty here");
        }
    }
    return curr;
}
Also used : SQLSessionContext(org.apache.derby.iapi.sql.conn.SQLSessionContext) StatementContext(org.apache.derby.iapi.sql.conn.StatementContext)

Example 5 with SQLSessionContext

use of org.apache.derby.iapi.sql.conn.SQLSessionContext in project derby by apache.

the class GenericLanguageConnectionContext method setupSessionContextMinion.

private void setupSessionContextMinion(Activation a, boolean push, boolean definersRights, String definer) throws StandardException {
    if (SanityManager.DEBUG) {
        if (definersRights) {
            SanityManager.ASSERT(push);
        }
    }
    SQLSessionContext sc = a.setupSQLSessionContextForChildren(push);
    if (definersRights) {
        sc.setUser(definer);
    } else {
        // A priori: invoker's rights: Current user
        sc.setUser(getCurrentUserId(a));
    }
    if (definersRights) {
        // No role a priori. Cf. SQL 2008, section 10.4 <routine
        // invocation>, GR 5 j) i) 1) B) "If the external security
        // characteristic of R is DEFINER, then the top cell of the
        // authorization stack of RSC is set to contain only the routine
        // authorization identifier of R.
        sc.setRole(null);
    } else {
        // Semantics for roles dictate (SQL 4.34.1.1 and 4.27.3.) that the
        // role is initially inherited from the current session context
        // when we run with INVOKER security characteristic.
        sc.setRole(getCurrentRoleId(a));
    }
    if (definersRights) {
        SchemaDescriptor sd = getDataDictionary().getSchemaDescriptor(definer, getTransactionExecute(), false);
        if (sd == null) {
            sd = new SchemaDescriptor(getDataDictionary(), definer, definer, (UUID) null, false);
        }
        sc.setDefaultSchema(sd);
    } else {
        // Inherit current default schema. The initial value of the
        // default schema is implementation defined. In Derby we
        // inherit it when we invoke stored procedures and functions.
        sc.setDefaultSchema(getDefaultSchema(a));
    }
    final SQLSessionContext ssc = getCurrentSQLSessionContext(a);
    sc.setDeferredAll(ssc.getDeferredAll());
    sc.setConstraintModes(ssc.getConstraintModes());
    StatementContext stmctx = getStatementContext();
    // Since the statement is an invocation (iff push=true), it will now be
    // associated with the pushed SQLSessionContext (and no longer just
    // share that of its caller (or top).  The statement contexts of nested
    // connection statements will inherit statement context so the SQL
    // session context is available through it when nested statements are
    // compiled (and executed, for the most part).  However, for dynamic
    // result sets, the relevant statement context (originating result set)
    // is no longer available for execution time references to the SQL
    // session context, so we rely on the activation of the caller for
    // accessing it, cf. e.g. overload variants of
    // getDefaultSchema/setDefaultSchema.  If such nested connections
    // themselves turn out to be invocations, they in turn get a new
    // SQLSessionContext associated with them etc.
    stmctx.setSQLSessionContext(sc);
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) SQLSessionContext(org.apache.derby.iapi.sql.conn.SQLSessionContext) UUID(org.apache.derby.catalog.UUID) StatementContext(org.apache.derby.iapi.sql.conn.StatementContext)

Aggregations

SQLSessionContext (org.apache.derby.iapi.sql.conn.SQLSessionContext)5 Activation (org.apache.derby.iapi.sql.Activation)2 StatementContext (org.apache.derby.iapi.sql.conn.StatementContext)2 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)2 CursorActivation (org.apache.derby.iapi.sql.execute.CursorActivation)2 UUID (org.apache.derby.catalog.UUID)1