From 26f68622a5d182dd41b7dba8bd7a51192adb1dbe Mon Sep 17 00:00:00 2001 From: Julian Hyde Date: Mon, 25 Jul 2011 21:42:07 +0000 Subject: [PATCH] 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 --- .../driver/xmla/XmlaOlap4jConnection.java | 13 ++++--- .../driver/xmla/XmlaOlap4jHierarchy.java | 5 ++- .../olap4j/driver/xmla/XmlaOlap4jSchema.java | 33 ++++++++++++++---- src/org/olap4j/impl/ArrayNamedListImpl.java | 33 +++++++++++++++++- src/org/olap4j/impl/NamedListImpl.java | 34 ++++++++++++++++++- src/org/olap4j/impl/Pair.java | 4 +-- testsrc/org/olap4j/ConnectionTest.java | 28 +++++++++++++++ 7 files changed, 132 insertions(+), 18 deletions(-) diff --git a/src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java b/src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java index 1a8df6f..e224481 100644 --- a/src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java +++ b/src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java @@ -1093,9 +1093,10 @@ public void handle( static class DimensionHandler extends HandlerImpl { 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, @@ -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); + } } } diff --git a/src/org/olap4j/driver/xmla/XmlaOlap4jHierarchy.java b/src/org/olap4j/driver/xmla/XmlaOlap4jHierarchy.java index cbe8478..d1f77c3 100644 --- a/src/org/olap4j/driver/xmla/XmlaOlap4jHierarchy.java +++ b/src/org/olap4j/driver/xmla/XmlaOlap4jHierarchy.java @@ -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. */ @@ -101,8 +101,7 @@ public NamedList getRootMembers() throws OlapException { olap4jDimension.olap4jCube.getMetadataReader().getLevelMembers( levels.get(0)); final NamedList list = - new NamedListImpl(); - list.addAll(memberList); + new NamedListImpl(memberList); return Olap4jUtil.cast(list); } diff --git a/src/org/olap4j/driver/xmla/XmlaOlap4jSchema.java b/src/org/olap4j/driver/xmla/XmlaOlap4jSchema.java index e938627..72f3b97 100644 --- a/src/org/olap4j/driver/xmla/XmlaOlap4jSchema.java +++ b/src/org/olap4j/driver/xmla/XmlaOlap4jSchema.java @@ -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. */ @@ -26,10 +26,12 @@ class XmlaOlap4jSchema implements Schema, Named { final XmlaOlap4jCatalog olap4jCatalog; private final String name; final NamedList cubes; + private final NamedList sharedDimensions; XmlaOlap4jSchema( XmlaOlap4jCatalog olap4jCatalog, String name) + throws OlapException { if (olap4jCatalog == null) { throw new NullPointerException("Catalog cannot be null."); @@ -40,16 +42,36 @@ class XmlaOlap4jSchema implements Schema, Named { this.olap4jCatalog = olap4jCatalog; this.name = name; - this.cubes = new DeferredNamedListImpl( - 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( + XmlaOlap4jConnection.MetadataRequest.MDSCHEMA_CUBES, + context, new XmlaOlap4jConnection.CubeHandler(), null); + + String[] restrictions = { + "CATALOG_NAME", olap4jCatalog.getName(), + "SCHEMA_NAME", getName(), + "CUBE_NAME", "" + }; + + this.sharedDimensions = new DeferredNamedListImpl( + XmlaOlap4jConnection.MetadataRequest.MDSCHEMA_DIMENSIONS, + context, + new XmlaOlap4jConnection.DimensionHandler(null), + restrictions); } public int hashCode() { @@ -78,8 +100,7 @@ public NamedList getCubes() throws OlapException { } public NamedList getSharedDimensions() throws OlapException { - // No shared dimensions - return Olap4jUtil.cast(new NamedListImpl()); + return Olap4jUtil.cast(sharedDimensions); } public Collection getSupportedLocales() throws OlapException { diff --git a/src/org/olap4j/impl/ArrayNamedListImpl.java b/src/org/olap4j/impl/ArrayNamedListImpl.java index 31eece4..fda4570 100644 --- a/src/org/olap4j/impl/ArrayNamedListImpl.java +++ b/src/org/olap4j/impl/ArrayNamedListImpl.java @@ -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. */ @@ -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 @@ -29,6 +30,36 @@ public abstract class ArrayNamedListImpl extends ArrayList implements NamedList { + /** + * 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 c) { + super(c); + } + protected abstract String getName(T t); public T get(String name) { diff --git a/src/org/olap4j/impl/NamedListImpl.java b/src/org/olap4j/impl/NamedListImpl.java index 4607cc3..b1759a2 100644 --- a/src/org/olap4j/impl/NamedListImpl.java +++ b/src/org/olap4j/impl/NamedListImpl.java @@ -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 @@ -21,6 +23,36 @@ public class NamedListImpl extends ArrayNamedListImpl { + /** + * 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 c) { + super(c); + } + protected final String getName(T t) { return t.getName(); } diff --git a/src/org/olap4j/impl/Pair.java b/src/org/olap4j/impl/Pair.java index 7402206..986f956 100644 --- a/src/org/olap4j/impl/Pair.java +++ b/src/org/olap4j/impl/Pair.java @@ -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. */ @@ -63,7 +63,7 @@ public int compareTo(Pair that) { } public String toString() { - return "<" + left + ", " + ">"; + return "<" + left + ", " + right + ">"; } // implement Map.Entry diff --git a/testsrc/org/olap4j/ConnectionTest.java b/testsrc/org/olap4j/ConnectionTest.java index 5cbf2cf..da605b9 100644 --- a/testsrc/org/olap4j/ConnectionTest.java +++ b/testsrc/org/olap4j/ConnectionTest.java @@ -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 list = new ArrayList(); + final NamedList 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"