use of org.obeonetwork.dsl.database.reverse.source.DataSource in project InformationSystem by ObeoNetwork.
the class DatabaseImportHelper method importDatabaseIntoModel.
public static boolean importDatabaseIntoModel(DatabaseInfos databaseInfos, String modelFilename, Collection<IFile> referencedFiles) {
DataSource dataSource = databaseInfos.getDataSource();
// Override this resolver to resolve external dependencies (i.e.: tables store in another schema)
MultiDataBaseQueries queries = new MultiDataBaseQueries();
for (IFile referencedFile : referencedFiles) {
addFileToResolver(queries, referencedFile);
}
ImportRunnable runnable = new ImportRunnable(dataSource, modelFilename, queries);
try {
PlatformUI.getWorkbench().getProgressService().run(true, false, runnable);
} catch (Exception e) {
Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error while importing database", e));
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error occured while importing database", "An error occured while importing the database. See Error Log view for more details.");
}
return runnable.getResult();
}
use of org.obeonetwork.dsl.database.reverse.source.DataSource in project InformationSystem by ObeoNetwork.
the class TestReverse method testMySQL.
@Test
public void testMySQL() {
DataSource dataSource = new DataSource("northwind", null);
dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/northwind");
dataSource.setJdbcUsername("root");
dataSource.setJdbcPassword(null);
dataSource.setVendor("MySQL-5");
DataBase database = DatabaseReverser.reverse(dataSource, new MultiDataBaseQueries(), null);
DataBase databaseRef = loadModel("resources/mysql/outputRef.database", "pathmap://NativeDBTypes/MySQL-5");
checkEquality(database, databaseRef);
}
use of org.obeonetwork.dsl.database.reverse.source.DataSource in project InformationSystem by ObeoNetwork.
the class TestReverse method testSQLServer.
@Test
public void testSQLServer() {
DataSource dataSource = new DataSource("Northwind", "dbo");
dataSource.setJdbcUrl("jdbc:sqlserver://localhost:1433;databaseName=Northwind");
dataSource.setJdbcUsername("testUser");
dataSource.setJdbcPassword("test");
dataSource.setVendor("SQLServer-2008");
DataBase database = DatabaseReverser.reverse(dataSource, new MultiDataBaseQueries(), null);
DataBase databaseRef = loadModel("resources/sqlserver/outputRef.database", "pathmap://NativeDBTypes/SQLServer-2008");
checkEquality(database, databaseRef);
}
use of org.obeonetwork.dsl.database.reverse.source.DataSource in project InformationSystem by ObeoNetwork.
the class TestReverse method testH2Embedded.
@Test
public void testH2Embedded() {
String databaseLocation = getH2DatabaseLocation(this.getClass(), "input");
DataSource dataSource = new DataSource("appli1", "PUBLIC");
dataSource.setJdbcUrl("jdbc:h2:" + databaseLocation);
dataSource.setJdbcUsername("sa");
dataSource.setVendor("H2-1.3");
DataBase database = DatabaseReverser.reverse(dataSource, new MultiDataBaseQueries(), null);
DataBase databaseRef = loadModel("resources/h2/outputRef.database", "pathmap://NativeDBTypes/H2-1.3");
checkEquality(database, databaseRef);
}
use of org.obeonetwork.dsl.database.reverse.source.DataSource in project InformationSystem by ObeoNetwork.
the class DatabaseImportWizard method performFinish.
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.Wizard#performFinish()
*/
public boolean performFinish() {
// First, check if a connection to the database can be established
if (databaseInfos != null) {
Connection connection = null;
DataSource dataSource = databaseInfos.getDataSource();
if (dataSource != null) {
try {
connection = dataSource.getConnection();
} catch (DataSourceException e) {
// Unable to connect
String message = "Unable to connect to database.\n\nReason : " + e.getCause().getMessage();
MessageDialog.openError(getShell(), "Import database...", message);
return false;
} finally {
JdbcUtils.closeConnection(connection);
}
}
}
String filename = mainPage.getTxtModelFile().getText();
boolean result = DatabaseImportHelper.importDatabaseIntoModel(databaseInfos, filename, mainPage.getReferencedFiles());
if (result == true) {
MessageDialog.openInformation(getShell(), "Database imported", "The database has been imported.\nThe model file '" + filename + "' has been created.");
IViewPart explorer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("org.eclipse.ui.navigator.ProjectExplorer");
if (explorer != null) {
if (explorer instanceof ProjectExplorer) {
ProjectExplorer projectExplorer = (ProjectExplorer) explorer;
// Create a selection to point on the generated file
final IFile generatedFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filename));
projectExplorer.selectReveal(new StructuredSelection(generatedFile));
}
}
} else {
MessageDialog.openError(getShell(), "Error while importing database", "The database could not be imported.");
}
return result;
}
Aggregations