Skip to content

Commit

Permalink
Make Property.Datatype a top-level enum; a few methods now throw Olap…
Browse files Browse the repository at this point in the history
…Exception; add methods to metadata classes.

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@50 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Dec 10, 2007
1 parent 863a7c4 commit 88d7976
Show file tree
Hide file tree
Showing 20 changed files with 866 additions and 197 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<property file="${project.location}/test.properties"/>
<property name="project.build.debug" value="on"/>
<property name="name" value="olap4j"/>
<property name="version" value="0.9.2"/>
<property name="version" value="0.9.3"/>
<property name="dist.name" value="${name}-${version}" />

<!-- properties related to paths -->
Expand Down
102 changes: 96 additions & 6 deletions doc/olap4j_fs.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h1>olap4j Specification</h1>
Version: 0.9 (beta)<br>
Revision: $Id$
(<a href="http://olap4j.svn.sourceforge.net/viewvc/olap4j/trunk/doc/olap4j_fs.html?view=log">log</a>)<br>
Last modified: December 2<sup>nd</sup>, 2007.</p>
Last modified: December 10<sup>th</sup>, 2007.</p>
<hr noshade="noshade">

<h2><a name="Contents">Contents</a></h2>
Expand Down Expand Up @@ -148,6 +148,8 @@ <h2><a name="Contents">Contents</a></h2>
<li><a href="#Member">The Member interface</a></li>
<li><a href="#Measure">The Measure interface</a></li>
<li><a href="#Property">The Property interface</a></li>
<li><a href="#NamedSet">The NamedSet interface</a></li>
<li><a href="#Datatype">The Datatype enum</a></li>
</ol></li>
<li>
<a href="#The_OlapDatabaseMetaData_interface_and_methods_which_return_schema_rowsets">The OlapDatabaseMetaData interface, and schema result sets</a><ol>
Expand Down Expand Up @@ -1302,6 +1304,7 @@ <h5>2.7.2.4. <a name="Cube">The Cube interface</a></h5>

<ul>
<li><code>NamedList&lt;Dimension&gt; getDimensions()</code></li>
<li><code>NamedList&lt;Hierarchy&gt; getHierarchies()</code></li>
<li><code>List&lt;Measure&gt; getMeasures()</code></li>
<li><code>NamedList&lt;NamedSet&gt; getSets()</code></li>
<li><code>Schema getSchema()</code></li>
Expand Down Expand Up @@ -1354,6 +1357,7 @@ <h5>2.7.2.7. <a name="Level">The Level interface</a></h5>
<li><code>Level.Type getLevelType()</code></li>
<li><code>NamedList&lt;Property&gt; getProperties()</code></li>
<li><code>List&lt;Member&gt; getMembers()</code></li>
<li><code>int getCardinality()</code></li>
</ul>
<h5>2.7.2.8. <a name="Member">The Member interface</a></h5>
<p>A <a class="javadoc" href="api/org/olap4j/metadata/Member.html">Member</a>&nbsp;
Expand All @@ -1378,6 +1382,7 @@ <h5>2.7.2.8. <a name="Member">The Member interface</a></h5>
<li><code>int getOrdinal()</code></li>
<li><code>boolean isHidden()</code></li>
<li><code>Member getDataMember()</code></li>
<li><code>int getChildMemberCount()</code></li>
</ul>

<h5>2.7.2.9. <a name="Measure">The Measure interface</a></h5>
Expand All @@ -1388,6 +1393,13 @@ <h5>2.7.2.9. <a name="Measure">The Measure interface</a></h5>
value of each cell, and is usually numeric.</p>

<p>Every measure is a member of a special dimension called &quot;Measures&quot;.</p>

<ul>
<li><code>boolean isVisible()</code></li>
<li><code>Aggregator getAggregator()</code></li>
<li><code>Datatype getDataType()</code></li>
</ul>

