Search in sources :

Example 66 with SchemaDescriptor

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

the class DDLStatementNode method getSchemaDescriptor.

/**
 * Get a schema descriptor for this DDL object.
 * Uses this.objectName.  Always returns a schema,
 * we lock in the schema name prior to execution.
 *
 * The most common call to this method is with 2nd
 * parameter true which says that SchemaDescriptor
 * should not be requested for system schema. The only
 * time this method will get called with 2nd parameter
 * set to false will be when user has requested for
 * inplace compress using
 * SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE
 * Above inplace compress can be invoked on system tables.
 * A call to SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE
 * internally gets translated into ALTER TABLE sql.
 * When ALTER TABLE is executed for SYSCS_INPLACE_COMPRESS_TABLE,
 * we want to allow SchemaDescriptor request for system
 * tables. DERBY-1062
 *
 * @param ownerCheck		If check for schema owner is needed
 * @param doSystemSchemaCheck   If check for system schema is needed.
 *    If set to true, then throw an exception if schema descriptor
 *    is requested for a system schema. The only time this param
 *    will be set to false is when user is asking for inplace
 *    compress of a system table. DERBY-1062
 *
 * @return Schema Descriptor
 *
 * @exception	StandardException	throws on schema name
 *						that doesn't exist
 */
protected final SchemaDescriptor getSchemaDescriptor(boolean ownerCheck, boolean doSystemSchemaCheck) throws StandardException {
    String schemaName = tableName.getSchemaName();
    // boolean needError = !(implicitCreateSchema || (schemaName == null));
    boolean needError = !implicitCreateSchema;
    SchemaDescriptor sd = getSchemaDescriptor(schemaName, needError);
    CompilerContext cc = getCompilerContext();
    if (sd == null) {
        /* Disable creating schemas starting with SYS */
        if (schemaName.startsWith("SYS"))
            throw StandardException.newException(SQLState.LANG_NO_USER_DDL_IN_SYSTEM_SCHEMA, statementToString(), schemaName);
        sd = new SchemaDescriptor(getDataDictionary(), schemaName, (String) null, (UUID) null, false);
        if (isPrivilegeCollectionRequired())
            cc.addRequiredSchemaPriv(schemaName, null, Authorizer.CREATE_SCHEMA_PRIV);
    }
    if (ownerCheck && isPrivilegeCollectionRequired())
        cc.addRequiredSchemaPriv(sd.getSchemaName(), null, Authorizer.MODIFY_SCHEMA_PRIV);
    /*
		** Catch the system schema here if the caller wants us to.
		** Currently, the only time we allow system schema is for inplace
		** compress table calls.
		*/
    if (doSystemSchemaCheck && sd.isSystemSchema()) {
        throw StandardException.newException(SQLState.LANG_NO_USER_DDL_IN_SYSTEM_SCHEMA, statementToString(), sd);
    }
    return sd;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) CompilerContext(org.apache.derby.iapi.sql.compile.CompilerContext) UUID(org.apache.derby.catalog.UUID)

Example 67 with SchemaDescriptor

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

the class SYSTABLESRowFactory method makeRow.

