HashMap indirectionTables = new HashMap();
// first we gather all participants for each m:n relationship
for (Iterator classDescIt = model.getDescriptorTable().values().iterator(); classDescIt.hasNext();)
{
ClassDescriptor classDesc = (ClassDescriptor)classDescIt.next();
for (Iterator collDescIt = classDesc.getCollectionDescriptors().iterator(); collDescIt.hasNext();)
{
CollectionDescriptor collDesc = (CollectionDescriptor)collDescIt.next();
String indirTable = collDesc.getIndirectionTable();
if ((indirTable != null) && (indirTable.length() > 0))
{
Set columns = (Set)indirectionTables.get(indirTable);
if (columns == null)
{
columns = new HashSet();
indirectionTables.put(indirTable, columns);
}
columns.addAll(Arrays.asList(collDesc.getFksToThisClass()));
columns.addAll(Arrays.asList(collDesc.getFksToItemClass()));
}
}
}
if (indirectionTables.isEmpty())
{
// nothing to do
return;
}
for (Iterator it = indirectionTables.keySet().iterator(); it.hasNext();)
{
String tableName = (String)it.next();
Set columns = (Set)indirectionTables.get(tableName);
String elementName = tableName;
for (Iterator classDescIt = model.getDescriptorTable().values().iterator(); classDescIt.hasNext();)
{
ClassDescriptor classDesc = (ClassDescriptor)classDescIt.next();
if (tableName.equals(classDesc.getFullTableName()))
{
elementName = getElementName(classDesc);
FieldDescriptor[] fieldDescs = classDesc.getFieldDescriptions();
if (fieldDescs != null)
{
for (int idx = 0; idx < fieldDescs.length; idx++)
{