<h5>2.7.2.10. <a name="Property">The Property interface</a></h5>
<p><a class="javadoc" href="api/org/olap4j/metadata/Property.html">Property</a>&nbsp;
(extends <a class="javadoc" href="api/org/olap4j/metadata/MetadataElement.html">
Expand All @@ -1407,22 +1419,100 @@ <h5>2.7.2.10. <a name="Property">The Property interface</a></h5>
&nbsp;&nbsp;&nbsp; Property.StandardMemberProperty.CATALOG_NAME);</div>
<p>Members:</p>
<ul>
<li><code>Datatype getType()</code></li>
<li><code>Scope getScope()</code></li>
<li><code>enum Scope { MEMBER, CELL }</code></li>
<li><code>enum Datatype { STRING, OTHER, NUMERIC, BOOLEAN }</code></li>
<li><code>Datatype getDatatype()</code></li>
<li><code>Set&lt;TypeFlag&gt; getType()</code></li>
<li><code>ContentType getContentType()</code></li>
<li><code>enum TypeFlag { MEMBER, CELL, SYSTEM, BLOB }</code></li>
<li><code>enum StandardMemberProperty implements Property { CATALOG_NAME, SCHEMA_NAME, CUBE_NAME, ...
}</code></li>
<li><code>enum StandardCellProperty implements Property { BACK_COLOR, CELL_EVALUATION_LIST, ... }</code></li>
<li><code>enum ContentType { REGULAR, ID, RELATION_TO_PARENT, ... }</code></li>
</ul>
<h5>2.7.2.11. <a name="The_NamedSet_interface">The NamedSet interface</a></h5>
<h5>2.7.2.11. <a name="NamedSet">The NamedSet interface</a></h5>
<p>A <a class="javadoc" href="api/org/olap4j/metadata/NamedSet.html">NamedSet</a>
(extends <a class="javadoc" href="api/org/olap4j/metadata/MetadataElement.html">
MetadataElement</a>) describes a set whose value is determined by an MDX
expression. It belongs to a cube.</p>
<ul>
<li><code>Cube getCube()</code></li>
<li><code>Expression getExpression()</code></li>
</ul>

<h5>2.7.2.12. <a name="Datatype">The Datatype enum</a></h5>

<p>The <a class="javadoc" href="api/org/olap4j/metadata/Datatype.html">
Datatype</a> enum describes the type of property and measure values. Because
olap4j drivers need to interoperate with OLE DB for OLAP and XMLA systems,
Datatype values have the same ordinals as in the OLE DB specification, and we
show here the
name and description of the corresponding type in the OLE DB specification. The table shows
the analogous Java type, if there is one.</p>

<table>
<tbody>
<tr>
<th>Datatype</th>
<th>Java&nbsp;type</th>
<th>OLE DB type</th>
<th>Description</th>
</tr>
<tr>
<td>INTEGER</td>
<td>int</td>
<td>DBTYPE_I4</td>
<td>A four-byte, signed integer: INTEGER</td>
</tr>
<tr>
<td>DOUBLE</td>
<td>double</td>
<td>DBTYPE_R8</td>
<td>A double-precision floating-point value: Double</td>
</tr>
<tr>
<td>CURRENCY</td>
<td>&nbsp;</td>
<td>DBTYPE_CY</td>
<td>A currency value: LARGE_INTEGER, Currency is a fixed-point number with four digits to the right of the decimal point. It is stored in an eight-byte signed integer, scaled by 10,000.</td>
</tr>
<tr>
<td>BOOLEAN</td>
<td>boolean</td>
<td>DBTYPE_BOOL</td>
<td>A Boolean value stored in the same way as in Automation: VARIANT_BOOL; 0 means false and ~0 (bitwise, the value is not 0; that is, all bits are set to 1) means true.</td>
</tr>
<tr>
<td>VARIANT</td>
<td>Object</td>
<td>DBTYPE_VARIANT</td>
<td>An Automation VARIANT</td>
</tr>
<tr>
<td>UNSIGNED_SHORT</td>
<td>-</td>
<td>DBTYPE_UI2</td>
<td>A two-byte, unsigned integer</td>
</tr>
<tr>
<td>UNSIGNED_INTEGER</td>
<td>-</td>
<td>DBTYPE_UI4</td>
<td>A four-byte, unsigned integer</td>
</tr>
<tr>
<td>LARGE_INTEGER</td>
<td>long</td>
<td>DBTYPE_I8</td>
<td>An eight-byte, signed integer: LARGE_INTEGER</td>
</tr>
<tr>
<td>STRING</td>
<td>String</td>
<td>DBTYPE_WSTR</td>
<td>A null-terminated Unicode character string: wchar_t[length]; If DBTYPE_WSTR is used by itself, the number of bytes allocated for the string, including the null-termination character, is specified by cbMaxLen in the DBBINDING structure. If DBTYPE_WSTR is combined with DBTYPE_BYREF, the number of bytes allocated for the string, including the null-termination character, is at least the length of the string plus two. In either case, the actual length of the string is determined from the bound length value. The maximum length of the string is the number of allocated bytes divided by sizeof(wchar_t) and truncated to the nearest integer.</td>
</tr>
</tbody>
</table>

