Search in sources :

Example 21 with AliasDescriptor

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

the class StaticMethodCallNode method resolveRoutine.

/**
 * Resolve a routine. Obtain a list of routines from the data dictionary
 * of the correct type (functions or procedures) and name.
 * Pick the best routine from the list. Currently only a single routine
 * with a given type and name is allowed, thus if changes are made to
 * support overloaded routines, careful code inspection and testing will
 * be required.
 */
private void resolveRoutine(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates, SchemaDescriptor sd, boolean noSchema) throws StandardException {
    if (sd.getUUID() != null) {
        List<AliasDescriptor> list = getDataDictionary().getRoutineList(sd.getUUID().toString(), methodName, forCallStatement ? AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR : AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR);
        for (int i = list.size() - 1; i >= 0; i--) {
            AliasDescriptor proc = list.get(i);
            RoutineAliasInfo rai = (RoutineAliasInfo) proc.getAliasInfo();
            int parameterCount = rai.getParameterCount();
            boolean hasVarargs = rai.hasVarargs();
            if (hasVarargs) {
                // for the trailing varargs argument
                if (methodParms.length < (parameterCount - 1)) {
                    continue;
                }
            } else if (parameterCount != methodParms.length) {
                continue;
            }
            // pre-form the method signature. If it is a dynamic result set procedure
            // then we need to add in the ResultSet array
            TypeDescriptor[] parameterTypes = rai.getParameterTypes();
            int sigParameterCount = parameterCount;
            if (rai.getMaxDynamicResultSets() > 0) {
                sigParameterCount++;
            }
            signature = new JSQLType[sigParameterCount];
            for (int p = 0; p < parameterCount; p++) {
                // find the declared type.
                TypeDescriptor td = parameterTypes[p];
                TypeId typeId = TypeId.getTypeId(td);
                TypeId parameterTypeId = typeId;
                // if it's an OUT or INOUT parameter we need an array.
                int parameterMode = rai.getParameterModes()[getRoutineArgIdx(rai, p)];
                if (parameterMode != (ParameterMetaData.parameterModeIn)) {
                    String arrayType;
                    switch(typeId.getJDBCTypeId()) {
                        case java.sql.Types.BOOLEAN:
                        case java.sql.Types.SMALLINT:
                        case java.sql.Types.INTEGER:
                        case java.sql.Types.BIGINT:
                        case java.sql.Types.REAL:
                        case java.sql.Types.DOUBLE:
                            arrayType = getTypeCompiler(typeId).getCorrespondingPrimitiveTypeName().concat("[]");
                            break;
                        default:
                            arrayType = typeId.getCorrespondingJavaTypeName().concat("[]");
                            break;
                    }
                    typeId = TypeId.getUserDefinedTypeId(arrayType);
                }
                // this is the type descriptor of the require method parameter
                DataTypeDescriptor methoddtd = new DataTypeDescriptor(typeId, td.getPrecision(), td.getScale(), td.isNullable(), td.getMaximumWidth());
                signature[p] = new JSQLType(methoddtd);
                // this is the SQL type of the procedure parameter.
                DataTypeDescriptor paramdtd = new DataTypeDescriptor(parameterTypeId, td.getPrecision(), td.getScale(), td.isNullable(), td.getMaximumWidth());
                // if this is the last argument of a varargs routine...
                if (hasVarargs && (p == parameterCount - 1)) {
                    // 
                    for (int idx = p; idx < methodParms.length; idx++) {
                        coerceMethodParameter(fromList, subqueryList, aggregates, rai, methodParms.length, paramdtd, parameterTypeId, parameterMode, idx);
                    }
                } else // NOT the last argument of a varargs routine
                {
                    coerceMethodParameter(fromList, subqueryList, aggregates, rai, methodParms.length, paramdtd, parameterTypeId, parameterMode, p);
                }
            }
            if (sigParameterCount != parameterCount) {
                DataTypeDescriptor dtd = new DataTypeDescriptor(TypeId.getUserDefinedTypeId("java.sql.ResultSet[]"), 0, 0, false, -1);
                signature[parameterCount] = new JSQLType(dtd);
            }
            this.routineInfo = rai;
            ad = proc;
            // SQL, note that we are in system code.
            if (sd.isSystemSchema() && (routineInfo.getReturnType() == null) && routineInfo.getSQLAllowed() != RoutineAliasInfo.NO_SQL) {
                isSystemCode = true;
            }
            routineDefiner = sd.getAuthorizationId();
            break;
        }
    }
    if ((ad == null) && (methodParms.length == 1)) {
        ad = AggregateNode.resolveAggregate(getDataDictionary(), sd, methodName, noSchema);
    }
}
Also used : TypeId(org.apache.derby.iapi.types.TypeId) RoutineAliasInfo(org.apache.derby.catalog.types.RoutineAliasInfo) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) JSQLType(org.apache.derby.iapi.types.JSQLType) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor)

Example 22 with AliasDescriptor

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

the class TablePrivilegesNode method bindPrivilegesForView.

/**
 *  Retrieve all the underlying stored dependencies such as table(s),
 *  view(s) and routine(s) descriptors which the view depends on.
 *  This information is then passed to the runtime to determine if
 *  the privilege is grantable to the grantees by this grantor at
 *  execution time.
 *
 *  Go through the providers regardless who the grantor is since
 *  the statement cache may be in effect.
 *
 * @param td the TableDescriptor to check
 *
 * @exception StandardException standard error policy.
 */
