use of org.obeonetwork.dsl.database.DataBase 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.DataBase in project InformationSystem by ObeoNetwork.
the class DatabaseModelWizard method performFinish.
/**
* Do the work after everything is specified.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
@Override
public boolean performFinish() {
try {
// Remember the file.
//
final IFile modelFile = getModelFile();
// Do the work within an operation.
//
WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor progressMonitor) {
try {
// Create a resource set
//
ResourceSet resourceSet = new ResourceSetImpl();
// Get the URI of the model file.
//
URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);
// Create a resource for this file.
//
Resource resource = resourceSet.createResource(fileURI);
// Add the initial model object to the contents.
//
EObject rootObject = createInitialModel();
// Set a default name on the root object
if (rootObject instanceof NamedElement) {
// Compute default name from model file path
String defaultName = modelFile.getName();
defaultName = defaultName.substring(0, defaultName.length() - modelFile.getFileExtension().length() - 1);
((NamedElement) rootObject).setName(defaultName);
}
if (rootObject != null) {
resource.getContents().add(rootObject);
}
// Set the types library
if (rootObject instanceof DataBase) {
Resource typesLibraryResource = null;
// We set the types library
String dbVendor = initialObjectCreationPage.dbVendorField.getText();
if (DB_MYSQL_5.equals(dbVendor)) {
typesLibraryResource = resourceSet.getResource(URI.createURI(MYSQL_PATHMAP), true);
} else if (DB_ORACLE_11G.equals(dbVendor)) {
typesLibraryResource = resourceSet.getResource(URI.createURI(ORACLE_PATHMAP), true);
} else if (DB_H2_13.equals(dbVendor)) {
typesLibraryResource = resourceSet.getResource(URI.createURI(H2_PATHMAP), true);
} else if (DB_POSTGRES_9.equals(dbVendor)) {
typesLibraryResource = resourceSet.getResource(URI.createURI(POSTGRES_PATHMAP), true);
} else if (DB_SQLSERVER_2008.equals(dbVendor)) {
typesLibraryResource = resourceSet.getResource(URI.createURI(SQLSERVER_PATHMAP), true);
} else if (DB_LOGICAL_TYPES.equals(dbVendor)) {
typesLibraryResource = resourceSet.getResource(URI.createURI(LOGICAL_PATHMAP), true);
}
if (typesLibraryResource != null) {
EObject typesRoot = typesLibraryResource.getContents().get(0);
if (typesRoot instanceof TypesLibrary) {
((DataBase) rootObject).getUsedLibraries().add((TypesLibrary) typesRoot);
}
}
}
// Save the contents of the resource to the file system.
//
Map<Object, Object> options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());
resource.save(options);
} catch (Exception exception) {
DatabaseEditorPlugin.INSTANCE.log(exception);
} finally {
progressMonitor.done();
}
}
};
getContainer().run(false, false, operation);
// Select the new file resource in the current view.
//
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();
final IWorkbenchPart activePart = page.getActivePart();
if (activePart instanceof ISetSelectionTarget) {
final ISelection targetSelection = new StructuredSelection(modelFile);
getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
((ISetSelectionTarget) activePart).selectReveal(targetSelection);
}
});
}
//
try {
page.openEditor(new FileEditorInput(modelFile), workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());
} catch (PartInitException exception) {
MessageDialog.openError(workbenchWindow.getShell(), DatabaseEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
return false;
}
return true;
} catch (Exception exception) {
DatabaseEditorPlugin.INSTANCE.log(exception);
return false;
}
}
use of org.obeonetwork.dsl.database.DataBase in project InformationSystem by ObeoNetwork.
the class DatabaseEditLabelServices method caseColumn.
@Override
public DatabaseElement caseColumn(Column column) {
// the label can be in the form "attributeName : typeName (precision, length)"
int pos = editedLabelContent.indexOf(':');
if (pos != -1) {
String attributeName = editedLabelContent.substring(0, pos).trim();
column.setName(attributeName);
String typeDef = editedLabelContent.substring(pos + 1).trim();
// Retrieve types libraries
DataBase database = getDataBase(column);
if (database != null) {
Collection<NativeTypesLibrary> nativeTypesLibraries = new ArrayList<NativeTypesLibrary>();
for (TypesLibrary library : database.getUsedLibraries()) {
if (library instanceof NativeTypesLibrary) {
nativeTypesLibraries.add((NativeTypesLibrary) library);
}
}
setType(column, typeDef, nativeTypesLibraries);
}
} else {
// there is only a name
return super.caseNamedElement(column);
}
return column;
}
use of org.obeonetwork.dsl.database.DataBase in project InformationSystem by ObeoNetwork.
the class ScaffoldingUtils method isValidInputForMpd.
public static boolean isValidInputForMpd(Object element) {
if (element instanceof EObject) {
EObject eltAsEObject = (EObject) element;
DataBase database = getDatabaseFromObject(eltAsEObject);
return usesLibraryOfKind(database, TypesLibraryKind.PHYSICAL_TYPES);
}
return false;
}
use of org.obeonetwork.dsl.database.DataBase in project InformationSystem by ObeoNetwork.
the class ScaffoldingUtils method isValidInputForMld.
public static boolean isValidInputForMld(Object element) {
if (element instanceof EObject) {
EObject eltAsEObject = (EObject) element;
DataBase database = getDatabaseFromObject(eltAsEObject);
return usesLibraryOfKind(database, TypesLibraryKind.LOGICAL_TYPES);
}
return false;
}
Aggregations