Skip to content

Commit

Permalink
MONDRIAN: Fixed "junit" target in runtime.xml;
Browse files Browse the repository at this point in the history
renamed Member.getProperty() to getPropertyValue(),
added Level.getInheritedProperties(),
added Member.getProperties().

[git-p4: depot-paths = "//open/mondrian/": change = 162]
  • Loading branch information
julianhyde committed Sep 20, 2002
1 parent efbf104 commit aee46a8
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 33 deletions.
4 changes: 3 additions & 1 deletion bin/mondrian.bat
Expand Up @@ -15,7 +15,9 @@ echo LIB=%LIB%
@goto end
:javaOk

%JAVA_HOME%/bin/java -classpath %LIB%/ant.jar;%LIB%/optional.jar;%LIB%/xercesImpl.jar;%LIB%/xml-apis.jar -Dant.home="%SRCROOT%" org.apache.tools.ant.Main -buildfile runtime.xml %1 %2 %3 %4 %5 %6 %7 %8 %9
@set CLASSPATH="%LIB%\ant.jar;%LIB%\optional.jar;%LIB%\xercesImpl.jar;%LIB%\xml-apis.jar;%LIB%\junit.jar"

%JAVA_HOME%\bin\java -classpath "%CLASSPATH%" -Dant.home="%SRCROOT%" org.apache.tools.ant.Main -buildfile runtime.xml %1 %2 %3 %4 %5 %6 %7 %8 %9

:end
@rem End mondrian.bat
Expand Down
14 changes: 5 additions & 9 deletions bin/runtime.xml
Expand Up @@ -25,6 +25,7 @@
<property name="tomcat.home" value="${myenv.TOMCAT_HOME}"/>

<path id="project.classpath">
<pathelement location="${lib.location}/${name}.jar"/>
<pathelement location="${tomcat.home}/common/lib/servlet.jar"/>
<pathelement location="${lib.location}/javacup.jar"/>
<pathelement location="${lib.location}/xalan.jar"/>
Expand Down Expand Up @@ -65,8 +66,8 @@ junit.jar"/>
todir="${tomcat.home}/webapps"/>
</target>

<target name="junit-main">
<mkdir dir="junit-results"/>
<target name="junit">
<mkdir dir="junit-results"/>
<junit printsummary="yes" fork="yes" haltonfailure="no" >
<classpath>
<path refid="project.classpath"/>
Expand All @@ -75,13 +76,7 @@ junit.jar"/>
<jvmarg value="-Dmondrian.test.connectString=Provider=mondrian;Jdbc='${mondrian.foodmart.jdbcURL}';Catalog='${mondrian.foodmart.catalogURL}'"/>
<formatter type="xml" />

<batchtest fork="yes" todir="junit-results">
<fileset dir="classes">
<include name="mondrian/test/**/*Test*.class" />
<exclude name="mondrian/test/**/*Testable*.class" />
<exclude name="mondrian/test/**/*TestContext*.class" />
</fileset>
</batchtest>
<test fork="yes" name="mondrian.test.Main" todir="junit-results"/>
</junit>

<junitreport todir="junit-results">
Expand All @@ -91,6 +86,7 @@ junit.jar"/>
<report format="frames" todir="junit-results/html"/>
</junitreport>

<echo>See results at junit-results/html/index.html.</echo>
</target>

</project>
8 changes: 2 additions & 6 deletions src/main/mondrian/olap/FunTable.java
Expand Up @@ -61,10 +61,6 @@ protected void defineFunctions() {
}

protected abstract void define(FunDef funDef);

/**
* Creates a JUnit test suite which calls every method of every function
* which starts with 'test'.
*/
public abstract TestSuite suite();
}

// End FunTable.java
3 changes: 3 additions & 0 deletions src/main/mondrian/olap/Level.java
Expand Up @@ -34,7 +34,10 @@ public interface Level extends OlapElement {
static final int MONTHS = 3;
static final int WEEKS = 4;
static final int DAYS = 5;
/** Returns properties defined against this level. **/
Property[] getProperties();
/** Returns properties defined against this level and parent levels. **/
Property[] getInheritedProperties();
}

// End Level.java
26 changes: 24 additions & 2 deletions src/main/mondrian/olap/Member.java
Expand Up @@ -15,7 +15,24 @@
import java.util.*;

