Skip to content

Commit

Permalink
Rename org.olap4j.OlapException to org.olap4j.driver.xmla.XmlaHelper
Browse files Browse the repository at this point in the history
(a utility class doesn't belong in the main package).
Make its methods non-static, and create an instance in each connection;
MondrianOlap4jConnection.Helper already works that way.


git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@236 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed May 12, 2009
1 parent 7de4b27 commit a7031a9
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 68 deletions.
12 changes: 9 additions & 3 deletions src/org/olap4j/driver/xmla/EmptyResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// 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.
// Copyright (C) 2007-2008 Julian Hyde
// Copyright (C) 2007-2009 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package org.olap4j.driver.xmla;

import org.olap4j.OlapExceptionHelper;
import org.olap4j.OlapWrapper;

import javax.sql.rowset.RowSetMetaDataImpl;
Expand Down Expand Up @@ -41,6 +40,13 @@ abstract class EmptyResultSet implements ResultSet, OlapWrapper {
private int rowOrdinal = -1;
private final RowSetMetaDataImpl metaData = new RowSetMetaDataImpl();

/**
* Creates an EmptyResultSet.
*
* @param olap4jConnection Connection
* @param headerList Column names
* @param rowList List of row values
*/
EmptyResultSet(
XmlaOlap4jConnection olap4jConnection,
List<String> headerList,
Expand Down Expand Up @@ -725,7 +731,7 @@ public <T> T unwrap(Class<T> iface) throws SQLException {
if (iface.isInstance(this)) {
return iface.cast(this);
}
throw OlapExceptionHelper.createException("cannot cast");
throw olap4jConnection.helper.createException("cannot cast");
}

public boolean isWrapperFor(Class<?> iface) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,50 @@
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package org.olap4j;
package org.olap4j.driver.xmla;

import org.olap4j.OlapException;
import org.olap4j.Cell;

import java.sql.SQLException;

/**
* Sugar class to help create OlapExceptions.
* Helper class which encapsulates policies which are
* common throughout a driver. These policies include exception handling
* and factory methods.
*
* @author Luc Boudreau
* @version $Id$
*/
public class OlapExceptionHelper {
public class XmlaHelper {

public static OlapException createException(String msg) {
public OlapException createException(String msg) {
return new OlapException(msg);
}

public static OlapException createException(Throwable cause) {
public OlapException createException(Throwable cause) {
return new OlapException(cause.getMessage(), cause);
}

public static OlapException createException(String msg, Throwable cause) {
public OlapException createException(String msg, Throwable cause) {
return new OlapException(msg, cause);
}

public static OlapException createException(Cell context, String msg) {
public OlapException createException(Cell context, String msg) {
OlapException exception = new OlapException(msg);
exception.setContext(context);
return exception;
}

public static OlapException createException(
public OlapException createException(
Cell context, String msg, Throwable cause)
{
OlapException exception = new OlapException(msg, cause);
exception.setContext(context);
return exception;
}

public static OlapException toOlapException(SQLException e) {
public OlapException toOlapException(SQLException e) {
if (e instanceof OlapException) {
return (OlapException) e;
} else {
Expand All @@ -52,4 +58,4 @@ public static OlapException toOlapException(SQLException e) {
}
}

// End OlapExceptionHelper.java
// End XmlaHelper.java
29 changes: 18 additions & 11 deletions src/org/olap4j/driver/xmla/XmlaOlap4jCellSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ abstract class XmlaOlap4jCellSet implements CellSet {
this.closed = false;
}

/**
* Returns the error-handler.
*
* @return Error handler
*/
private final XmlaHelper getHelper() {
return olap4jStatement.olap4jConnection.helper;
}

/**
* Gets response from the XMLA request and populates cell set axes and cells
* with it.
Expand All @@ -77,10 +86,10 @@ void populate() throws OlapException {
try {
doc = parse(bytes);
} catch (IOException e) {
throw OlapExceptionHelper.createException(
throw getHelper().createException(
"error creating CellSet", e);
} catch (SAXException e) {
throw OlapExceptionHelper.createException(
throw getHelper().createException(
"error creating CellSet", e);
}
// <SOAP-ENV:Envelope>
Expand Down Expand Up @@ -121,7 +130,7 @@ void populate() throws OlapException {
</SOAP-ENV:Fault>
*/
// TODO: log doc to logfile
throw OlapExceptionHelper.createException(
throw getHelper().createException(
"XMLA provider gave exception: " +
XmlaOlap4jUtil.prettyPrint(fault));
}
Expand Down Expand Up @@ -332,9 +341,9 @@ private Object getTypedValue(Element cell) throws OlapException {
return XmlaOlap4jUtil.stringElement(cell, "Value");
}
} catch (Exception e) {
throw OlapExceptionHelper.createException(
throw getHelper().createException(
"Error while casting a cell value to the correct java type for"
+ " its XSD type " + type,
+ " its XSD type " + type,
e);
}
}
Expand Down Expand Up @@ -363,7 +372,7 @@ private XmlaOlap4jCellSetMetaData createMetaData(Element root)
this.olap4jStatement.olap4jConnection.getSchema().getCubes().get(
cubeName);
if (cube == null) {
throw OlapExceptionHelper.createException(
throw getHelper().createException(
"Internal error: cube '" + cubeName + "' not found");
}
final Element axesInfo =
Expand Down Expand Up @@ -474,11 +483,9 @@ private Hierarchy lookupHierarchy(XmlaOlap4jCube cube, String hierarchyName)
}
}
if (hierarchy == null) {
throw OlapExceptionHelper
.createException(
"Internal error: hierarchy '" + hierarchyName
+ "' not found in cube '" + cube.getName()
+ "'");
throw getHelper().createException(
"Internal error: hierarchy '" + hierarchyName
+ "' not found in cube '" + cube.getName() + "'");
}
}
return hierarchy;
Expand Down
48 changes: 32 additions & 16 deletions src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
* @since May 23, 2007
*/
abstract class XmlaOlap4jConnection implements OlapConnection {
/**
* Handler for errors.
*/
final XmlaHelper helper = new XmlaHelper();

/**
* <p>Current schema.
*/
Expand All @@ -58,7 +63,7 @@ abstract class XmlaOlap4jConnection implements OlapConnection {
private boolean closed;

/**
* <p>URL of the HTTP server to which to send XML requests.
* URL of the HTTP server to which to send XML requests.
*/
final URL serverUrl;

Expand All @@ -68,12 +73,12 @@ abstract class XmlaOlap4jConnection implements OlapConnection {
private String roleName;

/**
* <p>Holds on to the provider name
* Provider name.
*/
private String providerName;

/**
* <p>Holds on to the datasource name.
* Datasource name.
*/
private String datasourceName;

Expand Down Expand Up @@ -144,7 +149,8 @@ abstract class XmlaOlap4jConnection implements OlapConnection {
// Set URL of HTTP server.
String serverUrl = map.get(XmlaOlap4jDriver.Property.Server.name());
if (serverUrl == null) {
throw OlapExceptionHelper.createException("Connection property '"
throw getHelper().createException(
"Connection property '"
+ XmlaOlap4jDriver.Property.Server.name()
+ "' must be specified");
}
Expand All @@ -168,14 +174,21 @@ abstract class XmlaOlap4jConnection implements OlapConnection {
try {
this.serverUrl = new URL(serverUrl);
} catch (MalformedURLException e) {
throw OlapExceptionHelper.createException(
throw getHelper().createException(
"Error while creating connection", e);
}

this.olap4jDatabaseMetaData =
factory.newDatabaseMetaData(this);
}

/**
* Returns the error-handler
* @return Error-handler
*/
private final XmlaHelper getHelper() {
return helper;
}

/**
* Initializes a cache object and configures it if cache
Expand Down Expand Up @@ -283,15 +296,16 @@ String getDataSourceInfo() throws OlapException {
// Throws exception to the client.
//Tells that there are no datasource corresponding to the search criterias.
if (this.nativeDatasourceName == null) {
throw OlapExceptionHelper.createException("No datasource could be found.");
throw getHelper().createException(
"No datasource could be found.");
}

// If there is a provider
return this.nativeDatasourceName;
} catch (OlapException e) {
throw e;
} catch (SQLException e) {
throw OlapExceptionHelper.createException("Datasource name not found.", e);
throw getHelper().createException("Datasource name not found.", e);
} finally {
try {
if (rSet != null) {
Expand Down Expand Up @@ -493,7 +507,7 @@ public <T> T unwrap(Class<T> iface) throws SQLException {
if (iface.isInstance(this)) {
return iface.cast(this);
}
throw OlapExceptionHelper.createException("does not implement '" + iface + "'");
throw getHelper().createException("does not implement '" + iface + "'");
}

public boolean isWrapperFor(Class<?> iface) throws SQLException {
Expand Down Expand Up @@ -602,20 +616,20 @@ Element xxx(String request) throws OlapException {
* This was a bad design which we will fix at some point but not
* before the 1.0 release.
*/
throw OlapExceptionHelper.createException(e);
throw getHelper().createException(e);
} catch (XmlaOlap4jProxyException e) {
throw OlapExceptionHelper.createException(
throw getHelper().createException(
"This connection encountered an exception while executing a query.",
e);
}
Document doc;
try {
doc = parse(bytes);
} catch (IOException e) {
throw OlapExceptionHelper.createException(
throw getHelper().createException(
"error discovering metadata", e);
} catch (SAXException e) {
throw OlapExceptionHelper.createException(
throw getHelper().createException(
"error discovering metadata", e);
}
// <SOAP-ENV:Envelope>
Expand Down Expand Up @@ -656,10 +670,12 @@ Element xxx(String request) throws OlapException {
</SOAP-ENV:Fault>
*/
// TODO: log doc to logfile
throw OlapExceptionHelper.createException(
"XMLA provider gave exception: " +
XmlaOlap4jUtil.prettyPrint(fault)
+ "\n Request was: \n" + request);
throw getHelper().createException(
"XMLA provider gave exception: "
+ XmlaOlap4jUtil.prettyPrint(fault)
+ "\n"
+ "Request was:\n"
+ request);
}
Element discoverResponse =
findChild(body, XMLA_NS, "DiscoverResponse");
Expand Down
14 changes: 11 additions & 3 deletions src/org/olap4j/driver/xmla/XmlaOlap4jDatabaseMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
package org.olap4j.driver.xmla;

import org.olap4j.*;
import org.olap4j.impl.ArrayMap;
import org.olap4j.impl.Olap4jUtil;
import org.olap4j.impl.*;
import org.olap4j.metadata.*;
import org.w3c.dom.Element;

Expand Down Expand Up @@ -908,10 +907,19 @@ public <T> T unwrap(Class<T> iface) throws SQLException {
if (iface.isInstance(this)) {
return iface.cast(this);
}
throw OlapExceptionHelper.createException(
throw getHelper().createException(
"does not implement '" + iface + "'");
}

/**
* Returns the error-handler.
*
* @return Error handler
*/
private final XmlaHelper getHelper() {
return olap4jConnection.helper;
}

public boolean isWrapperFor(Class<?> iface) throws SQLException {
return iface.isInstance(this);
}
Expand Down
22 changes: 19 additions & 3 deletions src/org/olap4j/driver/xmla/XmlaOlap4jPreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ abstract class XmlaOlap4jPreparedStatement
final XmlaOlap4jCellSetMetaData cellSetMetaData;
private final String mdx;

/**
* Creates an XmlaOlap4jPreparedStatement.
*
* @param olap4jConnection Connection
* @param mdx MDX query string
* @throws OlapException on error
*/
XmlaOlap4jPreparedStatement(
XmlaOlap4jConnection olap4jConnection,
String mdx) throws OlapException
Expand All @@ -55,14 +62,23 @@ abstract class XmlaOlap4jPreparedStatement
cellSet.close();
statement.close();
} catch (SQLException e) {
throw OlapExceptionHelper.createException(
throw getHelper().createException(
"Error while preparing statement '" + mdx + "'",
e);
}

this.mdx = mdx;
}

/**
* Returns the error-handler.
*
* @return Error handler
*/
private final XmlaHelper getHelper() {
return olap4jConnection.helper;
}

// override OlapStatement

public CellSet executeOlapQuery(String mdx) throws OlapException {
Expand Down Expand Up @@ -251,8 +267,8 @@ public String getParameterName(int param) throws OlapException {
private Parameter getParameter(int param) throws OlapException {
final List<Parameter> parameters = getParameters();
if (param < 1 || param > parameters.size()) {
throw OlapExceptionHelper.createException(
"parameter ordinal " + param + " out of range");
throw getHelper().createException(
"parameter ordinal " + param + " out of range");
}
return parameters.get(param - 1);
}
Expand Down
Loading

0 comments on commit a7031a9

Please sign in to comment.