Skip to content

Commit 26f6862

Browse files
committed
Fix bug 3375355, "getSharedDimensions returns empty result" (requires 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
1 parent 6f3f308 commit 26f6862

7 files changed

+132
-18
lines changed

src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -1093,9 +1093,10 @@ public void handle(
10931093
static class DimensionHandler extends HandlerImpl<XmlaOlap4jDimension> {
10941094
private final XmlaOlap4jCube cubeForCallback;
10951095

1096-
public DimensionHandler(XmlaOlap4jCube dimensionsByUname) {
1097-
this.cubeForCallback = dimensionsByUname;
1096+
public DimensionHandler(XmlaOlap4jCube cube) {
1097+
this.cubeForCallback = cube;
10981098
}
1099+
10991100
public void handle(
11001101
Element row,
11011102
Context context,
@@ -1168,9 +1169,11 @@ public int compare(
11681169
}
11691170
});
11701171
}
1171-
this.cubeForCallback.dimensionsByUname.put(
1172-
dimension.getUniqueName(),
1173-
dimension);
1172+
if (this.cubeForCallback != null) {
1173+
this.cubeForCallback.dimensionsByUname.put(
1174+
dimension.getUniqueName(),
1175+
dimension);
1176+
}
11741177
}
11751178
}
11761179

src/org/olap4j/driver/xmla/XmlaOlap4jHierarchy.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// This software is subject to the terms of the Eclipse Public License v1.0
33
// Agreement, available at the following URL:
44
// http://www.eclipse.org/legal/epl-v10.html.
5-
// Copyright (C) 2007-2010 Julian Hyde
5+
// Copyright (C) 2007-2011 Julian Hyde
66
// All Rights Reserved.
77
// You must accept the terms of that agreement to use this software.
88
*/
@@ -101,8 +101,7 @@ public NamedList<Member> getRootMembers() throws OlapException {
101101
olap4jDimension.olap4jCube.getMetadataReader().getLevelMembers(
102102
levels.get(0));
103103
final NamedList<XmlaOlap4jMember> list =
104-
new NamedListImpl<XmlaOlap4jMember>();
105-
list.addAll(memberList);
104+
new NamedListImpl<XmlaOlap4jMember>(memberList);
106105
return Olap4jUtil.cast(list);
107106
}
108107

src/org/olap4j/driver/xmla/XmlaOlap4jSchema.java

