* @throws ConstraintException If there is a problem with the foreign keys
*/
private void ensureReferencedFKs(ModelDef modelDef, CollectionDescriptorDef collDef) throws ConstraintException
{
String elementClassName = collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF);
ClassDescriptorDef elementClassDef = modelDef.getClass(elementClassName);
String fkFieldNames = collDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY);
ArrayList missingFields = new ArrayList();
SequencedHashMap fkFields = new SequencedHashMap();
// first we gather all field names
for (CommaListIterator it = new CommaListIterator(fkFieldNames); it.hasNext();)
{
String fieldName = (String)it.next();
FieldDescriptorDef fieldDef = elementClassDef.getField(fieldName);
if (fieldDef == null)
{
missingFields.add(fieldName);
}
fkFields.put(fieldName, fieldDef);
}
// next we traverse all sub types and gather fields as we go
for (Iterator it = elementClassDef.getAllExtentClasses(); it.hasNext() && !missingFields.isEmpty();)
{
ClassDescriptorDef subTypeDef = (ClassDescriptorDef)it.next();
for (int idx = 0; idx < missingFields.size();)
{
FieldDescriptorDef fieldDef = subTypeDef.getField((String)missingFields.get(idx));
if (fieldDef != null)
{
fkFields.put(fieldDef.getName(), fieldDef);
missingFields.remove(idx);