Skip to content

Commit

Permalink
Add notion of ParseRegion to parser and parse tree nodes.
Browse files Browse the repository at this point in the history
git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@23 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Jun 15, 2007
1 parent 7a691f0 commit b099238
Show file tree
Hide file tree
Showing 26 changed files with 1,307 additions and 252 deletions.
8 changes: 7 additions & 1 deletion src/mondrian/olap4j/MondrianOlap4jConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ abstract class MondrianOlap4jConnection implements OlapConnection {
* uses the traditional JDBC {@link java.sql.DriverManager}.
* See {@link mondrian.olap4j.MondrianOlap4jDriver} for more details.
*
* @pre acceptsURL(url)
*
* @param url Connect-string URL
* @param info Additional properties
* @throws SQLException if there is an error
Expand All @@ -93,7 +95,7 @@ abstract class MondrianOlap4jConnection implements OlapConnection {
throws SQLException
{
this.factory = factory;
if (!url.startsWith(CONNECT_STRING_PREFIX)) {
if (!acceptsURL(url)) {
// This is not a URL we can handle.
// DriverManager should not have invoked us.
throw new AssertionError(
Expand All @@ -111,6 +113,10 @@ abstract class MondrianOlap4jConnection implements OlapConnection {
this.olap4jSchema = toOlap4j(connection.getSchema());
}

static boolean acceptsURL(String url) {
return url.startsWith(CONNECT_STRING_PREFIX);
}

public OlapStatement createStatement() {
return new MondrianOlap4jStatement(this);
}
Expand Down
5 changes: 4 additions & 1 deletion src/mondrian/olap4j/MondrianOlap4jDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,14 @@ private static void register() throws SQLException {
}

public Connection connect(String url, Properties info) throws SQLException {
if (!MondrianOlap4jConnection.acceptsURL(url)) {
return null;
}
return factory.newConnection(url, info);
}

public boolean acceptsURL(String url) throws SQLException {
return url.startsWith("jdbc:mondrian:");
return MondrianOlap4jConnection.acceptsURL(url);
}

public DriverPropertyInfo[] getPropertyInfo(
Expand Down
33 changes: 22 additions & 11 deletions src/org/olap4j/mdx/AxisNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
*/
public class AxisNode implements ParseTreeNode {

private final ParseRegion region;
private boolean nonEmpty;
private ParseTreeNode exp;
final Axis axis;
private ParseTreeNode expression;
private final Axis axis;

private final List<IdentifierNode> dimensionProperties;

Expand All @@ -34,28 +35,34 @@ public class AxisNode implements ParseTreeNode {
*
* @param nonEmpty Whether to filter out members of this axis whose cells
* are all empty
* @param expr Expression to populate the axis
* @param expression Expression to populate the axis
* @param axisDef Which axis (ROWS, COLUMNS, etc.)
* @param dimensionProperties List of dimension properties
*/
public AxisNode(
ParseRegion region,
boolean nonEmpty,
ParseTreeNode expr,
ParseTreeNode expression,
Axis axisDef,
List<IdentifierNode> dimensionProperties)
{
this.region = region;
assert dimensionProperties != null;
this.nonEmpty = nonEmpty;
this.exp = expr;
this.expression = expression;
this.axis = axisDef;
this.dimensionProperties = dimensionProperties;
}

public ParseRegion getRegion() {
return region;
}

public <T> T accept(ParseTreeVisitor<T> visitor) {
final T o = visitor.visit(this);

// visit the expression which forms the axis
exp.accept(visitor);
expression.accept(visitor);

return o;
}
Expand Down Expand Up @@ -89,24 +96,24 @@ public void setNonEmpty(boolean nonEmpty) {
* Returns the expression which is used to compute the value of this axis.
*/
public ParseTreeNode getExpression() {
return exp;
return expression;
}

/**
* Sets the expression which is used to compute the value of this axis.
* See {@link #getExpression()}.
*/
public void setExpression(ParseTreeNode expr) {
this.exp = expr;
this.expression = expr;
}

public void unparse(ParseTreeWriter writer) {
PrintWriter pw = writer.getPrintWriter();
if (nonEmpty) {
pw.print("NON EMPTY ");
}
if (exp != null) {
exp.unparse(writer);
if (expression != null) {
expression.unparse(writer);
}
if (dimensionProperties.size() > 0) {
pw.print(" DIMENSION PROPERTIES ");
Expand All @@ -123,11 +130,15 @@ public void unparse(ParseTreeWriter writer) {
}
}

/**
* Returns the list of dimension properties of this axis.
*
* @return list of dimension properties
*/
public List<IdentifierNode> getDimensionProperties() {
return dimensionProperties;
}


public Type getType() {
// not an expression
return null;
Expand Down
10 changes: 9 additions & 1 deletion src/org/olap4j/mdx/CallNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class CallNode implements ParseTreeNode {
private final String name;
private final Syntax syntax;
private final List<ParseTreeNode> argList;
private final ParseRegion region;

/**
* Creates an CallNode.
Expand All @@ -55,10 +56,12 @@ public class CallNode implements ParseTreeNode {
* @param args List of zero or more arguments
*/
public CallNode(
ParseRegion region,
String name,
Syntax syntax,
List<ParseTreeNode> args)
{
this.region = region;
assert name != null;
assert syntax != null;
assert args != null;
Expand Down Expand Up @@ -99,11 +102,16 @@ public CallNode(
* @param args List of zero or more arguments
*/
public CallNode(
ParseRegion region,
String name,
Syntax syntax,
ParseTreeNode... args)
{
this(name, syntax, Arrays.asList(args));
this(region, name, syntax, Arrays.asList(args));
}

public ParseRegion getRegion() {
return region;
}

public Type getType() {
Expand Down
18 changes: 15 additions & 3 deletions src/org/olap4j/mdx/DimensionNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,26 @@
* @since Jun 4, 2007
*/
public class DimensionNode implements ParseTreeNode {
private final ParseRegion region;
private final Dimension dimension;


public DimensionNode(Dimension dimension) {
super();
public DimensionNode(
ParseRegion region,
Dimension dimension)
{
this.region = region;
this.dimension = dimension;
}

public ParseRegion getRegion() {
return region;
}

/**
* Returns the Dimension used in this expression.
*
* @return dimension used in this expression
*/
public Dimension getDimension() {
return dimension;
}
Expand Down
18 changes: 15 additions & 3 deletions src/org/olap4j/mdx/HierarchyNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,26 @@
* @since Jun 4, 2007
*/
public class HierarchyNode implements ParseTreeNode {
private final ParseRegion region;
private final Hierarchy hierarchy;


public HierarchyNode(Hierarchy hierarchy) {
super();
public HierarchyNode(
ParseRegion region,
Hierarchy hierarchy)
{
this.region = region;
this.hierarchy = hierarchy;
}

public ParseRegion getRegion() {
return region;
}

/**
* Returns the Hierarchy used in this expression.
*
* @return hierarchy used in this expression
*/
public Hierarchy getHierarchy() {
return hierarchy;
}
Expand Down
Loading

0 comments on commit b099238

Please sign in to comment.