+27-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// This software is subject to the terms of the Eclipse Public License v1.0
33
// Agreement, available at the following URL:
44
// http://www.eclipse.org/legal/epl-v10.html.
5-
// Copyright (C) 2007-2010 Julian Hyde
5+
// Copyright (C) 2007-2011 Julian Hyde
66
// All Rights Reserved.
77
// You must accept the terms of that agreement to use this software.
88
*/
@@ -26,10 +26,12 @@ class XmlaOlap4jSchema implements Schema, Named {
2626
final XmlaOlap4jCatalog olap4jCatalog;
2727
private final String name;
2828
final NamedList<XmlaOlap4jCube> cubes;
29+
private final NamedList<XmlaOlap4jDimension> sharedDimensions;
2930

3031
XmlaOlap4jSchema(
3132
XmlaOlap4jCatalog olap4jCatalog,
3233
String name)
34+
throws OlapException
3335
{
3436
if (olap4jCatalog == null) {
3537
throw new NullPointerException("Catalog cannot be null.");
@@ -40,16 +42,36 @@ class XmlaOlap4jSchema implements Schema, Named {
4042

4143
this.olap4jCatalog = olap4jCatalog;
4244
this.name = name;
43-
this.cubes = new DeferredNamedListImpl<XmlaOlap4jCube>(
44-
XmlaOlap4jConnection.MetadataRequest.MDSCHEMA_CUBES,
45+
46+
// Dummy cube to own shared dimensions.
47+
final XmlaOlap4jCube sharedCube =
48+
new XmlaOlap4jCube(this, "", "", "");
49+
50+
final XmlaOlap4jConnection.Context context =
4551
new XmlaOlap4jConnection.Context(
4652
olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection,
4753
olap4jCatalog.olap4jDatabaseMetaData,
4854
olap4jCatalog,
4955
this,
50-
null, null, null, null),
56+
sharedCube, null, null, null);
57+
58+
this.cubes = new DeferredNamedListImpl<XmlaOlap4jCube>(
59+
XmlaOlap4jConnection.MetadataRequest.MDSCHEMA_CUBES,
60+
context,
5161
new XmlaOlap4jConnection.CubeHandler(),
5262
null);
63+
64+
String[] restrictions = {
65+
"CATALOG_NAME", olap4jCatalog.getName(),
66+
"SCHEMA_NAME", getName(),
67+
"CUBE_NAME", ""
68+
};
69+
70+
this.sharedDimensions = new DeferredNamedListImpl<XmlaOlap4jDimension>(
71+
XmlaOlap4jConnection.MetadataRequest.MDSCHEMA_DIMENSIONS,
72+
context,
73+
new XmlaOlap4jConnection.DimensionHandler(null),
74+
restrictions);
5375
}
5476

5577
public int hashCode() {
@@ -78,8 +100,7 @@ public NamedList<Cube> getCubes() throws OlapException {
78100
}
79101

80102
public NamedList<Dimension> getSharedDimensions() throws OlapException {
81-
// No shared dimensions
82-
return Olap4jUtil.cast(new NamedListImpl<XmlaOlap4jDimension>());
103+
return Olap4jUtil.cast(sharedDimensions);
83104
}
84105

85106
public Collection<Locale> getSupportedLocales() throws OlapException {

src/org/olap4j/impl/ArrayNamedListImpl.java

+32-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// This software is subject to the terms of the Eclipse Public License v1.0
33
// Agreement, available at the following URL:
44
// http://www.eclipse.org/legal/epl-v10.html.
5-
// Copyright (C) 2007-2010 Julian Hyde
5+
// Copyright (C) 2007-2011 Julian Hyde
66
// All Rights Reserved.
77
// You must accept the terms of that agreement to use this software.
88
*/
@@ -11,6 +11,7 @@
1111
import org.olap4j.metadata.NamedList;
1212

1313
import java.util.ArrayList;
14+
import java.util.Collection;
1415

1516
/**
1617
* Implementation of {@link org.olap4j.metadata.NamedList} which uses
@@ -29,6 +30,36 @@ public abstract class ArrayNamedListImpl<T>
2930
extends ArrayList<T>
3031
implements NamedList<T>
3132
{
33+
/**
34+
* Creates an empty list with the specified initial capacity.
35+
*
36+
* @param initialCapacity the initial capacity of the list
37+
* @exception IllegalArgumentException if the specified initial capacity
38+
* is negative
39+
*/
40+
public ArrayNamedListImpl(int initialCapacity) {
41+
super(initialCapacity);
42+
}
43+
44+
/**
45+
* Creates an empty list.
46+
*/
47+
public ArrayNamedListImpl() {
48+
super();
49+
}
50+
51+
/**
52+
* Creates a list containing the elements of the specified
53+
* collection, in the order they are returned by the collection's
54+
* iterator.
55+
*
56+
* @param c the collection whose elements are to be placed into this list
57+
* @throws NullPointerException if the specified collection is null
58+
*/
59+
public ArrayNamedListImpl(Collection<? extends T> c) {
60+
super(c);
61+
}
62+
3263
protected abstract String getName(T t);
3364

3465
public T get(String name) {

src/org/olap4j/impl/NamedListImpl.java

+33-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
// This software is subject to the terms of the Eclipse Public License v1.0
44
// Agreement, available at the following URL:
55
// http://www.eclipse.org/legal/epl-v10.html.
6-
// Copyright (C) 2007-2010 Julian Hyde
6+
// Copyright (C) 2007-2011 Julian Hyde
77
// All Rights Reserved.
88
// You must accept the terms of that agreement to use this software.
99
*/
1010
package org.olap4j.impl;
1111

12+
import java.util.Collection;
13+
1214
/**
1315
* Implementation of {@link org.olap4j.metadata.NamedList} which uses
1416
* {@link java.util.ArrayList} for storage and assumes that elements implement
@@ -21,6 +23,36 @@
2123
public class NamedListImpl<T extends Named>
2224
extends ArrayNamedListImpl<T>
2325
{
26+
/**
27+
* Creates an empty list with the specified initial capacity.
28+
*
29+
* @param initialCapacity the initial capacity of the list
30+
* @exception IllegalArgumentException if the specified initial capacity
31+
* is negative
32+
*/
33+
public NamedListImpl(int initialCapacity) {
34+
super(initialCapacity);
35+
}
36+
37+
/**
38+
* Creates an empty list.
39+
*/
40+
public NamedListImpl() {
41+
super();
42+
}
43+
44+
/**
45+
* Creates a list containing the elements of the specified
46+
* collection, in the order they are returned by the collection's
47+
* iterator.
48+
*
49+
* @param c the collection whose elements are to be placed into this list
50+
* @throws NullPointerException if the specified collection is null
51+
*/
52+
public NamedListImpl(Collection<? extends T> c) {
53+
super(c);
54+
}
55+
2456
protected final String getName(T t) {
2557
return t.getName();
2658
}

src/org/olap4j/impl/Pair.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// This software is subject to the terms of the Eclipse Public License v1.0
33
// Agreement, available at the following URL:
44
// http://www.eclipse.org/legal/epl-v10.html.
5-
// Copyright (C) 2007-2010 Julian Hyde
5+
// Copyright (C) 2007-2011 Julian Hyde
66
// All Rights Reserved.
77
// You must accept the terms of that agreement to use this software.
88
*/
@@ -63,7 +63,7 @@ public int compareTo(Pair<L, R> that) {
6363
}
6464

6565
public String toString() {
66-
return "<" + left + ", " + ">";
66+
return "<" + left + ", " + right + ">";
6767
}
6868

6969
// implement Map.Entry

testsrc/org/olap4j/ConnectionTest.java

+28
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,34 @@ public void testMetadata() throws Exception {
20312031
measureNameSet);
20322032
}
20332033

2034+
/**
2035+
* Test case for {@link org.olap4j.metadata.Schema#getSharedDimensions()}.
2036+
* Bug 3375355, "getSharedDimensions returns empty result".
2037+
*/
2038+
public void testSchemaGetSharedDimensions() throws Exception {
2039+
Class.forName(tester.getDriverClassName());
2040+
connection = tester.createConnection();
2041+
OlapConnection olapConnection =
2042+
tester.getWrapper().unwrap(connection, OlapConnection.class);
2043+
final List<String> list = new ArrayList<String>();
2044+
final NamedList<Dimension> sharedDimensions =
2045+
olapConnection.getOlapSchema().getSharedDimensions();
2046+
for (Dimension dimension : sharedDimensions) {
2047+
list.add(dimension.getName());
2048+
}
2049+
2050+
// note that, per specification, list is sorted
2051+
assertEquals(
2052+
Arrays.asList(
2053+
"Product",
2054+
"Store",
2055+
"Store Size in SQFT",
2056+
"Store Type",
2057+
"Time",
2058+
"Warehouse"),
2059+
list);
2060+
}
2061+
20342062
/**
20352063
* Testcase for bug 3312701, "VirtualCube doesn't show
20362064
* Calculated Members"

0 commit comments

Comments
 (0)