Skip to content

Commit

Permalink
Fix bug 3375355, "getSharedDimensions returns empty result" (requires…
Browse files Browse the repository at this point in the history
… a fix to

mondrian, approx change 14490).
More constructors for NamedListImpl and ArrayNamedListImpl.
Fix Pair.toString().


git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@464 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Jul 25, 2011
1 parent 6f3f308 commit 26f6862
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 18 deletions.
13 changes: 8 additions & 5 deletions src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -1093,9 +1093,10 @@ public void handle(
static class DimensionHandler extends HandlerImpl<XmlaOlap4jDimension> {
private final XmlaOlap4jCube cubeForCallback;

public DimensionHandler(XmlaOlap4jCube dimensionsByUname) {
this.cubeForCallback = dimensionsByUname;
public DimensionHandler(XmlaOlap4jCube cube) {
this.cubeForCallback = cube;
}

public void handle(
Element row,
Context context,
Expand Down Expand Up @@ -1168,9 +1169,11 @@ public int compare(
}
});
}
this.cubeForCallback.dimensionsByUname.put(
dimension.getUniqueName(),
dimension);
if (this.cubeForCallback != null) {
this.cubeForCallback.dimensionsByUname.put(
dimension.getUniqueName(),
dimension);
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/org/olap4j/driver/xmla/XmlaOlap4jHierarchy.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2010 Julian Hyde
// Copyright (C) 2007-2011 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -101,8 +101,7 @@ public NamedList<Member> getRootMembers() throws OlapException {
olap4jDimension.olap4jCube.getMetadataReader().getLevelMembers(
levels.get(0));
final NamedList<XmlaOlap4jMember> list =
new NamedListImpl<XmlaOlap4jMember>();
list.addAll(memberList);
new NamedListImpl<XmlaOlap4jMember>(memberList);
return Olap4jUtil.cast(list);
}

Expand Down
33 changes: 27 additions & 6 deletions src/org/olap4j/driver/xmla/XmlaOlap4jSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2010 Julian Hyde
// Copyright (C) 2007-2011 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand All @@ -26,10 +26,12 @@ class XmlaOlap4jSchema implements Schema, Named {
final XmlaOlap4jCatalog olap4jCatalog;
private final String name;
final NamedList<XmlaOlap4jCube> cubes;
private final NamedList<XmlaOlap4jDimension> sharedDimensions;

XmlaOlap4jSchema(
XmlaOlap4jCatalog olap4jCatalog,
String name)
throws OlapException
{
if (olap4jCatalog == null) {
throw new NullPointerException("Catalog cannot be null.");
Expand All @@ -40,16 +42,36 @@ class XmlaOlap4jSchema implements Schema, Named {

this.olap4jCatalog = olap4jCatalog;
this.name = name;
this.cubes = new DeferredNamedListImpl<XmlaOlap4jCube>(
XmlaOlap4jConnection.MetadataRequest.MDSCHEMA_CUBES,

// Dummy cube to own shared dimensions.
final XmlaOlap4jCube sharedCube =
new XmlaOlap4jCube(this, "", "", "");

final XmlaOlap4jConnection.Context context =
new XmlaOlap4jConnection.Context(
olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection,
olap4jCatalog.olap4jDatabaseMetaData,
olap4jCatalog,
this,
null, null, null, null),
sharedCube, null, null, null);

this.cubes = new DeferredNamedListImpl<XmlaOlap4jCube>(
XmlaOlap4jConnection.MetadataRequest.MDSCHEMA_CUBES,
context,
new XmlaOlap4jConnection.CubeHandler(),
null);

String[] restrictions = {
"CATALOG_NAME", olap4jCatalog.getName(),
"SCHEMA_NAME", getName(),
"CUBE_NAME", ""
};

this.sharedDimensions = new DeferredNamedListImpl<XmlaOlap4jDimension>(
XmlaOlap4jConnection.MetadataRequest.MDSCHEMA_DIMENSIONS,
context,
new XmlaOlap4jConnection.DimensionHandler(null),
restrictions);
}

public int hashCode() {
Expand Down Expand Up @@ -78,8 +100,7 @@ public NamedList<Cube> getCubes() throws OlapException {
}

public NamedList<Dimension> getSharedDimensions() throws OlapException {
// No shared dimensions
return Olap4jUtil.cast(new NamedListImpl<XmlaOlap4jDimension>());
return Olap4jUtil.cast(sharedDimensions);
}

public Collection<Locale> getSupportedLocales() throws OlapException {
Expand Down
33 changes: 32 additions & 1 deletion src/org/olap4j/impl/ArrayNamedListImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2010 Julian Hyde
// Copyright (C) 2007-2011 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand All @@ -11,6 +11,7 @@
import org.olap4j.metadata.NamedList;

import java.util.ArrayList;
import java.util.Collection;

/**
* Implementation of {@link org.olap4j.metadata.NamedList} which uses
Expand All @@ -29,6 +30,36 @@ public abstract class ArrayNamedListImpl<T>
extends ArrayList<T>
implements NamedList<T>
{
/**
* Creates an empty list with the specified initial capacity.
*
* @param initialCapacity the initial capacity of the list
* @exception IllegalArgumentException if the specified initial capacity
* is negative
*/
public ArrayNamedListImpl(int initialCapacity) {
super(initialCapacity);
}

/**
* Creates an empty list.
*/
public ArrayNamedListImpl() {
super();
}

/**
* Creates a list containing the elements of the specified
* collection, in the order they are returned by the collection's
* iterator.
*
* @param c the collection whose elements are to be placed into this list
* @throws NullPointerException if the specified collection is null
*/
public ArrayNamedListImpl(Collection<? extends T> c) {
super(c);
}

protected abstract String getName(T t);

public T get(String name) {
Expand Down
34 changes: 33 additions & 1 deletion src/org/olap4j/impl/NamedListImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2010 Julian Hyde
// Copyright (C) 2007-2011 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package org.olap4j.impl;

import java.util.Collection;

/**
* Implementation of {@link org.olap4j.metadata.NamedList} which uses
* {@link java.util.ArrayList} for storage and assumes that elements implement
Expand All @@ -21,6 +23,36 @@
public class NamedListImpl<T extends Named>
extends ArrayNamedListImpl<T>
{
/**
* Creates an empty list with the specified initial capacity.
*
* @param initialCapacity the initial capacity of the list
* @exception IllegalArgumentException if the specified initial capacity
* is negative
*/
public NamedListImpl(int initialCapacity) {
super(initialCapacity);
}

/**
* Creates an empty list.
*/
public NamedListImpl() {
super();
}

/**
* Creates a list containing the elements of the specified
* collection, in the order they are returned by the collection's
* iterator.
*
* @param c the collection whose elements are to be placed into this list
* @throws NullPointerException if the specified collection is null
*/
public NamedListImpl(Collection<? extends T> c) {
super(c);
}

protected final String getName(T t) {
return t.getName();
}
Expand Down
4 changes: 2 additions & 2 deletions src/org/olap4j/impl/Pair.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2010 Julian Hyde
// Copyright (C) 2007-2011 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -63,7 +63,7 @@ public int compareTo(Pair<L, R> that) {
}

public String toString() {
return "<" + left + ", " + ">";
return "<" + left + ", " + right + ">";
}

// implement Map.Entry
Expand Down
28 changes: 28 additions & 0 deletions testsrc/org/olap4j/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2031,6 +2031,34 @@ public void testMetadata() throws Exception {
measureNameSet);
}

/**
* Test case for {@link org.olap4j.metadata.Schema#getSharedDimensions()}.
* Bug 3375355, "getSharedDimensions returns empty result".
*/
public void testSchemaGetSharedDimensions() throws Exception {
Class.forName(tester.getDriverClassName());
connection = tester.createConnection();
OlapConnection olapConnection =
tester.getWrapper().unwrap(connection, OlapConnection.class);
final List<String> list = new ArrayList<String>();
final NamedList<Dimension> sharedDimensions =
olapConnection.getOlapSchema().getSharedDimensions();
for (Dimension dimension : sharedDimensions) {
list.add(dimension.getName());
}

// note that, per specification, list is sorted
assertEquals(
Arrays.asList(
"Product",
"Store",
"Store Size in SQFT",
"Store Type",
"Time",
"Warehouse"),
list);
}

/**
* Testcase for bug 3312701, "VirtualCube doesn't show
* Calculated Members"
Expand Down

0 comments on commit 26f6862

Please sign in to comment.