Skip to content

Commit

Permalink
Set connection's catalog before executing query.
Browse files Browse the repository at this point in the history
git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@292 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Nov 23, 2009
1 parent 2a2b8a5 commit 11743a0
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/org/olap4j/query/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
*/
package org.olap4j.query;

import org.olap4j.metadata.Cube;
import org.olap4j.metadata.Dimension;
import org.olap4j.metadata.Member;
import org.olap4j.metadata.*;
import org.olap4j.*;
import org.olap4j.mdx.SelectNode;

Expand Down Expand Up @@ -56,9 +54,10 @@ public Query(String name, Cube cube) throws SQLException {
super();
this.name = name;
this.cube = cube;
final Catalog catalog = cube.getSchema().getCatalog();
this.connection =
cube.getSchema().getCatalog().getMetaData()
.getConnection().unwrap(OlapConnection.class);
catalog.getMetaData().getConnection().unwrap(OlapConnection.class);
this.connection.setCatalog(catalog.getName());
this.unused = new QueryAxis(this, null);
for (Dimension dimension : cube.getDimensions()) {
QueryDimension queryDimension = new QueryDimension(
Expand Down Expand Up @@ -265,14 +264,21 @@ public void validate() throws OlapException {
/**
* Executes the query against the current OlapConnection and returns
* a CellSet object representation of the data.
*
* @return A proper CellSet object that represents the query execution
* results.
* results.
* @throws OlapException If something goes sour, an OlapException will
* be thrown to the caller. It could be caused by many things, like
* a stale connection. Look at the root cause for more details.
* be thrown to the caller. It could be caused by many things, like
* a stale connection. Look at the root cause for more details.
*/
public CellSet execute() throws OlapException {
SelectNode mdx = getSelect();
final Catalog catalog = cube.getSchema().getCatalog();
try {
this.connection.setCatalog(catalog.getName());
} catch (SQLException e) {
throw new OlapException("Error while executing query", e);
}
OlapStatement olapStatement = connection.createStatement();
return olapStatement.executeOlapQuery(mdx);
}
Expand Down Expand Up @@ -317,4 +323,4 @@ public void setSelectDefaultMembers(boolean selectDefaultMembers) {
}
}

// End Query.java
// End Query.java

0 comments on commit 11743a0

Please sign in to comment.