use of org.pentaho.di.core.database.DatabaseMetaInformation in project pentaho-kettle by pentaho.
the class GetDatabaseInfoProgressDialog method open.
public DatabaseMetaInformation open() {
final DatabaseMetaInformation dmi = new DatabaseMetaInformation(dbInfo);
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
dmi.getData(Spoon.loggingObject, new ProgressMonitorAdapter(monitor));
} catch (Exception e) {
throw new InvocationTargetException(e, BaseMessages.getString(PKG, "GetDatabaseInfoProgressDialog.Error.GettingInfoTable", e.toString()));
}
}
};
try {
ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
pmd.run(true, true, op);
} catch (InvocationTargetException e) {
showErrorDialog(e);
return null;
} catch (InterruptedException e) {
showErrorDialog(e);
return null;
}
return dmi;
}
use of org.pentaho.di.core.database.DatabaseMetaInformation in project pentaho-kettle by pentaho.
the class XulDatabaseExplorerController method createDatabaseNodes.
/**
* @return true if all goes fine, false otherwise. This will signal to caller
* that it may not attempt to show broken dialog
*/
void createDatabaseNodes() {
this.status = UiPostActionStatus.NONE;
Database theDatabase = new Database(null, this.model.getDatabaseMeta());
try {
theDatabase.connect();
GetDatabaseInfoProgressDialog gdipd = new GetDatabaseInfoProgressDialog((Shell) this.dbExplorerDialog.getRootObject(), this.model.getDatabaseMeta());
DatabaseMetaInformation dmi = gdipd.open();
// Adds the main database node.
DatabaseExplorerNode theDatabaseNode = new DatabaseExplorerNode();
theDatabaseNode.setName(this.model.getDatabaseMeta().getName());
theDatabaseNode.setImage(DATABASE_IMAGE);
this.model.getDatabase().add(theDatabaseNode);
// Adds the Schema database node.
DatabaseExplorerNode theSchemasNode = new DatabaseExplorerNode();
theSchemasNode.setName(STRING_SCHEMAS);
theSchemasNode.setImage(FOLDER_IMAGE);
theDatabaseNode.add(theSchemasNode);
// Adds the Tables database node.
DatabaseExplorerNode theTablesNode = new DatabaseExplorerNode();
theTablesNode.setName(STRING_TABLES);
theTablesNode.setImage(FOLDER_IMAGE);
theDatabaseNode.add(theTablesNode);
// Adds the Views database node.
DatabaseExplorerNode theViewsNode = new DatabaseExplorerNode();
theViewsNode.setName(STRING_VIEWS);
theViewsNode.setImage(FOLDER_IMAGE);
theDatabaseNode.add(theViewsNode);
// Adds the Synonyms database node.
DatabaseExplorerNode theSynonymsNode = new DatabaseExplorerNode();
theSynonymsNode.setName(STRING_SYNONYMS);
theSynonymsNode.setImage(FOLDER_IMAGE);
theDatabaseNode.add(theSynonymsNode);
// Adds the database schemas.
Schema[] schemas = dmi.getSchemas();
if (schemas != null) {
DatabaseExplorerNode theSchemaNode = null;
for (int i = 0; i < schemas.length; i++) {
theSchemaNode = new DatabaseExplorerNode();
theSchemaNode.setName(schemas[i].getSchemaName());
theSchemaNode.setImage(SCHEMA_IMAGE);
theSchemaNode.setIsSchema(true);
theSchemasNode.add(theSchemaNode);
// Adds the database tables for the given schema.
String[] theTableNames = schemas[i].getItems();
if (theTableNames != null) {
for (int i2 = 0; i2 < theTableNames.length; i2++) {
DatabaseExplorerNode theTableNode = new DatabaseExplorerNode();
theTableNode.setIsTable(true);
theTableNode.setSchema(schemas[i].getSchemaName());
theTableNode.setName(theTableNames[i2]);
theTableNode.setImage(TABLE_IMAGE);
theSchemaNode.add(theTableNode);
theTableNode.setParent(theSchemaNode);
}
}
}
}
// Adds the database tables.
Map<String, Collection<String>> tableMap = dmi.getTableMap();
List<String> tableKeys = new ArrayList<String>(tableMap.keySet());
Collections.sort(tableKeys);
for (String schema : tableKeys) {
List<String> tables = new ArrayList<String>(tableMap.get(schema));
Collections.sort(tables);
for (String table : tables) {
DatabaseExplorerNode theTableNode = new DatabaseExplorerNode();
theTableNode.setIsTable(true);
theTableNode.setName(table);
theTableNode.setImage(TABLE_IMAGE);
theTablesNode.add(theTableNode);
}
}
// Adds the database views.
Map<String, Collection<String>> viewMap = dmi.getViewMap();
if (viewMap != null) {
List<String> viewKeys = new ArrayList<String>(viewMap.keySet());
Collections.sort(viewKeys);
for (String schema : viewKeys) {
List<String> views = new ArrayList<String>(viewMap.get(schema));
Collections.sort(views);
for (String view : views) {
DatabaseExplorerNode theViewNode = new DatabaseExplorerNode();
theViewNode.setIsTable(true);
theViewNode.setName(view);
theViewNode.setImage(TABLE_IMAGE);
theViewsNode.add(theViewNode);
}
}
}
// Adds the Synonyms.
Map<String, Collection<String>> synonymMap = dmi.getSynonymMap();
if (synonymMap != null) {
List<String> synonymKeys = new ArrayList<String>(synonymMap.keySet());
Collections.sort(synonymKeys);
for (String schema : synonymKeys) {
List<String> synonyms = new ArrayList<String>(synonymMap.get(schema));
Collections.sort(synonyms);
for (String synonym : synonyms) {
DatabaseExplorerNode theSynonymNode = new DatabaseExplorerNode();
theSynonymNode.setIsTable(true);
theSynonymNode.setName(synonym);
theSynonymNode.setImage(TABLE_IMAGE);
theSynonymsNode.add(theSynonymNode);
}
}
}
} catch (Exception e) {
// Something goes wrong?
this.status = UiPostActionStatus.ERROR;
theDatabase.disconnect();
new ErrorDialog(shell, "Error", "Unexpected explorer error:", e);
this.status = UiPostActionStatus.ERROR_DIALOG_SHOWN;
return;
} finally {
if (theDatabase != null) {
try {
theDatabase.disconnect();
} catch (Exception ignored) {
// Can't do anything else here...
}
theDatabase = null;
}
}
this.status = UiPostActionStatus.OK;
}
Aggregations