clone.setSourceToTargetKeyFields(new HashMap(getSourceToTargetKeyFields().size()));
clone.setTargetToSourceKeyFields(new HashMap(getTargetToSourceKeyFields().size()));
Map setOfFields = new HashMap(getTargetToSourceKeyFields().size());
for (Enumeration enumtr = getForeignKeyFields().elements(); enumtr.hasMoreElements();) {
DatabaseField field = (DatabaseField)enumtr.nextElement();
DatabaseField fieldClone = (DatabaseField)field.clone();
setOfFields.put(field, fieldClone);
clone.getForeignKeyFields().addElement(fieldClone);
}
//get clones from set for source hashtable. If they do not exist, create a new one.
Iterator sourceKeyIterator = getSourceToTargetKeyFields().keySet().iterator();
while (sourceKeyIterator.hasNext()) {
DatabaseField sourceField = (DatabaseField)sourceKeyIterator.next();
DatabaseField targetField = (DatabaseField)getSourceToTargetKeyFields().get(sourceField);
DatabaseField targetClone = (DatabaseField)setOfFields.get(targetField);
if (targetClone == null) {
targetClone = (DatabaseField)targetField.clone();
setOfFields.put(targetField, targetClone);
}
DatabaseField sourceClone = (DatabaseField)sourceField.clone();
if (sourceClone == null) {
sourceClone = (DatabaseField)sourceField.clone();
setOfFields.put(sourceField, sourceClone);
}
clone.getSourceToTargetKeyFields().put(sourceClone, targetClone);
}
//get clones from set for target hashtable. If they do not exist, create a new one.
Iterator targetKeyIterator = getTargetToSourceKeyFields().keySet().iterator();
while (targetKeyIterator.hasNext()) {
DatabaseField targetField = (DatabaseField)targetKeyIterator.next();
DatabaseField sourceField = (DatabaseField)getTargetToSourceKeyFields().get(targetField);
DatabaseField targetClone = (DatabaseField)setOfFields.get(targetField);
if (targetClone == null) {
targetClone = (DatabaseField)targetField.clone();
setOfFields.put(targetField, targetClone);
}
DatabaseField sourceClone = (DatabaseField)setOfFields.get(sourceField);
if (sourceClone == null) {
sourceClone = (DatabaseField)sourceField.clone();
setOfFields.put(sourceField, sourceClone);
}
clone.getTargetToSourceKeyFields().put(targetClone, sourceClone);