From 11743a0fcd49727e2c18790ef6536f2288fb803b Mon Sep 17 00:00:00 2001 From: Julian Hyde Date: Mon, 23 Nov 2009 00:58:06 +0000 Subject: [PATCH] Set connection's catalog before executing query. git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@292 c6a108a4-781c-0410-a6c6-c2d559e19af0 --- src/org/olap4j/query/Query.java | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/org/olap4j/query/Query.java b/src/org/olap4j/query/Query.java index 702134a..2a854c8 100644 --- a/src/org/olap4j/query/Query.java +++ b/src/org/olap4j/query/Query.java @@ -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; @@ -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( @@ -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); } @@ -317,4 +323,4 @@ public void setSelectDefaultMembers(boolean selectDefaultMembers) { } } -// End Query.java \ No newline at end of file +// End Query.java