Skip to content

Commit

Permalink
MONDRIAN: Improve error messages when schema.xml is invalid.
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian/": change = 1798]
  • Loading branch information
julianhyde committed Apr 28, 2004
1 parent 15c66f0 commit 40aa069
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 18 deletions.
28 changes: 23 additions & 5 deletions src/main/mondrian/olap/MondrianResource.xml
Expand Up @@ -279,15 +279,33 @@
</exception>

<exception id="400040" name="MustSpecifyPrimaryKeyForHierarchy">
<text>Must specify a primary key for hierarchy ''{0}''.</text>
<text>In usage of hierarchy ''{0}'' in cube ''{1}'', you must specify a primary key.</text>
</exception>

<exception id="400050" name="MustSpecifyForeignKeyForHierarchy">
<text>Must specify a foreign key for hierarchy ''{0}''.</text>
<exception id="400050" name="MustSpecifyPrimaryKeyTableForHierarchy">
<text>Must specify a primary key table for hierarchy ''{0}'', because it has more than one table.</text>
</exception>

<exception id="400060" name="LevelMustHaveNameExpression">
<text>Level ''{0}}'' must have a name expression (a ''column'' attribute or an &lt;Expression&gt; child</text>
<exception id="400060" name="MustSpecifyForeignKeyForHierarchy">
<text>In usage of hierarchy ''{0}'' in cube ''{1}'', you must specify a foreign key, because the hierarchy table is different from the fact table.</text>
</exception>

<exception id="400070" name="LevelMustHaveNameExpression">
<text>Level ''{0}'' must have a name expression (a ''column'' attribute or an &lt;Expression&gt; child</text>
</exception>

<!-- The 'foreignKey' attribute of is only applicable to private dimensions
or to dimension usages. -->
<exception id="400080" name="PublicDimensionMustNotHaveForeignKey">
<text>Dimension ''{0}'' has a foreign key. This attribute is only valid in private dimensions and dimension usages.</text>
</exception>

<exception id="400090" name="HierarchyMustNotHaveMoreThanOneSource">
<text>Hierarchy ''{0}'' has more than one source (memberReaderClass, &lt;Table&gt;, &lt;Join&gt; or &lt;View&gt;)</text>
</exception>

<exception id="40100" name="DimensionUsageHasUnknownLevel">
<text>In usage of dimension ''{0}'' in cube ''{1}'', the level ''{2}'' is unknown</text>
</exception>


Expand Down
27 changes: 17 additions & 10 deletions src/main/mondrian/rolap/HierarchyUsage.java
Expand Up @@ -59,9 +59,14 @@ void init(RolapCube cube, RolapHierarchy hierarchy,
// Three ways that a hierarchy can be joined to the fact table.
if (dimensionUsage != null && dimensionUsage.level != null) {
// 1. Specify an explicit 'level' attribute in a <DimensionUsage>.
RolapLevel joinLevel = (RolapLevel) Util.lookupHierarchyLevel(hierarchy, dimensionUsage.level);
RolapLevel joinLevel = (RolapLevel)
Util.lookupHierarchyLevel(hierarchy, dimensionUsage.level);
if (joinLevel == null) {
throw Util.newError("Level '" + dimensionUsage.level + "' not found");
throw MondrianResource.instance()
.newDimensionUsageHasUnknownLevel(
hierarchy.getUniqueName(),
cube.getUniqueName(),
dimensionUsage.level);
}
setJoinTable(hierarchy, joinLevel.keyExp.getTableAlias());
joinExp = joinLevel.keyExp;
Expand All @@ -73,15 +78,15 @@ void init(RolapCube cube, RolapHierarchy hierarchy,
if (hierarchy.xmlHierarchy.primaryKeyTable == null) {
joinTable = hierarchy.getUniqueTable();
if (joinTable == null) {
throw Util.newError(
"must specify primaryKeyTable for hierarchy " +
hierarchy.getUniqueName() +
", because it has more than one table");
throw MondrianResource.instance()
.newMustSpecifyPrimaryKeyTableForHierarchy(
hierarchy.getUniqueName());
}
} else {
setJoinTable(hierarchy, hierarchy.xmlHierarchy.primaryKeyTable);
}
joinExp = new MondrianDef.Column(joinTable.getAlias(), hierarchy.xmlHierarchy.primaryKey);
joinExp = new MondrianDef.Column(joinTable.getAlias(),
hierarchy.xmlHierarchy.primaryKey);
} else {
// 3. If neither of the above, the join is assumed to be to key of
// the last level.
Expand All @@ -98,12 +103,14 @@ void init(RolapCube cube, RolapHierarchy hierarchy,
if (joinExp == null) {
throw MondrianResource.instance()
.newMustSpecifyPrimaryKeyForHierarchy(
hierarchy.getUniqueName());
hierarchy.getUniqueName(),
cube.getUniqueName());
}
if (foreignKey == null) {
throw MondrianResource.instance()
.newMustSpecifyPrimaryKeyForHierarchy(
hierarchy.getUniqueName());
.newMustSpecifyForeignKeyForHierarchy(
hierarchy.getUniqueName(),
cube.getUniqueName());
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/mondrian/rolap/RolapCube.java
Expand Up @@ -242,6 +242,8 @@ private void registerDimension(RolapDimension dimension) {
}
RolapStar.Table table = star.factTable;
if (!relation.equals(table.relation)) {
// HierarchyUsage should have checked this.
Util.assertTrue(hierarchyUsage.foreignKey != null);
RolapStar.Condition joinCondition = new RolapStar.Condition(
new MondrianDef.Column(table.getAlias(), hierarchyUsage.foreignKey),
hierarchyUsage.joinExp);
Expand Down
6 changes: 3 additions & 3 deletions src/main/mondrian/rolap/RolapDimension.java
Expand Up @@ -74,9 +74,9 @@ class RolapDimension extends DimensionBase
/**
* @pre schema != null
*/
RolapDimension(
RolapSchema schema, RolapCube cube, MondrianDef.Dimension xmlDimension,
MondrianDef.CubeDimension xmlCubeDimension)
RolapDimension(RolapSchema schema, RolapCube cube,
MondrianDef.Dimension xmlDimension,
MondrianDef.CubeDimension xmlCubeDimension)
{
this(schema, xmlDimension.name, chooseOrdinal(cube, xmlCubeDimension));
Util.assertPrecondition(schema != null);
Expand Down
9 changes: 9 additions & 0 deletions src/main/mondrian/rolap/RolapSchema.java
Expand Up @@ -109,6 +109,15 @@ private void load(MondrianDef.Schema xmlSchema)
this.name = xmlSchema.name;
if (name == null || name.equals("")) {
throw Util.newError("<Schema> name must be set");
}
// Validate public dimensions.
for (int i = 0; i < xmlSchema.dimensions.length; i++) {
MondrianDef.Dimension xmlDimension = xmlSchema.dimensions[i];
if (xmlDimension.foreignKey != null) {
throw MondrianResource.instance()
.newPublicDimensionMustNotHaveForeignKey(
xmlDimension.name);
}
}
for (int i = 0; i < xmlSchema.cubes.length; i++) {
MondrianDef.Cube xmlCube = xmlSchema.cubes[i];
Expand Down

0 comments on commit 40aa069

Please sign in to comment.