Skip to content

Commit

Permalink
MONDRIAN: fixes for #2106108 and #2561069, oracle and jdbc metadata p…
Browse files Browse the repository at this point in the history
…roblems

[git-p4: depot-paths = "//open/mondrian/": change = 12330]
  • Loading branch information
Will Gorman committed Feb 5, 2009
1 parent 024030b commit 1c0d24f
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 22 deletions.
66 changes: 52 additions & 14 deletions src/main/mondrian/gui/JDBCMetaData.java
Expand Up @@ -202,9 +202,14 @@ private void setAllSchemas() {
gotSchema = true;
}
}
rs.close();
} catch (Exception e) {
LOGGER.debug("Exception : Database does not support schemas." + e.getMessage());
} finally {
try {
rs.close();
} catch (Exception e) {
// ignore
}
}

if (!gotSchema) {
Expand All @@ -222,35 +227,58 @@ private void setAllTables(DbSchema dbs) {
ResultSet rs = null;
try {
// Tables and views can be used
rs = md.getTables(null, dbs.name, null, new String[]{"TABLE", "VIEW"});
try {
rs = md.getTables(null, dbs.name, null, new String[]{"TABLE", "VIEW"});
} catch (Exception e) {
// this is a workaround for databases that throw an exception
// when views are requested.
rs = md.getTables(null, dbs.name, null, new String[]{"TABLE"});
}
while (rs.next()) {
// Oracle 10g Driver returns bogus BIN$ tables that cause
// exceptions
String tbname = rs.getString("TABLE_NAME");
if (!tbname.matches("(?!BIN\\$).+")) {
continue;
}

DbTable dbt;

/* Note : Imported keys are foreign keys which are primary keys of in some other tables
* : Exported keys are primary keys which are referenced as foreign keys in other tables.
*/
ResultSet rs_fks = md.getImportedKeys(null, dbs.name, tbname);
if (rs_fks.next()) {
dbt = new FactTable();
do {
((FactTable) dbt).addFks(rs_fks.getString("FKCOLUMN_NAME"),rs_fks.getString("pktable_name"));
} while (rs_fks.next());
} else {
dbt = new DbTable();
try {
if (rs_fks.next()) {
dbt = new FactTable();
do {
((FactTable) dbt).addFks(rs_fks.getString("FKCOLUMN_NAME"),rs_fks.getString("pktable_name"));
} while (rs_fks.next());
} else {
dbt = new DbTable();
}
} finally {
try {
rs_fks.close();
} catch (Exception e) {
// ignore
}
}
rs_fks.close();

dbt.schemaName = dbs.name;
dbt.name = tbname;
setPKey(dbt);
setColumns(dbt);
dbs.addDbTable(dbt);
db.addDbTable(dbt);
}
rs.close();
} catch (Exception e) {
LOGGER.error("setAllTables", e);
} finally {
try {
rs.close();
} catch (Exception e) {
// ignore
}
}
}

Expand All @@ -270,9 +298,14 @@ private void setPKey(DbTable dbt) {
//===dbt.pk = rs.getString("PK_NAME"); // a column may have been given a primary key name
dbt.pk = rs.getString("column_name"); // we need the column name which is primary key for the given table.
}
rs.close();
} catch (Exception e) {
LOGGER.error("setPKey", e);
} finally {
try {
rs.close();
} catch (Exception e) {
// ignore
}
}
}

Expand All @@ -284,9 +317,14 @@ private void setColumns(DbTable dbt) {
while (rs.next()) {
dbt.addColsDataType(rs.getString("COLUMN_NAME"), rs.getString("DATA_TYPE"));
}
rs.close();
} catch (Exception e) {
LOGGER.error("setColumns", e);
} finally {
try {
rs.close();
} catch (Exception e) {
// ignore
}
}
}

Expand Down
43 changes: 35 additions & 8 deletions src/main/mondrian/gui/JDBCTreeModel.java
Expand Up @@ -45,14 +45,41 @@ public JDBCTreeModel(Connection c) {
Node cat = new Node(catalogName, Node.CATALOG);

ResultSet trs = metadata.getTables(cat.name, null, null, null);
while (trs.next()) {
Node table = new Node(trs.getString(3), Node.TABLE);
cat.children.add(table);
//get the tables for each catalog.
ResultSet crs = metadata.getColumns(cat.name, null, table.name, null);
while (crs.next()) {
Node column = new Node(crs.getString(4), Node.COLUMN);
table.children.add(column);
try {
while (trs.next()) {
// Oracle 10g Driver returns bogus BIN$ tables that cause
// exceptions
String tbname = trs.getString("TABLE_NAME");
if (!tbname.matches("(?!BIN\\$).+")) {
continue;
}

Node table = new Node(trs.getString(3), Node.TABLE);
cat.children.add(table);
//get the tables for each catalog.
ResultSet crs = metadata.getColumns(cat.name, null, table.name, null);
try {
while (crs.next()) {
Node column = new Node(crs.getString(4), Node.COLUMN);
table.children.add(column);
}
} finally {
try {
if (crs != null) {
crs.close();
}
} catch (Exception e) {
// ignore
}
}
}
} finally {
try {
if (trs != null) {
trs.close();
}
} catch (Exception e) {
// ignore
}
}
root = cat;
Expand Down

0 comments on commit 1c0d24f

Please sign in to comment.