Skip to content

Commit

Permalink
MONDRIAN: First integration of Mondrian Workbench bug fixes into 3.0 …
Browse files Browse the repository at this point in the history
…Branch

	Fixed Workbench Publish Name Issue, bug 2138156 on SF.
	Fixes for bug 2138161 Workbench Dimension Selection Issue
	Fixes for bug [ 2153098 ] Mondrian exceptions when clicking on Dimension
	Fixed Workbench issue, Sourceforge [ 2153653 ] Database preferences not enforced when modified.
	Added feature [ 2155850 ] Workbench Database Schema Option.  This limits the metadata results in Workbench to a specified set of schemas.
	Changed to use the pentaho-mondrianschemaworkbench-plugins revision 1.0.33395
	include log4j.jar in workbench-dist

[git-p4: depot-paths = "//open/mondrian-release/3.0/": change = 11791]
  • Loading branch information
Will Gorman committed Oct 23, 2008
1 parent 6021e87 commit 88ad37a
Show file tree
Hide file tree
Showing 11 changed files with 364 additions and 116 deletions.
1 change: 1 addition & 0 deletions build.xml
Expand Up @@ -1493,6 +1493,7 @@ xalan.jar"/>
${doc.dir}/**/*.pdf,
lib/mondrian.jar,
lib/workbench.jar,
lib/log4j.jar,
lib/x*.jar,
lib/eigenbase*.jar,
lib/commons*.jar,
Expand Down
44 changes: 37 additions & 7 deletions src/main/mondrian/gui/JDBCMetaData.java
Expand Up @@ -30,6 +30,7 @@ public class JDBCMetaData {
String jdbcConnectionUrl = null; // "jdbc:postgresql://localhost:5432/hello?user=postgres&password=post"
String jdbcUsername = null;
String jdbcPassword = null;
String jdbcSchema = null;

Connection conn = null;
DatabaseMetaData md = null;
Expand Down Expand Up @@ -59,12 +60,15 @@ public class JDBCMetaData {
private String errMsg = null;
private Database db = new Database();

public JDBCMetaData(Workbench wb, String jdbcDriverClassName, String jdbcConnectionUrl, String jdbcUsername, String jdbcPassword) {
public JDBCMetaData(Workbench wb, String jdbcDriverClassName,
String jdbcConnectionUrl, String jdbcUsername,
String jdbcPassword, String jdbcSchema) {
this.workbench = wb;
this.jdbcConnectionUrl = jdbcConnectionUrl;
this.jdbcDriverClassName = jdbcDriverClassName;
this.jdbcUsername = jdbcUsername;
this.jdbcPassword = jdbcPassword;
this.jdbcSchema = jdbcSchema;

if (initConnection() == null) {
setAllSchemas();
Expand Down Expand Up @@ -146,6 +150,28 @@ public void closeConnection() {
}
}

/**
* Check to see if the schemaName is in the list of allowed jdbc schemas
*
* @param schemaName the name of the schmea
*
* @return true if found, or if jdbcSchema is null
*/
private boolean inJdbcSchemas(String schemaName) {
if (jdbcSchema == null || jdbcSchema.trim().length() == 0) {
return true;
}

String schemas[] = jdbcSchema.split("[,;]");
for (String schema : schemas) {
if (schema.trim().equals(schemaName)) {
return true;
}
}

return false;
}

/* set all schemas in the currently connected database */
private void setAllSchemas(){
LOGGER.debug("JDBCMetaData: setAllSchemas");
Expand All @@ -161,12 +187,15 @@ private void setAllSchemas(){
*/

while(rs.next()) {
DbSchema dbs = new DbSchema();
dbs.name = rs.getString("TABLE_SCHEM");
LOGGER.debug("JDBCMetaData: setAllTables - " + dbs.name);
setAllTables(dbs);
db.addDbSchema(dbs);
gotSchema = true;
String schemaName = rs.getString("TABLE_SCHEM");
if (inJdbcSchemas(schemaName)) {
DbSchema dbs = new DbSchema();
dbs.name = schemaName;
LOGGER.debug("JDBCMetaData: setAllTables - " + dbs.name);
setAllTables(dbs);
db.addDbSchema(dbs);
gotSchema = true;
}
}
rs.close();
} catch (Exception e) {
Expand Down Expand Up @@ -392,6 +421,7 @@ public String getErrMsg() {
}

public static void main(String[] args) {

/*
JDBCMetaData sb = new JDBCMetaData("org.postgresql.Driver","jdbc:postgresql://localhost:5432/testdb?user=admin&password=admin");
System.out.println("allSchemas="+sb.allSchemas);
Expand Down
50 changes: 37 additions & 13 deletions src/main/mondrian/gui/PreferencesDialog.java
Expand Up @@ -11,7 +11,6 @@
*/
package mondrian.gui;

import java.awt.Dimension;

/**
*
Expand All @@ -25,6 +24,8 @@ public class PreferencesDialog extends javax.swing.JDialog {
public PreferencesDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
pack();
setLocationRelativeTo(parent);
}

public boolean accepted() {
Expand Down Expand Up @@ -63,6 +64,14 @@ public String getJDBCDriverClassName() {
return driverClassTextField.getText();
}

public void setDatabaseSchema(String schema) {
this.schemaTextField.setText(schema);
}

public String getDatabaseSchema() {
return schemaTextField.getText();
}

/**
* @return the workbench i18n converter
*/
Expand All @@ -84,13 +93,15 @@ private void initComponents() {//GEN-BEGIN:initComponents
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();

// Set the url text field to 50 to drive the width of the dialog
jLabel5 = new javax.swing.JLabel();

// Set the url text field to 50 to drive the width of the dialog
urlTextField = new javax.swing.JTextField(50);

usernameTextField = new javax.swing.JTextField();
passwordTextField = new javax.swing.JTextField();
driverClassTextField = new javax.swing.JTextField();
schemaTextField = new javax.swing.JTextField();
acceptButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();

Expand Down Expand Up @@ -150,6 +161,15 @@ public void windowClosing(java.awt.event.WindowEvent evt) {
gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
jPanel1.add(urlTextField, gridBagConstraints);

jLabel5.setText(getResourceConverter().getString("preferences.schema.title","Schema (Optional)"));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
jPanel1.add(jLabel5, gridBagConstraints);

usernameTextField.setText("");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
Expand All @@ -170,6 +190,16 @@ public void windowClosing(java.awt.event.WindowEvent evt) {
gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
jPanel1.add(passwordTextField, gridBagConstraints);

schemaTextField.setText("");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 4;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
jPanel1.add(schemaTextField, gridBagConstraints);

driverClassTextField.setText("org.gjt.mm.mysql.Driver");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
Expand Down Expand Up @@ -223,12 +253,12 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {

private void acceptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptButtonActionPerformed
accepted = true;
hide();
setVisible(false);
}//GEN-LAST:event_acceptButtonActionPerformed

private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
accepted = false;
hide();
setVisible(false);
}//GEN-LAST:event_cancelButtonActionPerformed

/** Closes the dialog */
Expand All @@ -237,23 +267,17 @@ private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_clos
dispose();
}//GEN-LAST:event_closeDialog

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new PreferencesDialog(new javax.swing.JFrame(), true).show();
}


// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField driverClassTextField;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField urlTextField;
private javax.swing.JTextField usernameTextField;
private javax.swing.JTextField passwordTextField;
private javax.swing.JTextField schemaTextField;
private javax.swing.JButton acceptButton;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JButton cancelButton;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel2;
Expand Down
18 changes: 15 additions & 3 deletions src/main/mondrian/gui/PropertyTableModel.java
Expand Up @@ -195,8 +195,9 @@ public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
f.set(target,aValues[1]);
}
} else {
//EC: Avoids table="" to be set on schema
Field f = target.getClass().getField(propertyNames[rowIndex]);
f.set(target,aValue);
setFieldValue(f, aValue);
}
}

Expand All @@ -217,7 +218,9 @@ public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
if (aValue != null) { // split and save only if value exists
String[] aValues = ((String) aValue).split("->");
Field f = target.getClass().getField(propertyNames[rowIndex]);
f.set(target, aValues[aValues.length-1]); // save the last value in the array from split
//EC: Avoids *Column="" to be set on schema
aValue = aValues[aValues.length - 1];
setFieldValue(f, aValue);
}

} else {
Expand All @@ -230,14 +233,23 @@ && duplicateName(aValue) ) {
new String[] { aValue.toString() }));
} else {
Field f = target.getClass().getField(propertyNames[rowIndex]);
f.set(target,aValue);
//EC: Avoids property to be set on schema with an empty value.
setFieldValue(f, aValue);
}
}
} catch (Exception ex) {
LOGGER.error("setValueAt(aValue, row, index)", ex);
}
}

