Search in sources :

Example 11 with TableDescriptor

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

the class SYSTABLESRowFactory method buildDescriptorBody.

public TupleDescriptor buildDescriptorBody(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd, int isolationLevel) throws StandardException {
    if (SanityManager.DEBUG)
        SanityManager.ASSERT(row.nColumns() == SYSTABLES_COLUMN_COUNT, "Wrong number of columns for a SYSTABLES row");
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    String tableUUIDString;
    String schemaUUIDString;
    int tableTypeEnum;
    String lockGranularity;
    String tableName, tableType;
    DataValueDescriptor col;
    UUID tableUUID;
    UUID schemaUUID;
    SchemaDescriptor schema;
    TableDescriptor tabDesc;
    /* 1st column is TABLEID (UUID - char(36)) */
    col = row.getColumn(SYSTABLES_TABLEID);
    tableUUIDString = col.getString();
    tableUUID = getUUIDFactory().recreateUUID(tableUUIDString);
    /* 2nd column is TABLENAME (varchar(128)) */
    col = row.getColumn(SYSTABLES_TABLENAME);
    tableName = col.getString();
    /* 3rd column is TABLETYPE (char(1)) */
    col = row.getColumn(SYSTABLES_TABLETYPE);
    tableType = col.getString();
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(tableType.length() == 1, "Fourth column type incorrect");
    }
    switch(tableType.charAt(0)) {
        case 'T':
            tableTypeEnum = TableDescriptor.BASE_TABLE_TYPE;
            break;
        case 'S':
            tableTypeEnum = TableDescriptor.SYSTEM_TABLE_TYPE;
            break;
        case 'V':
            tableTypeEnum = TableDescriptor.VIEW_TYPE;
            break;
        case 'A':
            tableTypeEnum = TableDescriptor.SYNONYM_TYPE;
            break;
        default:
            if (SanityManager.DEBUG)
                SanityManager.THROWASSERT("Fourth column value invalid");
            tableTypeEnum = -1;
    }
    /* 4th column is SCHEMAID (UUID - char(36)) */
    col = row.getColumn(SYSTABLES_SCHEMAID);
    schemaUUIDString = col.getString();
    schemaUUID = getUUIDFactory().recreateUUID(schemaUUIDString);
    schema = dd.getSchemaDescriptor(schemaUUID, isolationLevel, null);
    /* 5th column is LOCKGRANULARITY (char(1)) */
    col = row.getColumn(SYSTABLES_LOCKGRANULARITY);
    lockGranularity = col.getString();
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(lockGranularity.length() == 1, "Fifth column type incorrect");
    }
    // RESOLVE - Deal with lock granularity
    tabDesc = ddg.newTableDescriptor(tableName, schema, tableTypeEnum, lockGranularity.charAt(0));
    tabDesc.setUUID(tableUUID);
    return tabDesc;
}
Also used : DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) UUID(org.apache.derby.catalog.UUID) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 12 with TableDescriptor

use of org.apache.derby.iapi.sql.dictionary.TableDescriptor 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)

Example 13 with TableDescriptor

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

the class DD_Version method dropSystemCatalog.

/**
 * Drop a System catalog.
 *	@param	tc	TransactionController
 *  @param  crf CatalogRowFactory for the catalog to drop.
 *	@exception StandardException  Standard Derby error policy.
 */
