Search in sources :

Example 31 with SchemaDescriptor

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

the class DDLStatementNode method justGetDescriptor.

/**
 * Just get the table descriptor. Don't worry if it belongs to a view,
 * system table, synonym or a real table. Let the caller decide what
 * to do.
 *
 * @param tableName
 *
 * @return TableDescriptor for the give TableName
 *
 * @throws StandardException on error
 */
private TableDescriptor justGetDescriptor(TableName tableName) throws StandardException {
    String schemaName = tableName.getSchemaName();
    SchemaDescriptor sd = getSchemaDescriptor(schemaName);
    TableDescriptor td = getTableDescriptor(tableName.getTableName(), sd);
    if (td == null) {
        throw StandardException.newException(SQLState.LANG_OBJECT_DOES_NOT_EXIST, statementToString(), tableName);
    }
    return td;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 32 with SchemaDescriptor

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

the class DMLModStatementNode method bindConstraints.

/**
 * Gets and binds all the constraints for an INSERT/UPDATE/DELETE.
 * First finds the constraints that are relevant to this node.
 * This is done by calling getAllRelevantConstriants().  If
 * getAllRelevantConstraints() has already been called, then
 * this list is used.  Then it creates appropriate
 * dependencies. Then binds check constraints.  It also
 * generates the array of FKInfo items that are used in
 * code generation.
 *
 * Note: we have a new flag here to see if defer processing is enabled or
 *       not, the only scenario that is disabled is when we reapply the
 *		 reply message we get from the source
 *
 * @param dataDictionary		The DataDictionary
 * @param targetTableDescriptor	The TableDescriptor
 * @param dependent			Parent object that will depend on all the constraints
 *							that we look up. If this argument is null, then we
 *							use the default dependent (the statement being compiled).
 * @param sourceRCL				RCL of the table being changed
 * @param changedColumnIds		If null, all columns being changed, otherwise array
 *								of 1-based column ids for columns being changed
 * @param readColsBitSet		bit set for the read scan
 * @param includeTriggers		whether triggers are included in the processing
 * @param hasDeferrableCheckConstraints
 *                        OUT semantics: set element 0 to true if the
 *                        target table has any deferrable CHECK constraints
 *
 * @return	The bound, ANDed check constraints as a query tree.
 *
 * @exception StandardException		Thrown on failure
 */
ValueNode bindConstraints(DataDictionary dataDictionary, OptimizerFactory optimizerFactory, TableDescriptor targetTableDescriptor, Dependent dependent, ResultColumnList sourceRCL, int[] changedColumnIds, FormatableBitSet readColsBitSet, boolean includeTriggers, boolean[] hasDeferrableCheckConstraints) throws StandardException {
    bound = true;
    /* Nothing to do if updatable VTI */
    if (targetVTI != null) {
        return null;
    }
    CompilerContext compilerContext = getCompilerContext();
    // Do not need privileges to execute constraints
    compilerContext.pushCurrentPrivType(Authorizer.NULL_PRIV);
    try {
        getAllRelevantConstraints(dataDictionary, targetTableDescriptor, changedColumnIds);
        createConstraintDependencies(dataDictionary, relevantCdl, dependent);
        generateFKInfo(relevantCdl, dataDictionary, targetTableDescriptor, readColsBitSet);
        getAllRelevantTriggers(dataDictionary, targetTableDescriptor, changedColumnIds, includeTriggers);
        createTriggerDependencies(relevantTriggers, dependent);
        generateTriggerInfo(relevantTriggers);
        checkConstraints = generateCheckTree(relevantCdl, targetTableDescriptor, hasDeferrableCheckConstraints);
        if (checkConstraints != null) {
            SchemaDescriptor originalCurrentSchema = targetTableDescriptor.getSchemaDescriptor();
            compilerContext.pushCompilationSchema(originalCurrentSchema);
            try {
                bindRowScopedExpression(optimizerFactory, getContextManager(), targetTableDescriptor, sourceRCL, checkConstraints);
            } finally {
                compilerContext.popCompilationSchema();
            }
        }
    } finally {
        compilerContext.popCurrentPrivType();
    }
    return checkConstraints;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) CompilerContext(org.apache.derby.iapi.sql.compile.CompilerContext)

Example 33 with SchemaDescriptor

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

the class DMLModStatementNode method verifyTargetTable.

/**
 * Verify the target table.  Get the TableDescriptor
 * if the target table is not a VTI.
 *
 * @exception StandardException		Thrown on error
 */
void verifyTargetTable() throws StandardException {
    DataDictionary dataDictionary = getDataDictionary();
    if (targetTableName != null) {
        /*
			** Get the TableDescriptor for the table we are inserting into
			*/
        SchemaDescriptor sdtc = getSchemaDescriptor(targetTableName.getSchemaName());
        targetTableDescriptor = getTableDescriptor(targetTableName.getTableName(), sdtc);
        if (targetTableDescriptor == null) {
            // Check if the reference is for a synonym.
            TableName synonymTab = resolveTableToSynonym(targetTableName);
            if (synonymTab == null)
                throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, targetTableName);
            synonymTableName = targetTableName;
            targetTableName = synonymTab;
            sdtc = getSchemaDescriptor(targetTableName.getSchemaName());
            targetTableDescriptor = getTableDescriptor(synonymTab.getTableName(), sdtc);
            if (targetTableDescriptor == null)
                throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, targetTableName);
        }
        targetTableName.setSchemaName(sdtc.getSchemaName());
        switch(targetTableDescriptor.getTableType()) {
            case TableDescriptor.VIEW_TYPE:
                // Views are currently not updatable
                throw StandardException.newException(SQLState.LANG_VIEW_NOT_UPDATEABLE, targetTableName);
            case TableDescriptor.VTI_TYPE:
            // fall through - currently all vti tables are system tables.
            case TableDescriptor.SYSTEM_TABLE_TYPE:
                // System tables are not updatable
                throw StandardException.newException(SQLState.LANG_UPDATE_SYSTEM_TABLE_ATTEMPTED, targetTableName);
            default:
                break;
        }
        /* We need to get some kind of table lock (IX here), to prevent
			 * another thread from adding a new index while we are binding,
			 * if we are a reader in DDL mode.  Just a row lock on system table
			 * SYSCONGLOMERATE is not enough: that wouldn't prevent another
			 * thread from adding a new entry.  Part of the fix for Beetle 3976.
			 * Same lock as in exec, compatible with row lock, for concurrency.
			 */
        targetTableDescriptor = lockTableForCompilation(targetTableDescriptor);
        getCompilerContext().createDependency(targetTableDescriptor);
    } else {
        /* VTI - VTIs in DML Mod are version 2 VTIs - They
			 * must implement java.sql.PreparedStatement and have
			 * the JDBC2.0 getMetaData() and getResultSetConcurrency()
			 * methods and return an updatable ResultSet.
			 */
        FromList dummyFromList = new FromList(getContextManager());
        targetVTI = (FromVTI) targetVTI.bindNonVTITables(dataDictionary, dummyFromList);
        targetVTI = (FromVTI) targetVTI.bindVTITables(dummyFromList);
    }
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary)

