Skip to content

Commit

Permalink
Add enums and constants related to XMLA (formerly in Mondrian).
Browse files Browse the repository at this point in the history
Add space-efficient maps ArrayMap and UnmodifiableArrayMap.


git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@298 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Jan 25, 2010
1 parent 5218d69 commit 2ab221b
Show file tree
Hide file tree
Showing 18 changed files with 1,798 additions and 263 deletions.
10 changes: 4 additions & 6 deletions src/org/olap4j/driver/xmla/XmlaOlap4jCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// 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-2008 Julian Hyde
// Copyright (C) 2007-2010 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package org.olap4j.driver.xmla;

import org.olap4j.*;
import org.olap4j.impl.ArrayMap;
import org.olap4j.impl.UnmodifiableArrayMap;
import org.olap4j.metadata.Property;

import java.sql.ResultSet;
Expand Down Expand Up @@ -42,12 +43,9 @@ class XmlaOlap4jCell implements Cell {
this.value = value;
this.formattedValue = formattedValue;

// Use emptyMap and ArrayMap for memory efficiency, because cells
// Use an ArrayMap for memory efficiency, because cells
// typically have few properties, but there are a lot of cells
this.propertyValues =
propertyValues.isEmpty()
? Collections.<Property, Object>emptyMap()
: new ArrayMap<Property, Object>(propertyValues);
this.propertyValues = UnmodifiableArrayMap.of(propertyValues);
}

public CellSet getCellSet() {
Expand Down
4 changes: 2 additions & 2 deletions src/org/olap4j/driver/xmla/XmlaOlap4jCellProperty.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-2008 Julian Hyde
// Copyright (C) 2007-2010 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -40,7 +40,7 @@ public Datatype getDatatype() {
}

public Set<TypeFlag> getType() {
return TypeFlag.forMask(TypeFlag.CELL.xmlaOrdinal);
return TypeFlag.CELL_TYPE_FLAG;
}

public String getName() {
Expand Down
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-2008 Julian Hyde
// Copyright (C) 2007-2010 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -43,7 +43,7 @@ public Datatype getDatatype() {
}

public Set<TypeFlag> getType() {
return TypeFlag.forMask(TypeFlag.MEMBER.xmlaOrdinal);
return TypeFlag.MEMBER_TYPE_FLAG;
}

