Skip to content

Commit

Permalink
Implemented the listener pattern for the Query Model. Also fixed many…
Browse files Browse the repository at this point in the history
… bugs introduced by the last commit; line endings were not properly replaced on Windows systems.

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@248 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
lucboudreau committed Jun 24, 2009
1 parent 2321361 commit 67f8a38
Show file tree
Hide file tree
Showing 21 changed files with 763 additions and 806 deletions.
46 changes: 23 additions & 23 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="testsrc"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-1.5.0_11"/>
<classpathentry kind="lib" path="lib/asm-commons.jar"/>
<classpathentry kind="lib" path="lib/asm.jar"/>
<classpathentry kind="lib" path="lib/javacup.jar"/>
<classpathentry kind="lib" path="lib/log4j.jar"/>
<classpathentry kind="lib" path="lib/retroweaver-rt.jar"/>
<classpathentry kind="lib" path="lib/retroweaver.jar"/>
<classpathentry kind="lib" path="lib/xercesImpl.jar"/>
<classpathentry kind="lib" path="testlib/commons-collections.jar"/>
<classpathentry kind="lib" path="testlib/commons-dbcp.jar"/>
<classpathentry kind="lib" path="testlib/commons-logging.jar"/>
<classpathentry kind="lib" path="testlib/commons-math.jar"/>
<classpathentry kind="lib" path="testlib/commons-pool.jar"/>
<classpathentry kind="lib" path="testlib/commons-vfs.jar"/>
<classpathentry kind="lib" path="testlib/eigenbase-properties.jar"/>
<classpathentry kind="lib" path="testlib/eigenbase-resgen.jar"/>
<classpathentry kind="lib" path="testlib/eigenbase-xom.jar"/>
<classpathentry kind="lib" path="testlib/hsqldb.jar"/>
<classpathentry kind="lib" path="testlib/junit.jar"/>
<classpathentry kind="lib" path="testlib/pdfdoclet.jar"/>
<classpathentry kind="lib" path="testlib/servlet-api.jar"/>
<classpathentry kind="lib" path="testlib/simple-jndi.jar"/>
<classpathentry kind="lib" path="testlib/mondrian.jar"/>
<classpathentry kind="output" path="eclipse-bin"/>
<classpathentry kind="lib" path="lib/asm-commons.jar" />
<classpathentry kind="lib" path="lib/asm.jar" />
<classpathentry kind="lib" path="lib/javacup.jar" />
<classpathentry kind="lib" path="lib/log4j.jar" />
<classpathentry kind="lib" path="lib/retroweaver-rt.jar" />
<classpathentry kind="lib" path="lib/retroweaver.jar" />
<classpathentry kind="lib" path="lib/xercesImpl.jar" />
<classpathentry kind="lib" path="testlib/commons-collections.jar" />
<classpathentry kind="lib" path="testlib/commons-dbcp.jar" />
<classpathentry kind="lib" path="testlib/commons-logging.jar" />
<classpathentry kind="lib" path="testlib/commons-math.jar" />
<classpathentry kind="lib" path="testlib/commons-pool.jar" />
<classpathentry kind="lib" path="testlib/commons-vfs.jar" />
<classpathentry kind="lib" path="testlib/eigenbase-properties.jar" />
<classpathentry kind="lib" path="testlib/eigenbase-resgen.jar" />
<classpathentry kind="lib" path="testlib/eigenbase-xom.jar" />
<classpathentry kind="lib" path="testlib/hsqldb.jar" />
<classpathentry kind="lib" path="testlib/junit.jar" />
<classpathentry kind="lib" path="testlib/mondrian.jar" />
<classpathentry kind="lib" path="testlib/pdfdoclet.jar" />
<classpathentry kind="lib" path="testlib/servlet-api.jar" />
<classpathentry kind="lib" path="testlib/simple-jndi.jar" />
</classpath>
Binary file removed dev-lib/mondrian-3.1-SNAPSHOT.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion foodmart/FoodMart.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<Schema name="FoodMart">
<!--
== $Id: //open/mondrian/demo/FoodMart.xml#75 $
== $Id:$
== 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.
Expand Down
4 changes: 2 additions & 2 deletions ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
<dependency org="hsqldb" name="hsqldb" rev="1.8.0.7"
transitive="false" conf="test->default" />

<!-- <dependency org="pentaho" name="mondrian" rev="3.1-SNAPSHOT" -->
<!-- transitive="false" changing="true" conf="test->default" />-->
<dependency org="pentaho" name="mondrian" rev="3.1.1"
transitive="false" changing="true" conf="test->default" />

<dependency org="eigenbase" name="eigenbase-xom" rev="1.3.0.11999"
conf="test->default"/>
Expand Down
59 changes: 50 additions & 9 deletions src/org/olap4j/query/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.olap4j.mdx.SelectNode;

import java.util.*;
import java.util.Map.Entry;
import java.sql.SQLException;

