From fd44edb4609632d0a874ba9d332a9fa2e571133c Mon Sep 17 00:00:00 2001 From: Luc Boudreau Date: Tue, 22 Mar 2011 20:48:15 +0000 Subject: [PATCH] Fixes the catalog XMLA object so that it first tries DBSCHEMA_SCHEMATA request to find schemas and falls back to MDSCHEMA_CUBES if the server rejected the first query. git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@425 c6a108a4-781c-0410-a6c6-c2d559e19af0 --- .../olap4j/driver/xmla/XmlaOlap4jCatalog.java | 43 ++++++++++++++++--- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/src/org/olap4j/driver/xmla/XmlaOlap4jCatalog.java b/src/org/olap4j/driver/xmla/XmlaOlap4jCatalog.java index 3d3303f..3e951c1 100644 --- a/src/org/olap4j/driver/xmla/XmlaOlap4jCatalog.java +++ b/src/org/olap4j/driver/xmla/XmlaOlap4jCatalog.java @@ -40,23 +40,52 @@ class XmlaOlap4jCatalog implements Catalog, Named { this.olap4jDatabaseMetaData = olap4jDatabaseMetaData; this.name = name; - // Fetching the schemas is a tricky part. There are no XMLA requests to - // obtain the available schemas for a given catalog. We therefore need - // to ask for the cubes, restricting results on the catalog, and while + // Some servers don't support MDSCHEMA_MDSCHEMATA, so we will + // override the list class so it tries it first, and falls + // back to the MDSCHEMA_CUBES trick, where ask for the cubes, + // restricting results on the catalog, and while // iterating on the cubes, take the schema name from this recordset. // // Many servers (SSAS for example) won't support the schema name column - // in the returned rowset. This has to be taken into account. + // in the returned rowset. This has to be taken into account as well. this.schemas = new DeferredNamedListImpl( - XmlaOlap4jConnection.MetadataRequest.MDSCHEMA_CUBES, + XmlaOlap4jConnection.MetadataRequest.DBSCHEMA_SCHEMATA, new XmlaOlap4jConnection.Context( olap4jDatabaseMetaData.olap4jConnection, olap4jDatabaseMetaData, this, null, null, null, null, null), - new XmlaOlap4jConnection.CatalogSchemaHandler(this.name), - null); + new XmlaOlap4jConnection.SchemaHandler(), + null) + { + @Override + protected void populateList(NamedList list) + throws OlapException + { + // First try DBSCHEMA_SCHEMATA + try { + super.populateList(list); + } catch (OlapException e) { + // Fallback to MDSCHEMA_CUBES trick + XmlaOlap4jConnection conn = + XmlaOlap4jCatalog.this + .olap4jDatabaseMetaData.olap4jConnection; + conn.populateList( + list, + new XmlaOlap4jConnection.Context( + conn, + conn.olap4jDatabaseMetaData, + XmlaOlap4jCatalog.this, + null, null, null, null, null), + XmlaOlap4jConnection.MetadataRequest + .MDSCHEMA_CUBES, + new XmlaOlap4jConnection.CatalogSchemaHandler( + XmlaOlap4jCatalog.this.name), + new Object[0]); + } + } + }; } public int hashCode() {