use of org.obeonetwork.dsl.database.Table 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.Table in project InformationSystem by ObeoNetwork.
the class TableTablePropertiesEditionComponent method initPart.
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#initPart(java.lang.Object, int, org.eclipse.emf.ecore.EObject,
* org.eclipse.emf.ecore.resource.ResourceSet)
*/
public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
setInitializing(true);
if (editingPart != null && key == partKey) {
editingPart.setContext(elt, allResource);
final Table table = (Table) elt;
final TablePropertiesEditionPart tablePart = (TablePropertiesEditionPart) editingPart;
// init values
if (isAccessible(DatabaseViewsRepository.Table.Properties.name))
tablePart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, table.getName()));
if (isAccessible(DatabaseViewsRepository.Table.Properties.columns)) {
columnsSettings = new ReferencesTableSettings(table, DatabasePackage.eINSTANCE.getTable_Columns());
tablePart.initColumns(columnsSettings);
}
if (isAccessible(DatabaseViewsRepository.Table.Properties.comments))
tablePart.setComments(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, table.getComments()));
if (isAccessible(DatabaseViewsRepository.Table.Properties.columns)) {
tablePart.addFilterToColumns(new ViewerFilter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
public boolean select(Viewer viewer, Object parentElement, Object element) {
// $NON-NLS-1$
return (element instanceof String && element.equals("")) || (element instanceof Column);
}
});
// Start of user code for additional businessfilters for columns
// End of user code
}
// init values for referenced views
// init filters for referenced views
}
setInitializing(false);
}
use of org.obeonetwork.dsl.database.Table 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);
}
}
use of org.obeonetwork.dsl.database.Table in project InformationSystem by ObeoNetwork.
the class EntityToMLD method createJoinTable.
private void createJoinTable(Reference reference, Table sourceTable, Table targetTable) {
if (getFromOutputTraceabilityMap(reference, DatabasePackage.Literals.TABLE) != null || getFromOutputTraceabilityMap(reference.getOppositeOf(), DatabasePackage.Literals.TABLE) != null) {
// Do nothing, already handled
return;
}
// Try to retrieve existing join table
Table joinTable = getFromInputTraceabilityMap(reference, DatabasePackage.Literals.TABLE);
if (joinTable == null) {
joinTable = getFromInputTraceabilityMap(reference.getOppositeOf(), DatabasePackage.Literals.TABLE);
}
if (joinTable == null) {
// The join table does not already exist, we have to create a new one
joinTable = DatabaseFactory.eINSTANCE.createTable();
sourceTable.getOwner().getTables().add(joinTable);
}
addToOutputTraceability(reference, joinTable);
addToOutputTraceability(reference.getOppositeOf(), joinTable);
// The following properties are modified even if they already existed
joinTable.setName(LabelProvider.getJoinTableName(sourceTable, targetTable));
joinTable.setComments("Table de jointure entre " + sourceTable.getName() + " et " + targetTable.getName());
createJoinTableForeignKey(joinTable, sourceTable);
createJoinTableForeignKey(joinTable, targetTable);
String pkComments = "Contrainte PK pour les colonnes ";
pkComments += joinTable.getPrimaryKey().getColumns().get(0).getName();
pkComments += " et ";
pkComments += joinTable.getPrimaryKey().getColumns().get(1).getName();
joinTable.getPrimaryKey().setComments(pkComments);
createAdditionalFields(joinTable);
}
use of org.obeonetwork.dsl.database.Table in project InformationSystem by ObeoNetwork.
the class EntityToMLD method createTable.
private void createTable(Entity entity) {
// Retrieve the existing table
Table table = getFromInputTraceabilityMap(entity, DatabasePackage.Literals.TABLE);
Namespace namespace = EntityUtils.getContainingNamespace(entity);
if (table == null) {
// The table does not already exist we have to create a new one
table = DatabaseFactory.eINSTANCE.createTable();
TableContainer targetTableContainer = getTargetTableContainer(namespace);
targetTableContainer.getTables().add(table);
} else {
// We have to ensure the schema name is correct
String realSchemaName = getSchemaNameFromNamespace(namespace);
TableContainer tableContainer = table.getOwner();
if (!realSchemaName.equals(tableContainer.getName())) {
tableContainer.setName(realSchemaName);
}
}
// Add to traceability map
addToOutputTraceability(entity, table);
// The following properties are modified even if they already existed
table.setName(LabelProvider.getTableNameFromEntity(entity));
table.setComments(entity.getDescription());
// Handle attributes
boolean hasPKAttribute = false;
Collection<Attribute> allAttributes = new ArrayList<Attribute>();
// Attributes from the entity and its supertypes
allAttributes.addAll(entity.getAttributes());
// Attributes from associated DTOs
for (StructuredType associatedType : entity.getAssociatedTypes()) {
allAttributes.addAll(associatedType.getAttributes());
}
for (Attribute attribute : allAttributes) {
createColumn(attribute, table);
if (attribute.isIsIdentifier()) {
hasPKAttribute = true;
}
}
// Create an ID column if no attribute was set as "primary key"
if (hasPKAttribute == false) {
createDefaultIdColumn(table);
}
// Update comments on PK
PrimaryKey primaryKey = table.getPrimaryKey();
if (primaryKey != null) {
primaryKey.setName(table.getName() + "_PK");
primaryKey.setComments(getPKComments(primaryKey));
}
// Create constraints
createConstraints(entity, table);
}
Aggregations