/**
Expand All @@ -25,7 +26,7 @@
* @version $Id$
* @since May 29, 2007
*/
public class Query {
public class Query extends QueryNodeImpl {

protected final String name;
protected Map<Axis, QueryAxis> axes = new HashMap<Axis, QueryAxis>();
Expand All @@ -37,8 +38,7 @@ public class Query {
protected Map<String, QueryDimension> dimensionMap =
new HashMap<String, QueryDimension>();
private final OlapConnection connection;
private final SelectionFactory selectionFactory =
new SelectionFactory(this);
private final SelectionFactory selectionFactory = new SelectionFactory();

public Query(String name, Cube cube) throws SQLException {
super();
Expand Down Expand Up @@ -108,15 +108,38 @@ public void swapAxes() {
tmpDown.addAll(down.getDimensions());

across.getDimensions().clear();
Map<Integer,QueryNode> acrossChildList =
new HashMap<Integer, QueryNode>();
for (int cpt = 0; cpt < tmpAcross.size();cpt++) {
acrossChildList.put(Integer.valueOf(cpt), tmpAcross.get(cpt));
}
across.notifyRemove(acrossChildList);

down.getDimensions().clear();
Map<Integer,QueryNode> downChildList =
new HashMap<Integer, QueryNode>();
for (int cpt = 0; cpt < tmpDown.size();cpt++) {
downChildList.put(Integer.valueOf(cpt), tmpDown.get(cpt));
}
down.notifyRemove(downChildList);

across.getDimensions().addAll(tmpDown);
across.notifyAdd(downChildList);

down.getDimensions().addAll(tmpAcross);
down.notifyAdd(acrossChildList);
}

public QueryAxis getAxis(Axis axis) {
return this.axes.get(axis);
}

/**
* Returns a map of the current query's axis.
* @return A standard Map object that represents the current query's axis.
* <p>Be aware that modifications to this list might
* have unpredictable consequences.</p>
* @return A standard Map object that represents the
* current query's axis.
*/
public Map<Axis, QueryAxis> getAxes() {
return axes;
Expand All @@ -132,6 +155,25 @@ public QueryAxis getUnusedAxis() {
return unused;
}

public void tearDown(boolean closeConnection) {
for (Entry<Axis, QueryAxis> entry : this.axes.entrySet()) {
entry.getValue().tearDown();
}
this.axes.clear();
this.clearListeners();
if (closeConnection) {
try {
this.connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

public void tearDown() {
this.tearDown(true);
}

public boolean validate() throws OlapException {
/*
* FIXME What's the exact purpose of this validation process?
Expand All @@ -154,12 +196,11 @@ public boolean validate() throws OlapException {
|| queryDimension.getAxis().getLocation() == null)
{
queryDimension.getSelections().clear();
queryDimension.getSelections().add(
queryDimension.createSelection(member));
queryDimension.select(member);

} else {
if (queryDimension.getSelections().size() == 0) {
queryDimension.getSelections().add(
queryDimension.createSelection(member));
queryDimension.select(member);
}
}
}
Expand Down Expand Up @@ -195,7 +236,7 @@ public String getName() {
* @return A standard Locale object.
*/
public Locale getLocale() {
// TODO Do queries really support locales?
// REVIEW Do queries really support locales?
return Locale.getDefault();
}

Expand Down
55 changes: 49 additions & 6 deletions src/org/olap4j/query/QueryAxis.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.AbstractList;
import java.util.Map;

/**
* An axis within an OLAP {@link Query}.
Expand All @@ -26,7 +28,7 @@
* @version $Id$
* @since May 29, 2007
*/
public class QueryAxis {
public class QueryAxis extends QueryNodeImpl {

protected final List<QueryDimension> dimensions = new DimensionList();

Expand Down Expand Up @@ -59,11 +61,8 @@ public Axis getLocation() {
/**
* Returns a list of the dimensions placed on this QueryAxis.
*
* <p>The list is mutable; you may call
* <code>getDimensions().clear()</code>,
* or <code>getDimensions().add(dimension)</code>, for instance.
* When a dimension is added to an axis, it is automatically removed from
* its previous axis.</p>
* <p>Be aware that modifications to this list might
* have unpredictable consequences.</p>
*
* @return list of dimensions
*/
Expand Down Expand Up @@ -91,7 +90,13 @@ public String getName() {
* It uses a zero based index.
*/
public void pullUp(int index) {
Map<Integer,QueryNode> removed = new HashMap<Integer, QueryNode>();
removed.put(Integer.valueOf(index),this.dimensions.get(index));
Map<Integer,QueryNode> added = new HashMap<Integer, QueryNode>();
added.put(Integer.valueOf(index - 1),this.dimensions.get(index));
Collections.swap(this.dimensions, index, index - 1);
this.notifyRemove(removed);
this.notifyAdd(added);
}

/**
Expand All @@ -105,7 +110,37 @@ public void pullUp(int index) {
* It uses a zero based index.
*/
public void pushDown(int index) {
Map<Integer,QueryNode> removed = new HashMap<Integer, QueryNode>();
removed.put(Integer.valueOf(index),this.dimensions.get(index));
Map<Integer,QueryNode> added = new HashMap<Integer, QueryNode>();
added.put(Integer.valueOf(index + 1),this.dimensions.get(index));
Collections.swap(this.dimensions, index, index + 1);
this.notifyRemove(removed);
this.notifyAdd(added);
}

/**
* Places a {@link QueryDimension} object on this axis.
* @param dimension The {@link QueryDimension} object to add
* to this axis.
*/
public void addDimension(QueryDimension dimension) {
this.getDimensions().add(dimension);
Integer index = Integer.valueOf(
this.getDimensions().indexOf(dimension));
this.notifyAdd(dimension,index);
}

/**
* Removes a {@link QueryDimension} object on this axis.
* @param dimension The {@link QueryDimension} object to remove
* from this axis.
*/
public void removeDimension(QueryDimension dimension) {
Integer index = Integer.valueOf(
this.getDimensions().indexOf(dimension));
this.getDimensions().remove(dimension);
this.notifyRemove(dimension,index);
}

/**
Expand Down Expand Up @@ -182,6 +217,14 @@ public QueryDimension remove(int index) {
return dimension;
}
}

void tearDown() {
for (QueryDimension node : this.getDimensions()) {
node.tearDown();
}
this.clearListeners();
this.getDimensions().clear();
}
}

// End QueryAxis.java
Loading

0 comments on commit 67f8a38

Please sign in to comment.