final public ConstraintDefinitionNode columnConstraint(TableName constraintName,
DataTypeDescriptor[] dataTypeDescriptor,
String columnName) throws ParseException, StandardException {
int constraintType;
Properties properties = null;
ConstraintDefinitionNode tcdn;
ResultColumnList refRcl = (ResultColumnList) nodeFactory.getNode(
C_NodeTypes.RESULT_COLUMN_LIST,
getContextManager());
TableName referencedTable;
int[] refActions = {StatementType.RA_NOACTION,
StatementType.RA_NOACTION} ;
switch (jj_nt.kind) {
case NOT:
jj_consume_token(NOT);
jj_consume_token(NULL);
//if column is explicitly defined not nullable, set following flag
explicitNotNull = true;
//if both null and not null constraints are defined for a column,
//throw an exception
if (explicitNull)
{if (true) throw StandardException.newException(SQLState.LANG_ADDING_COLUMN_WITH_NULL_AND_NOT_NULL_CONSTRAINT, columnName);}
// columns with generation clauses can omit the datatype
if ( dataTypeDescriptor[0] == null ) { {if (true) throw StandardException.newException(SQLState.LANG_NOT_NULL_NEEDS_DATATYPE);} }
dataTypeDescriptor[0] = dataTypeDescriptor[0].getNullabilityType(false);
{if (true) return null;}
break;
case PRIMARY:
case UNIQUE:
//pass the columnname as the second parameter. It will be used to throw an
//exception if null constraint is defined for this column-level primary
//key constraint
constraintType = uniqueSpecification(columnName);
switch (jj_nt.kind) {
case DERBYDASHPROPERTIES:
properties = propertyList(false);
jj_consume_token(CHECK_PROPERTIES);
break;
default:
jj_la1[313] = jj_gen;
;
}
ResultColumnList uniqueColumnList =
(ResultColumnList) nodeFactory.getNode(
C_NodeTypes.RESULT_COLUMN_LIST,
getContextManager());
uniqueColumnList.addElement(
(ResultColumn) nodeFactory.getNode(
C_NodeTypes.RESULT_COLUMN,
columnName,
null,
getContextManager()));
{if (true) return (ConstraintDefinitionNode) nodeFactory.getNode(
C_NodeTypes.CONSTRAINT_DEFINITION_NODE,
constraintName,
ReuseFactory.getInteger(constraintType),
uniqueColumnList,
properties,
null,
null,
getContextManager()
);}
break;
case REFERENCES:
referencedTable = referencesSpecification(refRcl, refActions);
switch (jj_nt.kind) {
case DERBYDASHPROPERTIES:
properties = propertyList(false);
jj_consume_token(CHECK_PROPERTIES);
break;
default:
jj_la1[314] = jj_gen;
;
}
ResultColumnList fkRcl = (ResultColumnList) nodeFactory.getNode(
C_NodeTypes.RESULT_COLUMN_LIST,
getContextManager());
fkRcl.addElement(
(ResultColumn) nodeFactory.getNode(
C_NodeTypes.RESULT_COLUMN,
columnName,
null,
getContextManager())
);
tcdn = (ConstraintDefinitionNode) nodeFactory.getNode(
C_NodeTypes.FK_CONSTRAINT_DEFINITION_NODE,
constraintName,
referencedTable,
fkRcl,
refRcl,
refActions,
getContextManager());
if (properties != null)
{
tcdn.setProperties(properties);
}
{if (true) return tcdn;}
break;
case CHECK:
tcdn = checkConstraintDefinition(constraintName, columnName);