diff --git a/src/org/olap4j/OlapConnection.java b/src/org/olap4j/OlapConnection.java index 656d16b..0adae57 100644 --- a/src/org/olap4j/OlapConnection.java +++ b/src/org/olap4j/OlapConnection.java @@ -59,13 +59,23 @@ public interface OlapConnection extends Connection, OlapWrapper { OlapStatement createStatement() throws OlapException; /** - * Returns the current {@link org.olap4j.metadata.Schema} of this - * connection. + * Returns the database name that was selected for this connection, + * either through the JDBC URL or via + * {@link OlapConnection#setDatabase(String)}. * - * @return current Schema - * @throws OlapException if database error occurs + * @return The name of the database that was selected for this connection. + * @throws OlapException If a server error occurs. */ - Schema getSchema() throws OlapException; + String getDatabase() throws OlapException; + + /** + * Sets the name of the database that will be used for this connection. + * Overrides the value passed, if any, through the JDBC URL. + * + * @param databaseName The name of the database to use. + * @throws OlapException If a server error occurs. + */ + void setDatabase(String databaseName) throws OlapException; /** * Returns a list of {@link org.olap4j.metadata.Catalog} objects which @@ -76,9 +86,43 @@ public interface OlapConnection extends Connection, OlapWrapper { * * @see OlapDatabaseMetaData#getCatalogs() * @return List of Catalogs in this connection's OLAP server + * @deprecated Deprecated in favor of + * {@link OlapDatabaseMetaData#getOlapCatalogs()}. Will be removed as + * of version 1.0. */ + @Deprecated NamedList getCatalogs(); + /** + * Returns the {@link Catalog} name that was selected for this connection, + * either through the JDBC URL or via + * {@link OlapConnection#setCatalog(String)}. + * + * @return The name of the catalog that was selected for this connection. + * @throws OlapException If a server error occurs. + */ + String getCatalog() throws OlapException; + + /** + * Sets the name of the catalog that will be used for this connection. + * Overrides the value passed, if any, through the JDBC URL. + * + * @param catalogName The name of the catalog to use for this connection. + * @throws OlapException If a server error occurs. + */ + void setCatalog(String catalogName) throws OlapException; + + /** + * Returns the current active {@link org.olap4j.metadata.Schema} + * of this connection. + * @return The currently active schema, or null of none are + * currently selected. + * @throws OlapException if database error occurs + * @deprecated Will be removed as of version 1.0. + */ + @Deprecated + Schema getSchema() throws OlapException; + /** * Sets the current locale of this connection. The value must not be null. * diff --git a/src/org/olap4j/OlapDatabaseMetaData.java b/src/org/olap4j/OlapDatabaseMetaData.java index d9b14a4..ac8adfd 100644 --- a/src/org/olap4j/OlapDatabaseMetaData.java +++ b/src/org/olap4j/OlapDatabaseMetaData.java @@ -9,11 +9,9 @@ */ package org.olap4j; -import org.olap4j.metadata.Member; +import org.olap4j.metadata.*; -import java.sql.DatabaseMetaData; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.util.Set; /** @@ -105,7 +103,7 @@ ResultSet getActions( String actionNamePattern) throws OlapException; /** - * Retrives a list of olap4j data sources that are available on the server. + * Retrieves a list of olap4j data sources that are available on the server. * *

Specification as for XML/A DISCOVER_DATASOURCES schema rowset. The * rows are ordered by DATA_SOURCE_NAME. @@ -146,11 +144,137 @@ ResultSet getActions( * * @return a ResultSet object in which each row is a * datasource description - * * @exception OlapException if a database access error occurs + * @deprecated Deprecated in favor of + * {@link OlapDatabaseMetaData#getDatabases()}. Will be removed + * in version 1.0. */ + @Deprecated ResultSet getDatasources() throws OlapException; + /** + * Retrieves a row set describing the databases that are available on the + * server. + * + *

Specification as for XML/A DISCOVER_DATASOURCES schema rowset. + * + *

    + *
  1. DATA_SOURCE_NAME String => The name of the data source, such + * as FoodMart 2000.
  2. + *
  3. DATA_SOURCE_DESCRIPTION String => A description of the data + * source, as entered by the publisher. (may be + * null)
  4. + *
  5. URL String => The unique path that shows where to invoke the + * XML for Analysis methods for that data source. (may be + * null)
  6. + *
  7. DATA_SOURCE_INFO String => A string containing any additional + * information required to connect to the data source. This can + * include the Initial Catalog property or other information for + * the provider.
    Example: "Provider=MSOLAP;Data + * Source=Local;" (may be null)
  8. + *
  9. PROVIDER_NAME String => The name of the provider behind the + * data source.
    Example: "MSDASQL" (may be + * null)
  10. + *
  11. PROVIDER_TYPE EnumerationArray => The types of data supported + * by the provider. May include one or more of the following + * types. Example follows this table.
    TDP: tabular data + * provider.
    MDP: multidimensional data provider.
    DMP: + * data mining provider. A DMP provider implements the OLE DB for + * Data Mining specification.
  12. + *
  13. AUTHENTICATION_MODE EnumString => Specification of what type + * of security mode the data source uses. Values can be one of + * the following:
    Unauthenticated: no user ID or password + * needs to be sent.
    Authenticated: User ID and Password must + * be included in the information required for the + * connection.
    Integrated: the data source uses the + * underlying security to determine authorization, such as + * Integrated Security provided by Microsoft Internet Information + * Services (IIS).
  14. + *
+ * + * @return a ResultSet object in which each row is an + * OLAP database description + * @throws OlapException if a database access error occurs + */ + ResultSet getDatabases() throws OlapException; + + /** + * Retrieves a list of olap4j catalogs that are available on the server. + * + *

Specification as for XML/A DBSCHEMA_CATALOGS schema rowset. + * + *

+ * The list of returned catalogs is dependent on the underlying connection + * Database parameter. To discover catalogs in another database, use + * {@link OlapDatabaseMetaData#getDatabases()} and + * {@link OlapConnection#setDatabase(String)} + * + *

    + *
  1. CATALOG_NAME String => The catalog name, such as + * FoodMart.
  2. + * + *
  3. DESCRIPTION String => A description of the + * catalog, as entered by the publisher. (may be + * null)
+ * + *
  • ROLES String => A comma separated list of role names + * that users can impersonate. (may be + * null)
  • + * + *
  • DATE_MODIFIED String => The date of the latest modifications + * to the catalog. (may be null)
  • + * + * @return a ResultSet object in which each row is an + * OLAP catalog description + * @throws OlapException if a database access error occurs + */ + ResultSet getCatalogs() throws OlapException; + + /** + * Returns a list of {@link org.olap4j.metadata.Catalog} objects which + * belong to this connection's OLAP server. + * + *

    + * The list of returned catalogs is dependent on the underlying connection + * Database parameter. To discover catalogs in another database, use + * {@link OlapDatabaseMetaData#getDatabases()} and + * {@link OlapConnection#setDatabase(String)} + * + *

    The caller should assume that the list is immutable; + * if the caller modifies the list, behavior is undefined.

    + * + * @return List of Catalogs in this connection's OLAP server + * @throws OlapException if a database access error occurs + */ + NamedList getOlapCatalogs() throws OlapException; + + /** + * Retrieves a list of olap4j schemas that are available on the server. + * + *

    Specification as for XML/A DBSCHEMA_SCHEMATA schema rowset. + * + *

    + * The list of returned catalogs is dependent on the underlying connection + * Database parameter. To discover schemas in another database, use + * {@link OlapDatabaseMetaData#getDatabases()} and + * {@link OlapConnection#setDatabase(String)} + * + *

      + *
    1. CATALOG_NAME String => The name of the parent catalog to which + * the schema belongs to.
    2. + * + *
    3. SCHEMA_NAME String => The name of the schema.
    4. + * + *
    5. SCHEMA_OWNER String => The name of the user who is the owner + * of the schema (may be null)
    6. + *
    + * + * @return a ResultSet object in which each row is an OLAP + * schema description + * @throws OlapException if a database access error occurs + */ + ResultSet getSchemas() throws OlapException; + /** * Retrieves a list of information on supported literals, including data * types and values. diff --git a/src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java b/src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java index 04011dd..add7077 100644 --- a/src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java +++ b/src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java @@ -70,8 +70,23 @@ abstract class XmlaOlap4jConnection implements OlapConnection { final URL serverUrl; private Locale locale; + + /** + * Name of the current catalog to which this connection is bound to, + * as specified by the server. + */ + private String nativeCatalogName; + + /** + * Name of the catalog to which the user wishes to bind + * this connection. This value can be set through the JDBC URL + * or via {@link XmlaOlap4jConnection#setCatalog(String)} + */ private String catalogName; - private final String driverCatalogName; + + /** + * Name of the role that this connection impersonates. + */ private String roleName; /** @@ -80,22 +95,30 @@ abstract class XmlaOlap4jConnection implements OlapConnection { private String providerName; /** - * Datasource name. + * Name of the database to which the user wishes to bind + * this connection. This value can be set through the JDBC URL + * or via {@link XmlaOlap4jConnection#setCatalog(String)} */ - private String datasourceName; + private String databaseName; /** - * Holds the datasource name as specified by the server. Necessary because - * some servers (such as mondrian) return both the provider - * name and the datasource name in their response. + * Holds the database name as specified by the server. Necessary because + * some servers (such as Mondrian) return both the provider + * name and the database name in their response. * - *

    It's this value that we use inside queries, and not the jdbc + *

    It's this value that we use inside queries, and not the JDBC * query value. */ - private String nativeDatasourceName; + private String nativeDatabaseName; + private boolean autoCommit; private boolean readOnly; + /** + * This is a private property used for development only. + * Enabling it makes the connection print out all queries + * to {@link System#out} + */ private static final boolean DEBUG = false; /** @@ -138,23 +161,27 @@ abstract class XmlaOlap4jConnection implements OlapConnection { Properties info) throws SQLException { - this.factory = factory; - this.driver = driver; - this.proxy = proxy; if (!acceptsURL(url)) { // This is not a URL we can handle. // DriverManager should not have invoked us. throw new AssertionError( "does not start with '" + CONNECT_STRING_PREFIX + "'"); } + + this.factory = factory; + this.driver = driver; + this.proxy = proxy; + Map map = parseConnectString(url, info); - this.providerName = map.get(XmlaOlap4jDriver.Property.Provider.name()); - this.datasourceName = - map.get(XmlaOlap4jDriver.Property.DataSource.name()); - this.driverCatalogName = + this.providerName = + map.get(XmlaOlap4jDriver.Property.Provider.name()); + + this.databaseName = + map.get(XmlaOlap4jDriver.Property.Database.name()); + + this.catalogName = map.get(XmlaOlap4jDriver.Property.Catalog.name()); - this.catalogName = driverCatalogName; // Set URL of HTTP server. String serverUrl = map.get(XmlaOlap4jDriver.Property.Server.name()); @@ -251,72 +278,68 @@ static boolean acceptsURL(String url) { return url.startsWith(CONNECT_STRING_PREFIX); } - /** - * Returns the native datasource name, using the cached value if already - * computed. - * - *

    Not part of public API. - * - * @return native datasource name - * @throws OlapException if cannot find a datasource that matches - */ - String getDataSourceInfo() throws OlapException { - // If we already know it, return it. - if (this.nativeDatasourceName != null) { - return this.nativeDatasourceName; + public void setDatabase(String databaseName) throws OlapException { + this.databaseName = databaseName; + this.nativeCatalogName = null; + } + public String getDatabase() throws OlapException { + // If we already know it, return it. + if (this.nativeDatabaseName != null) { + return this.nativeDatabaseName; } ResultSet rSet = null; try { // We need to query for it - rSet = this.olap4jDatabaseMetaData.getDatasources(); + rSet = this.olap4jDatabaseMetaData.getDatabases(); // Check if the user requested a particular one. - if (this.datasourceName != null || this.providerName != null) { - // We iterate through the datasources + if (this.databaseName != null || this.providerName != null) { + // We iterate through the databases while (rSet.next()) { // Get current values String currentDatasource = rSet.getString(DATA_SOURCE_NAME); String currentProvider = rSet.getString(PROVIDER_NAME); - // If datasource and provider match, we got it. - // If datasource matches but no provider is specified, we + // If database and provider match, we got it. + // If database matches but no provider is specified, we // got it. - // If provider matches but no datasource specified, we + // If provider matches but no database specified, we // consider it good. - if (currentDatasource.equals(this.datasourceName) + if (currentDatasource.equals(this.databaseName) && currentProvider.equals(this.providerName) - || currentDatasource.equals(this.datasourceName) + || currentDatasource.equals(this.databaseName) && this.providerName == null || currentProvider.equals(this.providerName) - && this.datasourceName == null) + && this.databaseName == null) { // Got it - this.nativeDatasourceName = currentDatasource; + this.nativeDatabaseName = currentDatasource; break; } } } else { // Use first if (rSet.first()) { - this.nativeDatasourceName = + this.nativeDatabaseName = rSet.getString(DATA_SOURCE_NAME); } } // Throws exception to the client. Tells that there are - // no datasource corresponding to the search criterias. - if (this.nativeDatasourceName == null) { + // no database corresponding to the search criteria. + if (this.nativeDatabaseName == null) { throw getHelper().createException( - "No datasource could be found."); + "No database could be found on the server."); } - // If there is a provider - return this.nativeDatasourceName; + return this.nativeDatabaseName; } catch (OlapException e) { throw e; } catch (SQLException e) { - throw getHelper().createException("Datasource name not found.", e); + throw getHelper().createException( + "An exception occured while trying to resolve the database name.", + e); } finally { try { if (rSet != null) { @@ -384,40 +407,24 @@ public boolean isReadOnly() throws SQLException { return readOnly; } - public void setCatalog(String catalog) throws SQLException { + public void setCatalog(String catalog) throws OlapException { this.catalogName = catalog; + this.nativeCatalogName = null; } public String getCatalog() throws OlapException { - // REVIEW: All this logic to deduce and check catalog name should be - // done on initialization (construction, or setCatalog), not here. This - // method should be very quick. - - if (this.catalogName == null) { - // This means that no particular catalog name - // was specified by the user. - List catalogs = this.getCatalogs(); - if (catalogs.size() == 0) { + if (this.nativeCatalogName == null) { + if (catalogName != null) { + this.nativeCatalogName = catalogName; + } else if (olap4jDatabaseMetaData.getOlapCatalogs().size() == 0) { throw new OlapException( "There is no catalog available to query against."); - } else if (driverCatalogName != null) { - this.catalogName = driverCatalogName; } else { - this.catalogName = catalogs.get(0).getName(); - } - } else { - // We must verify that the requested catalog name - // exists in the metadata. - Catalog buf = this.getCatalogs().get(this.catalogName); - if (buf != null) { - this.catalogName = buf.getName(); - } else { - throw new OlapException( - "There is no catalog named " + this.catalogName - + " available to query against."); + this.nativeCatalogName = + olap4jDatabaseMetaData.getOlapCatalogs().get(0).getName(); } } - return catalogName; + return nativeCatalogName; } public void setTransactionIsolation(int level) throws SQLException { @@ -568,6 +575,11 @@ public MdxValidator createMdxValidator(OlapConnection connection) { }; } + @Deprecated + /* + * This function must either be removed and the tests adapted or + * be made package private. + */ public synchronized org.olap4j.metadata.Schema getSchema() throws OlapException { @@ -828,7 +840,7 @@ public String generateRequest( // Add the datasource node only if this request requires it. if (metadataRequest.requiresDatasourceName()) { buf.append(" "); - xmlEncode(buf, context.olap4jConnection.getDataSourceInfo()); + xmlEncode(buf, context.olap4jConnection.getDatabase()); buf.append("\n"); } @@ -865,6 +877,13 @@ public String generateRequest( if (requestCatalogName != null && metadataRequest.allowsCatalogName()) { + if (getMetaData().getOlapCatalogs() + .get(requestCatalogName) == null) + { + throw new OlapException( + "No catalog named " + requestCatalogName + + " exist on the server."); + } buf.append(" "); xmlEncode(buf, requestCatalogName); buf.append("\n"); @@ -876,7 +895,7 @@ public String generateRequest( "\n" + " \n" + " \n" - + " \n" + + " \n" + "\n" + ""); return buf.toString(); @@ -1196,11 +1215,6 @@ public void handle( } static class MeasureHandler extends HandlerImpl { - private final XmlaOlap4jDimension measuresDimension; - - public MeasureHandler(XmlaOlap4jDimension measuresDimension) { - this.measuresDimension = measuresDimension; - } public void handle( Element row, Context context, @@ -1209,7 +1223,6 @@ public void handle( { /* Example: - FoodMart FoodMart diff --git a/src/org/olap4j/driver/xmla/XmlaOlap4jCube.java b/src/org/olap4j/driver/xmla/XmlaOlap4jCube.java index 04e0c18..9ce82c8 100644 --- a/src/org/olap4j/driver/xmla/XmlaOlap4jCube.java +++ b/src/org/olap4j/driver/xmla/XmlaOlap4jCube.java @@ -90,8 +90,7 @@ class XmlaOlap4jCube implements Cube, Named measures, context, XmlaOlap4jConnection.MetadataRequest.MDSCHEMA_MEASURES, - new XmlaOlap4jConnection.MeasureHandler( - this.dimensions.get("Measures")), + new XmlaOlap4jConnection.MeasureHandler(), restrictions); for (XmlaOlap4jMeasure measure : measures) { measuresMap.put(measure.getUniqueName(), measure); @@ -432,7 +431,7 @@ public void lookupMembersByUniqueName( Map memberMap) throws OlapException { if (olap4jSchema.olap4jCatalog.olap4jDatabaseMetaData - .olap4jConnection.getDataSourceInfo() + .olap4jConnection.getDatabase() .indexOf("Provider=Mondrian") != -1) //$NON-NLS-1$ { mondrianMembersLookup(memberUniqueNames, memberMap); diff --git a/src/org/olap4j/driver/xmla/XmlaOlap4jDatabaseMetaData.java b/src/org/olap4j/driver/xmla/XmlaOlap4jDatabaseMetaData.java index 670dfbb..988285a 100644 --- a/src/org/olap4j/driver/xmla/XmlaOlap4jDatabaseMetaData.java +++ b/src/org/olap4j/driver/xmla/XmlaOlap4jDatabaseMetaData.java @@ -64,7 +64,10 @@ abstract class XmlaOlap4jDatabaseMetaData implements OlapDatabaseMetaData { *

    Package-local because not part of olap4j API. * * @return List of catalog objects + * @deprecated Deprecated in favor of + * {@link OlapDatabaseMetaData#getOlapCatalogs()} */ + @Deprecated NamedList getCatalogObjects() { return catalogs; } @@ -694,16 +697,20 @@ public ResultSet getTables( throw new UnsupportedOperationException(); } - public ResultSet getSchemas() throws SQLException { + public ResultSet getSchemas() throws OlapException { return getMetadata( XmlaOlap4jConnection.MetadataRequest.DBSCHEMA_SCHEMATA); } - public ResultSet getCatalogs() throws SQLException { + public ResultSet getCatalogs() throws OlapException { return getMetadata( XmlaOlap4jConnection.MetadataRequest.DBSCHEMA_CATALOGS); } + public NamedList getOlapCatalogs() throws OlapException { + return Olap4jUtil.cast(catalogs); + } + public ResultSet getTableTypes() throws SQLException { throw new UnsupportedOperationException(); } @@ -989,6 +996,10 @@ public ResultSet getActions( } public ResultSet getDatasources() throws OlapException { + return this.getDatabases(); + } + + public ResultSet getDatabases() throws OlapException { return getMetadata( XmlaOlap4jConnection.MetadataRequest.DISCOVER_DATASOURCES); } diff --git a/src/org/olap4j/driver/xmla/XmlaOlap4jDriver.java b/src/org/olap4j/driver/xmla/XmlaOlap4jDriver.java index 82e1dd0..38bbee5 100644 --- a/src/org/olap4j/driver/xmla/XmlaOlap4jDriver.java +++ b/src/org/olap4j/driver/xmla/XmlaOlap4jDriver.java @@ -61,7 +61,14 @@ * * Provider Name of the XMLA provider. * - * DataSource Name of the XMLA datasource. When using a + * Database Name of the XMLA datasource. When using a + * Mondrian backed XMLA server, be sure to + * include the full datasource name between + * quotes. + * + * DataSource Deprecated in favor of + * 'Database'.
    + * Name of the XMLA datasource. When using a * Mondrian backed XMLA server, be sure to * include the full datasource name between * quotes. @@ -140,7 +147,7 @@ protected XmlaOlap4jDriver() { factoryClassName = "org.olap4j.driver.xmla.FactoryJdbc3Impl"; } try { - final Class clazz = Class.forName(factoryClassName); + final Class clazz = Class.forName(factoryClassName); factory = (Factory) clazz.newInstance(); } catch (ClassNotFoundException e) { throw new RuntimeException(e); @@ -301,6 +308,8 @@ public enum Property { Server("URL of HTTP server"), Catalog("Catalog name"), Provider("Name of the datasource provider"), + Database("Name of the database"), + @Deprecated DataSource("Name of the datasource"), Cache("Class name of the SOAP cache implementation"); diff --git a/src/org/olap4j/driver/xmla/XmlaOlap4jLevel.java b/src/org/olap4j/driver/xmla/XmlaOlap4jLevel.java index e6bfd0f..b1ea586 100644 --- a/src/org/olap4j/driver/xmla/XmlaOlap4jLevel.java +++ b/src/org/olap4j/driver/xmla/XmlaOlap4jLevel.java @@ -121,8 +121,7 @@ class XmlaOlap4jLevel olap4jHierarchy.olap4jDimension, olap4jHierarchy, this), - new XmlaOlap4jConnection.MeasureHandler( - olap4jHierarchy.olap4jDimension), + new XmlaOlap4jConnection.MeasureHandler(), restrictions)); } else { this.memberList = new DeferredNamedListImpl( diff --git a/src/org/olap4j/driver/xmla/XmlaOlap4jStatement.java b/src/org/olap4j/driver/xmla/XmlaOlap4jStatement.java index 3207d51..8f94739 100644 --- a/src/org/olap4j/driver/xmla/XmlaOlap4jStatement.java +++ b/src/org/olap4j/driver/xmla/XmlaOlap4jStatement.java @@ -275,7 +275,7 @@ public boolean isWrapperFor(Class iface) throws SQLException { public CellSet executeOlapQuery(String mdx) throws OlapException { final String catalog = olap4jConnection.getCatalog(); - final String dataSourceInfo = olap4jConnection.getDataSourceInfo(); + final String dataSourceInfo = olap4jConnection.getDatabase(); StringBuilder buf = new StringBuilder( "\n" + "To obtain the collection of catalogs in the current server, call the - * {@link org.olap4j.OlapConnection#getCatalogs()} method. + * {@link OlapDatabaseMetaData#getOlapCatalogs()} method. * *

    The hierarchy of metadata objects, rooted at the connection from which * they are accessed, is as follows: diff --git a/testsrc/org/olap4j/ConnectionTest.java b/testsrc/org/olap4j/ConnectionTest.java index c497566..47053d4 100644 --- a/testsrc/org/olap4j/ConnectionTest.java +++ b/testsrc/org/olap4j/ConnectionTest.java @@ -66,7 +66,7 @@ protected void tearDown() throws Exception { * Driver basics. */ public void testDriver() throws ClassNotFoundException, SQLException { - Class clazz = Class.forName(tester.getDriverClassName()); + Class clazz = Class.forName(tester.getDriverClassName()); assertNotNull(clazz); assertTrue(Driver.class.isAssignableFrom(clazz)); @@ -164,7 +164,7 @@ void assertIsClosed(Object o, boolean b) { } // assertTrue(statment.isClosed()); try { - Class clazz; + Class clazz; if (o instanceof Statement) { clazz = Statement.class; } else if (o instanceof ResultSet) { @@ -352,7 +352,7 @@ public void testXmlaCatalogParameter() throws Exception { info); assertEquals("FoodMart", connection.getCatalog()); final NamedList catalogs = - ((OlapConnection) connection).getCatalogs(); + ((OlapConnection) connection).getMetaData().getOlapCatalogs(); assertNotNull(catalogs); Statement statement = connection.createStatement(); OlapStatement olapStatement = @@ -380,11 +380,18 @@ public void testXmlaCatalogParameter() throws Exception { connection = DriverManager.getConnection( tester.getURL().replaceFirst("\\;Catalog=FoodMart", ""), info); - connection.getCatalog(); + Statement statement2 = connection.createStatement(); + OlapStatement olapStatement2 = + TestContext.Wrapper.NONE.unwrap( + statement, + OlapStatement.class); + CellSet cellSet2 = + olapStatement.executeOlapQuery( + "SELECT FROM [Sales]"); + fail(); } catch (OlapException e) { if (e.getMessage().equals( - "There is no catalog named FoodMartError available to " - + "query against.")) + "No catalog named FoodMartError exist on the server.")) { return; } @@ -489,9 +496,9 @@ public void testAxes() throws SQLException { assertEquals(2, axesList.size()); final Member rowsMember = axesList.get(0).getPositions().get(0).getMembers().get(0); -// assertTrue( -// rowsMember.getUniqueName(), -// rowsMember instanceof Measure); + assertTrue( + rowsMember.getUniqueName(), + rowsMember instanceof Measure); final Member columnsMember = axesList.get(1).getPositions().get(0).getMembers().get(0); assertTrue( @@ -1559,7 +1566,16 @@ public void testCubeLookupMember() throws Exception { connection = tester.createConnection(); OlapConnection olapConnection = tester.getWrapper().unwrap(connection, OlapConnection.class); - Cube cube = olapConnection.getSchema().getCubes().get("Sales Ragged"); + + Cube cube = + olapConnection + .getMetaData() + .getOlapCatalogs() + .get("FoodMart") + .getSchemas() + .get("FoodMart") + .getCubes() + .get("Sales Ragged"); Member member = cube.lookupMember(nameList("Time", "1997", "Q2")); @@ -1603,7 +1619,16 @@ public void testCubeLookupMembers() throws Exception { connection = tester.createConnection(); OlapConnection olapConnection = tester.getWrapper().unwrap(connection, OlapConnection.class); - Cube cube = olapConnection.getSchema().getCubes().get("Sales"); + + Cube cube = + olapConnection + .getMetaData() + .getOlapCatalogs() + .get("FoodMart") + .getSchemas() + .get("FoodMart") + .getCubes() + .get("Sales"); List memberList = cube.lookupMembers( @@ -1722,36 +1747,30 @@ public void testMetadata() throws Exception { connection = tester.createConnection(); OlapConnection olapConnection = tester.getWrapper().unwrap(connection, OlapConnection.class); - - // Schema - boolean found = false; - for (Catalog catalog : olapConnection.getCatalogs()) { - assertSame(olapConnection.getMetaData(), catalog.getMetaData()); - assertNotNull(catalog.getName()); - for (Schema schema : catalog.getSchemas()) { - assertSame(schema.getCatalog(), catalog); - if (schema.equals(olapConnection.getSchema())) { - found = true; - break; - } - } - } - assertTrue(found); + OlapDatabaseMetaData metadata = olapConnection.getMetaData(); // We engineered the XMLA test environment to have two catalogs. switch (tester.getFlavor()) { case REMOTE_XMLA: - assertEquals(1, olapConnection.getCatalogs().size()); + assertEquals(1, metadata.getOlapCatalogs().size()); break; case XMLA: - assertEquals(2, olapConnection.getCatalogs().size()); + assertEquals(2, metadata.getOlapCatalogs().size()); break; case MONDRIAN: - assertEquals(1, olapConnection.getCatalogs().size()); + assertEquals(1, metadata.getOlapCatalogs().size()); break; } - Cube cube = olapConnection.getSchema().getCubes().get("Sales"); + Cube cube = + olapConnection + .getMetaData() + .getOlapCatalogs() + .get("FoodMart") + .getSchemas() + .get("FoodMart") + .getCubes() + .get("Sales"); int z = 0; int hierarchyCount = 0; @@ -1796,7 +1815,6 @@ public void testMetadata() throws Exception { if (level.getCardinality() >= 100) { continue; } - int k = 0; if (level.getName().equals("Year")) { assertEquals( Level.Type.TIME_YEARS, level.getLevelType()); @@ -1849,7 +1867,15 @@ public void testMetadata() throws Exception { 2, timeWeeklyHierarchy.getDimension().getHierarchies().size()); Cube warehouseCube = - olapConnection.getSchema().getCubes().get("Warehouse"); + olapConnection + .getMetaData() + .getOlapCatalogs() + .get("FoodMart") + .getSchemas() + .get("FoodMart") + .getCubes() + .get("Warehouse"); + int count = 0; for (NamedSet namedSet : warehouseCube.getSets()) { ++count; @@ -2588,7 +2614,9 @@ private void buildQuery( boolean useCubeObject) throws OlapException { - Catalog catalog = olapConnection.getCatalogs().get("FoodMart"); + Catalog catalog = + olapConnection.getMetaData().getOlapCatalogs() + .get("FoodMart"); Schema schema = catalog.getSchemas().get("FoodMart"); Cube cube = schema.getCubes().get("Sales"); SelectNode query = new SelectNode(); @@ -2643,7 +2671,13 @@ public void testBuildQuery2() throws ClassNotFoundException, SQLException { OlapConnection olapConnection = tester.getWrapper().unwrap(connection, OlapConnection.class); - Schema schema = olapConnection.getSchema(); + Schema schema = + olapConnection + .getMetaData() + .getOlapCatalogs() + .get("FoodMart") + .getSchemas() + .get("FoodMart"); Cube cube = schema.getCubes().get("Sales"); Measure measure = cube.getMeasures().get(0); assertEquals("Unit Sales", measure.getName()); @@ -2734,7 +2768,15 @@ public void testCubeDimensionsOrder() throws Exception { connection = tester.createConnection(); OlapConnection olapConnection = tester.getWrapper().unwrap(connection, OlapConnection.class); - Cube cube = olapConnection.getSchema().getCubes().get("Sales"); + Cube cube = + olapConnection + .getMetaData() + .getOlapCatalogs() + .get("FoodMart") + .getSchemas() + .get("FoodMart") + .getCubes() + .get("Sales"); StringBuilder sb = new StringBuilder(); for (Dimension dimension : cube.getDimensions()) { sb.append(dimension.getUniqueName())