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);
}
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;
}
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;
}
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());
}
}
}
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);
}
}
Aggregations