Search in sources :

Example 1 with AliasDescriptor

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

the class DataDictionaryImpl method getRoutineList.

/**
 *		Get the list of routines matching the schema and routine name.
 *		While we only support a single alias for a given name,namespace just
 *		return a list of zero or one item.
 *		If the schema is SYSFUN then do not use the system catalogs,
 *        but instead look up the routines from the in-memory table driven
 *		by the contents of SYSFUN_FUNCTIONS.
 */
public java.util.List<AliasDescriptor> getRoutineList(String schemaID, String routineName, char nameSpace) throws StandardException {
    // We expect to find just a single function, since we currently
    // don't support multiple routines with the same name, but use a
    // list to support future extension.
    List<AliasDescriptor> list = new ArrayList<AliasDescriptor>(1);
    // Special in-memory table lookup for SYSFUN
    if (schemaID.equals(SchemaDescriptor.SYSFUN_SCHEMA_UUID) && nameSpace == AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR) {
        for (int f = 0; f < DataDictionaryImpl.SYSFUN_FUNCTIONS.length; f++) {
            String[] details = DataDictionaryImpl.SYSFUN_FUNCTIONS[f];
            String name = details[0];
            if (!name.equals(routineName))
                continue;
            AliasDescriptor ad = sysfunDescriptors[f];
            if (ad == null) {
                // details[1] Return type
                TypeDescriptor rt = DataTypeDescriptor.getBuiltInDataTypeDescriptor(details[1]).getCatalogType();
                boolean isDeterministic = Boolean.valueOf(details[SYSFUN_DETERMINISTIC_INDEX]).booleanValue();
                boolean hasVarargs = Boolean.valueOf(details[SYSFUN_VARARGS_INDEX]).booleanValue();
                // Determine the number of arguments (could be zero).
                int paramCount = details.length - SYSFUN_FIRST_PARAMETER_INDEX;
                TypeDescriptor[] pt = new TypeDescriptor[paramCount];
                String[] paramNames = new String[paramCount];
                int[] paramModes = new int[paramCount];
                for (int i = 0; i < paramCount; i++) {
                    pt[i] = DataTypeDescriptor.getBuiltInDataTypeDescriptor(details[SYSFUN_FIRST_PARAMETER_INDEX + i]).getCatalogType();
                    // Dummy names
                    paramNames[i] = "P" + (i + 1);
                    // All parameters must be IN.
                    paramModes[i] = (ParameterMetaData.parameterModeIn);
                }
                // details[3] = java method
                RoutineAliasInfo ai = new RoutineAliasInfo(details[3], paramCount, paramNames, pt, paramModes, 0, RoutineAliasInfo.PS_JAVA, RoutineAliasInfo.NO_SQL, isDeterministic, hasVarargs, false, /* hasDefinersRights */
                false, rt);
                // details[2] = class name
                ad = new AliasDescriptor(this, uuidFactory.createUUID(), name, uuidFactory.recreateUUID(schemaID), details[2], AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR, AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR, true, ai, null);
                sysfunDescriptors[f] = ad;
            }
            list.add(ad);
        }
        return list;
    }
    AliasDescriptor ad = getAliasDescriptor(schemaID, routineName, nameSpace);
    if (ad != null) {
        list.add(ad);
    }
    return list;
}
Also used : TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) RoutineAliasInfo(org.apache.derby.catalog.types.RoutineAliasInfo) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) ArrayList(java.util.ArrayList) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 2 with AliasDescriptor

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

the class DataDictionaryImpl method getAliasDescriptorForUDT.

/**
 * Get the alias descriptor for an ANSI UDT.
 *
 * @param tc The transaction to use: if null, use the compilation transaction
 * @param dtd The UDT's type descriptor
 *
 * @return The UDT's alias descriptor if it is an ANSI UDT; null otherwise.
 */
public AliasDescriptor getAliasDescriptorForUDT(TransactionController tc, DataTypeDescriptor dtd) throws StandardException {
    if (tc == null) {
        tc = getTransactionCompile();
    }
    if (dtd == null) {
        return null;
    }
    BaseTypeIdImpl btii = dtd.getTypeId().getBaseTypeId();
    if (!btii.isAnsiUDT()) {
        return null;
    }
    SchemaDescriptor sd = getSchemaDescriptor(btii.getSchemaName(), tc, true);
    AliasDescriptor ad = getAliasDescriptor(sd.getUUID().toString(), btii.getUnqualifiedName(), AliasInfo.ALIAS_NAME_SPACE_UDT_AS_CHAR);
    return ad;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) BaseTypeIdImpl(org.apache.derby.catalog.types.BaseTypeIdImpl)

Example 3 with AliasDescriptor

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

the class DataDictionaryImpl method createSystemProcedureOrFunction.

