Skip to content

Commit

Permalink
Fix XMLA driver for calculated members defined in query; and make hie…
Browse files Browse the repository at this point in the history
…rarchies and members returned for the slicer consistent between XMLA and mondrian drivers.

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@62 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Jan 13, 2008
1 parent 0428f8e commit dd62506
Show file tree
Hide file tree
Showing 3 changed files with 249 additions and 47 deletions.
145 changes: 144 additions & 1 deletion src/org/olap4j/driver/xmla/XmlaOlap4jCellSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.olap4j.driver.xmla;

import org.olap4j.*;
import org.olap4j.mdx.ParseTreeNode;
import org.olap4j.impl.Olap4jUtil;
import static org.olap4j.driver.xmla.XmlaOlap4jUtil.*;
import org.olap4j.metadata.*;
Expand Down Expand Up @@ -190,9 +191,19 @@ void populate() throws OlapException {
{
String hierarchyName =
memberNode.getAttribute("Hierarchy");
String uname = stringElement(memberNode, "UName");
final String uname = stringElement(memberNode, "UName");
Member member =
metaData.cube.lookupMemberByUniqueName(uname);
if (member == null) {
final String caption =
stringElement(memberNode, "Caption");
final int lnum = integerElement(memberNode, "LNum");
final Hierarchy hierarchy =
metaData.cube.getHierarchies().get(hierarchyName);
final Level level = hierarchy.getLevels().get(lnum);
member = new XmlaOlap4jSurpriseMember(
level, hierarchy, lnum, caption, uname);
}
propertyValues.clear();
for (Element childNode : childElements(memberNode)) {
XmlaOlap4jCellSetMemberProperty property =
Expand Down Expand Up @@ -1068,6 +1079,138 @@ public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw new UnsupportedOperationException();
}

/**
* Implementation of {@link Member} for a member which is not present
* in the cube (probably because the member is a calculated member
* defined in the query).
*/
private static class XmlaOlap4jSurpriseMember implements Member {
private final Level level;
private final Hierarchy hierarchy;
private final int lnum;
private final String caption;
private final String uname;

XmlaOlap4jSurpriseMember(
Level level,
Hierarchy hierarchy,
int lnum,
String caption,
String uname)
{
this.level = level;
this.hierarchy = hierarchy;
this.lnum = lnum;
this.caption = caption;
this.uname = uname;
}

public NamedList<? extends Member> getChildMembers()
{
return Olap4jUtil.emptyNamedList();
}

public int getChildMemberCount() {
return 0;
}

public Member getParentMember() {
return null;
}

public Level getLevel() {
return level;
}

public Hierarchy getHierarchy() {
return hierarchy;
}

public Dimension getDimension() {
return hierarchy.getDimension();
}

public Type getMemberType() {
return Type.UNKNOWN;
}

public boolean isAll() {
return false; // FIXME
}

public boolean isChildOrEqualTo(Member member) {
return false; // FIXME
}

public boolean isCalculated() {
return false; // FIXME
}

public int getSolveOrder() {
return 0; // FIXME
}

public ParseTreeNode getExpression() {
return null;
}

public List<Member> getAncestorMembers() {
return Collections.emptyList(); // FIXME
}

public boolean isCalculatedInQuery() {
return true; // probably
}

public Object getPropertyValue(Property property) {
return null;
}

public String getPropertyFormattedValue(Property property) {
return null;
}

public void setProperty(Property property, Object value)
{
throw new UnsupportedOperationException();
}

public NamedList<Property> getProperties() {
return Olap4jUtil.emptyNamedList();
}

public int getOrdinal() {
return -1; // FIXME
}

public boolean isHidden() {
return false;
}

public int getDepth() {
return lnum;
}

public Member getDataMember() {
return null;
}

public String getName() {
return caption;
}

public String getUniqueName() {
return uname;
}

public String getCaption(Locale locale) {
return caption;
}

public String getDescription(Locale locale) {
return null;
}
}
}

// End XmlaOlap4jCellSet.java
47 changes: 45 additions & 2 deletions src/org/olap4j/impl/Olap4jUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

import org.olap4j.metadata.NamedList;

import java.util.List;
import java.util.Set;
import java.util.*;

/**
* Utility methods common to multiple olap4j driver implementations.
Expand Down Expand Up @@ -48,6 +47,10 @@ public class Olap4jUtil {
"com.rc.retroweaver.runtime.Enum_");

private static final Olap4jUtilCompatible compatible;

private static final NamedList<?> EMPTY_NAMED_LIST =
new EmptyNamedList();

static {
String className;
if (PreJdk15 || Retrowoven) {
Expand All @@ -56,6 +59,7 @@ public class Olap4jUtil {
className = "org.olap4j.impl.Olap4jUtilCompatibleJdk15";
}
try {
//noinspection unchecked
Class<Olap4jUtilCompatible> clazz =
(Class<Olap4jUtilCompatible>) Class.forName(className);
compatible = clazz.newInstance();
Expand All @@ -68,22 +72,31 @@ public class Olap4jUtil {
}
}

@SuppressWarnings({"UnusedDeclaration"})
public static void discard(boolean b) { }

@SuppressWarnings({"UnusedDeclaration"})
public static void discard(byte b) { }

@SuppressWarnings({"UnusedDeclaration"})
public static void discard(char c) { }

@SuppressWarnings({"UnusedDeclaration"})
public static void discard(double v) { }

@SuppressWarnings({"UnusedDeclaration"})
public static void discard(float v) { }

@SuppressWarnings({"UnusedDeclaration"})
public static void discard(int i) { }

@SuppressWarnings({"UnusedDeclaration"})
public static void discard(long l) { }

@SuppressWarnings({"UnusedDeclaration"})
public static void discard(Object o) { }

@SuppressWarnings({"UnusedDeclaration"})
public static void discard(short i) { }

/**
Expand All @@ -92,6 +105,7 @@ public static void discard(short i) { }
* @param set Set
* @return Set of desired type
*/
@SuppressWarnings({"unchecked"})
public static <T> Set<T> cast(Set<?> set) {
return (Set<T>) set;
}
Expand All @@ -102,6 +116,7 @@ public static <T> Set<T> cast(Set<?> set) {
* @param list List
* @return List of desired type
*/
@SuppressWarnings({"unchecked"})
public static <T> List<T> cast(List<?> list) {
return (List<T>) list;
}
Expand All @@ -112,6 +127,7 @@ public static <T> List<T> cast(List<?> list) {
* @param list Named list
* @return Named list of desired type
*/
@SuppressWarnings({"unchecked"})
public static <T> NamedList<T> cast(NamedList<?> list) {
return (NamedList<T>) list;
}
Expand Down Expand Up @@ -322,8 +338,35 @@ public static RuntimeException needToImplement(Object o) {
throw new UnsupportedOperationException("need to implement " + o);
}

@SuppressWarnings({"unchecked"})
public static <T> NamedList<T> emptyNamedList() {
return (NamedList<T>) EMPTY_NAMED_LIST;
}

private enum DummyEnum {}

/**
* Implementation of {@link NamedList} whih is immutable and empty.
*/
private static class EmptyNamedList<T> extends AbstractNamedList<T> {
protected String getName(Object o) {
throw new UnsupportedOperationException();
}

public int size() {
return 0;
}

public T get(int index) {
throw new IndexOutOfBoundsException("Index: "+index);
}

// Preserves singleton property
@SuppressWarnings({"UnusedDeclaration"})
private Object readResolve() {
return EMPTY_NAMED_LIST;
}
}
}

// End Olap4jUtil.java
Loading

0 comments on commit dd62506

Please sign in to comment.