use of org.jooq.ConstraintForeignKeyOnStep in project jOOQ by jOOQ.
the class DefaultParseContext method parseForeignKeyReferenceSpecification.
private final Constraint parseForeignKeyReferenceSpecification(ConstraintTypeStep constraint, Field<?>[] referencing) {
Table<?> referencedTable = parseTableName();
Field<?>[] referencedFields = EMPTY_FIELD;
if (parseIf('(')) {
referencedFields = parseList(',', c -> parseFieldName()).toArray(EMPTY_FIELD);
parse(')');
if (referencing.length != referencedFields.length)
throw exception("Number of referencing columns (" + referencing.length + ") must match number of referenced columns (" + referencedFields.length + ")");
}
ConstraintForeignKeyOnStep e = constraint == null ? foreignKey(referencing).references(referencedTable, referencedFields) : constraint.foreignKey(referencing).references(referencedTable, referencedFields);
boolean onDelete = false;
boolean onUpdate = false;
while ((!onDelete || !onUpdate) && parseKeywordIf("ON")) {
if (!onDelete && parseKeywordIf("DELETE")) {
onDelete = true;
if (parseKeywordIf("CASCADE"))
e = e.onDeleteCascade();
else if (parseKeywordIf("NO ACTION"))
e = e.onDeleteNoAction();
else if (parseKeywordIf("RESTRICT"))
e = e.onDeleteRestrict();
else if (parseKeywordIf("SET DEFAULT"))
e = e.onDeleteSetDefault();
else if (parseKeywordIf("SET NULL"))
e = e.onDeleteSetNull();
else
throw expected("CASCADE", "NO ACTION", "RESTRICT", "SET DEFAULT", "SET NULL");
} else if (!onUpdate && parseKeywordIf("UPDATE")) {
onUpdate = true;
if (parseKeywordIf("CASCADE"))
e = e.onUpdateCascade();
else if (parseKeywordIf("NO ACTION"))
e = e.onUpdateNoAction();
else if (parseKeywordIf("RESTRICT"))
e = e.onUpdateRestrict();
else if (parseKeywordIf("SET DEFAULT"))
e = e.onUpdateSetDefault();
else if (parseKeywordIf("SET NULL"))
e = e.onUpdateSetNull();
else
throw expected("CASCADE", "NO ACTION", "RESTRICT", "SET DEFAULT", "SET NULL");
} else
throw expected("DELETE", "UPDATE");
}
return parseConstraintEnforcementIf(e);
}
Aggregations