Skip to content

Commit

Permalink
MONDRIAN: Refactor for olap4j.
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian/": change = 9335]
  • Loading branch information
julianhyde committed May 25, 2007
1 parent 6708997 commit 4a14bee
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 72 deletions.
43 changes: 43 additions & 0 deletions src/main/mondrian/olap/MondrianServer.java
Expand Up @@ -9,6 +9,10 @@
*/
package mondrian.olap;

import java.util.List;
import java.util.Collections;
import java.util.Arrays;

/**
* Interface by which to control an instance of Mondrian.
*
Expand Down Expand Up @@ -63,14 +67,53 @@ public static MondrianServer forConnection(Connection connection) {
*/
public abstract MondrianVersion getVersion();

/**
* Returns a list of MDX keywords.
* @return list of MDX keywords
*/
public abstract List<String> getKeywords();

/**
* Description of the version of the server.
*/
public interface MondrianVersion {
/**
* Returns the version string, for example "2.3.0".
*
* @see java.sql.DatabaseMetaData#getDatabaseProductVersion()
*/
String getVersionString();

/**
* Returns the major part of the version number.
*
* <p>For example, if the full version string is "2.3.0", the major
* version is 2.
*
* @return major part of the version number
* @see java.sql.DatabaseMetaData#getDatabaseMajorVersion()
*/
int getMajorVersion();

/**
* Returns the minor part of the version number.
*
* <p>For example, if the full version string is "2.3.0", the minor
* version is 3.
*
* @return minor part of the version number
*
* @see java.sql.DatabaseMetaData#getDatabaseProductVersion()
*/
int getMinorVersion();

/**
* Retrieves the name of this database product.
*
* @return database product name
* @see java.sql.DatabaseMetaData#getDatabaseProductName()
*/
String getProductName();
}
}

Expand Down
116 changes: 106 additions & 10 deletions src/main/mondrian/olap/MondrianServerImpl.java
Expand Up @@ -15,6 +15,9 @@
import java.io.IOException;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