<h4>2.7.3.
<a name="The_OlapDatabaseMetaData_interface_and_methods_which_return_schema_rowsets">The OlapDatabaseMetaData
interface, and methods which return schema rowsets</a></h4>
Expand Down
73 changes: 47 additions & 26 deletions src/mondrian/olap4j/MondrianOlap4jCube.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
*/
package mondrian.olap4j;

import mondrian.olap.Id;
import mondrian.olap.SchemaReader;
import org.olap4j.metadata.*;
import org.olap4j.OlapException;

import java.util.*;

Expand Down Expand Up @@ -64,10 +63,24 @@ public NamedList<Dimension> getDimensions() {
return (NamedList) list;
}

public NamedList<Hierarchy> getHierarchies() {
List<MondrianOlap4jHierarchy> list =
new NamedListImpl<MondrianOlap4jHierarchy>();
for (mondrian.olap.Dimension dimension : cube.getDimensions()) {
for (mondrian.olap.Hierarchy hierarchy : dimension.getHierarchies()) {
list.add(
new MondrianOlap4jHierarchy(
olap4jSchema, hierarchy));
}
}
return (NamedList) list;
}

public List<Measure> getMeasures() {
final Level measuresLevel =
getDimensions().get("Measures").getDefaultHierarchy()
.getLevels().get(0);
final MondrianOlap4jLevel measuresLevel =
(MondrianOlap4jLevel)
getDimensions().get("Measures").getDefaultHierarchy()
.getLevels().get(0);
return (List) measuresLevel.getMembers();
}

Expand Down Expand Up @@ -104,15 +117,18 @@ public String getDescription(Locale locale) {
return cube.getDescription();
}

