use of org.obeonetwork.dsl.database.ForeignKey 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);
}
}
}
use of org.obeonetwork.dsl.database.ForeignKey in project InformationSystem by ObeoNetwork.
the class MLDToEntity method getOppositeFKOnJoinTable.
private ForeignKey getOppositeFKOnJoinTable(ForeignKey foreignKey) {
Table sourceTable = foreignKey.getSourceTable();
if (isJoinTable(sourceTable)) {
ForeignKey fk1 = sourceTable.getForeignKeys().get(0);
ForeignKey fk2 = sourceTable.getForeignKeys().get(1);
if (foreignKey.equals(fk1)) {
return fk2;
} else if (foreignKey.equals(fk2)) {
return fk1;
}
}
return null;
}
use of org.obeonetwork.dsl.database.ForeignKey in project InformationSystem by ObeoNetwork.
the class MpdToMldBidiRules method createFK.
private void createFK(ForeignKey sourceFK, Table targetTable) {
if (sourceFK.getTarget() == null) {
return;
}
ForeignKey targetFK = getFromInputTraceabilityMap(sourceFK, DatabasePackage.Literals.FOREIGN_KEY);
if (targetFK != null) {
// Reuse existing FK
} else {
// We have to create a new FK
targetFK = DatabaseFactory.eINSTANCE.createForeignKey();
targetTable.getForeignKeys().add(targetFK);
}
addToOutputTraceability(sourceFK, targetFK);
targetFK.setName(sourceFK.getName());
targetFK.setComments(sourceFK.getComments());
// Try to retrieve the table referenced by the FK
Table fkTargetTable = getFromOutputTraceabilityMap(sourceFK.getTargetTable(), DatabasePackage.Literals.TABLE);
if (fkTargetTable == null) {
// We look into the additional resources
String fkTargetTableKey = ModelUtils.getKey(sourceFK.getTarget());
fkTargetTable = (Table) getAdditionalResourcesMap().get(fkTargetTableKey);
}
if (fkTargetTable == null) {
Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Cannot resolve table: " + sourceFK.getTargetTable().getName() + " for ForeignKey: " + sourceFK.getName() + "!"));
}
targetFK.setTarget(fkTargetTable);
for (ForeignKeyElement sourceFkElement : sourceFK.getElements()) {
createFKElement(sourceFkElement, targetFK);
}
}
use of org.obeonetwork.dsl.database.ForeignKey in project InformationSystem by ObeoNetwork.
the class MpdToMldBidiRules method createForeignKeys.
private void createForeignKeys(TableContainer sourceTableContainer) {
// create all foreignkeys
for (AbstractTable sourceAbstractTable : sourceTableContainer.getTables()) {
if (sourceAbstractTable instanceof Table) {
Table sourceTable = (Table) sourceAbstractTable;
Table targetTable = getFromOutputTraceabilityMap(sourceTable, DatabasePackage.Literals.TABLE);
for (ForeignKey foreignKey : sourceTable.getForeignKeys()) {
createFK(foreignKey, targetTable);
}
}
}
if (sourceTableContainer instanceof DataBase) {
DataBase sourceDataBase = (DataBase) sourceTableContainer;
for (Schema sourceSchema : sourceDataBase.getSchemas()) {
createForeignKeys(sourceSchema);
}
}
}
use of org.obeonetwork.dsl.database.ForeignKey in project InformationSystem by ObeoNetwork.
the class ForeignKeyElementPropertiesEditionComponent 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)
* @generated NOT
*/
public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
setInitializing(true);
if (editingPart != null && key == partKey) {
editingPart.setContext(elt, allResource);
final ForeignKeyElement foreignKeyElement = (ForeignKeyElement) elt;
final ForeignKeyElementPropertiesEditionPart foreignKeyElementPart = (ForeignKeyElementPropertiesEditionPart) editingPart;
// init values
if (foreignKeyElement.getComments() != null && isAccessible(DatabaseViewsRepository.ForeignKeyElement.Properties.comments))
foreignKeyElementPart.setComments(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, foreignKeyElement.getComments()));
if (isAccessible(DatabaseViewsRepository.ForeignKeyElement.Properties.fKColumn)) {
// init part
fkColumnSettings = new EObjectFlatComboSettings(foreignKeyElement, DatabasePackage.eINSTANCE.getForeignKeyElement_FkColumn());
foreignKeyElementPart.initFKColumn(fkColumnSettings);
// set the button mode
foreignKeyElementPart.setFKColumnButtonMode(ButtonsModeEnum.BROWSE);
}
if (isAccessible(DatabaseViewsRepository.ForeignKeyElement.Properties.pKColumn)) {
// init part
pkColumnSettings = new EObjectFlatComboSettings(foreignKeyElement, DatabasePackage.eINSTANCE.getForeignKeyElement_PkColumn());
foreignKeyElementPart.initPKColumn(pkColumnSettings);
// set the button mode
foreignKeyElementPart.setPKColumnButtonMode(ButtonsModeEnum.BROWSE);
}
// Custom code to prevent NPE when creating new FKElement
ForeignKeyElement fkElt = (ForeignKeyElement) semanticObject;
if (fkElt.getFkColumn() != null) {
if (sourceTableSettings.getValue() != null && isAccessible(DatabaseViewsRepository.ForeignKeyElement.Properties.sourceTable))
foreignKeyElementPart.setSourceTable(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, sourceTableSettings.getValue()));
} else {
EObject container = fkElt.eContainer();
if (container instanceof ForeignKey) {
Table table = ((ForeignKey) container).getSourceTable();
if (table != null) {
foreignKeyElementPart.setSourceTable(table.getName());
}
}
}
if (fkElt.getPkColumn() != null) {
if (targetTableSettings.getValue() != null && isAccessible(DatabaseViewsRepository.ForeignKeyElement.Properties.targetTable))
foreignKeyElementPart.setTargetTable(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, targetTableSettings.getValue()));
} else {
EObject container = fkElt.eContainer();
if (container instanceof ForeignKey) {
Table table = ((ForeignKey) container).getTargetTable();
if (table != null) {
foreignKeyElementPart.setTargetTable(table.getName());
}
}
}
if (isAccessible(DatabaseViewsRepository.ForeignKeyElement.Properties.fKColumn)) {
foreignKeyElementPart.addFilterToFKColumn(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 fkColumn
// End of user code
}
if (isAccessible(DatabaseViewsRepository.ForeignKeyElement.Properties.pKColumn)) {
foreignKeyElementPart.addFilterToPKColumn(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 pkColumn
// End of user code
}
// init values for referenced views
// init filters for referenced views
}
setInitializing(false);
}
Aggregations