Search in sources :

Example 71 with LanguageConnectionContext

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

the class T_CreateConglomRet method isdbActive.

/**
 * Check wheather the database is active or not
 * @return {@code true} if the database is active, {@code false} otherwise
 */
public boolean isdbActive() {
    LanguageConnectionContext lcc = (LanguageConnectionContext) getContextOrNull(LanguageConnectionContext.CONTEXT_ID);
    Database db = (Database) (lcc != null ? lcc.getDatabase() : null);
    return (db != null ? db.isActive() : false);
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) Database(org.apache.derby.iapi.db.Database)

Example 72 with LanguageConnectionContext

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

the class XPLAINDefaultVisitor method doXPLAIN.

public void doXPLAIN(RunTimeStatistics rss, Activation activation) {
    LanguageConnectionContext lcc;
    try {
        lcc = ConnectionUtil.getCurrentLCC();
        HeaderPrintWriter istream = lcc.getLogQueryPlan() ? Monitor.getStream() : null;
        if (istream != null) {
            istream.printlnWithHeader(LanguageConnectionContext.xidStr + lcc.getTransactionExecute().getTransactionIdString() + "), " + LanguageConnectionContext.lccStr + lcc.getInstanceNumber() + "), " + rss.getStatementText() + " ******* " + rss.getStatementExecutionPlanText());
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) SQLException(java.sql.SQLException) HeaderPrintWriter(org.apache.derby.shared.common.stream.HeaderPrintWriter)

Example 73 with LanguageConnectionContext

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

the class XPLAINFactory method getXPLAINVisitor.

/**
 * the factory method, which gets called to determine
 * and return an appropriate XPLAINVisitor instance
 */
public XPLAINVisitor getXPLAINVisitor() throws StandardException {
    try {
        LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
        String schema = lcc.getXplainSchema();
        if (schema != currentSchema) {
            currentSchema = schema;
            if (currentSchema == null)
                currentVisitor = new XPLAINDefaultVisitor();
            else
                currentVisitor = new XPLAINSystemTableVisitor();
        }
    } catch (SQLException e) {
        throw StandardException.plainWrapException(e);
    }
    return currentVisitor;
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) SQLException(java.sql.SQLException)

Example 74 with LanguageConnectionContext

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

the class GenericPrivilegeInfo method executeGrantRevoke.

// /////////////////////////////////////////////////////////////////////////////////
// 
// PrivilegeInfo BEHAVIOR
// 
// /////////////////////////////////////////////////////////////////////////////////
/**
 *	This is the guts of the Execution-time logic for GRANT/REVOKE generic privileges.
 *
 * @param activation
 * @param grant true if grant, false if revoke
 * @param grantees a list of authorization ids (strings)
 *
 * @exception StandardException		Thrown on failure
 */
public void executeGrantRevoke(Activation activation, boolean grant, List grantees) throws StandardException {
    // Check that the current user has permission to grant the privileges.
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    String currentUser = lcc.getCurrentUserId(activation);
    TransactionController tc = lcc.getTransactionExecute();
    SchemaDescriptor sd = _tupleDescriptor.getSchemaDescriptor();
    UUID objectID = _tupleDescriptor.getUUID();
    String objectTypeName = _tupleDescriptor.getObjectTypeName();
    // Check that the current user has permission to grant the privileges.
    checkOwnership(currentUser, (TupleDescriptor) _tupleDescriptor, sd, dd);
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    PermDescriptor permDesc = ddg.newPermDescriptor(null, objectTypeName, objectID, _privilege, currentUser, null, false);
    dd.startWriting(lcc);
    for (Iterator itr = grantees.iterator(); itr.hasNext(); ) {
        // Keep track to see if any privileges are revoked by a revoke
        // statement. If a privilege is not revoked, we need to raise a
        // warning.
        boolean privileges_revoked = false;
        String grantee = (String) itr.next();
        if (dd.addRemovePermissionsDescriptor(grant, permDesc, grantee, tc)) {
            // 
            // We fall in here if we are performing REVOKE.
            // 
            privileges_revoked = true;
            int invalidationType = _restrict ? DependencyManager.REVOKE_PRIVILEGE_RESTRICT : DependencyManager.REVOKE_PRIVILEGE;
            dd.getDependencyManager().invalidateFor(permDesc, invalidationType, lcc);
            // Now invalidate all GPSs refering to the object.
            dd.getDependencyManager().invalidateFor(_tupleDescriptor, invalidationType, lcc);
        }
        addWarningIfPrivilegeNotRevoked(activation, grant, privileges_revoked, grantee);
    }
}
Also used : DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) Iterator(java.util.Iterator) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TransactionController(org.apache.derby.iapi.store.access.TransactionController) UUID(org.apache.derby.catalog.UUID) PermDescriptor(org.apache.derby.iapi.sql.dictionary.PermDescriptor)

Example 75 with LanguageConnectionContext

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

the class SetRoleConstantAction method executeConstantAction.

// INTERFACE METHODS
/**
 *  This is the guts of the Execution-time logic for SET ROLE.
 *
 *  @see ConstantAction#executeConstantAction
 *
 * @exception StandardException     Thrown on failure
 */
public void executeConstantAction(Activation activation) throws StandardException {
    LanguageConnectionContext lcc;
    DataDictionary dd;
    // find the language context.
    lcc = activation.getLanguageConnectionContext();
    dd = lcc.getDataDictionary();
    String thisRoleName = roleName;
    final String currentAuthId = lcc.getCurrentUserId(activation);
    final String dbo = lcc.getDataDictionary().getAuthorizationDatabaseOwner();
    TransactionController tc = lcc.getTransactionExecute();
    // SQL 2003, section 18.3, General rule 1:
    if (!tc.isIdle()) {
        throw StandardException.newException(SQLState.INVALID_TRANSACTION_STATE_ACTIVE_CONNECTION);
    }
    if (type == StatementType.SET_ROLE_DYNAMIC) {
        ParameterValueSet pvs = activation.getParameterValueSet();
        DataValueDescriptor dvs = pvs.getParameter(0);
        // SQL 2003, section 18.3, GR2: trim whitespace first, and
        // interpret as identifier, then we convert it to case normal form
        // here.
        String roleId = dvs.getString();
        if (roleId == null) {
            throw StandardException.newException(SQLState.ID_PARSE_ERROR);
        }
        thisRoleName = IdUtil.parseRoleId(roleId);
    }
    RoleGrantDescriptor rdDef = null;
    try {
        String oldRole = lcc.getCurrentRoleId(activation);
        if (oldRole != null && !oldRole.equals(thisRoleName)) {
            rdDef = dd.getRoleDefinitionDescriptor(oldRole);
            if (rdDef != null) {
                dd.getDependencyManager().invalidateFor(rdDef, DependencyManager.RECHECK_PRIVILEGES, lcc);
            }
        // else: old role else no longer exists, so ignore.
        }
        if (thisRoleName != null) {
            rdDef = dd.getRoleDefinitionDescriptor(thisRoleName);
            // SQL 2003, section 18.3, General rule 4:
            if (rdDef == null) {
                throw StandardException.newException(SQLState.ROLE_INVALID_SPECIFICATION, thisRoleName);
            }
            if (!lcc.roleIsSettable(activation, thisRoleName)) {
                throw StandardException.newException(SQLState.ROLE_INVALID_SPECIFICATION_NOT_GRANTED, thisRoleName);
            }
        }
    } finally {
        // reading above changes idle state, so reestablish it
        lcc.userCommit();
    }
    lcc.setCurrentRole(activation, rdDef != null ? thisRoleName : null);
}
Also used : ParameterValueSet(org.apache.derby.iapi.sql.ParameterValueSet) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TransactionController(org.apache.derby.iapi.store.access.TransactionController) RoleGrantDescriptor(org.apache.derby.iapi.sql.dictionary.RoleGrantDescriptor)

Aggregations

LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)126 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)57 TransactionController (org.apache.derby.iapi.store.access.TransactionController)47 StandardException (org.apache.derby.shared.common.error.StandardException)36 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)20 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)20 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)20 UUID (org.apache.derby.catalog.UUID)14 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)13 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)11 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)10 StatementContext (org.apache.derby.iapi.sql.conn.StatementContext)7 ReferencedKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor)7 RoleGrantDescriptor (org.apache.derby.iapi.sql.dictionary.RoleGrantDescriptor)7 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)6 SQLException (java.sql.SQLException)5 Iterator (java.util.Iterator)5 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)5 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)5 ArrayList (java.util.ArrayList)4