Skip to content

Commit

Permalink
Change enumerated values of Level.Type to uppercase, and
Browse files Browse the repository at this point in the history
add new values such as TIME_HALF_YEAR, TIME_HOURS, TIME_UNDEFINED.


git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@242 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed May 19, 2009
1 parent 5b2a39d commit 4bd09de
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 21 deletions.
8 changes: 6 additions & 2 deletions src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,8 @@ public void handle(
}

static class LevelHandler extends HandlerImpl<XmlaOlap4jLevel> {
public static final int MDLEVEL_TYPE_CALCULATED = 0x0002;

public void handle(Element row, Context context, List<XmlaOlap4jLevel> list) {
/*
Example:
Expand Down Expand Up @@ -987,15 +989,17 @@ public void handle(Element row, Context context, List<XmlaOlap4jLevel> list) {
stringElement(row, "DESCRIPTION");
final int levelNumber =
integerElement(row, "LEVEL_NUMBER");
final Integer levelTypeCode = integerElement(row, "LEVEL_TYPE");
final Level.Type levelType =
Level.Type.forXmlaOrdinal(integerElement(row, "LEVEL_TYPE"));
Level.Type.forXmlaOrdinal(levelTypeCode);
boolean calculated = (levelTypeCode & MDLEVEL_TYPE_CALCULATED) != 0;
final int levelCardinality =
integerElement(row, "LEVEL_CARDINALITY");
list.add(
new XmlaOlap4jLevel(
context.getHierarchy(row), levelUniqueName, levelName,
levelCaption, description, levelNumber, levelType,
levelCardinality));
calculated, levelCardinality));
}
}

Expand Down
20 changes: 20 additions & 0 deletions src/org/olap4j/driver/xmla/XmlaOlap4jLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,35 @@ class XmlaOlap4jLevel
private final Type type;
private final int cardinality;
private final NamedList<XmlaOlap4jProperty> propertyList;
private final boolean calculated;

/**
* Creates an XmlaOlap4jLevel.
*
* @param olap4jHierarchy Hierarchy
* @param uniqueName Unique name
* @param name Name
* @param caption Caption
* @param description Description
* @param depth Distance to root
* @param type Level type
* @param calculated Whether level is calculated
* @param cardinality Number of members in this level
*/
XmlaOlap4jLevel(
final XmlaOlap4jHierarchy olap4jHierarchy,
String uniqueName, String name,
String caption,
String description,
int depth,
Type type,
boolean calculated,
int cardinality)
{
super(uniqueName, name, caption, description);
assert olap4jHierarchy != null;
this.type = type;
this.calculated = calculated;
this.cardinality = cardinality;
this.depth = depth;
this.olap4jHierarchy = olap4jHierarchy;
Expand Down Expand Up @@ -89,6 +105,10 @@ public Dimension getDimension() {
return olap4jHierarchy.olap4jDimension;
}

public boolean isCalculated() {
return calculated;
}

public Type getLevelType() {
return type;
}
Expand Down
134 changes: 115 additions & 19 deletions src/org/olap4j/metadata/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public interface Level extends MetadataElement {
*/
Level.Type getLevelType();

/**
* Returns whether the level is calculated.
*/
boolean isCalculated();

/**
* Returns a list of definitions for the properties available to members
* of this <code>Level</code>.
Expand Down Expand Up @@ -95,13 +100,43 @@ public interface Level extends MetadataElement {
/**
* Enumeration of the types of a {@link Level}.
*
* <p>Several of the values are defined by XMLA, sans the "MDLEVEL_TYPE_"
* prefix to their name. For example, {@link #GEO_CONTINENT} corresponds to
* <p>Several of the values are defined by OLE DB for OLAP and/or XML/A,
* sans the "MDLEVEL_TYPE_" prefix to their name. For example,
* {@link #GEO_CONTINENT} corresponds to
* the value <code>MDLEVEL_TYPE_GEO_CONTINENT</code> for the
* <code>LEVEL_TYPE</code> property in the <code>MDSCHEMA_LEVELS</code>
* schema rowset.
*
* <p>Some of the values are specified by OLE DB for OLAP:
* <ul>
* <li>MDLEVEL_TYPE_REGULAR (0x0000)
* <li>MDLEVEL_TYPE_ALL (0x0001)
* <li>MDLEVEL_TYPE_TIME_YEARS (0x0014)
* <li>MDLEVEL_TYPE_TIME_HALF_YEAR (0x0024)
* <li>MDLEVEL_TYPE_TIME_QUARTERS (0x0044)
* <li>MDLEVEL_TYPE_TIME_MONTHS (0x0084)
* <li>MDLEVEL_TYPE_TIME_WEEKS (0x0104)
* <li>MDLEVEL_TYPE_TIME_DAYS (0x0204)
* <li>MDLEVEL_TYPE_TIME_HOURS (0x0304)
* <li>MDLEVEL_TYPE_TIME_MINUTES (0x0404)
* <li>MDLEVEL_TYPE_TIME_SECONDS (0x0804)
* <li>MDLEVEL_TYPE_TIME_UNDEFINED (0x1004)
* </ul>
*
* Some of the OLE DB for OLAP values are as flags, and do not become
* values of the enumeration:
* <ul>
* <li>MDLEVEL_TYPE_UNKNOWN (0x0000) signals that no other flags are set.
* Use {@link #REGULAR}
* <li>MDLEVEL_TYPE_CALCULATED (0x0002) indicates that the level is
* calculated. Use {@link Level#isCalculated}.
* <li>MDLEVEL_TYPE_TIME (0x0004) indicates that the level is time-related.
* Use {@link #isTime}.
* <li>MDLEVEL_TYPE_RESERVED1 (0x0008) is reserved for future use.
* </ul>
*
* <p>Some of the values are specified by XMLA:
* <ul>
* <li>MDLEVEL_TYPE_GEO_CONTINENT (0x2001)
* <li>MDLEVEL_TYPE_GEO_REGION (0x2002)
* <li>MDLEVEL_TYPE_GEO_COUNTRY (0x2003)
Expand All @@ -128,6 +163,7 @@ public interface Level extends MetadataElement {
* <li>MDLEVEL_TYPE_CHANNEL (0x1061)
* <li>MDLEVEL_TYPE_REPRESENTATIVE (0x1062)
* <li>MDLEVEL_TYPE_PROMOTION (0x1071)
* </ul>
*
* @see Level#getLevelType
* @see org.olap4j.OlapDatabaseMetaData#getLevels
Expand All @@ -137,47 +173,88 @@ public enum Type {
/**
* Indicates that the level is not related to time.
*/
Regular(0),
REGULAR(0x0000),

/**
* Indicates that the level contains the 'all' member of its hierarchy.
*/
ALL(0x0001),

/**
* Indicates that a level holds the null member. Does not correspond to
* an XMLA or OLE DB value.
*/
NULL(-1),

/**
* Indicates that a level refers to years.
* It must be used in a dimension whose type is
* {@link org.olap4j.metadata.Dimension.Type#TIME}.
*/
TimeYears(1),
TIME_YEARS(0x0014),

/**
* Indicates that a level refers to half years.
* It must be used in a dimension whose type is
* {@link org.olap4j.metadata.Dimension.Type#TIME}.
*/
TIME_HALF_YEAR(0x0024),

/**
* Indicates that a level refers to quarters.
* It must be used in a dimension whose type is
* {@link org.olap4j.metadata.Dimension.Type#TIME}.
*/
TimeQuarters(2),
TIME_QUARTERS(0x0044),

/**
* Indicates that a level refers to months.
* It must be used in a dimension whose type is
* {@link org.olap4j.metadata.Dimension.Type#TIME}.
*/
TimeMonths(3),
TIME_MONTHS(0x0084),

/**
* Indicates that a level refers to weeks.
* It must be used in a dimension whose type is
* {@link org.olap4j.metadata.Dimension.Type#TIME}.
*/
TimeWeeks(4),
TIME_WEEKS(0x0104),

/**
* Indicates that a level refers to days.
* It must be used in a dimension whose type is
* {@link org.olap4j.metadata.Dimension.Type#TIME}.
*/
TimeDays(5),
TIME_DAYS(0x0204),

/**
* Indicates that a level holds the null member.
* Indicates that a level refers to hours.
* It must be used in a dimension whose type is
* {@link org.olap4j.metadata.Dimension.Type#TIME}.
*/
Null(6),
TIME_HOURS(0x0304),

/**
* Indicates that a level refers to minutes.
* It must be used in a dimension whose type is
* {@link org.olap4j.metadata.Dimension.Type#TIME}.
*/
TIME_MINUTES(0x0404),

/**
* Indicates that a level refers to seconds.
* It must be used in a dimension whose type is
* {@link org.olap4j.metadata.Dimension.Type#TIME}.
*/
TIME_SECONDS(0x0804),

/**
* Indicates that a level refers to days.
* It must be used in a dimension whose type is
* {@link org.olap4j.metadata.Dimension.Type#TIME}.
*/
TIME_UNDEFINED(0x1004),

GEO_CONTINENT(0x2001),
GEO_REGION(0x2002),
Expand Down Expand Up @@ -217,8 +294,14 @@ public enum Type {
}
}

private Type(int code) {
this.xmlaOrdinal = code;
/**
* Creates a level type.
*
* @param xmlaOrdinal Ordinal code in XMLA or OLE DB for OLAP
* specification
*/
private Type(int xmlaOrdinal) {
this.xmlaOrdinal = xmlaOrdinal;
}

/**
Expand Down Expand Up @@ -248,18 +331,31 @@ public static Type forXmlaOrdinal(int xmlaOrdinal) {

/**
* Returns whether this is a time-related level
* ({@link #TimeYears}, {@link #TimeQuarters}, {@link #TimeMonths},
* {@link #TimeWeeks}, {@link #TimeDays}).
* ({@link #TIME_YEARS},
* {@link #TIME_HALF_YEAR},
* {@link #TIME_QUARTERS},
* {@link #TIME_MONTHS},
* {@link #TIME_WEEKS},
* {@link #TIME_DAYS},
* {@link #TIME_HOURS},
* {@link #TIME_MINUTES},
* {@link #TIME_SECONDS},
* {@link #TIME_UNDEFINED}).
*
* @return whether this is a time-related level
*/
public boolean isTime() {
switch (this) {
case TimeYears:
case TimeQuarters:
case TimeMonths:
case TimeWeeks:
case TimeDays:
case TIME_YEARS:
case TIME_HALF_YEAR:
case TIME_QUARTERS:
case TIME_MONTHS:
case TIME_WEEKS:
case TIME_DAYS:
case TIME_HOURS:
case TIME_MINUTES:
case TIME_SECONDS:
case TIME_UNDEFINED:
return true;
default:
return false;
Expand Down
18 changes: 18 additions & 0 deletions testsrc/org/olap4j/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,7 @@ public void testMetadata() throws Exception {

Cube cube = olapConnection.getSchema().getCubes().get("Sales");

int z = 0;
int hierarchyCount = 0;
for (Dimension dimension : cube.getDimensions()) {
// Call every method of Dimension
Expand Down Expand Up @@ -1570,6 +1571,22 @@ public void testMetadata() throws Exception {
continue;
}
int k = 0;
if (level.getName().equals("Year")) {
assertEquals(
Level.Type.TIME_YEARS, level.getLevelType());
assertFalse(level.isCalculated());
++z;
}
if (level.getName().equals("Gender")) {
assertEquals(Level.Type.REGULAR, level.getLevelType());
assertFalse(level.isCalculated());
++z;
}
if (level.getName().equals("Measures")) {
assertEquals(Level.Type.REGULAR, level.getLevelType());
assertFalse(level.isCalculated());
++z;
}
for (Member member : level.getMembers()) {
assertNotNull(member.getName());
assertEquals(level, member.getLevel());
Expand All @@ -1593,6 +1610,7 @@ public void testMetadata() throws Exception {
assertNotNull(hierarchy.getName());
}
assertEquals(0, hierarchyCount);
assertEquals("found Year, Measures, Gender levels", 3, z);

// Look for the Time.Weekly hierarchy, the 2nd hierarchy in the Time
// dimension.
Expand Down

0 comments on commit 4bd09de

Please sign in to comment.