Search in sources :

Example 1 with ForeignKey

use of org.obeonetwork.dsl.database.ForeignKey in project InformationSystem by ObeoNetwork.

the class DatabaseServices method allReferencedTables.

/**
 * Retrieve all referenced Tables.
 * @param context the Table Container
 * @return list of Tables
 */
public List<Table> allReferencedTables(TableContainer context) {
    // Retrieve all tables
    List<AbstractTable> abstractTables = context.getTables();
    List<Table> tables = new ArrayList<Table>();
    List<Table> tablesFKtarget = new ArrayList<Table>();
    // Retrieve all tables instance of Table
    for (AbstractTable abstractTable : abstractTables) {
        if (abstractTable instanceof Table) {
            tables.add((Table) abstractTable);
        }
    }
    // Retrieve all foreigns keys for the tables
    for (Table table : tables) {
        for (ForeignKey fk : table.getForeignKeys()) {
            if (!tablesFKtarget.contains(fk.getTarget())) {
                // retrieve all table from target of foreigns keys
                tablesFKtarget.add(fk.getTarget());
            }
        }
    }
    Set<Table> allReferencedTables = new HashSet<Table>();
    // Remove duplicates
    allReferencedTables.addAll(tablesFKtarget);
    return new ArrayList<Table>(allReferencedTables);
}
Also used : AbstractTable(org.obeonetwork.dsl.database.AbstractTable) Table(org.obeonetwork.dsl.database.Table) AbstractTable(org.obeonetwork.dsl.database.AbstractTable) ArrayList(java.util.ArrayList) ForeignKey(org.obeonetwork.dsl.database.ForeignKey) HashSet(java.util.HashSet)

Example 2 with ForeignKey

use of org.obeonetwork.dsl.database.ForeignKey in project InformationSystem by ObeoNetwork.

the class DatabaseServices method createForeignKey.

public ForeignKey createForeignKey(Table source, Table target) {
    ForeignKey fk = DatabaseFactory.eINSTANCE.createForeignKey();
    source.getForeignKeys().add(fk);
    fk.setTarget(target);
    // Initialize with columns
    if (target.getPrimaryKey() != null) {
        for (Column pkColumn : target.getPrimaryKey().getColumns()) {
            Column fkColumn = getOrCreateColumn(source, pkColumn);
            if (pkColumn != null && fkColumn != null) {
                ForeignKeyElement fke = DatabaseFactory.eINSTANCE.createForeignKeyElement();
                fke.setPkColumn(pkColumn);
                fke.setFkColumn(fkColumn);
                fk.getElements().add(fke);
            }
        }
    }
    return fk;
}
Also used : ForeignKeyElement(org.obeonetwork.dsl.database.ForeignKeyElement) Column(org.obeonetwork.dsl.database.Column) ForeignKey(org.obeonetwork.dsl.database.ForeignKey)

Example 3 with ForeignKey

use of org.obeonetwork.dsl.database.ForeignKey in project InformationSystem by ObeoNetwork.

the class DatabaseServices method getForeignKeys.

/**
 * Return ForeignKeys from tables.
 * @param tableContainer
 * @return foreignKeys
 */
public List<ForeignKey> getForeignKeys(TableContainer tableContainer, DSemanticDiagram diagram) {
    List<ForeignKey> foreignKeys = new ArrayList<ForeignKey>();
    List<AbstractTable> tables = tableContainer.getTables();
    for (AbstractTable abstractTable : tables) {
        if (abstractTable instanceof Table) {
            foreignKeys.addAll(((Table) abstractTable).getForeignKeys());
        }
    }
    // Foreign keys from external tables on diagram
    for (DDiagramElement diagramElement : diagram.getDiagramElements()) {
        EObject semanticElt = diagramElement.getTarget();
        if (semanticElt instanceof Table) {
            foreignKeys.addAll(((Table) semanticElt).getForeignKeys());
        }
    }
    return foreignKeys;
}
Also used : AbstractTable(org.obeonetwork.dsl.database.AbstractTable) Table(org.obeonetwork.dsl.database.Table) AbstractTable(org.obeonetwork.dsl.database.AbstractTable) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) ForeignKey(org.obeonetwork.dsl.database.ForeignKey) DDiagramElement(org.eclipse.sirius.diagram.DDiagramElement)

