Search in sources :

Example 76 with SchemaDescriptor

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

the class DropIndexNode method bindStatement.

/**
 * Bind this DropIndexNode.  This means looking up the index,
 * verifying it exists and getting the conglomerate number.
 *
 * @exception StandardException		Thrown on error
 */
@Override
public void bindStatement() throws StandardException {
    CompilerContext cc = getCompilerContext();
    DataDictionary dd = getDataDictionary();
    SchemaDescriptor sd;
    sd = getSchemaDescriptor();
    if (sd.getUUID() != null)
        cd = dd.getConglomerateDescriptor(getRelativeName(), sd, false);
    if (cd == null) {
        throw StandardException.newException(SQLState.LANG_INDEX_NOT_FOUND, getFullName());
    }
    /* Get the table descriptor */
    td = getTableDescriptor(cd.getTableID());
    /* Drop index is not allowed on an index backing a constraint -
		 * user must drop the constraint, which will drop the index.
		 * Drop constraint drops the constraint before the index,
		 * so it's okay to drop a backing index if we can't find its
		 * ConstraintDescriptor.
		 */
    if (cd.isConstraint()) {
        ConstraintDescriptor conDesc;
        String constraintName;
        conDesc = dd.getConstraintDescriptor(td, cd.getUUID());
        if (conDesc != null) {
            constraintName = conDesc.getConstraintName();
            throw StandardException.newException(SQLState.LANG_CANT_DROP_BACKING_INDEX, getFullName(), constraintName);
        }
    }
    /* Statement is dependent on the TableDescriptor and ConglomerateDescriptor */
    cc.createDependency(td);
    cc.createDependency(cd);
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) CompilerContext(org.apache.derby.iapi.sql.compile.CompilerContext) ConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary)

Example 77 with SchemaDescriptor

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

the class LockTableNode method bindStatement.

/**
 * Bind this LockTableNode.  This means looking up the table,
 * verifying it exists and getting the heap conglomerate number.
 *
 * @exception StandardException		Thrown on error
 */
@Override
public void bindStatement() throws StandardException {
    CompilerContext cc = getCompilerContext();
    ConglomerateDescriptor cd;
    SchemaDescriptor sd;
    String schemaName = tableName.getSchemaName();
    sd = getSchemaDescriptor(schemaName);
    // Users are not allowed to lock system tables
    if (sd.isSystemSchema()) {
        throw StandardException.newException(SQLState.LANG_NO_USER_DDL_IN_SYSTEM_SCHEMA, statementToString(), schemaName);
    }
    lockTableDescriptor = getTableDescriptor(tableName.getTableName(), sd);
    if (lockTableDescriptor == null) {
        // Check if the reference is for a synonym.
        TableName synonymTab = resolveTableToSynonym(tableName);
        if (synonymTab == null)
            throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, tableName);
        tableName = synonymTab;
        sd = getSchemaDescriptor(tableName.getSchemaName());
        lockTableDescriptor = getTableDescriptor(synonymTab.getTableName(), sd);
        if (lockTableDescriptor == null)
            throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, tableName);
    }
    // throw an exception if user is attempting to lock a temporary table
    if (lockTableDescriptor.getTableType() == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE) {
        throw StandardException.newException(SQLState.LANG_NOT_ALLOWED_FOR_DECLARED_GLOBAL_TEMP_TABLE);
    }
    conglomerateNumber = lockTableDescriptor.getHeapConglomerateId();
    /* Get the base conglomerate descriptor */
    cd = lockTableDescriptor.getConglomerateDescriptor(conglomerateNumber);
    /* Statement is dependent on the TableDescriptor and ConglomerateDescriptor */
    cc.createDependency(lockTableDescriptor);
    cc.createDependency(cd);
    if (isPrivilegeCollectionRequired()) {
        // need SELECT privilege to perform lock table statement.
        cc.pushCurrentPrivType(Authorizer.SELECT_PRIV);
        cc.addRequiredTablePriv(lockTableDescriptor);
        cc.popCurrentPrivType();
    }
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) CompilerContext(org.apache.derby.iapi.sql.compile.CompilerContext) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)

Example 78 with SchemaDescriptor

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

the class NextSequenceNode method bindExpression.