public Member lookupMember(String... nameParts) {
public MondrianOlap4jMember lookupMember(String... nameParts) {
final MondrianOlap4jConnection olap4jConnection =
olap4jSchema.olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection;
final SchemaReader schemaReader =
final mondrian.olap.SchemaReader schemaReader =
cube.getSchemaReader(olap4jConnection.connection.getRole());

final List<Id.Segment> segmentList = new ArrayList<Id.Segment>();
final List<mondrian.olap.Id.Segment> segmentList =
new ArrayList<mondrian.olap.Id.Segment>();
for (String namePart : nameParts) {
segmentList.add(new Id.Segment(namePart, Id.Quoting.QUOTED));
segmentList.add(
new mondrian.olap.Id.Segment(
namePart, mondrian.olap.Id.Quoting.QUOTED));
}
final mondrian.olap.Member member =
schemaReader.getMemberByUniqueName(segmentList, false);
Expand All @@ -124,24 +140,25 @@ public Member lookupMember(String... nameParts) {

public List<Member> lookupMembers(
Set<Member.TreeOp> treeOps,
String... nameParts)
String... nameParts) throws OlapException
{
final Member member = lookupMember(nameParts);
final MondrianOlap4jMember member = lookupMember(nameParts);
if (member == null) {
return Collections.emptyList();
}

// Add ancestors and/or the parent. Ancestors are prepended, to ensure
// hierarchical order.
final List<Member> list = new ArrayList<Member>();
final List<MondrianOlap4jMember> list =
new ArrayList<MondrianOlap4jMember>();
if (treeOps.contains(Member.TreeOp.ANCESTORS)) {
for (Member m = member.getParentMember();
for (MondrianOlap4jMember m = member.getParentMember();
m != null;
m = m.getParentMember()) {
list.add(0, m);
}
} else if (treeOps.contains(Member.TreeOp.PARENT)) {
final Member parentMember = member.getParentMember();
final MondrianOlap4jMember parentMember = member.getParentMember();
if (parentMember != null) {
list.add(parentMember);
}
Expand All @@ -150,21 +167,22 @@ public List<Member> lookupMembers(
// Add siblings. Siblings which occur after the member are deferred,
// because they occur after children and descendants in the
// hierarchical ordering.
List<Member> remainingSiblingsList = null;
List<MondrianOlap4jMember> remainingSiblingsList = null;
if (treeOps.contains(Member.TreeOp.SIBLINGS)) {
final Member parentMember = member.getParentMember();
NamedList<? extends Member> siblingMembers;
final MondrianOlap4jMember parentMember = member.getParentMember();
NamedList<MondrianOlap4jMember> siblingMembers;
if (parentMember != null) {
siblingMembers = parentMember.getChildMembers();
} else {
siblingMembers = member.getHierarchy().getRootMembers();
siblingMembers =
(NamedList) member.getHierarchy().getRootMembers();
}
List<Member> targetList = list;
for (Member siblingMember : siblingMembers) {
List<MondrianOlap4jMember> targetList = list;
for (MondrianOlap4jMember siblingMember : siblingMembers) {
if (siblingMember.equals(member)) {
targetList =
remainingSiblingsList =
new ArrayList<Member>();
new ArrayList<MondrianOlap4jMember>();
} else {
targetList.add(siblingMember);
}
Expand All @@ -178,12 +196,12 @@ public List<Member> lookupMembers(

// Add descendants and/or children.
if (treeOps.contains(Member.TreeOp.DESCENDANTS)) {
for (Member childMember : member.getChildMembers()) {
for (MondrianOlap4jMember childMember : member.getChildMembers()) {
list.add(childMember);
addDescendants(list, childMember);
}
} else if (treeOps.contains(Member.TreeOp.CHILDREN)) {
for (Member childMember : member.getChildMembers()) {
for (MondrianOlap4jMember childMember : member.getChildMembers()) {
list.add(childMember);
}
}
Expand All @@ -192,11 +210,14 @@ public List<Member> lookupMembers(
if (remainingSiblingsList != null) {
list.addAll(remainingSiblingsList);
}
return list;
return (List) list;
}

private static void addDescendants(List<Member> list, Member member) {
for (Member childMember : member.getChildMembers()) {
private static void addDescendants(
List<MondrianOlap4jMember> list,
MondrianOlap4jMember member)
{
for (MondrianOlap4jMember childMember : member.getChildMembers()) {
list.add(childMember);
addDescendants(list, childMember);
}
Expand Down
17 changes: 8 additions & 9 deletions src/mondrian/olap4j/MondrianOlap4jLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
*/
package mondrian.olap4j;

import mondrian.olap.*;
import org.olap4j.metadata.*;
import org.olap4j.metadata.Dimension;
import org.olap4j.metadata.Hierarchy;
import org.olap4j.metadata.Level;
import org.olap4j.metadata.Member;
import org.olap4j.metadata.Property;

import java.util.*;

Expand All @@ -31,7 +25,7 @@ class MondrianOlap4jLevel implements Level, Named {
private final MondrianOlap4jSchema olap4jSchema;
private final mondrian.olap.Level level;

public MondrianOlap4jLevel(
MondrianOlap4jLevel(
MondrianOlap4jSchema olap4jSchema,
mondrian.olap.Level level)
{
Expand Down Expand Up @@ -83,7 +77,7 @@ protected String getName(Property property) {
public List<Member> getMembers() {
final MondrianOlap4jConnection olap4jConnection =
olap4jSchema.olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection;
final SchemaReader schemaReader =
final mondrian.olap.SchemaReader schemaReader =
olap4jConnection.connection.getSchemaReader();
final mondrian.olap.Member[] levelMembers =
schemaReader.getLevelMembers(level, true);
Expand Down Expand Up @@ -112,7 +106,12 @@ public String getCaption(Locale locale) {
}

public String getDescription(Locale locale) {
throw new UnsupportedOperationException();
// todo: localize
return level.getDescription();
}

public int getCardinality() {
return level.getApproxRowCount();
}
}

Expand Down
Loading

0 comments on commit 88d7976

Please sign in to comment.