Skip to content

Commit

Permalink
Merge of changes 8fa75e276f638b1156e0fa1c447fc49006112f88 ba93ad762db…
Browse files Browse the repository at this point in the history
…859d04d6aa2411e4587280ca06249 160dadad7af7dee209fa85ba8cbd9106fa60c799 from Mondrian's master.
  • Loading branch information
lucboudreau committed Feb 21, 2013
1 parent d87b6ad commit 2f444e2
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 19 deletions.
12 changes: 9 additions & 3 deletions src/main/java/mondrian/xmla/RowsetDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,9 @@ public void populateImpl(
{
final XmlaHandler.XmlaExtra extra =
handler.connectionFactory.getExtra();
for (Catalog catalog : catIter(connection, catalogNameCond)) {
for (Catalog catalog
: catIter(connection, catalogNameCond, catNameCond()))
{
for (Schema schema : catalog.getSchemas()) {
Row row = new Row();
row.set(CatalogName.name, catalog.getName());
Expand Down Expand Up @@ -2337,7 +2339,9 @@ public void populateImpl(
List<Row> rows)
throws XmlaException, OlapException
{
for (Catalog catalog : catIter(connection, tableCatalogCond)) {
for (Catalog catalog
: catIter(connection, tableCatalogCond, catNameCond()))
{
// By definition, mondrian catalogs have only one
// schema. It is safe to use get(0)
final Schema schema = catalog.getSchemas().get(0);
Expand Down Expand Up @@ -2890,7 +2894,9 @@ public void populateImpl(
List<Row> rows)
throws XmlaException, OlapException
{
for (Catalog catalog : catIter(connection, catalogNameCond)) {
for (Catalog catalog
: catIter(connection, catalogNameCond, catNameCond()))
{
for (Schema schema : catalog.getSchemas()) {
Row row = new Row();
row.set(CatalogName.name, catalog.getName());
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/mondrian/xmla/XmlaHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,31 @@ public OlapConnection getConnection(
.getProperties()
.get(PropertyDefinition.DataSourceInfo.name());

final String catalogName =
String catalogName =
request
.getProperties()
.get(PropertyDefinition.Catalog.name());

if (catalogName == null
&& request.getRestrictions().containsKey(
Property.StandardMemberProperty
.CATALOG_NAME.name()))
{
Object restriction =
request.getRestrictions().get(
Property.StandardMemberProperty
.CATALOG_NAME.name());
if (restriction instanceof List) {
final List requiredValues = (List) restriction;
catalogName =
String.valueOf(
requiredValues.get(0));
} else {
throw Util.newInternal(
"unexpected restriction type: " + restriction.getClass());
}
}

return
getConnection(
databaseName,
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/mondrian/xmla/impl/DefaultSaxWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.xml.sax.Attributes;

import java.io.*;
import java.util.regex.Pattern;

/**
* Default implementation of {@link SaxWriter}.
Expand All @@ -40,6 +41,7 @@ public class DefaultSaxWriter implements SaxWriter {
private final ArrayStack<String> stack = new ArrayStack<String>();
private int state = STATE_END_ELEMENT;

private final static Pattern nlPattern = Pattern.compile("\\r\\n|\\r|\\n");

/**
* Creates a DefaultSaxWriter writing to an {@link java.io.OutputStream}.
Expand Down Expand Up @@ -170,18 +172,15 @@ public void endSequence() {
public final void textElement(String name, Object data) {
try {
_startElement(null, null, name, EmptyAttributes);
String s = data.toString();

// Replace line endings with spaces. IBM's DOM implementation keeps
// line endings, whereas Sun's does not. For consistency, always
// strip them.
//
// REVIEW: It would be better to enclose in CDATA, but some clients
// might not be expecting this.
if (s != null && s.length() > 0) {
s = Util.replace(s, Util.nl, " ");
_characters(s);
}
characters(
nlPattern.matcher(data.toString()).replaceAll(" "));
_endElement();
} catch (IOException e) {
throw new RuntimeException("Error while appending XML", e);
Expand Down
45 changes: 35 additions & 10 deletions src/main/java/mondrian/xmla/impl/DefaultXmlaRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,37 +187,37 @@ private void initDiscover(Element discoverRoot) throws XmlaException {
XmlaUtil.filterChildElements(
discoverRoot,
NS_XMLA,
"Restrictions");
"Properties");
if (childElems.length != 1) {
StringBuilder buf = new StringBuilder(100);
buf.append(MSG_INVALID_XMLA);
buf.append(": Wrong number of Restrictions elements: ");
buf.append(": Wrong number of Properties elements: ");
buf.append(childElems.length);
throw new XmlaException(
CLIENT_FAULT_FC,
HSB_BAD_RESTRICTIONS_CODE,
HSB_BAD_RESTRICTIONS_FAULT_FS,
HSB_BAD_PROPERTIES_CODE,
HSB_BAD_PROPERTIES_FAULT_FS,
Util.newError(buf.toString()));
}
initRestrictions(childElems[0]); // <Restriciotns><RestrictionList>
initProperties(childElems[0]); // <Properties><PropertyList>

childElems =
XmlaUtil.filterChildElements(
discoverRoot,
NS_XMLA,
"Properties");
"Restrictions");
if (childElems.length != 1) {
StringBuilder buf = new StringBuilder(100);
buf.append(MSG_INVALID_XMLA);
buf.append(": Wrong number of Properties elements: ");
buf.append(": Wrong number of Restrictions elements: ");
buf.append(childElems.length);
throw new XmlaException(
CLIENT_FAULT_FC,
HSB_BAD_PROPERTIES_CODE,
HSB_BAD_PROPERTIES_FAULT_FS,
HSB_BAD_RESTRICTIONS_CODE,
HSB_BAD_RESTRICTIONS_FAULT_FS,
Util.newError(buf.toString()));
}
initProperties(childElems[0]); // <Properties><PropertyList>
initRestrictions(childElems[0]); // <Restriciotns><RestrictionList>
}

private void initExecute(Element executeRoot) throws XmlaException {
Expand Down Expand Up @@ -311,6 +311,31 @@ private void initRestrictions(Element restrictionsRoot)
HSB_BAD_RESTRICTION_LIST_FAULT_FS,
Util.newError(buf.toString()));
}

// If there is a Catalog property,
// we have to consider it a constraint as well.
String key =
org.olap4j.metadata.XmlaConstants
.Literal.CATALOG_NAME.name();

if (this.properties.containsKey(key)
&& !restrictions.containsKey(key))
{
List<String> values;
values = new ArrayList<String>();
restrictions.put(this.properties.get(key), values);

if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"DefaultXmlaRequest.initRestrictions: "
+ " key=\""
+ key
+ "\", value=\""
+ this.properties.get(key)
+ "\"");
}
}

this.restrictions = (Map) Collections.unmodifiableMap(restrictions);
}

Expand Down

0 comments on commit 2f444e2

Please sign in to comment.