use of org.obeonetwork.dsl.entity.Entity in project InformationSystem by ObeoNetwork.
the class MLDToEntity method addPhysicalUnique.
private void addPhysicalUnique(Index index) {
if (index.isUnique()) {
if (index.getElements().size() == 1) {
// Add annotation on Attribute
IndexElement indexElement = index.getElements().get(0);
String annotationValue = indexElement.isAsc() ? "ASC" : "DESC";
Attribute uniqueAttribute = getFromOutputTraceabilityMap(indexElement.getColumn(), EnvironmentPackage.Literals.ATTRIBUTE);
if (uniqueAttribute != null) {
AnnotationHelper.setPhysicalUniqueAnnotation(uniqueAttribute, annotationValue);
} else {
// We can only handle the FK situation
if (indexElement.getColumn().isInForeignKey()) {
// Search the reference corresponding to a FK
for (ForeignKey fk : indexElement.getColumn().getForeignKeys()) {
Reference reference = getFromOutputTraceabilityMap(fk, EnvironmentPackage.Literals.REFERENCE);
if (reference != null) {
AnnotationHelper.setPhysicalUniqueAnnotation(reference, annotationValue);
}
}
}
}
} else {
// Add annotation on Table
Entity entity = getFromOutputTraceabilityMap(index.getOwner(), EntityPackage.Literals.ENTITY);
// Retrieve the current value of the annotation.
String annotationValue = AnnotationHelper.getPhysicalUnique(entity);
// Construct the term corresponding to the index being considered.
String annotationTerm = "";
int i = 0;
for (IndexElement indexElement : index.getElements()) {
if (i > 0) {
annotationTerm += ",";
}
annotationTerm += indexElement.getColumn().getName() + ":";
if (indexElement.isAsc()) {
annotationTerm += "ASC";
} else {
annotationTerm += "DESC";
}
i++;
}
if (annotationValue != null && !annotationValue.isEmpty()) {
annotationValue += " | ";
} else if (annotationValue == null) {
annotationValue = "";
}
annotationValue += annotationTerm;
AnnotationHelper.setPhysicalUniqueAnnotation(entity, annotationValue);
}
}
}
Aggregations