Example 34 with SchemaDescriptor

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

the class DropSequenceNode method bindStatement.

/**
 * Bind this DropSequenceNode.
 *
 * @throws StandardException Thrown on error
 */
@Override
public void bindStatement() throws StandardException {
    DataDictionary dataDictionary = getDataDictionary();
    String sequenceName = getRelativeName();
    SequenceDescriptor seqDesc = null;
    SchemaDescriptor sd = getSchemaDescriptor();
    if (sd.getUUID() != null) {
        seqDesc = dataDictionary.getSequenceDescriptor(sd, sequenceName);
    }
    if (seqDesc == null) {
        throw StandardException.newException(SQLState.LANG_OBJECT_DOES_NOT_EXIST, statementToString(), sequenceName);
    }
    // Statement is dependent on the SequenceDescriptor
    getCompilerContext().createDependency(seqDesc);
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) SequenceDescriptor(org.apache.derby.iapi.sql.dictionary.SequenceDescriptor)

Example 35 with SchemaDescriptor

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

the class DropTriggerNode method bindStatement.

/**
 * Bind this DropTriggerNode.  This means looking up the trigger,
 * verifying it exists and getting its table uuid.
 *
 * @exception StandardException		Thrown on error
 */
@Override
public void bindStatement() throws StandardException {
    CompilerContext cc = getCompilerContext();
    DataDictionary dd = getDataDictionary();
    SchemaDescriptor sd = getSchemaDescriptor();
    TriggerDescriptor triggerDescriptor = null;
    if (sd.getUUID() != null)
        triggerDescriptor = dd.getTriggerDescriptor(getRelativeName(), sd);
    if (triggerDescriptor == null) {
        throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "TRIGGER", getFullName());
    }
    /* Get the table descriptor */
    td = triggerDescriptor.getTableDescriptor();
    cc.createDependency(td);
    cc.createDependency(triggerDescriptor);
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) CompilerContext(org.apache.derby.iapi.sql.compile.CompilerContext) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TriggerDescriptor(org.apache.derby.iapi.sql.dictionary.TriggerDescriptor)

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