Search in sources :

Example 6 with Reference

use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.

the class ReferenceLabelProvider method getText.

@Override
public String getText(Object element) {
    if (element instanceof Reference) {
        StringBuilder sb = new StringBuilder();
        Reference ref = (Reference) element;
        if (ref.getName() != null) {
            sb.append(ref.getName());
        }
        sb.append("[");
        if (ref.getMultiplicity() != null) {
            sb.append(ref.getMultiplicity());
        } else {
            sb.append(UNKNOWN);
        }
        sb.append("] (");
        if (ref.getContainingType() != null) {
            sb.append(ref.getContainingType().getName());
        } else {
            sb.append(UNKNOWN);
        }
        sb.append(" -> ");
        if (ref.getReferencedType() != null) {
            sb.append(ref.getReferencedType().getName());
        } else {
            sb.append(UNKNOWN);
        }
        sb.append(")");
        return sb.toString();
    }
    return super.getText(element);
}
Also used : Reference(org.obeonetwork.dsl.environment.Reference)

Example 7 with Reference

use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.

the class AbstractTransformation method removeOldObjects.

private void removeOldObjects() {
    // Traverse the whole target resource to remove objects which have not been reused or created by this transformation
    Collection<EObject> objectsToKeep = new ArrayList<EObject>();
    objectsToKeep.addAll(outputTraceabilityMap.values());
    objectsToKeep.addAll(objectsToBeKept);
    Collection<EObject> objectsToBeDeleted = new ArrayList<EObject>();
    for (Iterator<EObject> it = getResult().getAllContents(); it.hasNext(); ) {
        EObject object = it.next();
        if (object instanceof Entity || object instanceof Attribute || object instanceof Reference || object instanceof Table || object instanceof Column || object instanceof ForeignKey || object instanceof Index || object instanceof Constraint) {
            if (!objectsToKeep.contains(object)) {
                objectsToBeDeleted.add(object);
            }
        }
    }
    // Remove objects
    Session session = SessionManager.INSTANCE.getSession(scaffoldInfo);
    for (EObject objectToBeDeleted : objectsToBeDeleted) {
        deleteObject(objectToBeDeleted, session);
    }
}
Also used : Entity(org.obeonetwork.dsl.entity.Entity) Table(org.obeonetwork.dsl.database.Table) Attribute(org.obeonetwork.dsl.environment.Attribute) Constraint(org.obeonetwork.dsl.database.Constraint) Reference(org.obeonetwork.dsl.environment.Reference) ArrayList(java.util.ArrayList) Index(org.obeonetwork.dsl.database.Index) ForeignKey(org.obeonetwork.dsl.database.ForeignKey) Column(org.obeonetwork.dsl.database.Column) EObject(org.eclipse.emf.ecore.EObject) Session(org.eclipse.sirius.business.api.session.Session)

Example 8 with Reference

use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.

the class EntityToMLD method getPointingReferencesForIndexCreation.

private Collection<Reference> getPointingReferencesForIndexCreation(Entity entity) {
    @SuppressWarnings("serial") Collection<Setting> settings = new EcoreUtil.UsageCrossReferencer(entity.eResource().getResourceSet()) {

        @Override
        protected boolean crossReference(EObject eObject, EReference eReference, EObject crossReferencedEObject) {
            return super.crossReference(eObject, eReference, crossReferencedEObject) && eReference == EnvironmentPackage.Literals.REFERENCE__REFERENCED_TYPE;
        }

        @Override
        protected boolean containment(EObject eObject) {
            return (eObject instanceof Reference || eObject instanceof Entity || eObject instanceof Namespace || eObject instanceof Root || eObject instanceof org.obeonetwork.dsl.overview.Root);
        }

        public Collection<Setting> findUsage(EObject object) {
            return super.findUsage(object);
        }
    }.findUsage(entity);
    Collection<Reference> references = new ArrayList<Reference>();
    for (Setting setting : settings) {
        if (setting.getEObject() instanceof Reference) {
            Reference reference = (Reference) setting.getEObject();
            if (shouldCreateFKInTarget(reference)) {
                references.add(reference);
            }
        }
    }
    return references;
}
Also used : Entity(org.obeonetwork.dsl.entity.Entity) Root(org.obeonetwork.dsl.entity.Root) Reference(org.obeonetwork.dsl.environment.Reference) EReference(org.eclipse.emf.ecore.EReference) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) ArrayList(java.util.ArrayList) Namespace(org.obeonetwork.dsl.environment.Namespace) EObject(org.eclipse.emf.ecore.EObject) Collection(java.util.Collection) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) EReference(org.eclipse.emf.ecore.EReference)

Example 9 with Reference

use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.

the class MLDToEntity method createReference.

