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());
}
}
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);
}
Aggregations