}
String endName = null;
// primary association
AssociationEnd primaryEnd =
corePackage.getAssociationEnd().createAssociationEnd(
endName,
VisibilityKindEnum.VK_PUBLIC,
false,
true,
OrderingKindEnum.OK_UNORDERED,
AggregationKindEnum.AK_NONE,
ScopeKindEnum.SK_INSTANCE,
this.createMultiplicity(
corePackage.getDataTypes(),
0,
primaryUpper),
ChangeableKindEnum.CK_CHANGEABLE);
primaryEnd.setParticipant((Classifier)this.classes.get(tableName));
association.getConnection().add(primaryEnd);
boolean required = !this.isColumnNullable(metadata, tableName, fkColumnName);
int foreignLower = 0;
if (required)
{
foreignLower = 1;
}
int deleteRule = columnRs.getInt("DELETE_RULE");
// determine if we should have composition for
// the foreign association end depending on cascade delete
AggregationKindEnum foreignAggregation = AggregationKindEnum.AK_NONE;
if (deleteRule == DatabaseMetaData.importedKeyCascade)
{
foreignAggregation = AggregationKindEnum.AK_COMPOSITE;
}
// foriegn association
AssociationEnd foreignEnd =
corePackage.getAssociationEnd().createAssociationEnd(
endName,
VisibilityKindEnum.VK_PUBLIC,
false,
true,
OrderingKindEnum.OK_UNORDERED,
foreignAggregation,
ScopeKindEnum.SK_INSTANCE,
this.createMultiplicity(
corePackage.getDataTypes(),
foreignLower,
1),
ChangeableKindEnum.CK_CHANGEABLE);
final Classifier foreignParticipant = (Classifier)this.classes.get(foreignTableName);
if (foreignParticipant == null)
{
throw new SchemaTransformerException(
"The associated table '" + foreignTableName +
"' must be available in order to create the association");
}
foreignEnd.setParticipant(foreignParticipant);
if (StringUtils.isNotEmpty(this.columnTaggedValue))
{
// add the tagged value for the foreign association end
TaggedValue taggedValue = this.createTaggedValue(corePackage, this.columnTaggedValue, fkColumnName);
if (taggedValue != null)
{
foreignEnd.getTaggedValue().add(taggedValue);
}
}
association.getConnection().add(foreignEnd);
associations.add(association);
if (logger.isInfoEnabled())
{
logger.info(
"adding association: '" + primaryEnd.getParticipant().getName() + " <--> " +
foreignEnd.getParticipant().getName() + "'");
}
}
DbUtils.closeQuietly(columnRs);
return associations;
}