private void createReference(ForeignKey foreignKey) {
    Table sourceTable = foreignKey.getSourceTable();
    boolean isJoinTable = isJoinTable(sourceTable);
    if (isJoinTable) {
        sourceTable = getOppositeFKOnJoinTable(foreignKey).getTargetTable();
    }
    Table targetTable = foreignKey.getTargetTable();
    Entity sourceEntity = getFromOutputTraceabilityMap(targetTable, EntityPackage.Literals.ENTITY);
    Entity targetEntity = getFromOutputTraceabilityMap(sourceTable, EntityPackage.Literals.ENTITY);
    if (targetEntity == null) {
        // Entity was not found in the newly created entities
        // try to retrieve it from additional resources
        String targetTableKey = LabelProvider.getEntityKeyForTable(targetTable);
        EObject sourceObject = getAdditionalResourcesMap().get(targetTableKey);
        if (sourceObject instanceof Entity) {
            targetEntity = (Entity) sourceObject;
        } else {
            Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Cannot resolve entity: " + targetTableKey + " for Reference!"));
            return;
        }
    }
    // Try to retrieve existing reference
    Reference reference = getFromInputTraceabilityMap(foreignKey, EnvironmentPackage.Literals.REFERENCE);
    if (reference != null) {
        // Ensure it is contained by the right entity
        if (!EcoreUtil.equals(reference.getContainingType(), sourceEntity)) {
            sourceEntity.getOwnedReferences().add(reference);
        }
        // Ensure it references the right entity
        if (!EcoreUtil.equals(reference.getReferencedType(), targetEntity)) {
            reference.setReferencedType(targetEntity);
        }
    } else {
        boolean nullable = !areAllColumnsNonNullable(foreignKey);
        String referenceName = LabelProvider.getReferenceNameFromFK(foreignKey);
        Reference reference1 = EnvironmentFactory.eINSTANCE.createReference();
        sourceEntity.getOwnedReferences().add(reference1);
        reference1.setReferencedType(targetEntity);
        reference1.setName(referenceName);
        reference1.setNavigable(true);
        // Define the required multiplicity
        MultiplicityKind multiplicity = (nullable || isJoinTable) ? MultiplicityKind.ZERO_STAR_LITERAL : MultiplicityKind.ONE_STAR_LITERAL;
        reference1.setMultiplicity(multiplicity);
        // The reference does not already exist, we have to crate a new one
        reference = reference1;
    }
    addToOutputTraceability(foreignKey, reference);
    // The following properties are modified even if they already existed
    reference.setDescription("Contrainte FK avec la table " + sourceTable.getName());
    AnnotationHelper.setPhysicalNameAnnotation(reference, LabelProvider.getReferencePhysicalNameFromFK(foreignKey));
    // For join tables, set the oppositeOf property
    if (isJoinTable) {
        ForeignKey oppositeFK = getOppositeFKOnJoinTable(foreignKey);
        // Check if the reference corresponding to the opposite FK has already been created
        Reference oppositeReference = getFromOutputTraceabilityMap(oppositeFK, EnvironmentPackage.Literals.REFERENCE);
        if (oppositeReference != null) {
            reference.setOppositeOf(oppositeReference);
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Entity(org.obeonetwork.dsl.entity.Entity) MultiplicityKind(org.obeonetwork.dsl.environment.MultiplicityKind) Table(org.obeonetwork.dsl.database.Table) AbstractTable(org.obeonetwork.dsl.database.AbstractTable) Reference(org.obeonetwork.dsl.environment.Reference) EObject(org.eclipse.emf.ecore.EObject) ForeignKey(org.obeonetwork.dsl.database.ForeignKey)

Example 10 with Reference

use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.

the class EntityFilterImpl method getReferenceReferences.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
public EList<Reference> getReferenceReferences() {
    BasicEList<Reference> result = new UniqueEList<Reference>() {

        private static final long serialVersionUID = 5391913769894408421L;

        protected Object[] newData(int capacity) {
            return new Reference[capacity];
        }

        protected boolean useEquals() {
            return false;
        }
    };
    for (Property property : getOwnedPropertyReferences()) {
        if (property instanceof Reference) {
            result.add((Reference) property);
        }
    }
    result.shrink();
    EList<Reference> unmodifiableResult = new EcoreEList.UnmodifiableEList.FastCompare<Reference>(this, ExtensionUtilitiesPackage.eINSTANCE.getEntityFilter_ReferenceReferences(), result.size(), result.data());
    return unmodifiableResult;
}
Also used : UniqueEList(org.eclipse.emf.common.util.UniqueEList) Reference(org.obeonetwork.dsl.environment.Reference) EcoreEList(org.eclipse.emf.ecore.util.EcoreEList) Property(org.obeonetwork.dsl.environment.Property)

Aggregations

Reference (org.obeonetwork.dsl.environment.Reference)21 StructuredType (org.obeonetwork.dsl.environment.StructuredType)9 ArrayList (java.util.ArrayList)7 EObject (org.eclipse.emf.ecore.EObject)6 Attribute (org.obeonetwork.dsl.environment.Attribute)5 ForeignKey (org.obeonetwork.dsl.database.ForeignKey)4 Entity (org.obeonetwork.dsl.entity.Entity)4 HashMap (java.util.HashMap)3 Table (org.obeonetwork.dsl.database.Table)3 HashSet (java.util.HashSet)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 EReference (org.eclipse.emf.ecore.EReference)2 Setting (org.eclipse.emf.ecore.EStructuralFeature.Setting)2 CompositePropertiesEditionPart (org.eclipse.emf.eef.runtime.impl.parts.CompositePropertiesEditionPart)2 Session (org.eclipse.sirius.business.api.session.Session)2 Column (org.obeonetwork.dsl.database.Column)2 Constraint (org.obeonetwork.dsl.database.Constraint)2 Index (org.obeonetwork.dsl.database.Index)2 IndexElement (org.obeonetwork.dsl.database.IndexElement)2