protected void dropSystemCatalog(TransactionController tc, CatalogRowFactory crf) throws StandardException {
    SchemaDescriptor sd = bootingDictionary.getSystemSchemaDescriptor();
    TableDescriptor td = bootingDictionary.getTableDescriptor(crf.getCatalogName(), sd, tc);
    ConglomerateDescriptor[] cds = td.getConglomerateDescriptors();
    for (int index = 0; index < cds.length; index++) {
        tc.dropConglomerate(cds[index].getConglomerateNumber());
    }
    dropSystemCatalogDescription(tc, td);
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 14 with TableDescriptor

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

the class PrivilegeNode method bind.

/**
 * Bind this GrantNode. Resolve all table, column, and routine references. Register
 * a dependency on the object of the privilege if it has not already been done
 *
 * @param dependencies The list of privilege objects that this statement has already seen.
 *               If the object of this privilege is not in the list then this statement is registered
 *               as dependent on the object.
 * @param grantees The list of grantees
 * @param isGrant grant if true; revoke if false
 * @return the bound node
 *
 * @exception StandardException	Standard error policy.
 */
public QueryTreeNode bind(HashMap<Provider, Provider> dependencies, List<String> grantees, boolean isGrant) throws StandardException {
    // The below code handles the case where objectName.getSchemaName()
    // returns null, in which case we'll fetch the schema descriptor for
    // the current compilation schema (see getSchemaDescriptor).
    SchemaDescriptor sd = getSchemaDescriptor(objectName.getSchemaName(), true);
    objectName.setSchemaName(sd.getSchemaName());
    // Can not grant/revoke permissions from self
    if (grantees.contains(sd.getAuthorizationId())) {
        throw StandardException.newException(SQLState.AUTH_GRANT_REVOKE_NOT_ALLOWED, objectName.getFullTableName());
    }
    switch(objectType) {
        case TABLE_PRIVILEGES:
            // can't grant/revoke privileges on system tables
            if (sd.isSystemSchema()) {
                throw StandardException.newException(SQLState.AUTH_GRANT_REVOKE_NOT_ALLOWED, objectName.getFullTableName());
            }
            TableDescriptor td = getTableDescriptor(objectName.getTableName(), sd);
            if (td == null) {
                throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, objectName);
            }
            // a temporary table is created later with same name.
            if (isSessionSchema(sd.getSchemaName())) {
                throw StandardException.newException(SQLState.LANG_OPERATION_NOT_ALLOWED_ON_SESSION_SCHEMA_TABLES);
            }
            if (td.getTableType() != TableDescriptor.BASE_TABLE_TYPE && td.getTableType() != TableDescriptor.VIEW_TYPE) {
                throw StandardException.newException(SQLState.AUTH_GRANT_REVOKE_NOT_ALLOWED, objectName.getFullTableName());
            }
            specificPrivileges.bind(td, isGrant);
            dependencyProvider = td;
            break;
        case ROUTINE_PRIVILEGES:
            if (!sd.isSchemaWithGrantableRoutines()) {
                throw StandardException.newException(SQLState.AUTH_GRANT_REVOKE_NOT_ALLOWED, objectName.getFullTableName());
            }
            AliasDescriptor proc = null;
            List<AliasDescriptor> list = getDataDictionary().getRoutineList(sd.getUUID().toString(), objectName.getTableName(), routineDesignator.isFunction ? AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR : AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR);
            if (routineDesignator.paramTypeList == null) {
                // No signature was specified. Make sure that there is exactly one routine with that name.
                if (list.size() > 1) {
                    throw StandardException.newException((routineDesignator.isFunction ? SQLState.LANG_AMBIGUOUS_FUNCTION_NAME : SQLState.LANG_AMBIGUOUS_PROCEDURE_NAME), objectName.getFullTableName());
                }
                if (list.size() != 1) {
                    if (routineDesignator.isFunction) {
                        throw StandardException.newException(SQLState.LANG_NO_SUCH_FUNCTION, objectName.getFullTableName());
                    } else {
                        throw StandardException.newException(SQLState.LANG_NO_SUCH_PROCEDURE, objectName.getFullTableName());
                    }
                }
                proc = list.get(0);
            } else {
                // The full signature was specified
                boolean found = false;
                for (int i = list.size() - 1; (!found) && i >= 0; i--) {
                    proc = list.get(i);
                    RoutineAliasInfo routineInfo = (RoutineAliasInfo) proc.getAliasInfo();
                    int parameterCount = routineInfo.getParameterCount();
                    if (parameterCount != routineDesignator.paramTypeList.size())
                        continue;
                    TypeDescriptor[] parameterTypes = routineInfo.getParameterTypes();
                    found = true;
                    for (int parmIdx = 0; parmIdx < parameterCount; parmIdx++) {
                        if (!parameterTypes[parmIdx].equals(routineDesignator.paramTypeList.get(parmIdx))) {
                            found = false;
                            break;
                        }
                    }
                }
                if (!found) {
                    // reconstruct the signature for the error message
                    StringBuilder sb = new StringBuilder(objectName.getFullTableName());
                    sb.append("(");
                    for (int i = 0; i < routineDesignator.paramTypeList.size(); i++) {
                        if (i > 0)
                            sb.append(",");
                        sb.append(routineDesignator.paramTypeList.get(i).toString());
                    }
                    throw StandardException.newException(SQLState.LANG_NO_SUCH_METHOD_ALIAS, sb.toString());
                }
            }
            routineDesignator.setAliasDescriptor(proc);
            dependencyProvider = proc;
            break;
        case AGGREGATE_PRIVILEGES:
            dependencyProvider = getDataDictionary().getAliasDescriptor(sd.getUUID().toString(), objectName.getTableName(), AliasInfo.ALIAS_NAME_SPACE_AGGREGATE_AS_CHAR);
            if (dependencyProvider == null) {
                throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "DERBY AGGREGATE", objectName.getFullTableName());
            }
            break;
        case SEQUENCE_PRIVILEGES:
            dependencyProvider = getDataDictionary().getSequenceDescriptor(sd, objectName.getTableName());
            if (dependencyProvider == null) {
                throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "SEQUENCE", objectName.getFullTableName());
            }
            break;
        case UDT_PRIVILEGES:
            dependencyProvider = getDataDictionary().getAliasDescriptor(sd.getUUID().toString(), objectName.getTableName(), AliasInfo.ALIAS_NAME_SPACE_UDT_AS_CHAR);
            if (dependencyProvider == null) {
                throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "TYPE", objectName.getFullTableName());
            }
            break;
        default:
            throw unimplementedFeature();
    }
    if (dependencyProvider != null) {
        if (dependencies.get(dependencyProvider) == null) {
            getCompilerContext().createDependency(dependencyProvider);
            dependencies.put(dependencyProvider, dependencyProvider);
        }
    }
    return this;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) RoutineAliasInfo(org.apache.derby.catalog.types.RoutineAliasInfo) TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 15 with TableDescriptor

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