/**
 * Generic create procedure routine.
 * <p>
 * Takes the input procedure and inserts it into the appropriate
 * catalog.
 *
 * Assumes all arguments are "IN" type.
 *
 * @param routine_name  name of the routine in java and the SQL
 *                      procedure name.
 *
 * @param arg_names     String array of procedure argument names in order.
 *
 * @param arg_types     Internal SQL types of the arguments
 *
 * @param routine_sql_control
 *                      One of the RoutineAliasInfo constants:
 *                          MODIFIES_SQL_DATA
 *                          READS_SQL_DATA
 *                          CONTAINS_SQL
 *                          NO_SQL
 *
 * @param isDeterministic True if the procedure/function is DETERMINISTIC
 *
 * @param return_type   null for procedure.  For functions the return type
 *                      of the function.
 *
 * @param newlyCreatedRoutines evolving set of routines, some of which may need permissions later on
 * @param tc            an instance of the TransactionController
 *
 * @param procClass     the fully qualified name of the class that contains
 *                      java definitions for the stored procedures
 *
 * @return UUID 		UUID of system routine that got created.
 *
 * @exception  StandardException  Standard exception policy.
 */
private final UUID createSystemProcedureOrFunction(String routine_name, UUID schema_uuid, String[] arg_names, TypeDescriptor[] arg_types, int num_out_param, int num_result_sets, short routine_sql_control, boolean isDeterministic, boolean hasVarargs, TypeDescriptor return_type, HashSet<String> newlyCreatedRoutines, TransactionController tc, String procClass) throws StandardException {
    int num_args = 0;
    if (arg_names != null)
        num_args = arg_names.length;
    if (SanityManager.DEBUG) {
        if (num_args != 0) {
            SanityManager.ASSERT(arg_names != null);
            SanityManager.ASSERT(arg_types != null);
            SanityManager.ASSERT(arg_names.length == arg_types.length);
        }
    }
    // all args are only "in" arguments
    int[] arg_modes = null;
    if (num_args != 0) {
        arg_modes = new int[num_args];
        int num_in_param = num_args - num_out_param;
        for (int i = 0; i < num_in_param; i++) arg_modes[i] = (ParameterMetaData.parameterModeIn);
        for (int i = 0; i < num_out_param; i++) arg_modes[num_in_param + i] = (ParameterMetaData.parameterModeOut);
    }
    RoutineAliasInfo routine_alias_info = new RoutineAliasInfo(// name of routine
    routine_name, // number of params
    num_args, // names of params
    arg_names, // types of params
    arg_types, // all "IN" params
    arg_modes, // number of result sets
    num_result_sets, // link to java routine
    RoutineAliasInfo.PS_JAVA, // one of:
    routine_sql_control, // whether the procedure/function is DETERMINISTIC
    isDeterministic, // whether the procedure/function has VARARGS
    hasVarargs, // not definer's rights
    false, // true - calledOnNullInput
    true, return_type);
    UUID routine_uuid = getUUIDFactory().createUUID();
    AliasDescriptor ads = new AliasDescriptor(this, routine_uuid, routine_name, schema_uuid, procClass, (return_type == null) ? AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR : AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR, (return_type == null) ? AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR : AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR, false, routine_alias_info, null);
    addDescriptor(ads, null, DataDictionary.SYSALIASES_CATALOG_NUM, false, tc);
    newlyCreatedRoutines.add(routine_name);
    return routine_uuid;
}
Also used : RoutineAliasInfo(org.apache.derby.catalog.types.RoutineAliasInfo) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) UUID(org.apache.derby.catalog.UUID) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 4 with AliasDescriptor

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

the class DataDictionaryImpl method getVTIClass.

/**
 * @see DataDictionary#getVTIClass(TableDescriptor, boolean)
 */
public String getVTIClass(TableDescriptor td, boolean asTableFunction) throws StandardException {
    if (SchemaDescriptor.STD_SYSTEM_DIAG_SCHEMA_NAME.equals(td.getSchemaName())) {
        return getBuiltinVTIClass(td, asTableFunction);
    } else // see if it's a user-defined table function
    {
        String schemaName = td.getSchemaName();
        String functionName = td.getDescriptorName();
        SchemaDescriptor sd = getSchemaDescriptor(td.getSchemaName(), null, true);
        if (sd != null) {
            AliasDescriptor ad = getAliasDescriptor(sd.getUUID().toString(), functionName, AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR);
            if ((ad != null) && ad.isTableFunction()) {
                return ad.getJavaClassName();
            }
            throw StandardException.newException(SQLState.LANG_NOT_TABLE_FUNCTION, schemaName, functionName);
        }
    }
    return null;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor)

Example 5 with AliasDescriptor

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

the class PermissionsCacheable method setIdentity.

