Search in sources :

Example 11 with Entity

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);
        }
    }
}
Also used : Entity(org.obeonetwork.dsl.entity.Entity) Attribute(org.obeonetwork.dsl.environment.Attribute) Reference(org.obeonetwork.dsl.environment.Reference) ForeignKey(org.obeonetwork.dsl.database.ForeignKey) Constraint(org.obeonetwork.dsl.database.Constraint) IndexElement(org.obeonetwork.dsl.database.IndexElement)

Aggregations

Entity (org.obeonetwork.dsl.entity.Entity)11 EObject (org.eclipse.emf.ecore.EObject)5 Table (org.obeonetwork.dsl.database.Table)4 Reference (org.obeonetwork.dsl.environment.Reference)4 ArrayList (java.util.ArrayList)3 Constraint (org.obeonetwork.dsl.database.Constraint)3 ForeignKey (org.obeonetwork.dsl.database.ForeignKey)3 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Column (org.obeonetwork.dsl.database.Column)2 Attribute (org.obeonetwork.dsl.environment.Attribute)2 Namespace (org.obeonetwork.dsl.environment.Namespace)2 Collection (java.util.Collection)1 EReference (org.eclipse.emf.ecore.EReference)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 Setting (org.eclipse.emf.ecore.EStructuralFeature.Setting)1 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)1 EObjectFilter (org.eclipse.emf.eef.runtime.impl.filters.EObjectFilter)1 EObjectFlatComboSettings (org.eclipse.emf.eef.runtime.ui.widgets.eobjflatcombo.EObjectFlatComboSettings)1 ReferencesTableSettings (org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings)1