use of org.obeonetwork.dsl.database.reverse.source.DataSourceException in project InformationSystem by ObeoNetwork.
the class AbstractDataBaseBuilder method initialize.
private void initialize(DataSource source, ProgressListener progressListener, Queries queries) throws SQLException {
connection = null;
try {
connection = source.getConnection();
} catch (DataSourceException e) {
throw new SQLException("Unable to connect to database", e.getCause());
}
if (connection != null) {
try {
this.metaData = connection.getMetaData();
} catch (SQLException e) {
JdbcUtils.closeConnection(connection);
throw e;
}
}
this.progressListener = progressListener;
if (this.progressListener == null) {
this.progressListener = new ProgressListener() {
@Override
public void start(int numberOfSteps) {
}
@Override
public void progressTo(int step, String message) {
}
@Override
public void end(String message) {
}
};
}
this.queries = queries;
dataBase = buildDataBase(source.getDatabaseName());
queries.registerDatabase(dataBase);
tableContainer = dataBase;
if (isSet(source.getSchemaName())) {
tableContainer = buildSchema(source.getSchemaName(), (DataBase) tableContainer);
}
setUsedLibraries();
}
use of org.obeonetwork.dsl.database.reverse.source.DataSourceException 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