/* Cacheable interface */
public Cacheable setIdentity(Object key) throws StandardException {
    // to access that column subset.
    if (key instanceof TablePermsDescriptor) {
        TablePermsDescriptor tablePermsKey = (TablePermsDescriptor) key;
        permissions = dd.getUncachedTablePermsDescriptor(tablePermsKey);
        if (permissions == null) {
            // The owner has all privileges unless they have been revoked.
            TableDescriptor td = dd.getTableDescriptor(tablePermsKey.getTableUUID());
            SchemaDescriptor sd = td.getSchemaDescriptor();
            if (sd.isSystemSchema()) {
                // RESOLVE The access to system tables is hard coded to SELECT only to everyone.
                // Is this the way we want Derby to work? Should we allow revocation of read access
                // to system tables? If so we must explicitly add a row to the SYS.SYSTABLEPERMISSIONS
                // table for each system table when a database is created.
                permissions = new TablePermsDescriptor(dd, tablePermsKey.getGrantee(), (String) null, tablePermsKey.getTableUUID(), "Y", "N", "N", "N", "N", "N");
                // give the permission the same UUID as the system table
                ((TablePermsDescriptor) permissions).setUUID(tablePermsKey.getTableUUID());
            } else if (tablePermsKey.getGrantee().equals(sd.getAuthorizationId())) {
                permissions = new TablePermsDescriptor(dd, tablePermsKey.getGrantee(), Authorizer.SYSTEM_AUTHORIZATION_ID, tablePermsKey.getTableUUID(), "Y", "Y", "Y", "Y", "Y", "Y");
            } else {
                permissions = new TablePermsDescriptor(dd, tablePermsKey.getGrantee(), (String) null, tablePermsKey.getTableUUID(), "N", "N", "N", "N", "N", "N");
            }
        }
    } else if (key instanceof ColPermsDescriptor) {
        ColPermsDescriptor colPermsKey = (ColPermsDescriptor) key;
        permissions = dd.getUncachedColPermsDescriptor(colPermsKey);
        if (permissions == null)
            permissions = new ColPermsDescriptor(dd, colPermsKey.getGrantee(), (String) null, colPermsKey.getTableUUID(), colPermsKey.getType(), (FormatableBitSet) null);
    } else if (key instanceof RoutinePermsDescriptor) {
        RoutinePermsDescriptor routinePermsKey = (RoutinePermsDescriptor) key;
        permissions = dd.getUncachedRoutinePermsDescriptor(routinePermsKey);
        if (permissions == null) {
            // The owner has all privileges unless they have been revoked.
            try {
                AliasDescriptor ad = dd.getAliasDescriptor(routinePermsKey.getRoutineUUID());
                SchemaDescriptor sd = dd.getSchemaDescriptor(ad.getSchemaUUID(), ConnectionUtil.getCurrentLCC().getTransactionExecute());
                if (sd.isSystemSchema() && !sd.isSchemaWithGrantableRoutines())
                    permissions = new RoutinePermsDescriptor(dd, routinePermsKey.getGrantee(), (String) null, routinePermsKey.getRoutineUUID(), true);
                else if (routinePermsKey.getGrantee().equals(sd.getAuthorizationId()))
                    permissions = new RoutinePermsDescriptor(dd, routinePermsKey.getGrantee(), Authorizer.SYSTEM_AUTHORIZATION_ID, routinePermsKey.getRoutineUUID(), true);
            } catch (java.sql.SQLException sqle) {
                throw StandardException.plainWrapException(sqle);
            }
        }
    } else if (key instanceof PermDescriptor) {
        PermDescriptor permKey = (PermDescriptor) key;
        permissions = dd.getUncachedGenericPermDescriptor(permKey);
        if (permissions == null) {
            // The owner has all privileges unless they have been revoked.
            String objectType = permKey.getObjectType();
            String privilege = permKey.getPermission();
            UUID protectedObjectsID = permKey.getPermObjectId();
            PrivilegedSQLObject pso = PermDescriptor.getProtectedObject(dd, protectedObjectsID, objectType);
            SchemaDescriptor sd = pso.getSchemaDescriptor();
            if (permKey.getGrantee().equals(sd.getAuthorizationId())) {
                permissions = new PermDescriptor(dd, null, objectType, pso.getUUID(), privilege, Authorizer.SYSTEM_AUTHORIZATION_ID, permKey.getGrantee(), true);
            }
        }
    } else {
        if (SanityManager.DEBUG)
            SanityManager.NOTREACHED();
        return null;
    }
    if (permissions != null) {
        return this;
    }
    return null;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) PrivilegedSQLObject(org.apache.derby.iapi.sql.dictionary.PrivilegedSQLObject) PermDescriptor(org.apache.derby.iapi.sql.dictionary.PermDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) ColPermsDescriptor(org.apache.derby.iapi.sql.dictionary.ColPermsDescriptor) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) RoutinePermsDescriptor(org.apache.derby.iapi.sql.dictionary.RoutinePermsDescriptor) UUID(org.apache.derby.catalog.UUID) TablePermsDescriptor(org.apache.derby.iapi.sql.dictionary.TablePermsDescriptor)

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