Search in sources :

Example 6 with DefaultDescriptor

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

the class DefaultNode method bindExpression.

/**
 * Bind this expression.  This means binding the sub-expressions,
 * as well as figuring out what the return type is for this expression.
 * In this case, there are no sub-expressions, and the return type
 * is already known, so this is just a stub.
 *
 * @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.
 *
 * @exception StandardException		Thrown on failure
 */
@Override
ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) throws StandardException {
    ColumnDescriptor cd;
    TableDescriptor td;
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(fromList.size() != 0, "fromList expected to be non-empty");
        if (!(fromList.elementAt(0) instanceof FromBaseTable)) {
            SanityManager.THROWASSERT("fromList.elementAt(0) expected to be instanceof FromBaseTable, not " + fromList.elementAt(0).getClass().getName());
        }
    }
    // Get the TableDescriptor for the target table
    td = ((FromBaseTable) fromList.elementAt(0)).getTableDescriptor();
    // Get the ColumnDescriptor for the column
    cd = td.getColumnDescriptor(columnName);
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(cd != null, "cd expected to be non-null");
    }
    /* If we have the default text, then parse and bind it and
		 * return the tree.
		 */
    DefaultInfoImpl defaultInfo = (DefaultInfoImpl) cd.getDefaultInfo();
    if (defaultInfo != null) {
        String defaultTxt = defaultInfo.getDefaultText();
        ValueNode defaultTre = parseDefault(defaultTxt, getLanguageConnectionContext(), getCompilerContext());
        /* Query is dependent on the DefaultDescriptor */
        DefaultDescriptor defaultDescriptor = cd.getDefaultDescriptor(getDataDictionary());
        getCompilerContext().createDependency(defaultDescriptor);
        return defaultTre.bindExpression(fromList, subqueryList, aggregates);
    } else {
        // Default is null
        return new UntypedNullConstantNode(getContextManager());
    }
}
Also used : ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) DefaultDescriptor(org.apache.derby.iapi.sql.dictionary.DefaultDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) DefaultInfoImpl(org.apache.derby.catalog.types.DefaultInfoImpl)

Example 7 with DefaultDescriptor

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

the class ModifyColumnNode method bindAndValidateDefault.

/**
 * Check the validity of the default, if any, for this node.
 *
 * @param dd		The DataDictionary.
 * @param td		The TableDescriptor.
 *
 * @exception StandardException		Thrown on error
 */
@Override
void bindAndValidateDefault(DataDictionary dd, TableDescriptor td) throws StandardException {
    ColumnDescriptor cd;
    // First verify that the column exists
    cd = td.getColumnDescriptor(name);
    if (cd == null) {
        throw StandardException.newException(SQLState.LANG_COLUMN_NOT_FOUND_IN_TABLE, name, td.getName());
    }
    // Get the UUID for the old default
    DefaultDescriptor defaultDescriptor = cd.getDefaultDescriptor(dd);
    oldDefaultUUID = (defaultDescriptor == null) ? null : defaultDescriptor.getUUID();
    // Remember the column position
    columnPosition = cd.getPosition();
    // No other work to do if no user specified default
    if (kind != K_MODIFY_COLUMN_DEFAULT) {
        return;
    }
    // and does not lose the other aspecs.
    if (keepCurrentDefault) {
        defaultInfo = (DefaultInfoImpl) cd.getDefaultInfo();
    } else {
        if (cd.hasGenerationClause() || cd.isAutoincrement()) {
            throw StandardException.newException(SQLState.LANG_GEN_COL_DEFAULT, cd.getColumnName());
        }
    }
    if (autoinc_create_or_modify_Start_Increment == ColumnDefinitionNode.MODIFY_AUTOINCREMENT_RESTART_VALUE) {
        autoincrementIncrement = cd.getAutoincInc();
        autoincrementCycle = cd.getAutoincCycle();
    }
    if (autoinc_create_or_modify_Start_Increment == ColumnDefinitionNode.MODIFY_AUTOINCREMENT_INC_VALUE) {
        autoincrementStart = cd.getAutoincStart();
        autoincrementCycle = cd.getAutoincCycle();
    }
    if (autoinc_create_or_modify_Start_Increment == ColumnDefinitionNode.MODIFY_AUTOINCREMENT_CYCLE_VALUE) {
        autoincrementIncrement = cd.getAutoincInc();
        autoincrementStart = cd.getAutoincStart();
    }
    /* Fill in the DataTypeServices from the DataDictionary */
    type = cd.getType();
    // Now validate the default
    validateDefault(dd, td);
}
Also used : ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) DefaultDescriptor(org.apache.derby.iapi.sql.dictionary.DefaultDescriptor)

Aggregations

DefaultDescriptor (org.apache.derby.iapi.sql.dictionary.DefaultDescriptor)7 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)6 UUID (org.apache.derby.catalog.UUID)3 DefaultInfoImpl (org.apache.derby.catalog.types.DefaultInfoImpl)2 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)2 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)2 DependableFinder (org.apache.derby.catalog.DependableFinder)1 ContextManager (org.apache.derby.iapi.services.context.ContextManager)1 ResultColumnDescriptor (org.apache.derby.iapi.sql.ResultColumnDescriptor)1 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)1 Provider (org.apache.derby.iapi.sql.depend.Provider)1 ProviderInfo (org.apache.derby.iapi.sql.depend.ProviderInfo)1 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)1 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)1 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)1 SequenceDescriptor (org.apache.derby.iapi.sql.dictionary.SequenceDescriptor)1 TriggerDescriptor (org.apache.derby.iapi.sql.dictionary.TriggerDescriptor)1 TransactionController (org.apache.derby.iapi.store.access.TransactionController)1 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)1 RowLocation (org.apache.derby.iapi.types.RowLocation)1