/**
* todo:
* A <code>Member</code> is a 'point' on a dimension of a cube. Examples are
* <code>[Time].[1997].[January]</code>,
* <code>[Customer].[All Customers]</code>,
* <code>[Customer].[USA].[CA]</code>,
* <code>[Measures].[Unit Sales]</code>.
*
* <p> Every member belongs to a {@link Level} of a {@link Hierarchy}. Members
* except the root member have a parent, and members not at the leaf level
* have one or more children.
*
* <p> Measures are a special kind of member. They belong to their own
* dimension, <code>[Measures]</code>.
*
* <p> There are also special members representing the 'All' value of a
* hierarchy, the null value, and the error value.
*
* <p> Members can have member properties. Their {@link Level#getProperties}
* defines which are allowed.
**/
public interface Member extends OlapElement {

Expand Down Expand Up @@ -122,7 +139,12 @@ public interface Member extends OlapElement {
/**
* Returns the value of the property named <code>propertyName</code>.
*/
Object getProperty(String propertyName);
Object getPropertyValue(String propertyName);

/**
* Returns the definitions of the properties this member may have.
*/
Property[] getProperties();
}

// End Member.java
22 changes: 20 additions & 2 deletions src/main/mondrian/olap/fun/BuiltinFunTable.java
Expand Up @@ -14,6 +14,7 @@

import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.framework.Test;
import mondrian.olap.*;
import mondrian.test.FoodMartTestCase;
import mondrian.test.TestContext;
Expand Down Expand Up @@ -2026,6 +2027,18 @@ public void testPropertiesFilter(FoodMartTestCase test) {
"FROM [Sales]");
test.assertEquals(8, result.getAxes()[1].positions.length);
}

public void testPropertyInCalculatedMember(FoodMartTestCase test) {
Result result = test.execute(
"WITH MEMBER [Measures].[Store Sales per Sqft]" + nl +
"AS '[Measures].[Store Sales] / " +
" [Store].CurrentMember.Properties(\"Store Sqft\")'" + nl +
"SELECT " + nl +
" {[Measures].[Unit Sales], [Measures].[Store Sales per Sqft]} ON COLUMNS," + nl +
" {[Store].[Store Name].members} ON ROWS" + nl +
"FROM Sales");
test.assertEquals("foo", result.getCell(new int[] {0,0}).getFormattedValue());
}
});

//
Expand Down Expand Up @@ -2101,7 +2114,7 @@ private Boolean toBoolean(boolean b) {
return b ? Boolean.TRUE : Boolean.FALSE;
}