private void setFieldValue(Field aField, Object aValue) throws IllegalAccessException {
if (aValue != null && aValue.toString().trim().length() == 0) {
aField.set(target,null);
} else {
aField.set(target,aValue);
}
}

public Object getValue() {
return target;
}
Expand Down
59 changes: 59 additions & 0 deletions src/main/mondrian/gui/SchemaExplorer.java
Expand Up @@ -21,6 +21,7 @@
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.EventObject;
import java.util.Set;

import javax.swing.*;
import javax.swing.border.EtchedBorder;
Expand Down Expand Up @@ -3366,6 +3367,64 @@ public boolean isEditModeXML() {
public I18n getResourceConverter() {
return workbench.getResourceConverter();
}
public static void getTableNamesForJoin(MondrianGuiDef.RelationOrJoin aRelOrJoin, Set aTableNames) {
//EC: Loops join tree and collects table names.
if (aRelOrJoin instanceof MondrianGuiDef.Join) {
MondrianGuiDef.RelationOrJoin theRelOrJoin_L = ((MondrianGuiDef.Join) aRelOrJoin).left;
MondrianGuiDef.RelationOrJoin theRelOrJoin_R = ((MondrianGuiDef.Join) aRelOrJoin).right;
for (int i = 0 ; i < 2; i ++) { // Searches first using the Left Join and then the Right.
MondrianGuiDef.RelationOrJoin theCurrentRelOrJoin = (i == 0) ? theRelOrJoin_L : theRelOrJoin_R;
if (theCurrentRelOrJoin instanceof MondrianGuiDef.Table) {
MondrianGuiDef.Table theTable = ((MondrianGuiDef.Table) theCurrentRelOrJoin);
String theTableName = (theTable.alias != null && theTable.alias.trim().length() > 0) ? theTable.alias : theTable.name;
aTableNames.add(theTableName);
} else {
//calls recursively collecting all table names down the join tree.
getTableNamesForJoin(theCurrentRelOrJoin, aTableNames);
}
}
}
}
public static String getTableNameForAlias(MondrianGuiDef.RelationOrJoin aRelOrJoin, String anAlias) {
String theTableName = anAlias;
//EC: Loops join tree and finds the table name for an alias.
if (aRelOrJoin instanceof MondrianGuiDef.Join) {
MondrianGuiDef.RelationOrJoin theRelOrJoin_L = ((MondrianGuiDef.Join) aRelOrJoin).left;
MondrianGuiDef.RelationOrJoin theRelOrJoin_R = ((MondrianGuiDef.Join) aRelOrJoin).right;
for (int i = 0 ; i < 2; i ++) { // Searches first using the Left Join and then the Right.
MondrianGuiDef.RelationOrJoin theCurrentRelOrJoin = (i == 0) ? theRelOrJoin_L : theRelOrJoin_R;
if (theCurrentRelOrJoin instanceof MondrianGuiDef.Table) {
MondrianGuiDef.Table theTable = ((MondrianGuiDef.Table) theCurrentRelOrJoin);
if (theTable.alias != null && theTable.alias.equals(anAlias)) {
theTableName = theTable.name; // If the alias was found get its table name and return it.
}
} else {
//otherwise continue down the join tree.
theTableName = getTableNameForAlias(theCurrentRelOrJoin, anAlias);
}
}
}
return theTableName;
}

public void resetMetaData(JDBCMetaData aMetaData) {
//EC: Updates the JDBCMetaData in the SchemaExplorer.
jdbcMetaData = aMetaData;

//EC: Updates the database label.
String[] theArgs = { jdbcMetaData.getDbCatalogName(), jdbcMetaData.getDatabaseProductName()};
String theLabel = getResourceConverter().getFormattedString("schemaExplorer.database.text","Database - {0} ({1})", theArgs);
databaseLabel.setText(theLabel);

//EC: Updates the JDBCMetaData in the SchemaTreeCellRenderer.
renderer.setMetaData(aMetaData);

//EC: Updates the JDBCMetaData in the SchemaPropertyCellEditor.
TableCellEditor theTableCellEditor = propertyTable.getDefaultEditor(Object.class);
if (theTableCellEditor instanceof SchemaPropertyCellEditor) {
((SchemaPropertyCellEditor) theTableCellEditor).setMetaData(aMetaData);
}
}
}

// End SchemaExplorer.java

0 comments on commit 88ad37a

Please sign in to comment.