Skip to content

Commit

Permalink
Back out revisions 110-113.
Browse files Browse the repository at this point in the history
git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@114 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Aug 25, 2008
1 parent bfe29fc commit 82777df
Show file tree
Hide file tree
Showing 26 changed files with 188 additions and 795 deletions.
51 changes: 51 additions & 0 deletions src/org/olap4j/OlapExceptionHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2007-2008 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package org.olap4j;

import java.sql.SQLException;

/**
* Sugar class to help create OlapExceptions.
* @author Luc Boudreau
* @version $Id: $
*/
public class OlapExceptionHelper {

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

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

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

public static 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) {
if (e instanceof OlapException) {
return (OlapException) e;
} else {
return new OlapException(null, e);
}
}
}

//End ExceptionHelper.java
10 changes: 4 additions & 6 deletions src/org/olap4j/driver/xmla/EmptyResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
*/
package org.olap4j.driver.xmla;

import org.olap4j.*;
import org.olap4j.driver.xmla.messages.*;

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

import javax.sql.rowset.RowSetMetaDataImpl;
import java.sql.*;
import javax.sql.rowset.*;
import java.sql.Date;
import java.math.BigDecimal;
import java.io.InputStream;
Expand Down Expand Up @@ -726,8 +725,7 @@ public <T> T unwrap(Class<T> iface) throws SQLException {
if (iface.isInstance(this)) {
return iface.cast(this);
}
throw XmlaOlap4jMessenger.getInstance().createException(
"EmptyResultSet.unwrap_error"); //$NON-NLS-1$
throw OlapExceptionHelper.createException("cannot cast");
}

public boolean isWrapperFor(Class<?> iface) throws SQLException {
Expand Down
110 changes: 54 additions & 56 deletions src/org/olap4j/driver/xmla/XmlaOlap4jCellSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.olap4j.*;
import org.olap4j.mdx.ParseTreeNode;
import org.olap4j.driver.xmla.messages.XmlaOlap4jMessenger;
import org.olap4j.impl.Olap4jUtil;
import static org.olap4j.driver.xmla.XmlaOlap4jUtil.*;
import org.olap4j.metadata.*;
Expand Down Expand Up @@ -78,11 +77,11 @@ void populate() throws OlapException {
try {
doc = parse(bytes);
} catch (IOException e) {
throw XmlaOlap4jMessenger.getInstance().createException(
"XmlaOlap4jCellSet.parse_error", e);
throw OlapExceptionHelper.createException(
"error creating CellSet", e);
} catch (SAXException e) {
throw XmlaOlap4jMessenger.getInstance().createException(
"XmlaOlap4jCellSet.parse_error", e);
throw OlapExceptionHelper.createException(
"error creating CellSet", e);
}
// <SOAP-ENV:Envelope>
// <SOAP-ENV:Header/>
Expand All @@ -107,8 +106,27 @@ void populate() throws OlapException {
Element fault =
findChild(body, SOAP_NS, "Fault");
if (fault != null) {
/*
Example:
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client.00HSBC01</faultcode>
<faultstring>XMLA connection datasource not found</faultstring>
<faultactor>Mondrian</faultactor>
<detail>
<XA:error xmlns:XA="http://mondrian.sourceforge.net">
<code>00HSBC01</code>
<desc>The Mondrian XML: Mondrian Error:Internal
error: no catalog named 'LOCALDB'</desc>
</XA:error>
</detail>
</SOAP-ENV:Fault>
*/
// TODO: log doc to logfile
throw XmlaOlap4jMessenger.getInstance().createException(fault);
final Element faultstring = findChild(fault, null, "faultstring");
String message = faultstring.getTextContent();
throw OlapExceptionHelper.createException(
"XMLA provider gave exception: " + message);
}
Element executeResponse =
findChild(body, XMLA_NS, "ExecuteResponse");
Expand Down Expand Up @@ -276,8 +294,7 @@ void populate() throws OlapException {
propertyValues));
}
}



