Author: kevin1219
Date: Fri Aug 29 08:41:26 2008
New Revision: 2663
Modified:
trunk/src/ca/sqlpower/architect/olap/OLAPUtil.java
trunk/src/ca/sqlpower/architect/swingui/olap/LevelEditPanel.java
trunk/src/ca/sqlpower/architect/swingui/olap/action/CreateDimensionUsageAction.java
trunk/src/ca/sqlpower/architect/swingui/olap/action/CreateLevelAction.java
Log:
Fixed a bug where the hierarchy automatically created when creating a level
in a dimension with no hierarchies failed to set the required default
values.
Moved the hierarchy fudging code from dimension usage creation. Now, when
you open a level edit panel, it checks if the hierarchy has a relation, if
not then it will try to find the appropriate one and set it.
Modified: trunk/src/ca/sqlpower/architect/olap/OLAPUtil.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/olap/OLAPUtil.java (original)
+++ trunk/src/ca/sqlpower/architect/olap/OLAPUtil.java Fri Aug 29 08:41:26
2008
@@ -194,10 +194,8 @@
RelationOrJoin relation = hier.getRelation();
// If this hierarchy belongs to a shared dimension, its relation
is all
- // we can get.
- // But if this hierarchy belongs to a private dimension, its
cube's fact
- // specifies
- // the default table.
+ // we can get. But if this hierarchy belongs to a private
dimension, its cube's fact
+ // specifies the default table.
if (relation == null && hier.getParent().getParent() instanceof
Cube) {
Cube owningCube = (Cube) hier.getParent().getParent();
relation = owningCube.getFact();
Modified: trunk/src/ca/sqlpower/architect/swingui/olap/LevelEditPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/olap/LevelEditPanel.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/olap/LevelEditPanel.java Fri
Aug 29 08:41:26 2008
@@ -49,10 +49,16 @@
import ca.sqlpower.architect.SQLTable;
import ca.sqlpower.architect.olap.OLAPChildEvent;
import ca.sqlpower.architect.olap.OLAPChildListener;
+import ca.sqlpower.architect.olap.OLAPSession;
import ca.sqlpower.architect.olap.OLAPUtil;
+import ca.sqlpower.architect.olap.MondrianModel.Cube;
+import ca.sqlpower.architect.olap.MondrianModel.CubeDimension;
+import ca.sqlpower.architect.olap.MondrianModel.DimensionUsage;
import ca.sqlpower.architect.olap.MondrianModel.Hierarchy;
import ca.sqlpower.architect.olap.MondrianModel.Level;
import ca.sqlpower.architect.olap.MondrianModel.Property;
+import ca.sqlpower.architect.olap.MondrianModel.Schema;
+import ca.sqlpower.architect.olap.MondrianModel.Table;
import ca.sqlpower.swingui.table.EditableJTable;
import ca.sqlpower.validation.Status;
import ca.sqlpower.validation.ValidateResult;
@@ -102,7 +108,60 @@
builder.append("Caption", captionField = new
JTextField(level.getCaption()));
builder.append("Column", columnChooser = new JComboBox());
- SQLTable dimensionTable = OLAPUtil.tableForHierarchy((Hierarchy)
level.getParent());
+ Hierarchy hierarchy = (Hierarchy) level.getParent();
+ SQLTable dimensionTable = OLAPUtil.tableForHierarchy(hierarchy);
+
+ // if the hierarchy's table was not set, then we try to find it
from elsewhere.
+ // we'll look through the cubes that reference the hierarchy's
parent dimension
+ // and if the fact table and foreign keys of those are same
through out, we set
+ // those values for the hierarchy.
+ if (dimensionTable == null) {
+ OLAPSession oSession = OLAPUtil.getSession(level);
+ Schema sch = oSession.getSchema();
+ String parentDimName = hierarchy.getParent().getName();
+
+ boolean valid = true;
+ Table fact = null;
+ String foreignKey = null;
+ for (int i = 0; i < sch.getCubes().size() && valid; i++) {
+ Cube c = sch.getCubes().get(i);
+ if (c.getFact() == null) continue;
+ for (CubeDimension cd : c.getDimensions()) {
+ if (cd instanceof DimensionUsage) {
+ DimensionUsage du = (DimensionUsage) cd;
+ if
(du.getSource().equalsIgnoreCase(parentDimName)) {
+ Table rel = (Table) c.getFact();
+ String fk = du.getForeignKey();
+
+ if (fk != null) {
+ if (fact == null && foreignKey == null) {
+ fact = rel;
+ foreignKey = fk;
+ } else {
+ if
(!fact.getSchema().equalsIgnoreCase(rel.getSchema()) ||
+ !fact.getName().equalsIgnoreCase(rel.getName())
|
|
+ !foreignKey.equalsIgnoreCase(fk))
{
+ valid = false;
+ }
+ }
+ }
+
+ break;
+ }
+ }
+ }
+ }
+
+ if (valid) {
+ dimensionTable =
OLAPUtil.getSQLTableFromOLAPTable(oSession.getDatabase(), fact);
+ Table tab = new Table();
+ tab.setSchema(fact.getSchema());
+ tab.setName(fact.getName());
+ hierarchy.setRelation(tab);
+ hierarchy.setPrimaryKey(foreignKey);
+ }
+ }
+
if (dimensionTable == null) {
columnChooser.addItem("Parent hierarchy has no table");
columnChooser.setEnabled(false);
Modified:
trunk/src/ca/sqlpower/architect/swingui/olap/action/CreateDimensionUsageAction.java
==============================================================================
---
trunk/src/ca/sqlpower/architect/swingui/olap/action/CreateDimensionUsageAction.java
(original)
+++
trunk/src/ca/sqlpower/architect/swingui/olap/action/CreateDimensionUsageAction.java
Fri Aug 29 08:41:26 2008
@@ -33,8 +33,6 @@
import ca.sqlpower.architect.olap.MondrianModel.Cube;
import ca.sqlpower.architect.olap.MondrianModel.Dimension;
import ca.sqlpower.architect.olap.MondrianModel.DimensionUsage;
-import ca.sqlpower.architect.olap.MondrianModel.Hierarchy;
-import ca.sqlpower.architect.olap.MondrianModel.Table;
import ca.sqlpower.architect.swingui.ArchitectSwingSession;
import ca.sqlpower.architect.swingui.PlayPen;
import ca.sqlpower.architect.swingui.olap.CubePane;
@@ -73,21 +71,7 @@
final DataEntryPanel mep = new DimensionUsageEditPanel(du);
Callable<Boolean> okCall = new Callable<Boolean>() {
public Boolean call() throws Exception {
- boolean changesApplied = mep.applyChanges();
- if (!dimension.getHierarchies().isEmpty() &&
dimension.getHierarchies().get(0).getName()==null) {
- Hierarchy hierarchy =
dimension.getHierarchies().get(0);
- hierarchy.startCompoundEdit("Set lowest level
hierarchy to conform to cube fact table.");
- Table fact = (Table) cube.getFact();
- Table rel = new Table();
- rel.setAlias(fact.getAlias());
- rel.setFilter(fact.getFilter());
- rel.setName(fact.getName());
- rel.setSchema(fact.getSchema());
- hierarchy.setRelation(rel);
- hierarchy.setPrimaryKey(du.getForeignKey());
- hierarchy.endCompoundEdit();
- }
- return changesApplied;
+ return mep.applyChanges();
}
};
Callable<Boolean> cancelCall = new Callable<Boolean>() {
Modified:
trunk/src/ca/sqlpower/architect/swingui/olap/action/CreateLevelAction.java
==============================================================================
---
trunk/src/ca/sqlpower/architect/swingui/olap/action/CreateLevelAction.java
(original)
+++
trunk/src/ca/sqlpower/architect/swingui/olap/action/CreateLevelAction.java
Fri Aug 29 08:41:26 2008
@@ -46,6 +46,7 @@
Dimension d = pane.getModel();
if (d.getHierarchies().size() == 0) {
Hierarchy h = new Hierarchy();
+ h.setHasAll(true);
d.addHierarchy(h);
}