Search in sources :

Example 11 with AliasDescriptor

use of org.apache.derby.iapi.sql.dictionary.AliasDescriptor in project derby by apache.

the class SecurityUtil method authorize.

/**
 * Raise an exception if the current user does not have permission
 * to perform the indicated operation.
 */
public static void authorize(Securable operation) throws StandardException {
    LanguageConnectionContext lcc = (LanguageConnectionContext) getContextOrNull(LanguageConnectionContext.CONTEXT_ID);
    if (lcc.usesSqlAuthorization()) {
        Authorizer authorizer = lcc.getAuthorizer();
        DataDictionary dd = lcc.getDataDictionary();
        AliasDescriptor ad = dd.getRoutineList(operation.routineSchemaID, operation.routineName, operation.routineType).get(0);
        ArrayList<StatementPermission> requiredPermissions = new ArrayList<StatementPermission>();
        StatementRoutinePermission executePermission = new StatementRoutinePermission(ad.getObjectID());
        requiredPermissions.add(executePermission);
        authorizer.authorize(requiredPermissions, lcc.getLastActivation());
    }
}
Also used : StatementPermission(org.apache.derby.iapi.sql.dictionary.StatementPermission) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) Authorizer(org.apache.derby.iapi.sql.conn.Authorizer) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) ArrayList(java.util.ArrayList) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) StatementRoutinePermission(org.apache.derby.iapi.sql.dictionary.StatementRoutinePermission)

Example 12 with AliasDescriptor

use of org.apache.derby.iapi.sql.dictionary.AliasDescriptor in project derby by apache.

the class CreateAliasNode method bindAggregate.

/**
 * Extra logic for binding user-defined aggregate definitions
 */
private void bindAggregate() throws StandardException {
    String unqualifiedName = getRelativeName();
    // 
    // A user-defined aggregate cannot have the name of a builtin function which takes 1 argument.
    // 
    SchemaDescriptor sysfun = getSchemaDescriptor("SYSFUN", true);
    List<AliasDescriptor> systemFunctions = getDataDictionary().getRoutineList(sysfun.getUUID().toString(), unqualifiedName, AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR);
    for (int i = 0; i < systemFunctions.size(); i++) {
        AliasDescriptor function = systemFunctions.get(i);
        RoutineAliasInfo routineInfo = (RoutineAliasInfo) function.getAliasInfo();
        int parameterCount = routineInfo.getParameterCount();
        if (parameterCount == 1) {
            throw illegalAggregate();
        }
    }
    // 
    for (int i = 0; i < NON_RESERVED_FUNCTION_NAMES.length; i++) {
        if (NON_RESERVED_FUNCTION_NAMES[i].equals(unqualifiedName)) {
            throw illegalAggregate();
        }
    }
    // 
    for (int i = 0; i < NON_RESERVED_AGGREGATES.length; i++) {
        if (NON_RESERVED_AGGREGATES[i].equals(unqualifiedName)) {
            throw illegalAggregate();
        }
    }
    // now bind the input and return types
    AggregateAliasInfo aai = (AggregateAliasInfo) aliasInfo;
    aai.setCollationTypeForAllStringTypes(getSchemaDescriptor().getCollationType());
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) RoutineAliasInfo(org.apache.derby.catalog.types.RoutineAliasInfo) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) AggregateAliasInfo(org.apache.derby.catalog.types.AggregateAliasInfo)

Example 13 with AliasDescriptor

use of org.apache.derby.iapi.sql.dictionary.AliasDescriptor in project derby by apache.

the class XMLOptTrace method getOptimizableName.

/**
 * Get the name of an optimizable
 */