// ///////////////////////////////////////////////////////////////////////////
// 
// METHODS
// 
// ///////////////////////////////////////////////////////////////////////////
/**
 * Make a SYSTABLES row
 *
 * @return	Row suitable for inserting into SYSTABLES.
 *
 * @exception   StandardException thrown on failure
 */
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    UUID oid;
    String tabSType = null;
    int tabIType;
    ExecRow row;
    String lockGranularity = null;
    String tableID = null;
    String schemaID = null;
    String tableName = null;
    if (td != null) {
        /*
			** We only allocate a new UUID if the descriptor doesn't already have one.
			** For descriptors replicated from a Source system, we already have an UUID.
			*/
        TableDescriptor descriptor = (TableDescriptor) td;
        SchemaDescriptor schema = (SchemaDescriptor) parent;
        oid = descriptor.getUUID();
        if (oid == null) {
            oid = getUUIDFactory().createUUID();
            descriptor.setUUID(oid);
        }
        tableID = oid.toString();
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(schema != null, "Schema should not be null unless empty row is true");
            if (schema.getUUID() == null) {
                SanityManager.THROWASSERT("schema " + schema + " has a null OID");
            }
        }
        schemaID = schema.getUUID().toString();
        tableName = descriptor.getName();
        /* RESOLVE - Table Type should really be a char in the descriptor
			 * T, S, V, S instead of 0, 1, 2, 3
			 */
        tabIType = descriptor.getTableType();
        switch(tabIType) {
            case TableDescriptor.BASE_TABLE_TYPE:
                tabSType = "T";
                break;
            case TableDescriptor.SYSTEM_TABLE_TYPE:
                tabSType = "S";
                break;
            case TableDescriptor.VIEW_TYPE:
                tabSType = "V";
                break;
            case TableDescriptor.SYNONYM_TYPE:
                tabSType = "A";
                break;
            default:
                if (SanityManager.DEBUG)
                    SanityManager.THROWASSERT("invalid table type");
        }
        char[] lockGChar = new char[1];
        lockGChar[0] = descriptor.getLockGranularity();
        lockGranularity = new String(lockGChar);
    }
    /* Insert info into systables */
    /* RESOLVE - It would be nice to require less knowledge about systables
		 * and have this be more table driven.
		 */
    /* Build the row to insert  */
    row = getExecutionFactory().getValueRow(SYSTABLES_COLUMN_COUNT);
    /* 1st column is TABLEID (UUID - char(36)) */
    row.setColumn(SYSTABLES_TABLEID, new SQLChar(tableID));
    /* 2nd column is NAME (varchar(30)) */
    row.setColumn(SYSTABLES_TABLENAME, new SQLVarchar(tableName));
    /* 3rd column is TABLETYPE (char(1)) */
    row.setColumn(SYSTABLES_TABLETYPE, new SQLChar(tabSType));
    /* 4th column is SCHEMAID (UUID - char(36)) */
    row.setColumn(SYSTABLES_SCHEMAID, new SQLChar(schemaID));
    /* 5th column is LOCKGRANULARITY (char(1)) */
    row.setColumn(SYSTABLES_LOCKGRANULARITY, new SQLChar(lockGranularity));
    return row;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLChar(org.apache.derby.iapi.types.SQLChar) UUID(org.apache.derby.catalog.UUID) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 68 with SchemaDescriptor

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

the class CompilerContextImpl method popCompilationSchema.

/**
 * @see CompilerContext#popCompilationSchema
 */
public void popCompilationSchema() {
    SchemaDescriptor sd = defaultSchemaStack.remove(defaultSchemaStack.size() - 1);
    setCompilationSchema(sd);
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)

Example 69 with SchemaDescriptor

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

the class CreateIndexNode method makeConstantAction.

/**
 * Create the Constant information that will drive the guts of Execution.
 *
 * @exception StandardException		Thrown on failure
 */
@Override
public ConstantAction makeConstantAction() throws StandardException {
    SchemaDescriptor sd = getSchemaDescriptor();
    int columnCount = columnNames.length;
    int approxLength = 0;
    // so we do not have to consider key columns of long types
    for (int i = 0; i < columnCount; i++) {
        ColumnDescriptor columnDescriptor = td.getColumnDescriptor(columnNames[i]);
        DataTypeDescriptor dts = columnDescriptor.getType();
        approxLength += dts.getTypeId().getApproximateLengthInBytes(dts);
    }
    if (approxLength > Property.IDX_PAGE_SIZE_BUMP_THRESHOLD) {
        if (((properties == null) || (properties.get(Property.PAGE_SIZE_PARAMETER) == null)) && (PropertyUtil.getServiceProperty(getLanguageConnectionContext().getTransactionCompile(), Property.PAGE_SIZE_PARAMETER) == null)) {
            if (properties == null)
                properties = new Properties();
            properties.put(Property.PAGE_SIZE_PARAMETER, Property.PAGE_SIZE_DEFAULT_LONG);
        }
    }
    return getGenericConstantActionFactory().getCreateIndexConstantAction(// not for CREATE TABLE
    false, unique, // it's not a UniqueWithDuplicateNulls Index
    false, // it's not a constraint, so its checking
    false, // initiallyDeferred: N/A
    false, // constraintType: N/A
    -1, indexType, sd.getSchemaName(), indexName.getTableName(), tableName.getTableName(), td.getUUID(), columnNames, isAscending, false, null, properties);
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) Properties(java.util.Properties)

Example 70 with SchemaDescriptor

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

SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)85 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)33 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)27 UUID (org.apache.derby.catalog.UUID)21 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)20 TransactionController (org.apache.derby.iapi.store.access.TransactionController)20 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)14 CompilerContext (org.apache.derby.iapi.sql.compile.CompilerContext)12 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)12 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)11 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)9 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)9 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)8 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)8 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)8 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)8 Properties (java.util.Properties)5 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)5 StandardException (org.apache.derby.shared.common.error.StandardException)5 RoutineAliasInfo (org.apache.derby.catalog.types.RoutineAliasInfo)4