}
}
} break;
case NodeTypes.FK_CONSTRAINT_DEFINITION_NODE: {
FKConstraintDefinitionNode fkNode = (FKConstraintDefinitionNode) node;
if(fkNode.getConstraintType() == ConstraintType.DROP) {
if(fkNode.isGrouping()) {
if(origTable.getParentJoin() == null) {
skipOrThrow(context, fkNode.getExistenceCheck(), null, new NoSuchGroupingFKException(origTable.getName()));
fkNode = null;
}
} else {
if(fkNode.getConstraintName() == null) {
Collection<ForeignKey> fkeys = origTable.getReferencingForeignKeys();
if(fkeys.size() == 0) {
skipOrThrow(context, fkNode.getExistenceCheck(), null, new UnsupportedFKIndexException());
fkNode = null;
} else if(fkeys.size() != 1) {
throw new UnsupportedFKIndexException();
} else {
try {
fkNode.setConstraintName(fkeys.iterator().next().getConstraintName().getTableName());
} catch(StandardException ex) {
throw new SQLParserInternalException(ex);
}
}
} else if(origTable.getReferencingForeignKey(fkNode.getConstraintName().getTableName()) == null) {
skipOrThrow(context,
fkNode.getExistenceCheck(),
null,
new NoSuchForeignKeyException(fkNode.getConstraintName().getTableName(), origTable.getName()));
fkNode = null;
}
if(fkNode != null) {
// Also drop the referencing index.
indexChanges.add(TableChange.createDrop(fkNode.getConstraintName().getTableName()));
}
}
}
if(fkNode != null) {
fkDefNodes.add(fkNode);