{
// Generate the interface if rootAncestor (so has subclasses) and
// itself is not an interface...
if (entity.isRootAncestor())
{
Entity rootAncestor = entity;
if (!entity.isAbstract())
{
// generate a new interface
rootAncestor = new Entity("_" + entity.getName() + "Interface", entity.getName(),
model.getDatabase());
rootAncestor
.setDescription("Identity map table for "
+ entity.getName()
+ " and all its subclasses. "
+ "For each row that is added to "
+ entity.getName()
+ " or one of its subclasses, first a row must be added to this table to get a valid primary key value.");
// rootAncestor.setAbstract( true );
// copy key fields to interface and unset auto key in child
Vector<Field> keyfields = entity.getKey(0).getFields();
Vector<String> keyfields_copy = new Vector<String>();
for (Field f : keyfields)
{
Field key_field = new Field(rootAncestor, f.getType(), f.getName(), f.getName(), f.isAuto(),
f.isNillable(), f.isReadOnly(), f.getDefaultValue());
key_field.setDescription("Primary key field unique in " + entity.getName()
+ " and its subclasses.");
if (key_field.getType() instanceof StringField) key_field.setVarCharLength(key_field
.getVarCharLength());
rootAncestor.addField(key_field);
keyfields_copy.add(key_field.getName());
if (f.isAuto())
{
// unset auto key in original, but
// SOLVED BY TRIGGERS Field autoField =
// entity.getField(f.getName());
// SOLVED BY TRIGGERS autoField.setAuto(false);
}
}
rootAncestor.addKey(keyfields_copy, entity.getKey(0).isSubclass(), null);
Vector<String> parents = new Vector<String>();
parents.add(rootAncestor.getName());
entity.setParents(parents);
}
// add the type enum to the root element
Vector<Entity> subclasses = entity.getAllDescendants();
Vector<String> enumOptions = new Vector<String>();
enumOptions.add(entity.getName());
for (Entity subclass : subclasses)
{
enumOptions.add(subclass.getName());
}
Field type_field = new Field(rootAncestor, new EnumField(), Field.TYPE_FIELD, Field.TYPE_FIELD, true,
false, false, null);
type_field.setDescription("Subtypes of " + entity.getName() + ". Have to be set to allow searching");
type_field.setEnumOptions(enumOptions);
type_field.setHidden(true);
rootAncestor.addField(0, type_field);
}
}
}