public TestSuite suite() {
TestSuite createSuite() {
TestSuite suite = new TestSuite("builtin functions");
for (Iterator resolverses = upperName2Resolvers.values().iterator();
resolverses.hasNext();) {
Expand All @@ -2114,6 +2127,11 @@ public TestSuite suite() {
return suite;
}

/** Standard method recognised by JUnit. **/
public static Test suite() {
return ((BuiltinFunTable) instance()).createSuite();
}

void test() {
String[] stmts = new String[]{
"select CoalesceEmpty(1,2) from Sales",
Expand Down Expand Up @@ -2181,7 +2199,7 @@ public PropertiesFunDef(
public Object evaluate(Evaluator evaluator, Exp[] args) {
Member member = getMemberArg(evaluator, args, 0, true);
String s = getStringArg(evaluator, args, 1, null);
Object o = member.getProperty(s);
Object o = member.getPropertyValue(s);
if (o == null) {
if (isValidProperty(member, s)) {
o = member.getHierarchy().getNullMember();
Expand Down
2 changes: 1 addition & 1 deletion src/main/mondrian/rolap/RolapEvaluator.java
Expand Up @@ -203,7 +203,7 @@ Object getProperty(String name)
int maxSolve = Integer.MIN_VALUE;
for (int i = 0; i < currentMembers.length; i++) {
RolapMember member = currentMembers[i];
Object p = member.getProperty(name);
Object p = member.getPropertyValue(name);
if (p != null) {
int solve = member.getSolveOrder();
if (solve > maxSolve) {
Expand Down
41 changes: 41 additions & 0 deletions src/main/mondrian/rolap/RolapLevel.java
Expand Up @@ -14,6 +14,9 @@
import mondrian.olap.*;
import mondrian.rolap.sql.SqlQuery;

import java.util.ArrayList;
import java.util.Iterator;

/**
* <code>RolapLevel</code> implements {@link Level} for a ROLAP database.
*
Expand All @@ -35,6 +38,7 @@ class RolapLevel extends LevelBase
static final int NUMERIC = 1;
static final int ALL = 2;
RolapProperty[] properties;
RolapProperty[] inheritedProperties;

/**
* Creates a level.
Expand Down Expand Up @@ -64,6 +68,27 @@ class RolapLevel extends LevelBase
}
}
this.properties = properties;
ArrayList list = new ArrayList();
for (Level level = this; level != null;
level = level.getParentLevel()) {
final Property[] levelProperties = level.getProperties();
for (int i = 0; i < levelProperties.length; i++) {
final Property levelProperty = levelProperties[i];
Property existingProperty = lookupProperty(
list, levelProperty.getName());
if (existingProperty == null) {
list.add(levelProperty);
} else if (existingProperty.getType() !=
levelProperty.getType()) {
throw Util.newError(
"Property " + this.getName() + "." +
levelProperty.getName() + " overrides a " +
"property with the same name but different type");
}
}
}
this.inheritedProperties = (RolapProperty[]) list.toArray(
new RolapProperty[0]);
this.flags = flags;
this.depth = depth;
this.levelType = Level.STANDARD;
Expand All @@ -78,6 +103,18 @@ class RolapLevel extends LevelBase
}
}

private Property lookupProperty(ArrayList list, String propertyName) {
Property existingProperty = null;
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
Property property = (Property) iterator.next();
if (property.getName().equals(propertyName)) {
existingProperty = property;
break;
}
}
return existingProperty;
}

RolapLevel(RolapHierarchy hierarchy, int depth, MondrianDef.Level xmlLevel)
{
this(
Expand Down Expand Up @@ -156,6 +193,10 @@ public String getTableAlias() {
public Property[] getProperties() {
return properties;
}

public Property[] getInheritedProperties() {
return inheritedProperties;
}
}

// End RolapLevel.java
10 changes: 5 additions & 5 deletions src/main/mondrian/rolap/RolapMember.java
Expand Up @@ -11,10 +11,7 @@
*/

package mondrian.rolap;
import mondrian.olap.Evaluator;
import mondrian.olap.Member;
import mondrian.olap.MemberBase;
import mondrian.olap.Util;
import mondrian.olap.*;

import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -95,9 +92,12 @@ public void setProperty(String name, Object value) {
}
mapPropertyNameToValue.put(name, value);
}
public Object getProperty(String name) {
public Object getPropertyValue(String name) {
return mapPropertyNameToValue.get(name);
}
public Property[] getProperties() {
return level.getInheritedProperties();
}
// implement Exp
public Object evaluateScalar(Evaluator evaluator)
{
Expand Down
8 changes: 2 additions & 6 deletions src/main/mondrian/test/Main.java
Expand Up @@ -28,15 +28,11 @@
/**
* <code>Main</code> is the main test suite for Mondrian.
**/
public class Main extends TestCase {
public class Main {
static public void main(String[] args) {
new Main().runSafe(args);
}

Main() {
super("mondrian");
}

private void runSafe(String[] args) {
try {
run(args);
Expand Down Expand Up @@ -113,7 +109,7 @@ public static Test suite() throws Exception {
}
TestSuite suite = new TestSuite();
suite.addTestSuite(FoodMartTestCase.class);
suite.addTest(BuiltinFunTable.instance().suite());
suite.addTest(BuiltinFunTable.suite());
suite.addTestSuite(Schedule.ScheduleTestCase.class);
suite.addTest(Util.suite());
suite.addTest(CachePool.suite());
Expand Down
2 changes: 1 addition & 1 deletion src/main/mondrian/web/taglib/DOMBuilder.java
Expand Up @@ -301,7 +301,7 @@ private void addMemberProperties(Member m, Element e) {
if (props != null) {
for (int i = 0; i < props.length; i++) {
String propName = props[i].getName();
String propValue = "" + m.getProperty(propName);
String propValue = "" + m.getPropertyValue(propName);
Element propElem = elem("property", e);
propElem.setAttribute("name", propName);
propElem.setAttribute("value", propValue);
Expand Down

0 comments on commit aee46a8

Please sign in to comment.