Skip to content

Commit

Permalink
Created a messaging framework for Olap4j so that all messages and Ola…
Browse files Browse the repository at this point in the history
…pExceptions can be easily localized, parametrized and build correctly by both Olap4j itself and implementing drivers.

For now, Olap4j API doesn't use the messaging framework. Only the XML/A driver was converted. This will be a tedious work and I expect all developers to use it. Send all comments please.

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@111 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
lucboudreau committed Aug 19, 2008
1 parent 3108dd2 commit b67641a
Show file tree
Hide file tree
Showing 26 changed files with 796 additions and 188 deletions.
51 changes: 0 additions & 51 deletions src/org/olap4j/OlapExceptionHelper.java

This file was deleted.

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

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


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 @@ -725,7 +726,8 @@ public <T> T unwrap(Class<T> iface) throws SQLException {
if (iface.isInstance(this)) {
return iface.cast(this);
}
throw OlapExceptionHelper.createException("cannot cast");
throw XmlaOlap4jMessenger.getInstance().createException(
"EmptyResultSet.unwrap_error"); //$NON-NLS-1$
}

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

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 @@ -77,11 +78,11 @@ void populate() throws OlapException {
try {
doc = parse(bytes);
} catch (IOException e) {
throw OlapExceptionHelper.createException(
"error creating CellSet", e);
throw XmlaOlap4jMessenger.getInstance().createException(
"XmlaOlap4jCellSet.parse_error", e);
} catch (SAXException e) {
throw OlapExceptionHelper.createException(
"error creating CellSet", e);
throw XmlaOlap4jMessenger.getInstance().createException(
"XmlaOlap4jCellSet.parse_error", e);
}
// <SOAP-ENV:Envelope>
// <SOAP-ENV:Header/>
Expand All @@ -106,27 +107,8 @@ 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
final Element faultstring = findChild(fault, null, "faultstring");
String message = faultstring.getTextContent();
throw OlapExceptionHelper.createException(
"XMLA provider gave exception: " + message);
throw XmlaOlap4jMessenger.getInstance().createException(fault);
}
Element executeResponse =
findChild(body, XMLA_NS, "ExecuteResponse");
Expand Down Expand Up @@ -294,7 +276,8 @@ 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 @@ -323,25 +306,33 @@ private Object getTypedValue(Element cell) throws OlapException {
String type = elm.getAttribute("xsi:type");
try {
if (type.equals("xsd:int")) {
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");
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$
} else {
return XmlaOlap4jUtil.stringElement(cell, "Value");
return XmlaOlap4jUtil
.stringElement(cell, "Value"); //$NON-NLS-1$
}
} catch (Exception e) {
throw OlapExceptionHelper.createException(
"Error while casting a cell value to the correct java type for"
+ " its XSD type " + type,
e);
throw XmlaOlap4jMessenger.getInstance().createException(
"XmlaOlap4jCellSet.xsd_cast_error",
e,
type,
elm);
}
}

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

0 comments on commit b67641a

Please sign in to comment.