/**
* Returns the value of a cell, cast to the appropriate Java object type
* corresponding to the XML schema (XSD) type of the value.
Expand Down Expand Up @@ -306,33 +323,25 @@ private Object getTypedValue(Element cell) throws OlapException {
String type = elm.getAttribute("xsi:type");
try {
if (type.equals("xsd:int")) {
return XmlaOlap4jUtil
.intElement(cell, "Value"); //$NON-NLS-1$
} else if (type.equals("xsd:integer")) { //$NON-NLS-1$
return XmlaOlap4jUtil
.integerElement(cell, "Value"); //$NON-NLS-1$
} else if (type.equals("xsd:double")) { //$NON-NLS-1$
return XmlaOlap4jUtil
.doubleElement(cell, "Value"); //$NON-NLS-1$
} else if (type.equals("xsd:float")) { //$NON-NLS-1$
return XmlaOlap4jUtil
.floatElement(cell, "Value"); //$NON-NLS-1$
} else if (type.equals("xsd:long")) { //$NON-NLS-1$
return XmlaOlap4jUtil
.longElement(cell, "Value"); //$NON-NLS-1$
} else if (type.equals("xsd:boolean")) { //$NON-NLS-1$
return XmlaOlap4jUtil
.booleanElement(cell, "Value"); //$NON-NLS-1$
return XmlaOlap4jUtil.intElement(cell, "Value");
} else if (type.equals("xsd:integer")) {
return XmlaOlap4jUtil.integerElement(cell, "Value");
} else if (type.equals("xsd:double")) {
return XmlaOlap4jUtil.doubleElement(cell, "Value");
} else if (type.equals("xsd:float")) {
return XmlaOlap4jUtil.floatElement(cell, "Value");
} else if (type.equals("xsd:long")) {
return XmlaOlap4jUtil.longElement(cell, "Value");
} else if (type.equals("xsd:boolean")) {
return XmlaOlap4jUtil.booleanElement(cell, "Value");
} else {
return XmlaOlap4jUtil
.stringElement(cell, "Value"); //$NON-NLS-1$
return XmlaOlap4jUtil.stringElement(cell, "Value");
}
} catch (Exception e) {
throw XmlaOlap4jMessenger.getInstance().createException(
"XmlaOlap4jCellSet.xsd_cast_error",
e,
type,
elm);
throw OlapExceptionHelper.createException(
"Error while casting a cell value to the correct java type for"
+ " its XSD type " + type,
e);
}
}

Expand Down Expand Up @@ -360,7 +369,7 @@ private XmlaOlap4jCellSetMetaData createMetaData(Element root)
this.olap4jStatement.olap4jConnection.getSchema().getCubes().get(
cubeName);
if (cube == null) {
throw new RuntimeException(
throw OlapExceptionHelper.createException(
"Internal error: cube '" + cubeName + "' not found");
}
final Element axesInfo =
Expand Down Expand Up @@ -474,7 +483,8 @@ private Hierarchy lookupHierarchy(XmlaOlap4jCube cube, String hierarchyName)
}
}
if (hierarchy == null) {
throw new RuntimeException(
throw OlapExceptionHelper
.createException(
"Internal error: hierarchy '" + hierarchyName
+ "' not found in cube '" + cube.getName()
+ "'");
Expand Down Expand Up @@ -514,12 +524,7 @@ public Cell getCell(int ordinal) {
public Cell getCell(Position... positions) {
if (positions.length != getAxes().size()) {
throw new IllegalArgumentException(
XmlaOlap4jMessenger.getInstance()
.getMessage(
"XmlaOlap4jCellSet.wrong_nb_coordinates",
(Locale)null,
getAxes().size())
);
"cell coordinates should have dimension " + getAxes().size());
}
List<Integer> coords = new ArrayList<Integer>(positions.length);
for (Position position : positions) {
Expand Down Expand Up @@ -602,11 +607,9 @@ public List<Integer> ordinalToCoordinates(int ordinal) {
}
if (ordinal < 0 || ordinal >= modulo) {
throw new IndexOutOfBoundsException(
XmlaOlap4jMessenger.getInstance().getMessage(
"XmlaOlap4jCellSet.ordinal_not_within_range",
(Locale)null,
ordinal,
getBoundsAsString()));
"Cell ordinal " + ordinal
+ ") lies outside CellSet bounds ("
+ getBoundsAsString() + ")");
}
return list;
}
Expand All @@ -615,11 +618,8 @@ public int coordinatesToOrdinal(List<Integer> coordinates) {
List<CellSetAxis> axes = getAxes();
if (coordinates.size() != axes.size()) {
throw new IllegalArgumentException(
XmlaOlap4jMessenger.getInstance().getMessage(
"XmlaOlap4jCellSet.wrong_nb_coordinates",
(Locale)null,
coordinates.size(),
axes.size()));
"Coordinates have different dimension " + coordinates.size()
+ " than axes " + axes.size());
}
int modulo = 1;
int ordinal = 0;
Expand All @@ -628,12 +628,10 @@ public int coordinatesToOrdinal(List<Integer> coordinates) {
final Integer coordinate = coordinates.get(k++);
if (coordinate < 0 || coordinate >= axis.getPositionCount()) {
throw new IndexOutOfBoundsException(
XmlaOlap4jMessenger.getInstance().getMessage(
"XmlaOlap4jCellSet.coordinates_not_within_range",
null,
coordinate,
k,
getBoundsAsString()));
"Coordinate " + coordinate
+ " of axis " + k
+ " is out of range ("
+ getBoundsAsString() + ")");
}
ordinal += coordinate * modulo;
modulo *= axis.getPositionCount();
Expand Down
Loading

0 comments on commit 82777df

Please sign in to comment.