/**
 * Bind this expression.  This means binding the sub-expressions,
 * as well as figuring out what the return type is for this expression.
 *
 * @param fromList        The FROM list for the query this
 *                        expression is in, for binding columns.
 * @param subqueryList    The subquery list being built as we find SubqueryNodes
 * @param aggregates      The aggregate list being built as we find AggregateNodes
 * @return The new top of the expression tree.
 * @throws StandardException Thrown on error
 */
@Override
ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates, boolean forQueryRewrite) throws StandardException {
    // 
    if (sequenceDescriptor != null) {
        return this;
    }
    CompilerContext cc = getCompilerContext();
    if ((cc.getReliability() & CompilerContext.NEXT_VALUE_FOR_ILLEGAL) != 0) {
        throw StandardException.newException(SQLState.LANG_NEXT_VALUE_FOR_ILLEGAL);
    }
    // lookup sequence object in the data dictionary
    sequenceName.bind();
    SchemaDescriptor sd = getSchemaDescriptor(sequenceName.getSchemaName());
    sequenceDescriptor = getDataDictionary().getSequenceDescriptor(sd, sequenceName.getTableName());
    if (sequenceDescriptor == null) {
        throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "SEQUENCE", sequenceName.getFullTableName());
    }
    // 
    if (sd.isSystemSchema()) {
        throw StandardException.newException(SQLState.LANG_SYSTEM_SEQUENCE);
    }
    // set the datatype of the value node
    this.setType(sequenceDescriptor.getDataType());
    // 
    if (cc.isReferenced(sequenceDescriptor)) {
        throw StandardException.newException(SQLState.LANG_SEQUENCE_REFERENCED_TWICE, sequenceName.getFullTableName());
    }
    cc.addReferencedSequence(sequenceDescriptor);
    ValueNode returnNode = this;
    // set up dependency on sequence and compile a check for USAGE
    // priv if needed
    getCompilerContext().createDependency(sequenceDescriptor);
    if (isPrivilegeCollectionRequired()) {
        getCompilerContext().addRequiredUsagePriv(sequenceDescriptor);
    }
    return returnNode;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) CompilerContext(org.apache.derby.iapi.sql.compile.CompilerContext)

Example 79 with SchemaDescriptor

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

the class DataDictionaryImpl method upgrade_addInvisibleColumns.

/**
 *	Add invisible columns to an existing system catalog
 *
 *	@param	rowFactory				Associated with this catalog.
 *	@param	newColumnIDs			Array of 1-based column ids.
 *	@param	tc						Transaction controller
 *
 *	@exception StandardException Standard Derby error policy
 */
public void upgrade_addInvisibleColumns(CatalogRowFactory rowFactory, int[] newColumnIDs, TransactionController tc) throws StandardException {
    ExecRow templateRow = rowFactory.makeEmptyRowForCurrentVersion();
    SchemaDescriptor sd = getSystemSchemaDescriptor();
    long conglomID = getTableDescriptor(rowFactory.getCatalogName(), sd, tc).getHeapConglomerateId();
    widenConglomerate(templateRow, newColumnIDs, conglomID, tc);
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow)

Example 80 with SchemaDescriptor

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

the class DataDictionaryImpl method dropSchemaDescriptor.

/**
 * Drop the descriptor for a schema, given the schema's name
 *
 * @param schemaName	The name of the schema to drop
 * @param tc			TransactionController for the transaction
 *
 * @exception StandardException		Thrown on error
 */
public void dropSchemaDescriptor(String schemaName, TransactionController tc) throws StandardException {
    ExecIndexRow keyRow1 = null;
    DataValueDescriptor schemaNameOrderable;
    TabInfoImpl ti = coreInfo[SYSSCHEMAS_CORE_NUM];
    if (SanityManager.DEBUG) {
        SchemaDescriptor sd = getSchemaDescriptor(schemaName, getTransactionCompile(), true);
        if (!isSchemaEmpty(sd)) {
            SanityManager.THROWASSERT("Attempt to drop schema " + schemaName + " that is not empty");
        }
    }
    /* Use schemaNameOrderable in both start 
		 * and stop position for index 1 scan. 
		 */
    schemaNameOrderable = new SQLVarchar(schemaName);
    /* Set up the start/stop position for the scan */
    keyRow1 = exFactory.getIndexableRow(1);
    keyRow1.setColumn(1, schemaNameOrderable);
    ti.deleteRow(tc, keyRow1, SYSSCHEMASRowFactory.SYSSCHEMAS_INDEX1_ID);
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

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