private void bindPrivilegesForView(TableDescriptor td) throws StandardException {
    LanguageConnectionContext lcc = getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    ViewDescriptor vd = dd.getViewDescriptor(td);
    DependencyManager dm = dd.getDependencyManager();
    ProviderInfo[] pis = dm.getPersistentProviderInfos(vd);
    this.descriptorList = new ArrayList<Provider>();
    int siz = pis.length;
    for (int i = 0; i < siz; i++) {
        Provider provider = (Provider) pis[i].getDependableFinder().getDependable(dd, pis[i].getObjectId());
        if (provider instanceof TableDescriptor || provider instanceof ViewDescriptor || provider instanceof AliasDescriptor) {
            descriptorList.add(provider);
        }
    }
}
Also used : ProviderInfo(org.apache.derby.iapi.sql.depend.ProviderInfo) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) ViewDescriptor(org.apache.derby.iapi.sql.dictionary.ViewDescriptor) Provider(org.apache.derby.iapi.sql.depend.Provider)

Example 23 with AliasDescriptor

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

the class AggregateNode method resolveAggregate.

/**
 * Resolve a user-defined aggregate.
 */
static AliasDescriptor resolveAggregate(DataDictionary dd, SchemaDescriptor sd, String rawName, boolean noSchema) throws StandardException {
    // first see if this is one of the builtin aggregates which
    // implements the Aggregator interface
    AliasDescriptor ad = resolveBuiltinAggregate(dd, rawName, noSchema);
    if (ad != null) {
        return ad;
    }
    // been created yet. in that case, it doesn't have any aggregates in it.
    if (sd.getUUID() == null) {
        return null;
    }
    java.util.List<AliasDescriptor> list = dd.getRoutineList(sd.getUUID().toString(), rawName, AliasInfo.ALIAS_NAME_SPACE_AGGREGATE_AS_CHAR);
    if (list.size() > 0) {
        return list.get(0);
    }
    return null;
}
Also used : AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor)

Example 24 with AliasDescriptor

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

the class AggregateNode method resolveBuiltinAggregate.

/**
 * Construct an AliasDescriptor for a modern builtin aggregate.
 */
private static AliasDescriptor resolveBuiltinAggregate(DataDictionary dd, String rawName, boolean noSchema) throws StandardException {
    // builtin aggregates may not be schema-qualified
    if (!noSchema) {
        return null;
    }
    BuiltinAggDescriptor bad = null;
    for (BuiltinAggDescriptor aggDescriptor : BUILTIN_MODERN_AGGS) {
        if (aggDescriptor.aggName.equals(rawName)) {
            bad = aggDescriptor;
            break;
        }
    }
    if (bad == null) {
        return null;
    }
    AliasInfo aliasInfo = new AggregateAliasInfo(bad.argType, bad.returnType);
    return new AliasDescriptor(dd, null, rawName, dd.getSystemSchemaDescriptor().getUUID(), bad.aggClassName, AliasInfo.ALIAS_TYPE_AGGREGATE_AS_CHAR, AliasInfo.ALIAS_NAME_SPACE_AGGREGATE_AS_CHAR, false, aliasInfo, null);
}
Also used : AggregateAliasInfo(org.apache.derby.catalog.types.AggregateAliasInfo) AliasInfo(org.apache.derby.catalog.AliasInfo) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) AggregateAliasInfo(org.apache.derby.catalog.types.AggregateAliasInfo)

Example 25 with AliasDescriptor

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

the class TablePrivilegeInfo method checkPrivileges.

/**
 * Determines if the privilege is grantable by this grantor
 * for the given view.
 *
 * Note that the database owner can access database objects
 * without needing to be their owner.  This method should only
 * be called if it is a GRANT.
 *
 * @param user					authorizationId of current user
 * @param td		            TableDescriptor to be checked against
 * @param sd					SchemaDescriptor
 * @param dd					DataDictionary
 * @param lcc                   LanguageConnectionContext
 *
 * @exception StandardException if user does not have permission to grant
 */
private void checkPrivileges(String user, TableDescriptor td, SchemaDescriptor sd, DataDictionary dd, LanguageConnectionContext lcc) throws StandardException {
    if (user.equals(dd.getAuthorizationDatabaseOwner()))
        return;
    // check view specific
    if (td.getTableType() == TableDescriptor.VIEW_TYPE) {
        if (descriptorList != null) {
            TransactionController tc = lcc.getTransactionExecute();
            int siz = descriptorList.size();
            for (int i = 0; i < siz; i++) {
                TupleDescriptor p;
                SchemaDescriptor s = null;
                p = (TupleDescriptor) descriptorList.get(i);
                if (p instanceof TableDescriptor) {
                    TableDescriptor t = (TableDescriptor) p;
                    s = t.getSchemaDescriptor();
                } else if (p instanceof ViewDescriptor) {
                    ViewDescriptor v = (ViewDescriptor) p;
                    s = dd.getSchemaDescriptor(v.getCompSchemaId(), tc);
                } else if (p instanceof AliasDescriptor) {
                    AliasDescriptor a = (AliasDescriptor) p;
                    s = dd.getSchemaDescriptor(a.getSchemaUUID(), tc);
                }
                if (s != null && !user.equals(s.getAuthorizationId())) {
                    throw StandardException.newException(SQLState.AUTH_NO_OBJECT_PERMISSION, user, "grant", sd.getSchemaName(), td.getName());
                }
            // FUTURE: if object is not own by grantor then check if
            // the grantor have grant option.
            }
        }
    }
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) TransactionController(org.apache.derby.iapi.store.access.TransactionController) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) ViewDescriptor(org.apache.derby.iapi.sql.dictionary.ViewDescriptor)

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