private TableName getOptimizableName(Optimizable optimizable) {
    try {
        if (isBaseTable(optimizable)) {
            ProjectRestrictNode prn = (ProjectRestrictNode) optimizable;
            TableDescriptor td = ((FromBaseTable) prn.getChildResult()).getTableDescriptor();
            return makeTableName(td.getSchemaName(), td.getName(), _cm);
        } else if (OptimizerImpl.isTableFunction(optimizable)) {
            ProjectRestrictNode prn = (ProjectRestrictNode) optimizable;
            AliasDescriptor ad = ((StaticMethodCallNode) ((FromVTI) prn.getChildResult()).getMethodCall()).ad;
            return makeTableName(ad.getSchemaName(), ad.getName(), _cm);
        } else if (isFromTable(optimizable)) {
            TableName retval = ((FromTable) ((ProjectRestrictNode) optimizable).getChildResult()).getTableName();
            if (retval != null) {
                return retval;
            }
        }
    } catch (StandardException e) {
    // Technically, an exception could occur here if the table name
    // was not previously bound and if an error occured while binding it.
    // But the optimizable should have been bound long before optimization,
    // so this should not be a problem.
    }
    String nodeClass = optimizable.getClass().getName();
    String unqualifiedName = nodeClass.substring(nodeClass.lastIndexOf(".") + 1);
    return makeTableName(null, unqualifiedName, _cm);
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 14 with AliasDescriptor

use of org.apache.derby.iapi.sql.dictionary.AliasDescriptor in project derby by apache.

the class DDLConstantAction method adjustUDTDependencies.

/**
 * Add and drop dependencies of a routine on UDTs.
 *
 * @param lcc Interpreter's state variable for this session.
 * @param dd Metadata
 * @param ad Alias descriptor for the routine
 * @param adding True if we are adding dependencies, false if we're dropping them
 */
protected void adjustUDTDependencies(LanguageConnectionContext lcc, DataDictionary dd, AliasDescriptor ad, boolean adding) throws StandardException {
    RoutineAliasInfo routineInfo = null;
    AggregateAliasInfo aggInfo = null;
    // nothing to do if this is not a routine
    switch(ad.getAliasType()) {
        case AliasInfo.ALIAS_TYPE_AGGREGATE_AS_CHAR:
            aggInfo = (AggregateAliasInfo) ad.getAliasInfo();
            break;
        case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
        case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
            routineInfo = (RoutineAliasInfo) ad.getAliasInfo();
            break;
        default:
            return;
    }
    TransactionController tc = lcc.getTransactionExecute();
    HashMap<String, AliasDescriptor> addUdtMap = new HashMap<String, AliasDescriptor>();
    HashMap<String, AliasDescriptor> dropUdtMap = new HashMap<String, AliasDescriptor>();
    HashMap<String, AliasDescriptor> udtMap = adding ? addUdtMap : dropUdtMap;
    TypeDescriptor rawReturnType = aggInfo != null ? aggInfo.getReturnType() : routineInfo.getReturnType();
    if (rawReturnType != null) {
        AliasDescriptor returnTypeAD = dd.getAliasDescriptorForUDT(tc, DataTypeDescriptor.getType(rawReturnType));
        if (returnTypeAD != null) {
            udtMap.put(returnTypeAD.getObjectID().toString(), returnTypeAD);
        }
    }
    // table functions can have udt columns. track those dependencies.
    if ((rawReturnType != null) && rawReturnType.isRowMultiSet()) {
        TypeDescriptor[] columnTypes = rawReturnType.getRowTypes();
        int columnCount = columnTypes.length;
        for (int i = 0; i < columnCount; i++) {
            AliasDescriptor columnTypeAD = dd.getAliasDescriptorForUDT(tc, DataTypeDescriptor.getType(columnTypes[i]));
            if (columnTypeAD != null) {
                udtMap.put(columnTypeAD.getObjectID().toString(), columnTypeAD);
            }
        }
    }
    TypeDescriptor[] paramTypes = aggInfo != null ? new TypeDescriptor[] { aggInfo.getForType() } : routineInfo.getParameterTypes();
    if (paramTypes != null) {
        int paramCount = paramTypes.length;
        for (int i = 0; i < paramCount; i++) {
            AliasDescriptor paramType = dd.getAliasDescriptorForUDT(tc, DataTypeDescriptor.getType(paramTypes[i]));
            if (paramType != null) {
                udtMap.put(paramType.getObjectID().toString(), paramType);
            }
        }
    }
    adjustUDTDependencies(lcc, dd, ad, addUdtMap, dropUdtMap);
}
Also used : RoutineAliasInfo(org.apache.derby.catalog.types.RoutineAliasInfo) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) HashMap(java.util.HashMap) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) AggregateAliasInfo(org.apache.derby.catalog.types.AggregateAliasInfo) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 15 with AliasDescriptor

use of org.apache.derby.iapi.sql.dictionary.AliasDescriptor in project derby by apache.

the class DDLConstantAction method adjustUDTDependencies.

/**
 * Add and drop dependencies of an object on UDTs.
 *
 * @param lcc Interpreter's state variable for this session.
 * @param dd Metadata
 * @param dependent Object which depends on UDT
 * @param addUdtMap Map of UDTs for which dependencies should be added
 * @param dropUdtMap Map of UDT for which dependencies should be dropped
 */
private void adjustUDTDependencies(LanguageConnectionContext lcc, DataDictionary dd, Dependent dependent, HashMap<String, AliasDescriptor> addUdtMap, HashMap<String, AliasDescriptor> dropUdtMap) throws StandardException {
    // again, nothing to do if there are no columns of udt type
    if ((addUdtMap.isEmpty()) && (dropUdtMap.isEmpty())) {
        return;
    }
    TransactionController tc = lcc.getTransactionExecute();
    DependencyManager dm = dd.getDependencyManager();
    ContextManager cm = lcc.getContextManager();
    // add new dependencies
    for (AliasDescriptor ad : addUdtMap.values()) {
        dm.addDependency(dependent, ad, cm);
    }
    // drop dependencies that are orphaned
    for (AliasDescriptor ad : dropUdtMap.values()) {
        DependencyDescriptor dep = new DependencyDescriptor(dependent, ad);
        dd.dropStoredDependency(dep, tc);
    }
}
Also used : DependencyDescriptor(org.apache.derby.iapi.sql.dictionary.DependencyDescriptor) ContextManager(org.apache.derby.iapi.services.context.ContextManager) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Aggregations

AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)31 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)11 RoutineAliasInfo (org.apache.derby.catalog.types.RoutineAliasInfo)9 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)9 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)7 UUID (org.apache.derby.catalog.UUID)6 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)6 TypeDescriptor (org.apache.derby.catalog.TypeDescriptor)5 TransactionController (org.apache.derby.iapi.store.access.TransactionController)5 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)4 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)4 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)4 AliasInfo (org.apache.derby.catalog.AliasInfo)3 AggregateAliasInfo (org.apache.derby.catalog.types.AggregateAliasInfo)3 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)3 SQLChar (org.apache.derby.iapi.types.SQLChar)3 SQLLongint (org.apache.derby.iapi.types.SQLLongint)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 SynonymAliasInfo (org.apache.derby.catalog.types.SynonymAliasInfo)2