the class QueryTreeNode method getTableDescriptor.

/**
 * Get the descriptor for the named table within the given schema.
 * If the schema parameter is NULL, it looks for the table in the
 * current (default) schema. Table descriptors include object ids,
 * object types (table, view, etc.)
 * If the schema is SESSION, then before looking into the data dictionary
 * for persistent tables, it first looks into LCC for temporary tables.
 * If no temporary table tableName found for the SESSION schema, then it goes and
 * looks through the data dictionary for persistent table
 * We added getTableDescriptor here so that we can look for non data dictionary
 * tables(ie temp tables) here. Any calls to getTableDescriptor in data dictionary
 * should be only for persistent tables
 *
 * @param tableName	The name of the table to get the descriptor for
 * @param schema	The descriptor for the schema the table lives in.
 *			If null, use the current (default) schema.
 *
 * @return	The descriptor for the table, null if table does not
 *		exist.
 *
 * @exception StandardException		Thrown on failure
 */
protected final TableDescriptor getTableDescriptor(String tableName, SchemaDescriptor schema) throws StandardException {
    TableDescriptor retval;
    // Following if means we are dealing with SESSION schema.
    if (isSessionSchema(schema)) {
        // First we need to look in the list of temporary tables to see if this table is a temporary table.
        retval = getLanguageConnectionContext().getTableDescriptorForDeclaredGlobalTempTable(tableName);
        if (retval != null)
            // this is a temporary table
            return retval;
    }
    // because there is no physical SESSION schema
    if (schema.getUUID() == null)
        return null;
    // it is not a temporary table, so go through the data dictionary to find the physical persistent table
    TableDescriptor td = getDataDictionary().getTableDescriptor(tableName, schema, this.getLanguageConnectionContext().getTransactionCompile());
    if (td == null || td.isSynonymDescriptor())
        return null;
    return td;
}
Also used : TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Aggregations

TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)80 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)27 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)23 UUID (org.apache.derby.catalog.UUID)22 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)20 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)20 TransactionController (org.apache.derby.iapi.store.access.TransactionController)20 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)19 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)11 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)11 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)9 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)9 StandardException (org.apache.derby.shared.common.error.StandardException)9 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)7 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)7 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)7 ArrayList (java.util.ArrayList)6 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)6 ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)6 ViewDescriptor (org.apache.derby.iapi.sql.dictionary.ViewDescriptor)6