Skip to content

Commit

Permalink
MONDRIAN: XMLA server: MDSCHEMA_DIMENSIONS (also MDSCHEMA_HIERARCHIES…
Browse files Browse the repository at this point in the history
…, ...)

    returns shared dimensions if CUBE_NAME is the empty string.

    Add class Composite (utilities for composite collections).

[git-p4: depot-paths = "//open/mondrian/": change = 14492]
  • Loading branch information
julianhyde committed Jul 26, 2011
1 parent 0667356 commit c2808d7
Show file tree
Hide file tree
Showing 9 changed files with 758 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/main/mondrian/olap4j/MondrianOlap4jExtra.java
Expand Up @@ -247,9 +247,9 @@ public List<String> getSchemaRoleNames(Schema schema) {
}

public String getCubeType(Cube cube) {
MondrianOlap4jCube olap4jCube = (MondrianOlap4jCube) cube;
return
((RolapCube) olap4jCube.cube).isVirtual()
(cube instanceof MondrianOlap4jCube)
&& ((RolapCube) ((MondrianOlap4jCube) cube).cube).isVirtual()
? RowsetDefinition.MdschemaCubesRowset.MD_CUBTYPE_VIRTUAL_CUBE
: RowsetDefinition.MdschemaCubesRowset.MD_CUBTYPE_CUBE;
}
Expand Down
26 changes: 19 additions & 7 deletions src/main/mondrian/olap4j/MondrianOlap4jSchema.java
Expand Up @@ -3,7 +3,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 @@ -16,9 +16,7 @@
import org.olap4j.OlapException;
import org.olap4j.impl.*;

import java.util.Locale;
import java.util.Collection;
import java.util.Collections;
import java.util.*;

import mondrian.olap.Hierarchy;

Expand Down Expand Up @@ -73,13 +71,27 @@ public NamedList<Cube> getCubes() throws OlapException {
}

public NamedList<Dimension> getSharedDimensions() throws OlapException {
NamedList<MondrianOlap4jDimension> list =
new NamedListImpl<MondrianOlap4jDimension>();
final MondrianOlap4jConnection olap4jConnection =
olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection;
final SortedSet<MondrianOlap4jDimension> dimensions =
new TreeSet<MondrianOlap4jDimension>(
new Comparator<MondrianOlap4jDimension>() {
public int compare(
MondrianOlap4jDimension o1,
MondrianOlap4jDimension o2)
{
return o1.getName().compareTo(o2.getName());
}
}
);
for (Hierarchy hierarchy : schema.getSharedHierarchies()) {
list.add(olap4jConnection.toOlap4j(hierarchy.getDimension()));
dimensions.add(
olap4jConnection.toOlap4j(hierarchy.getDimension()));
}
mondrian.util.Bug.olap4jUpgrade("use NamedListImpl(Collection)");
NamedList<MondrianOlap4jDimension> list =
new NamedListImpl<MondrianOlap4jDimension>();
list.addAll(dimensions);
return Olap4jUtil.cast(list);
}

Expand Down
151 changes: 151 additions & 0 deletions src/main/mondrian/util/Composite.java
@@ -0,0 +1,151 @@
/*
// $Id$
// 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) 2011-2011 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package mondrian.util;

import java.util.*;

/**
* Composite collections.
*
* @version $Id$
* @author jhyde
*/
public abstract class Composite {

/**
* Creates a composite list, inferring the element type from the arguments.
*
* @param lists One or more lists
* @param <T> element type
* @return composite list
*/
public static <T> List<T> of(
List<? extends T>... lists)
{
return CompositeList.<T>of(lists);
}

/**
* Creates a composite iterable, inferring the element type from the
* arguments.
*
* @param iterables One or more iterables
* @param <T> element type
* @return composite iterable
*/
public static <T> Iterable<T> of(
Iterable<? extends T>... iterables)
{
return new CompositeIterable<T>(iterables);
}

/**
* Creates a composite list, inferring the element type from the arguments.
*
* @param iterators One or more iterators
* @param <T> element type
* @return composite list
*/
public static <T> Iterator<T> of(
Iterator<? extends T>... iterators)
{
final Iterator[] iterators1 = (Iterator[]) iterators;
return new CompositeIterator<T>(iterators1);
}

private static class CompositeIterable<T> implements Iterable<T> {
private final Iterable<? extends T>[] iterables;

public CompositeIterable(Iterable<? extends T>[] iterables) {
this.iterables = iterables;
}

public Iterator<T> iterator() {
return new CompositeIterator(iterables);
}
}

private static class CompositeIterator<T> implements Iterator<T> {
private final Iterator<Iterator<T>> iteratorIterator;
private boolean hasNext;
private T next;
private Iterator<T> iterator;

public CompositeIterator(Iterator<T>[] iterables) {
this.iteratorIterator = Arrays.asList(iterables).iterator();
this.iterator = Collections.<T>emptyList().iterator();
this.hasNext = true;
advance();
}

public CompositeIterator(final Iterable<T>[] iterables) {
this.iteratorIterator =
new IterableIterator<T>(iterables);
Arrays.asList(iterables).iterator();
this.iterator = Collections.<T>emptyList().iterator();
this.hasNext = true;
advance();
}

private void advance() {
for (;;) {
if (iterator.hasNext()) {
next = iterator.next();
return;
}
if (!iteratorIterator.hasNext()) {
hasNext = false;
break;
}
iterator = iteratorIterator.next();
}
}

public boolean hasNext() {
return hasNext;
}

public T next() {
final T next1 = next;
advance();
return next1;
}

public void remove() {
throw new UnsupportedOperationException();
}
}

private static class IterableIterator<T>
implements Iterator<Iterator<T>>
{
private int i;
private final Iterable<T>[] iterables;

public IterableIterator(Iterable<T>[] iterables) {
this.iterables = iterables;
i = 0;
}

public boolean hasNext() {
return i < iterables.length;
}

public Iterator<T> next() {
return iterables[i++].iterator();
}

public void remove() {
throw new UnsupportedOperationException();
}
}
}

// End Composite.java
3 changes: 3 additions & 0 deletions src/main/mondrian/xmla/Rowset.java
Expand Up @@ -415,6 +415,9 @@ public Boolean apply(E element) {
final List<V> requiredValues = (List) restriction;
return new Util.Functor1<Boolean, E>() {
public Boolean apply(E element) {
if (element == null) {
return requiredValues.contains("");
}
V value = getter.apply(element);
return requiredValues.contains(value);
}
Expand Down

0 comments on commit c2808d7

Please sign in to comment.