public String getName() {
Expand Down
24 changes: 15 additions & 9 deletions src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ abstract class XmlaOlap4jConnection implements OlapConnection {
* Returns the error-handler
* @return Error-handler
*/
private final XmlaHelper getHelper() {
private XmlaHelper getHelper() {
return helper;
}

Expand Down Expand Up @@ -975,6 +975,7 @@ public void handle(

static class DimensionHandler extends HandlerImpl<XmlaOlap4jDimension> {
private final XmlaOlap4jCube cubeForCallback;

public DimensionHandler(XmlaOlap4jCube dimensionsByUname) {
this.cubeForCallback = dimensionsByUname;
}
Expand Down Expand Up @@ -1016,7 +1017,7 @@ public void handle(
final int dimensionType =
integerElement(row, "DIMENSION_TYPE");
final Dimension.Type type =
Dimension.Type.forXmlaOrdinal(dimensionType);
Dimension.Type.getDictionary().forOrdinal(dimensionType);
final String defaultHierarchyUniqueName =
stringElement(row, "DEFAULT_HIERARCHY");
final Integer dimensionOrdinal =
Expand Down Expand Up @@ -1117,6 +1118,7 @@ public void handle(
static class LevelHandler extends HandlerImpl<XmlaOlap4jLevel> {
public static final int MDLEVEL_TYPE_CALCULATED = 0x0002;
private final XmlaOlap4jCube cubeForCallback;

public LevelHandler(XmlaOlap4jCube cubeForCallback) {
this.cubeForCallback = cubeForCallback;
}
Expand Down Expand Up @@ -1161,7 +1163,7 @@ public void handle(
integerElement(row, "LEVEL_NUMBER");
final Integer levelTypeCode = integerElement(row, "LEVEL_TYPE");
final Level.Type levelType =
Level.Type.forXmlaOrdinal(levelTypeCode);
Level.Type.getDictionary().forOrdinal(levelTypeCode);
boolean calculated = (levelTypeCode & MDLEVEL_TYPE_CALCULATED) != 0;
final int levelCardinality =
integerElement(row, "LEVEL_CARDINALITY");
Expand All @@ -1178,6 +1180,7 @@ public void handle(

static class MeasureHandler extends HandlerImpl<XmlaOlap4jMeasure> {
private final XmlaOlap4jDimension measuresDimension;

public MeasureHandler(XmlaOlap4jDimension measuresDimension) {
this.measuresDimension = measuresDimension;
}
Expand Down Expand Up @@ -1213,10 +1216,11 @@ public void handle(
final String description =
stringElement(row, "DESCRIPTION");
final Measure.Aggregator measureAggregator =
Measure.Aggregator.forXmlaOrdinal(
integerElement(row, "MEASURE_AGGREGATOR"));
Measure.Aggregator.getDictionary().forOrdinal(
integerElement(
row, "MEASURE_AGGREGATOR"));
final Datatype datatype =
Datatype.forXmlaOrdinal(
Datatype.getDictionary().forOrdinal(
integerElement(row, "DATA_TYPE"));
final boolean measureIsVisible =
booleanElement(row, "MEASURE_IS_VISIBLE");
Expand Down Expand Up @@ -1533,6 +1537,7 @@ public void handle(
}

static class PropertyHandler extends HandlerImpl<XmlaOlap4jProperty> {

public void handle(
Element row,
Context context, List<XmlaOlap4jProperty> list) throws OlapException
Expand Down Expand Up @@ -1561,17 +1566,18 @@ public void handle(
String caption = stringElement(row, "PROPERTY_CAPTION");
String name = stringElement(row, "PROPERTY_NAME");
Datatype dataType =
Datatype.forXmlaOrdinal(
Datatype.getDictionary().forOrdinal(
integerElement(row, "DATA_TYPE"));
final Integer contentTypeOrdinal =
integerElement(row, "PROPERTY_CONTENT_TYPE");
Property.ContentType contentType =
contentTypeOrdinal == null
? null
: Property.ContentType.forXmlaOrdinal(contentTypeOrdinal);
: Property.ContentType.getDictionary().forOrdinal(
contentTypeOrdinal);
int propertyType = integerElement(row, "PROPERTY_TYPE");
Set<Property.TypeFlag> type =
Property.TypeFlag.forMask(propertyType);
Property.TypeFlag.getDictionary().forMask(propertyType);
list.add(
new XmlaOlap4jProperty(
uniqueName, name, caption, description, dataType, type,
Expand Down
9 changes: 2 additions & 7 deletions src/org/olap4j/driver/xmla/XmlaOlap4jMember.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-2008 Julian Hyde
// Copyright (C) 2007-2010 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -81,12 +81,7 @@ class XmlaOlap4jMember
this.parentMemberUniqueName = parentMemberUniqueName;
this.type = type;
this.childMemberCount = childMemberCount;
if (propertyValueMap.isEmpty()) {
this.propertyValueMap = Collections.emptyMap();
} else {
this.propertyValueMap =
new ArrayMap<Property, Object>(propertyValueMap);
}
this.propertyValueMap = UnmodifiableArrayMap.of(propertyValueMap);
}

public int hashCode() {
Expand Down
48 changes: 44 additions & 4 deletions src/org/olap4j/impl/ArrayMap.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-2009 Julian Hyde
// Copyright (C) 2007-2010 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -53,6 +53,27 @@ public ArrayMap(Map<K, V> map) {
}
}

/**
* Returns an array map with given contents.
*
* @param key First key
* @param value First value
* @param keyValues Second and sequent key/value pairs
* @param <K> Key type
* @param <V> Value type
* @return Map with given contents
*/
public static <K, V> Map<K, V> of(
K key,
V value,
Object... keyValues)
{
// Because ArrayMap is so bad at bulk inserts, it makes sense to build
// another map (HashMap) just so we can populate the ArrayMap in one
// shot.
return new ArrayMap<K, V>(Olap4jUtil.mapOf(key, value, keyValues));
}

public boolean equals(Object o) {
if (o == this) {
return true;
Expand All @@ -65,9 +86,7 @@ public boolean equals(Object o) {
return false;
}
try {
Iterator<Entry<K, V>> i = entrySet().iterator();
while (i.hasNext()) {
Entry<K, V> e = i.next();
for (Entry<K, V> e : entrySet()) {
K key = e.getKey();
V value = e.getValue();
if (value == null) {
Expand Down Expand Up @@ -210,6 +229,27 @@ public Set<Entry<K, V>> entrySet() {
return new EntrySet();
}

public String toString() {
Iterator<Entry<K, V>> i = entrySet().iterator();
if (! i.hasNext()) {
return "{}";
}
StringBuilder sb = new StringBuilder();
sb.append('{');
for (;;) {
Entry<K, V> e = i.next();
K key = e.getKey();
V value = e.getValue();
sb.append(key == this ? "(this Map)" : key);
sb.append('=');
sb.append(value == this ? "(this Map)" : value);
if (! i.hasNext()) {
return sb.append('}').toString();
}
sb.append(", ");
}
}

private class KeySet extends AbstractSet<K> {
public Iterator<K> iterator() {
return new Iterator<K>() {
Expand Down
34 changes: 33 additions & 1 deletion src/org/olap4j/impl/Olap4jUtil.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-2008 Julian Hyde
// Copyright (C) 2007-2010 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -143,6 +143,38 @@ public static <T> NamedList<T> cast(NamedList<?> list) {
return (NamedList<T>) list;
}

/**
* Returns a hashmap with given contents.
*
* <p>Use this method in initializers. Type parameters are inferred from
* context, and the contents are initialized declaratively. For example,
*
* <blockquote><code>Map&lt;String, Integer&gt; population =<br/>
* &nbsp;&nbsp;Olap4jUtil.mapOf(<br/>
* &nbsp;&nbsp;&nbsp;&nbsp;"UK", 65000000,<br/>
* &nbsp;&nbsp;&nbsp;&nbsp;"USA", 300000000);</code></blockquote>
*
* @see org.olap4j.impl.UnmodifiableArrayMap#of(Object, Object, Object...)
* @see org.olap4j.impl.ArrayMap#of(Object, Object, Object...)
*
* @param key First key
* @param value First value
* @param keyValues Second and sequent key/value pairs
* @param <K> Key type
* @param <V> Value type
* @return Map with given contents
*/
public static <K, V> Map<K, V> mapOf(K key, V value, Object... keyValues)
{
final Map<K, V> map = new LinkedHashMap<K, V>(1 + keyValues.length);
map.put(key, value);
for (int i = 0; i < keyValues.length;) {
//noinspection unchecked
map.put((K) keyValues[i++], (V) keyValues[i++]);
}
return map;
}

/**
* Returns an exception indicating that we didn't expect to find this value
* here.
Expand Down
Loading

0 comments on commit 2ab221b

Please sign in to comment.