Example 4 with ForeignKey

use of org.obeonetwork.dsl.database.ForeignKey in project InformationSystem by ObeoNetwork.

the class TableForeignKeysPropertiesEditionComponent method updateSemanticModel.

/**
 * {@inheritDoc}
 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updateSemanticModel(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 */
public void updateSemanticModel(final IPropertiesEditionEvent event) {
    Table table = (Table) semanticObject;
    if (DatabaseViewsRepository.ForeignKeys.Properties.foreignKeys_ == event.getAffectedEditor()) {
        if (event.getKind() == PropertiesEditionEvent.ADD) {
            EReferencePropertiesEditionContext context = new EReferencePropertiesEditionContext(editingContext, this, foreignKeysSettings, editingContext.getAdapterFactory());
            PropertiesEditingProvider provider = (PropertiesEditingProvider) editingContext.getAdapterFactory().adapt(semanticObject, PropertiesEditingProvider.class);
            if (provider != null) {
                PropertiesEditingPolicy policy = provider.getPolicy(context);
                if (policy instanceof CreateEditingPolicy) {
                    policy.execute();
                }
            }
        } else if (event.getKind() == PropertiesEditionEvent.EDIT) {
            EObjectPropertiesEditionContext context = new EObjectPropertiesEditionContext(editingContext, this, (EObject) event.getNewValue(), editingContext.getAdapterFactory());
            PropertiesEditingProvider provider = (PropertiesEditingProvider) editingContext.getAdapterFactory().adapt((EObject) event.getNewValue(), PropertiesEditingProvider.class);
            if (provider != null) {
                PropertiesEditingPolicy editionPolicy = provider.getPolicy(context);
                if (editionPolicy != null) {
                    editionPolicy.execute();
                }
            }
        } else if (event.getKind() == PropertiesEditionEvent.REMOVE) {
            foreignKeysSettings.removeFromReference((EObject) event.getNewValue());
        } else if (event.getKind() == PropertiesEditionEvent.MOVE) {
            foreignKeysSettings.move(event.getNewIndex(), (ForeignKey) event.getNewValue());
        }
    }
}
Also used : EObjectPropertiesEditionContext(org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext) Table(org.obeonetwork.dsl.database.Table) PropertiesEditingProvider(org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider) EObject(org.eclipse.emf.ecore.EObject) PropertiesEditingPolicy(org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy) CreateEditingPolicy(org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy) ForeignKey(org.obeonetwork.dsl.database.ForeignKey) EReferencePropertiesEditionContext(org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext)

Example 5 with ForeignKey

use of org.obeonetwork.dsl.database.ForeignKey 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)

Aggregations

ForeignKey (org.obeonetwork.dsl.database.ForeignKey)27 Table (org.obeonetwork.dsl.database.Table)16 EObject (org.eclipse.emf.ecore.EObject)8 AbstractTable (org.obeonetwork.dsl.database.AbstractTable)8 ForeignKeyElement (org.obeonetwork.dsl.database.ForeignKeyElement)8 Column (org.obeonetwork.dsl.database.Column)7 ArrayList (java.util.ArrayList)6 Reference (org.obeonetwork.dsl.environment.Reference)4 HashMap (java.util.HashMap)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 Viewer (org.eclipse.jface.viewers.Viewer)3 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)3 Constraint (org.obeonetwork.dsl.database.Constraint)3 Index (org.obeonetwork.dsl.database.Index)3 IndexElement (org.obeonetwork.dsl.database.IndexElement)3 Entity (org.obeonetwork.dsl.entity.Entity)3 Attribute (org.obeonetwork.dsl.environment.Attribute)3 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2