/**
* Implementation of {@link MondrianServer}.
Expand All @@ -25,6 +28,66 @@
*/
class MondrianServerImpl extends MondrianServer {
private static MondrianVersion version = null;
public static final String[] keywords = new String[] {
"$AdjustedProbability", "$Distance", "$Probability",
"$ProbabilityStDev", "$ProbabilityStdDeV", "$ProbabilityVariance",
"$StDev", "$StdDeV", "$Support", "$Variance",
"AddCalculatedMembers", "Action", "After", "Aggregate", "All",
"Alter", "Ancestor", "And", "Append", "As", "ASC", "Axis",
"Automatic", "Back_Color", "BASC", "BDESC", "Before",
"Before_And_After", "Before_And_Self", "Before_Self_After",
"BottomCount", "BottomPercent", "BottomSum", "Break", "Boolean",
"Cache", "Calculated", "Call", "Case", "Catalog_Name", "Cell",
"Cell_Ordinal", "Cells", "Chapters", "Children",
"Children_Cardinality", "ClosingPeriod", "Cluster",
"ClusterDistance", "ClusterProbability", "Clusters",
"CoalesceEmpty", "Column_Values", "Columns", "Content",
"Contingent", "Continuous", "Correlation", "Cousin", "Covariance",
"CovarianceN", "Create", "CreatePropertySet", "CrossJoin", "Cube",
"Cube_Name", "CurrentMember", "CurrentCube", "Custom", "Cyclical",
"DefaultMember", "Default_Member", "DESC", "Descendents",
"Description", "Dimension", "Dimension_Unique_Name", "Dimensions",
"Discrete", "Discretized", "DrillDownLevel",
"DrillDownLevelBottom", "DrillDownLevelTop", "DrillDownMember",
"DrillDownMemberBottom", "DrillDownMemberTop", "DrillTrough",
"DrillUpLevel", "DrillUpMember", "Drop", "Else", "Empty", "End",
"Equal_Areas", "Exclude_Null", "ExcludeEmpty", "Exclusive",
"Expression", "Filter", "FirstChild", "FirstRowset",
"FirstSibling", "Flattened", "Font_Flags", "Font_Name",
"Font_size", "Fore_Color", "Format_String", "Formatted_Value",
"Formula", "From", "Generate", "Global", "Head", "Hierarchize",
"Hierarchy", "Hierary_Unique_name", "IIF", "IsEmpty",
"Include_Null", "Include_Statistics", "Inclusive", "Input_Only",
"IsDescendant", "Item", "Lag", "LastChild", "LastPeriods",
"LastSibling", "Lead", "Level", "Level_Unique_Name", "Levels",
"LinRegIntercept", "LinRegR2", "LinRegPoint", "LinRegSlope",
"LinRegVariance", "Long", "MaxRows", "Median", "Member",
"Member_Caption", "Member_Guid", "Member_Name", "Member_Ordinal",
"Member_Type", "Member_Unique_Name", "Members",
"Microsoft_Clustering", "Microsoft_Decision_Trees", "Mining",
"Model", "Model_Existence_Only", "Models", "Move", "MTD", "Name",
"Nest", "NextMember", "Non", "Normal", "Not", "Ntext", "Nvarchar",
"OLAP", "On", "OpeningPeriod", "OpenQuery", "Or", "Ordered",
"Ordinal", "Pages", "Pages", "ParallelPeriod", "Parent",
"Parent_Level", "Parent_Unique_Name", "PeriodsToDate", "PMML",
"Predict", "Predict_Only", "PredictAdjustedProbability",
"PredictHistogram", "Prediction", "PredictionScore",
"PredictProbability", "PredictProbabilityStDev",
"PredictProbabilityVariance", "PredictStDev", "PredictSupport",
"PredictVariance", "PrevMember", "Probability",
"Probability_StDev", "Probability_StdDev", "Probability_Variance",
"Properties", "Property", "QTD", "RangeMax", "RangeMid",
"RangeMin", "Rank", "Recursive", "Refresh", "Related", "Rename",
"Rollup", "Rows", "Schema_Name", "Sections", "Select", "Self",
"Self_And_After", "Sequence_Time", "Server", "Session", "Set",
"SetToArray", "SetToStr", "Shape", "Skip", "Solve_Order", "Sort",
"StdDev", "Stdev", "StripCalculatedMembers", "StrToSet",
"StrToTuple", "SubSet", "Support", "Tail", "Text", "Thresholds",
"ToggleDrillState", "TopCount", "TopPercent", "TopSum",
"TupleToStr", "Under", "Uniform", "UniqueName", "Use", "Value",
"Value", "Var", "Variance", "VarP", "VarianceP", "VisualTotals",
"When", "Where", "With", "WTD", "Xor",
};

public void flushSchemaCache() {
RolapSchema.clearCache();
Expand All @@ -38,28 +101,53 @@ public MondrianVersion getVersion() {
return getVersionStatic();
}

public List<String> getKeywords() {
return Collections.unmodifiableList(Arrays.asList(keywords));
}

private static synchronized MondrianVersion getVersionStatic() {
if (version == null) {
final String versionString = loadVersionFile();
final String[] vendorTitleVersion = loadVersionFile();
String vendor = vendorTitleVersion[0];
final String title = vendorTitleVersion[1];
final String versionString = vendorTitleVersion[2];
int dot1 = versionString.indexOf('.');
final int majorVersion =
Integer.valueOf(versionString.substring(0, dot1));
int dot2 = versionString.indexOf('.', dot1 + 1);
final int minorVersion =
Integer.valueOf(versionString.substring(dot1 + 1, dot2));
version = new MondrianVersion() {
public String getVersionString() {
return versionString;
}

public int getMajorVersion() {
return majorVersion;
}

public int getMinorVersion() {
return minorVersion;
}

public String getProductName() {
return title;
}
};
}
return version;
}

private static String loadVersionFile() {
private static String[] loadVersionFile() {
// First, try to read the version info from the package. If the classes
// came from a jar, this info will be set from manifest.mf.
Package pakkage = MondrianServerImpl.class.getPackage();
String implementationVersion = pakkage.getImplementationVersion();
if (implementationVersion != null) {
return implementationVersion;
}

// Second, try to read VERSION.txt.
String version = null;
String title = null;
String vendor = null;
URL resource =
MondrianServerImpl.class.getClassLoader()
.getResource("DefaultRules.xml");
Expand All @@ -81,16 +169,24 @@ private static String loadVersionFile() {
Matcher matcher = pattern.matcher(versionString);
if (matcher.matches()) {
int groupCount = matcher.groupCount();
String title = matcher.group(1);
String version = matcher.group(2);
String vendor = matcher.group(3);
return version;
assert groupCount == 3;
title = matcher.group(1);
version = matcher.group(2);
vendor = matcher.group(3);
}
} catch (IOException e) {
e.printStackTrace();
}
}
return "Unknown version";

// Version from jar manifest overrides that from VERSION.txt.
if (implementationVersion != null) {
version = implementationVersion;
}
if (version == null) {
version = "Unknown version";
}
return new String[] {vendor, title, version};
}
}

Expand Down
64 changes: 2 additions & 62 deletions src/main/mondrian/xmla/RowsetDefinition.java
Expand Up @@ -1922,73 +1922,13 @@ static class DiscoverKeywordsRowset extends Rowset {
"A list of all the keywords reserved by a provider.\n" +
"Example: AND");

private static final String[] keywords = new String[] {
"$AdjustedProbability", "$Distance", "$Probability",
"$ProbabilityStDev", "$ProbabilityStdDeV", "$ProbabilityVariance",
"$StDev", "$StdDeV", "$Support", "$Variance",
"AddCalculatedMembers", "Action", "After", "Aggregate", "All",
"Alter", "Ancestor", "And", "Append", "As", "ASC", "Axis",
"Automatic", "Back_Color", "BASC", "BDESC", "Before",
"Before_And_After", "Before_And_Self", "Before_Self_After",
"BottomCount", "BottomPercent", "BottomSum", "Break", "Boolean",
"Cache", "Calculated", "Call", "Case", "Catalog_Name", "Cell",
"Cell_Ordinal", "Cells", "Chapters", "Children",
"Children_Cardinality", "ClosingPeriod", "Cluster",
"ClusterDistance", "ClusterProbability", "Clusters",
"CoalesceEmpty", "Column_Values", "Columns", "Content",
"Contingent", "Continuous", "Correlation", "Cousin", "Covariance",
"CovarianceN", "Create", "CreatePropertySet", "CrossJoin", "Cube",
"Cube_Name", "CurrentMember", "CurrentCube", "Custom", "Cyclical",
"DefaultMember", "Default_Member", "DESC", "Descendents",
"Description", "Dimension", "Dimension_Unique_Name", "Dimensions",
"Discrete", "Discretized", "DrillDownLevel",
"DrillDownLevelBottom", "DrillDownLevelTop", "DrillDownMember",
"DrillDownMemberBottom", "DrillDownMemberTop", "DrillTrough",
"DrillUpLevel", "DrillUpMember", "Drop", "Else", "Empty", "End",
"Equal_Areas", "Exclude_Null", "ExcludeEmpty", "Exclusive",
"Expression", "Filter", "FirstChild", "FirstRowset",
"FirstSibling", "Flattened", "Font_Flags", "Font_Name",
"Font_size", "Fore_Color", "Format_String", "Formatted_Value",
"Formula", "From", "Generate", "Global", "Head", "Hierarchize",
"Hierarchy", "Hierary_Unique_name", "IIF", "IsEmpty",
"Include_Null", "Include_Statistics", "Inclusive", "Input_Only",
"IsDescendant", "Item", "Lag", "LastChild", "LastPeriods",
"LastSibling", "Lead", "Level", "Level_Unique_Name", "Levels",
"LinRegIntercept", "LinRegR2", "LinRegPoint", "LinRegSlope",
"LinRegVariance", "Long", "MaxRows", "Median", "Member",
"Member_Caption", "Member_Guid", "Member_Name", "Member_Ordinal",
"Member_Type", "Member_Unique_Name", "Members",
"Microsoft_Clustering", "Microsoft_Decision_Trees", "Mining",
"Model", "Model_Existence_Only", "Models", "Move", "MTD", "Name",
"Nest", "NextMember", "Non", "Normal", "Not", "Ntext", "Nvarchar",
"OLAP", "On", "OpeningPeriod", "OpenQuery", "Or", "Ordered",
"Ordinal", "Pages", "Pages", "ParallelPeriod", "Parent",
"Parent_Level", "Parent_Unique_Name", "PeriodsToDate", "PMML",
"Predict", "Predict_Only", "PredictAdjustedProbability",
"PredictHistogram", "Prediction", "PredictionScore",
"PredictProbability", "PredictProbabilityStDev",
"PredictProbabilityVariance", "PredictStDev", "PredictSupport",
"PredictVariance", "PrevMember", "Probability",
"Probability_StDev", "Probability_StdDev", "Probability_Variance",
"Properties", "Property", "QTD", "RangeMax", "RangeMid",
"RangeMin", "Rank", "Recursive", "Refresh", "Related", "Rename",
"Rollup", "Rows", "Schema_Name", "Sections", "Select", "Self",
"Self_And_After", "Sequence_Time", "Server", "Session", "Set",
"SetToArray", "SetToStr", "Shape", "Skip", "Solve_Order", "Sort",
"StdDev", "Stdev", "StripCalculatedMembers", "StrToSet",
"StrToTuple", "SubSet", "Support", "Tail", "Text", "Thresholds",
"ToggleDrillState", "TopCount", "TopPercent", "TopSum",
"TupleToStr", "Under", "Uniform", "UniqueName", "Use", "Value",
"Value", "Var", "Variance", "VarP", "VarianceP", "VisualTotals",
"When", "Where", "With", "WTD", "Xor",
};

public void populate(
XmlaResponse response,
List<Row> rows)
throws XmlaException
{
for (String keyword : keywords) {
MondrianServer mondrianServer = MondrianServer.forConnection(null);
for (String keyword : mondrianServer.getKeywords()) {
Row row = new Row();
row.set(Keyword.name, keyword);
addRow(row, rows);
Expand Down

0 comments on commit 4a14bee

Please sign in to comment.