Skip to content

Commit

Permalink
xmla driver: add connection properties and roles to statement call as…
Browse files Browse the repository at this point in the history
… well

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@496 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
pstoellberger committed Jan 30, 2012
1 parent 0c40d41 commit 4180611
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
51 changes: 30 additions & 21 deletions src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ abstract class XmlaOlap4jConnection implements OlapConnection {
* calls as part of &lt;PropertyList/&gt;.<br />
* Can be passed to connection via connection string properties.
*/
private final Map<String,String> databaseProperties;
private final Map<String, String> databaseProperties;

private boolean autoCommit;
private boolean readOnly;
Expand Down Expand Up @@ -186,7 +186,7 @@ abstract class XmlaOlap4jConnection implements OlapConnection {

final Map<String, String> map = parseConnectString(url, info);

this.databaseProperties = new HashMap<String,String>();
this.databaseProperties = new HashMap<String, String>();
for (String infoKey : map.keySet()) {
databaseProperties.put(infoKey, map.get(infoKey));
}
Expand Down Expand Up @@ -313,6 +313,25 @@ static boolean acceptsURL(String url) {
return url.startsWith(CONNECT_STRING_PREFIX);
}

String makeConnectionPropertyList() {
StringBuilder buf = new StringBuilder();
for (String prop : databaseProperties.keySet()) {
try {
XmlaOlap4jDriver.Property.valueOf(prop);
continue;
} catch (IllegalArgumentException e) {
buf.append(" <");
xmlEncode(buf, prop);
buf.append(">");
xmlEncode(buf, databaseProperties.get(prop));
buf.append("</");
xmlEncode(buf, prop);
buf.append(">\n");
}
}
return buf.toString();
}

public OlapStatement createStatement() {
return factory.newStatement(this);
}
Expand Down Expand Up @@ -927,19 +946,15 @@ public String generateRequest(
+ " <Properties>\n"
+ " <PropertyList>\n");

for (String prop : databaseProperties.keySet()) {
try {
XmlaOlap4jDriver.Property.valueOf(prop);
continue;
} catch (IllegalArgumentException e) {
buf.append(" <");
xmlEncode(buf,prop);
buf.append(">");
xmlEncode(buf, databaseProperties.get(prop));
buf.append("</");
xmlEncode(buf, prop);
buf.append(">");
}
String conProperties = makeConnectionPropertyList();
if (conProperties != null && !("".equals(conProperties))) {
buf.append(conProperties);
}

if (roleName != null && !("".equals(roleName))) {
buf.append(" <Roles>");
xmlEncode(buf, roleName);
buf.append("</Roles>\n");
}

// Add the datasource node only if this request requires it.
Expand All @@ -949,12 +964,6 @@ public String generateRequest(
buf.append("</DataSourceInfo>\n");
}

if (roleName != null && !("".equals(roleName))) {
buf.append(" <Roles>");
xmlEncode(buf, roleName);
buf.append("</Roles>\n");
}

String requestCatalogName = null;
if (restrictedCatalogName != null
&& restrictedCatalogName.length() > 0)
Expand Down
10 changes: 10 additions & 0 deletions src/org/olap4j/driver/xmla/XmlaOlap4jStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ public boolean isWrapperFor(Class<?> iface) throws SQLException {
public CellSet executeOlapQuery(String mdx) throws OlapException {
final String catalog = olap4jConnection.getCatalog();
final String dataSourceInfo = olap4jConnection.getDatabase();
final String roleName = olap4jConnection.getRoleName();
final String propList = olap4jConnection.makeConnectionPropertyList();
StringBuilder buf = new StringBuilder(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<soapenv:Envelope\n"
Expand All @@ -305,6 +307,14 @@ public CellSet executeOlapQuery(String mdx) throws OlapException {
buf.append(catalog);
buf.append("</Catalog>\n");
}
if (propList != null) {
buf.append(propList);
}
if (roleName != null && !("".equals(roleName))) {
buf.append(" <Roles>");
buf.append(roleName);
buf.append("</Roles>\n");
}
if (dataSourceInfo != null) {
buf.append(" <DataSourceInfo>");
buf.append(dataSourceInfo);
Expand Down

0 comments on commit 4180611

Please sign in to comment.