diff --git a/doc/olap4j_fs.html b/doc/olap4j_fs.html index c3bc0f9..2211b72 100644 --- a/doc/olap4j_fs.html +++ b/doc/olap4j_fs.html @@ -82,7 +82,7 @@

olap4j Functional Specification

Version: 0.6-dev (draft)
Revision: $Id: $ (log)
-Last modified: May 26th, 2007.

+Last modified: June 10th, 2007.


Contents

@@ -134,13 +134,13 @@

Contents

interface -
  • MDX query model
  • +
  • MDX parse tree model
  • +
  • MDX parser
  • MDX type model
  • Metadata
    1. Access control
    2. Metadata objects
      1. The MetadataElement interface
      2. -
      3. The Database interface
      4. The Catalog interface
      5. The Schema interface
      6. The Cube interface
      7. @@ -505,6 +505,11 @@

        2.2. Connections

        java.sql.Connection) is a connection to an OLAP data source.

        +

        +Methods:

        +
          +
        • NamedList<Catalog> getCatalogs()
        • +

        2.2.2. Connection pooling

        @@ -523,7 +528,8 @@

        2.2.2. Connection pooling

        OlapConnection. To access methods of the OlapConnection, the client application must first strip away the wrapper object.

        -

        If you are using a connection-pooling library, olap4j provides a helper class to access the object underneath a wrapped +

        If you are using a connection-pooling library, olap4j provides a helper +method unwrap(Class) to access the object underneath a wrapped connection, statement, prepared statement or result set. For instance,

        DataSource dataSource; // a data source using a connection @@ -535,24 +541,13 @@

        2.2.2. Connection pooling

                "Catalog=/WEB-INF/queries/FoodMart.xml;" +
                "Role='California manager'");
        - OlapConnection olapConnection = Olap4j.convert(connection);
        + OlapConnection olapConnection = connection.unwrap(OlapConnection.class);
        OlapStatement statement = olapConnection.createOlapStatement();
        -

        The - -Olap4j.convert(Connection) method returns an OlapConnection. It -works with common connection pools, and the resulting object is instrumented so -that any statements or prepared statements created from that connection also -work with the connection pool.

        -

        The problem does not just affect connections: some connection pools also wrap -Statement, PreparedStatement, CellSet -and - -DatabaseMetaData objects, so there are convert() -methods for these too.

        -

        Hopefully this problem will only be temporary. As olap4j gains popularity, we -expect connection pools to add support for the extended interfaces, and it will -be sufficient merely to cast the objects returned from factory methods.

        +

        The unwrap method is part of the +java.sql.Wrapper interface introduced in JDBC 4.0, but +will also work when olap4j is used with JDBC 3.0. We hope that popular +connection pools will utilize this method in the near future.

        2.3. Statements

        2.3.1. The OlapStatement interface

        @@ -656,17 +651,42 @@

        2.3.7. The Cell interface

        2.3.8. The CellSetMetaData interface

        -

        Extends ResultSetMetaData

        +

        Extends + +java.sql.ResultSetMetaData.

        +

        Methods:

        +
          +
        • List<Property> getCellProperties()
        • +
        • Cube getCube()
        • +
        • List<CellSetAxisMetaData> getAxesMetaData()
        • +

        2.3.9. The OlapDatabaseMetaData interface

        -

        Extends DatabaseMetaData

        +

        Extends + +java.sql.DatabaseMetaData.

        2.3.10. The CellSetAxis interface

        +

        Methods:

        +
          +
        • int getOrdinal()
        • +
        • CellSet getCellSet()
        • +
        • CellSetAxisMetaData getAxisMetaData()
        • +
        • List<Position> getPositions()
        • +
        • int getPositionCount()
        • +
        • ListIterator<Position> iterate()
        • +

        2.3.11. The CellSetAxisMetaData interface

        +

        Methods:

        +
          +
        • Axis getAxis()
        • +
        • List<Hierarchy> getHierarchies()
        • +
        • List<Property> getProperties()
        • +

        2.4. MDX query model

        @@ -694,56 +714,76 @@

        2.4. MDX query model

        // Create a query model.
        - OlapConnection connection;
        - Query query = new Query();
        - query.setFrom("Sales");
        - query.getAxes().add(
        -    new Axis(
        -        "ROWS",
        -        false,
        -        new UnresolvedFunCall(
        -            "{}",
        -            - Syntax.Special,
        -            new Id(new - String[] {"Measures", "Unit Sales"})));
        + SelectNode query = new SelectNode();
        + query.setCubeName(
        +    new IdentifierNode(
        +        new + IdentifierNode.Segment("Sales")));
        + query.getAxisList().add(
        +    new AxisNode(
        +        false,
        +        new CallNode(
        +            "{}",
        +            + Syntax.Braces,
        +            new + IdentifierNode(
        +                + new IdentifierNode.Segment("Measures"),
        +                + new IdentifierNode.Segment("Unit Sales"))),
        +        Axis.ROWS,
        +        new ArrayList<IdentifierNode>()));

        // Create a statement based upon the query model.
        OlapStatement stmt;
        try {
        -    stmt = connection.createOlapStatement(query);
        +    stmt = connection.createStatement();
        } catch (OlapException e) {
        -    System.out.println("Validation failed: " + e);
        -    return;
        +    System.out.println("Validation failed: " + e);
        +    return;
        }

        // Execute the statement.
        CellSet cset;
        try {
        -    cset = stmt.execute();
        +    cset = stmt.executeOlapQuery(query);
        } catch (OlapException e) {
        -    System.out.println("Execution failed: " + e);
        - }
        +    System.out.println("Execution failed: " + e);
        + }

        Package name: org.olap4j.mdx

        Classes:

          -
        • Query
        • -
        • Axis
        • -
        • FunCall
        • -
        • UnresolvedFunCall
        • -
        • Id
        • -
        • Literal
        • -
        • MemberExpr
        • -
        • LevelExpr
        • -
        • HierarchyExpr
        • -
        • DimensionExpr
        • -
        • ParserFactory
        • -
        • Parser
        • +
        • ParseTreeNode
        • +
        • SelectNode
        • +
        • AxisNode
        • +
        • CallNode
        • +
        • IdentifierNode
        • +
        • LiteralNode
        • +
        • MemberNode
        • +
        • LevelNode
        • +
        • HierarchyNode
        • +
        • DimensionNode
        • +
        • WithMemberNode
        • +
        • WithSetNode
        • +
        • PropertyValueNode
        • +
        + +

        2.5. MDX parser

        + +

        Package name: org.olap4j.mdx.parser

        + +

        Represents the types of nodes in an MDX query model.

        + +
          +
        • MdxParserFactory
        • +
        • MdxParser
        -

        2.5. MDX type model

        +

        2.6. MDX type model

        Package name: org.olap4j.type

        @@ -849,7 +889,7 @@

        2.5. MDX type model

        CrossJoin({[Gender].[F], [Gender].[M]}, [Store].Members) is Set(Tuple(Member(level=[Gender].[Gender]), Member(hierarchy=[Store])). -

        2.6. Metadata

        +

        2.7. Metadata

        Package name: org.olap4j.metadata

        @@ -868,7 +908,7 @@

        2.6. Metadata

        OlapDatabaseMetaData.getCubes(<schemaName>, <cubeName>). -

        2.6.1. Access control

        +

        2.7.1. Access control

        A user's view of metadata may be subject to access control. For example, a user may not have read access to certain hierarchies within a cube, or to @@ -882,7 +922,7 @@

        2.6.1. Access control

        is invisible to him.

        -

        2.6.2. Metadata objects

        +

        2.7.2. Metadata objects

        [Diagram of object model, showing relationships. Catalog contains Schema; Schema contains Cube and shared Dimension; Cube contains Dimension, Measure and Set; Measure is a Member; Dimension contains Hierarchy; Hierarchy contains @@ -905,7 +945,7 @@

        2.6.2. Metadata objects

        and do not use IdentityHashMap.

        -
        2.6.2.1. The MetadataElement interfacee
        +
        2.7.2.1. The MetadataElement interface

        MetadataElement is the base class for Cube, Dimension, Hierarchy, Level, Member, Property; provides name and unique-name properties (not localized), and localized caption and @@ -916,21 +956,19 @@

        2.6.2.1. The MetadataElement interfacee
      8. String getCaption(Locale locale)
      9. String getDescription(Locale locale)
      10. -
        2.6.2.2. The Database interface
        -

        Database -is the root element in a hierarchy of metadata elements.

        -

        Methods:

        -
          -
        • NamedList<Catalog> getCatalogs()
        • -
        -
        2.6.2.3. The Catalog interface
        +
        2.7.2.2. The Catalog interface

        Catalog -...

        +is the highest level element in the hierarchy of metadata objects.

        +

        Some OLAP servers may only have one catalog. Mondrian is one such OLAP +server; its sole catalog is always called "LOCALDB".

        +

        To obtain the collection of catalogs in the current server, call the +OlapConnection.getCatalogs() method.

        +

        Methods:

        • String getName()
        • NamedList<Schema> getSchemas()
        -
        2.6.2.4. The Schema interface
        +
        2.7.2.3. The Schema interface

        Schema ...

        -
        2.6.2.5. The Cube interface
        +
        2.7.2.4. The Cube interface

        Cube ...

        -
        2.6.2.6. The Dimension interface
        +
        2.7.2.5. The Dimension interface

        Dimension (extends MetadataElement)

        @@ -958,7 +996,7 @@
        2.6.2.6. The Dimension interface
      11. List<Member> getRootMembers()
      12. Dimension.Type getDimensionType()
      13. -
        2.6.2.7. The Hierarchy interface
        +
        2.7.2.6. The Hierarchy interface

        Hierarchy  (extends MetadataElement) @@ -968,8 +1006,9 @@

        2.6.2.7. The Hierarchy interface
      14. String getName()
      15. List<Level> getLevels()
      16. boolean hasAll()
      17. +
      18. Member getDefaultMember()
      19. -
        2.6.2.8. The Level interface
        +
        2.7.2.7. The Level interface

        Level  (extends MetadataElement) ...

        @@ -979,7 +1018,7 @@
        2.6.2.8. The Level interface
      20. Level.Type getLevelType()
      21. List<Property> getProperties()
      22. -
        2.6.2.9. The Member interface
        +
        2.7.2.8. The Member interface

        Member  (extends MetadataElement) ...

        @@ -1002,14 +1041,14 @@
        2.6.2.9. The Member interface
      23. boolean isHidden()
      24. Member getDataMember()
      25. -
        2.6.2.10. The Measure interface
        +
        2.7.2.9. The Measure interface

        Measure  (extends MetadataElement) ...

        • extends Member
        -
        2.6.2.11. The Property interface
        +
        2.7.2.10. The Property interface

        Property  (extends MetadataElement) @@ -1025,7 +1064,7 @@

        2.6.2.11. The Property interface
        }
      26. enum StandardCellProperty { BACK_COLOR, CELL_EVALUATION_LIST, ... }
      27. -
        2.6.2.12. The NamedSet interface
        +
        2.7.2.11. The NamedSet interface

        NamedSet (extends MetadataElement) @@ -1033,7 +1072,7 @@

        2.6.2.12. The NamedSet interface
        • Cube getCube()
        -

        2.6.3. +

        2.7.3. The OlapDatabaseMetaData interface, and methods which return schema rowsets

        @@ -1253,7 +1292,7 @@

        2.6.3. DBTYPE_BOOL to boolean; DBTYPE_I4, DBTYPE_UI4, DBTYPE_I2 and DBTYPE_UI2 all map to int. Column names: mapped CamelCase to UPPER_CASE.]

        -
        2.6.3.1. getDatasources
        +

        2.7.3.1. getDatasources

        Specified by the DISCOVER_DATASOURCES XML for Analysis method.

        The returned result set contains the following columns.

        @@ -1349,7 +1388,7 @@
        2.6.3.1. getDatasources
        -
        2.6.3.2. getDatabaseProperties
        +
        2.7.3.2. getDatabaseProperties

        Returns information about the standard and provider-specific properties supported by an @@ -1418,7 +1457,7 @@

        2.6.3.2. getDatabaseProperties

        [Is VALUE a JDBC reserved word? If so, change it.]

        -
        2.6.3.3 getLiterals
        +
        2.7.3.3 getLiterals

        Retrieves a list of information on supported literals, including data types and values.

        Specified by the DISCOVER_LITERALS XML for Analysis method.

        @@ -1483,7 +1522,7 @@
        2.6.3.3 getLiterals
        -
        2.6.3.4. getCubes
        +
        2.7.3.4. getCubes

        Describes the structure of cubes within a database.

        Specified by the MDSCHEMA_CUBES XML for Analysis method.

        @@ -1599,7 +1638,7 @@
        2.6.3.4. getCubes

        The rowset is sorted on CATALOG_NAME, SCHEMA_NAME, CUBE_NAME.

        -
        2.6.3.5. getDimensions
        +
        2.7.3.5. getDimensions

        Retrieves a result set describing the shared and private dimensions within a database.

        Specified by the MDSCHEMA_DIMENSIONS XML for Analysis method.

        @@ -1738,7 +1777,7 @@
        2.6.3.5. getDimensions

        The result set is sorted on CATALOG_NAME, SCHEMA_NAME, CUBE_NAME, DIMENSION_NAME.

        -
        2.6.3.6. getFunctions
        +
        2.7.3.6. getFunctions

        Retrieves a result set describing the functions available to client applications connected to the database.

        @@ -1837,7 +1876,7 @@
        2.6.3.6. getFunctions

        The rowset is sorted on ORIGIN, INTERFACE_NAME, FUNCTION_NAME.

        -
        2.6.3.7. getHierarchies
        +
        2.7.3.7. getHierarchies

        Retrieves a result set describing each hierarchy within a particular dimension.

        Specified by the MDSCHEMA_HIERARCHIES XML for Analysis method.

        @@ -2059,7 +2098,7 @@
        2.6.3.7. getHierarchies
        SCHEMA_NAME, CUBE_NAME, DIMENSION_UNIQUE_NAME, HIERARCHY_NAME.

        -
        2.6.3.8. getLevels
        +
        2.7.3.8. getLevels

        Retrieves a result set describing each level within a particular hierarchy.

        Specified by the MDSCHEMA_LEVELS XML for Analysis method.

        The returned result set contains the following columns.

        @@ -2302,7 +2341,7 @@
        2.6.3.8. getLevels
        SCHEMA_NAME, CUBE_NAME, DIMENSION_UNIQUE_NAME, HIERARCHY_UNIQUE_NAME, LEVEL_NUMBER.

        -
        2.6.3.9. getMeasures
        +
        2.7.3.9. getMeasures

        Retrieves a result set describing each measure within a cube.

        Specified by the MDSCHEMA_MEASURES XML for Analysis method.

        The returned result set contains the following columns.

        @@ -2468,7 +2507,7 @@
        2.6.3.9. getMeasures

        The rowset is sorted on CATALOG_NAME, SCHEMA_NAME, CUBE_NAME, MEASURE_NAME.

        -
        2.6.3.10. getMembers
        +
        2.7.3.10. getMembers

        Retrieves a result set describing the members within a database.

        Specified by the MDSCHEMA_MEMBERS XML for Analysis method.

        The returned result set contains the following columns.

        @@ -2650,7 +2689,7 @@
        2.6.3.10. getMembers
        HIERARCHY_UNIQUE_NAME, LEVEL_UNIQUE_NAME, LEVEL_NUMBER, MEMBER_ORDINAL.

        -
        2.6.3.11. getProperties
        +
        2.7.3.11. getProperties

        Retrieves a list of descriptions of member and cell Properties.

        Specified by the MDSCHEMA_PROPERTIES XML for Analysis method.

        @@ -2937,7 +2976,7 @@
        2.6.3.11. getProperties

        This schema rowset is not sorted.

        -
        2.6.3.12. getSets
        +
        2.7.3.12. getSets

        Retrieves a result set describing any sets that are currently defined in a database, including session-scoped sets.

        Specified by the MDSCHEMA_SETS XML for Analysis method.

        @@ -3015,7 +3054,7 @@
        2.6.3.12. getSets

        The rowset is sorted on CATALOG_NAME, SCHEMA_NAME, CUBE_NAME.

        -

        2.6.4. Other methods

        +

        2.7.4. Other methods

        @@ -3035,7 +3074,7 @@

        2.6.4. Other methods

        -

        2.7. Transform

        +

        2.8. Transform

        A transform is an operation which maps a query model to a new query model. It is usually triggered by a gesture within the user-interface. For example, @@ -3076,7 +3115,7 @@

        2.7. Transform

      28. Slicer
      29. -

        2.7.1. Query Model Details

        +

        2.8.1. Query Model Details

        This section should probably be moved into Section 2.4

        The MDX query language uses a data model based on cubes, dimensions, tuples @@ -3089,12 +3128,12 @@

        2.7.1. Query Model Details

        zero or more axes using a data slicer. (The axes loosely correspond to the "SELECT" clause in a SQL query, and the slicer to the "WHERE".) -

        2.7.2. Navigation Actions

        +

        2.8.2. Navigation Actions

        The defined set of navigations can be divided into four categories: Slicing, Restructuring, Drilling, Scoping.

        -
        2.7.2.1. Slicing Navigations
        +
        2.8.2.1. Slicing Navigations
        setSlicer
        Secifies the slicer to use, replacing any current one.
        getSlicer
        Retrieve the current slicer.
        @@ -3103,7 +3142,7 @@
        2.7.2.1. Slicing Navigations
        for a specified measure.
        -
        2.7.2.2. Restructuring Navigations
        +
        2.8.2.2. Restructuring Navigations

        Restructuring navigations change the axes of the returned cube.

        @@ -3122,7 +3161,7 @@
        2.7.2.2. Restructuring NavigationsdeleteTotal
        Deletes an aggregation from the specified member.
        -
        2.7.2.3. Drilling Navigations
        +
        2.8.2.3. Drilling Navigations

        Navigations that allow a user to move through the levels in a hierarchy. All drill navigations operate on a single Axis.

          @@ -3130,7 +3169,7 @@
          2.7.2.3. Drilling Navigations
          hierarchy. All members of the hierarchy are replaced by this action.
        -
        2.7.2.4. Scoping Navigations
        +
        2.8.2.4. Scoping Navigations

        Navigations that allow a user to expand/collapse sections of a result set. All scoping navigations operate on single Axis.

        -
        2.7.2.5. Supporting Actions
        +
        2.8.2.5. Supporting Actions

        Axis Operations

        -

        2.8. Layout

        +

        2.9. Layout

        The layout package provides data models for graphical OLAP applications. In particular, the GridModel class provides, for OLAP data, what Swing's @@ -3363,8 +3402,13 @@

        Appendix F. Change log

      30. Rename OlapResultSet to CellSet, OlapResultSetMetaData to CellSetMetaData, OlapResultAxis to CellSetAxis, ResultCell to Cell, ResultSetPosition to Position.
      31. +
      32. Removed class org.olap4j.metadata.Database; it was not adding much value + over OlapDatabaseMetaData, and was confusing because Database is a synonym + for Catalog in some servers.
      33. +
      34. Removed class Olap4j; unwrapping of Connections etc. is now provided + using java.sql.Wrapper.unwrap.

      35. - + \ No newline at end of file diff --git a/src/mondrian/olap4j/MondrianOlap4jCatalog.java b/src/mondrian/olap4j/MondrianOlap4jCatalog.java index 2648217..51c823b 100644 --- a/src/mondrian/olap4j/MondrianOlap4jCatalog.java +++ b/src/mondrian/olap4j/MondrianOlap4jCatalog.java @@ -12,22 +12,22 @@ import org.olap4j.metadata.Catalog; import org.olap4j.metadata.NamedList; import org.olap4j.metadata.Schema; -import org.olap4j.metadata.Database; import org.olap4j.OlapException; +import org.olap4j.OlapDatabaseMetaData; /** - * MondrianOlap4jCatalog ... + * Implementation of {@link org.olap4j.metadata.Catalog} for Mondrian. * * @author jhyde * @version $Id: $ * @since May 23, 2007 */ class MondrianOlap4jCatalog implements Catalog, Named { - final MondrianOlap4jDatabase olap4jDatabase; + final MondrianOlap4jDatabaseMetaData olap4jDatabaseMetaData; MondrianOlap4jCatalog( - MondrianOlap4jDatabase olap4jDatabase) { - this.olap4jDatabase = olap4jDatabase; + MondrianOlap4jDatabaseMetaData olap4jDatabaseMetaData) { + this.olap4jDatabaseMetaData = olap4jDatabaseMetaData; } public NamedList getSchemas() throws OlapException { @@ -38,18 +38,18 @@ public NamedList getSchemas() throws OlapException { list.add( new MondrianOlap4jSchema( this, - olap4jDatabase.metaData.connection.getSchemaReader(), - olap4jDatabase.metaData.connection.getSchema())); + olap4jDatabaseMetaData.connection.getSchemaReader(), + olap4jDatabaseMetaData.connection.getSchema())); return (NamedList) list; } - public Database getDatabase() { - return olap4jDatabase; - } - public String getName() { return "LOCALDB"; } + + public OlapDatabaseMetaData getMetaData() { + return olap4jDatabaseMetaData; + } } // End MondrianOlap4jCatalog.java diff --git a/src/mondrian/olap4j/MondrianOlap4jConnection.java b/src/mondrian/olap4j/MondrianOlap4jConnection.java index 1fbcb76..4737518 100644 --- a/src/mondrian/olap4j/MondrianOlap4jConnection.java +++ b/src/mondrian/olap4j/MondrianOlap4jConnection.java @@ -17,8 +17,8 @@ import org.olap4j.*; import org.olap4j.metadata.Schema; -import org.olap4j.metadata.Database; import org.olap4j.metadata.Catalog; +import org.olap4j.metadata.NamedList; import org.olap4j.mdx.parser.MdxParserFactory; import org.olap4j.mdx.parser.MdxParser; import org.olap4j.mdx.parser.impl.DefaultMdxParserImpl; @@ -46,6 +46,8 @@ class MondrianOlap4jConnection implements OlapConnection { */ MondrianOlap4jSchema olap4jSchema; + private final MondrianOlap4jDatabaseMetaData olap4jDatabaseMetaData; + /** * The name of the sole catalog. */ @@ -77,9 +79,10 @@ class MondrianOlap4jConnection implements OlapConnection { } this.connection = mondrian.olap.DriverManager.getConnection(list, null); - final OlapDatabaseMetaData olapDatabaseMetaData = getMetaData(); - final Database database = olapDatabaseMetaData.getDatabase(); - final Catalog catalog = database.getCatalogs().get(getCatalog()); + this.olap4jDatabaseMetaData = + new MondrianOlap4jDatabaseMetaData(this, connection); + String catalogName = getCatalog(); + final Catalog catalog = getCatalogs().get(catalogName); this.olap4jSchema = new MondrianOlap4jSchema( (MondrianOlap4jCatalog) catalog, @@ -132,7 +135,11 @@ public boolean isClosed() throws SQLException { } public OlapDatabaseMetaData getMetaData() { - return new MondrianOlap4jDatabaseMetaData(this, connection); + return olap4jDatabaseMetaData; + } + + public NamedList getCatalogs() { + return olap4jDatabaseMetaData.getCatalogObjects(); } public void setReadOnly(boolean readOnly) throws SQLException { diff --git a/src/mondrian/olap4j/MondrianOlap4jDatabase.java b/src/mondrian/olap4j/MondrianOlap4jDatabase.java deleted file mode 100644 index 777cdf8..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jDatabase.java +++ /dev/null @@ -1,50 +0,0 @@ -/* -// $Id: $ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import org.olap4j.metadata.Database; -import org.olap4j.metadata.Catalog; -import org.olap4j.metadata.NamedList; -import org.olap4j.OlapDatabaseMetaData; -import mondrian.olap.MondrianServer; - -/** - * MondrianOlap4jDatabase ... - * - * @author jhyde - * @version $Id: $ - * @since May 23, 2007 - */ -class MondrianOlap4jDatabase implements Database { - final MondrianServer mondrianServer; - final MondrianOlap4jDatabaseMetaData metaData; - - MondrianOlap4jDatabase( - MondrianServer mondrianServer, - MondrianOlap4jDatabaseMetaData metaData) - { - this.mondrianServer = mondrianServer; - this.metaData = metaData; - } - - public NamedList getCatalogs() { - // A mondrian instance contains only one catalog. - NamedListImpl list = - new NamedListImpl(); - list.add(new MondrianOlap4jCatalog(this)); - return (NamedList) list; - } - - public OlapDatabaseMetaData getMetaData() { - return metaData; - } -} - -// End MondrianOlap4jDatabase.java diff --git a/src/mondrian/olap4j/MondrianOlap4jDatabaseMetaData.java b/src/mondrian/olap4j/MondrianOlap4jDatabaseMetaData.java index 3854750..e0f5eb8 100644 --- a/src/mondrian/olap4j/MondrianOlap4jDatabaseMetaData.java +++ b/src/mondrian/olap4j/MondrianOlap4jDatabaseMetaData.java @@ -14,7 +14,8 @@ import org.olap4j.OlapDatabaseMetaData; import org.olap4j.OlapException; -import org.olap4j.metadata.Database; +import org.olap4j.metadata.Catalog; +import org.olap4j.metadata.NamedList; import java.sql.ResultSet; import java.sql.RowIdLifetime; @@ -41,6 +42,17 @@ class MondrianOlap4jDatabaseMetaData implements OlapDatabaseMetaData { mondrianServer = MondrianServer.forConnection(connection); } + // package-protected + NamedList getCatalogObjects() { + // A mondrian instance contains only one catalog. + NamedList list = + new NamedListImpl(); + list.add(new MondrianOlap4jCatalog(this)); + return (NamedList) list; + } + + // implement DatabaseMetaData + public boolean allProceduresAreCallable() throws SQLException { throw new UnsupportedOperationException(); } @@ -817,11 +829,6 @@ public boolean isWrapperFor(Class iface) throws SQLException { // implement OlapDatabaseMetaData - public Database getDatabase() { - return new MondrianOlap4jDatabase( - mondrianServer, this); - } - public ResultSet getActions() throws OlapException { return new EmptyResultSet(olap4jConnection); } diff --git a/src/org/olap4j/Olap4j.java b/src/org/olap4j/Olap4j.java deleted file mode 100644 index 6c4f8f2..0000000 --- a/src/org/olap4j/Olap4j.java +++ /dev/null @@ -1,237 +0,0 @@ -/* -// $Id: $ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2006-2006 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package org.olap4j; - -import org.olap4j.mdx.parser.MdxParserFactory; - -import java.sql.*; - -/** - * Miscellaneous utility functions, in particular dealing with the wrapped - * objects created by connection pools. - * - *

        Connection pools typically work by creating wrapped versions of - * connection, statement, prepared statement, result set, and metadata objects. - * These are problematic for olap4j, because olap4j extends the JDBC interfaces, - * and the wrapped objects will not implement those interfaces. The following - * table lists the interfaces extended by olap4j:

        - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
        olap4j classextends JDBC classcreated by
        {@link OlapConnection}{@link Connection} - *
          - *
        • {@link DriverManager#getConnection(String) Connection DriverManager.getConnection(String)}
        • - *
        • {@link javax.sql.DataSource#getConnection() Connection DataSource.getConnection()}
        • - *
        - *
        {@link OlapStatement}{@link Statement} - *
          - *
        • {@link java.sql.Connection#createStatement() Statement Connection.createStatement()}
        • - *
        - *
        {@link PreparedOlapStatement}{@link PreparedStatement} - *
          - *
        • {@link Connection#prepareStatement(String) PreparedStatement Connection.prepareStatement(String)}
        • - *
        - *
        {@link CellSet}{@link ResultSet} - *
          - *
        • {@link Statement#execute(String) ResultSet Statement.executeQuery(String)}
        • - *
        • {@link PreparedStatement#execute(String) ResultSet PreparedStatement.executeQuery()}
        • - *
        - *
        - * - *

        If you are using a connection pool, you cannot safely cast a - * {@link Connection} to an {@link OlapConnection}, or a {@link Statement} to - * a {@link OlapStatement}. Use the appropriate - * {@link #convert(java.sql.Connection)} method, and the resulting object will - * implement the necessary interface and also implement the behavior required - * by the connection pool in order to manage sub-objects safely. - * - *

        We plan to support common connection-pooling libraries: - *

        - * - * @author jhyde - * @version $Id: $ - * @since Oct 13, 2006 - */ -public class Olap4j { - /** - * Converts a JDBC connection ({@link java.sql.Connection}) - * to an olap4j connection ({@link OlapConnection}). - * - *

        The connection produced by an olap4j driver will already implement the - * OlapConnection interface, but certain connection pools - * add wrappers. This method removes those wrappers. - */ - public static OlapConnection convert(Connection connection) { - return adapterFor(connection).convert(connection); - } - - /** - * Converts a JDBC statement ({@link java.sql.Statement}) - * to an olap4j statement ({@link OlapStatement}). - * - *

        The statement produced by an olap4j driver will already implement the - * OlapStatement interface, but certain connection pools - * add wrappers. This method removes those wrappers. - */ - public static OlapStatement convert(Statement stmt) { - return adapterFor(stmt).convert(stmt); - } - - /** - * Converts a JDBC prepared statement ({@link java.sql.Connection}) - * to an olap4j prepared statement ({@link PreparedOlapStatement}). - * - *

        The prepared statement produced by an olap4j driver will already - * implement the PreparedOlapStatement interface, but certain - * connection pools add wrappers. This method removes those wrappers. - */ - public static PreparedOlapStatement convert(PreparedStatement pstmt) { - return adapterFor(pstmt).convert(pstmt); - } - - /** - * Converts a JDBC result set ({@link java.sql.ResultSet}) - * to an olap4j result set ({@link CellSet}). - * - *

        The result set eproduced by an olap4j driver will already - * implement the CellSet interface, but certain - * connection pools add wrappers. This method removes those wrappers. - */ - public static CellSet convert(ResultSet resultSet) { - return adapterFor(resultSet).convert(resultSet); - } - - /** - * Converts a JDBC result set ({@link java.sql.DatabaseMetaData}) - * to an olap4j result set ({@link OlapDatabaseMetaData}). - * - *

        The DatabaseMetaData eproduced by an olap4j driver will - * already implement the OlapDatabaseMetaData interface, but - * certain connection pools add wrappers. This method removes those - * wrappers. - */ - public static OlapDatabaseMetaData convert(DatabaseMetaData metadata) { - return adapterFor(metadata).convert(metadata); - } - - /** - * Helper method to automatically create the right adapter to unpack a - * connection. - */ - private static Adapter adapterFor(Connection connection) { - return CastingAdapter.INSTANCE; - } - - /** - * Helper method to automatically create the right adapter to unpack a - * statement. - */ - private static Adapter adapterFor(Statement stmt) { - return CastingAdapter.INSTANCE; - } - - /** - * Helper method to automatically create the right adapter to unpack a - * prepared statement. - */ - private static Adapter adapterFor(PreparedStatement pstmt) { - return CastingAdapter.INSTANCE; - } - - /** - * Helper method to automatically create the right adapter to unpack a - * database metadata. - */ - private static Adapter adapterFor(DatabaseMetaData metadata) { - return CastingAdapter.INSTANCE; - } - - /** - * Helper method to automatically create the right adapter to unpack a - * result set. - */ - private static Adapter adapterFor(ResultSet resultSet) { - return CastingAdapter.INSTANCE; - } - - public static MdxParserFactory getParserFactory(Connection connection) { - return convert(connection).getParserFactory(); - } - - /** - * Specification for a helper which can remove the wrappers added by - * certain connection pools. - */ - private static interface Adapter { - OlapConnection convert(Connection connection); - OlapStatement convert(Statement stmt); - PreparedOlapStatement convert(PreparedStatement pstmt); - OlapDatabaseMetaData convert(DatabaseMetaData metadata); - CellSet convert(ResultSet resultSet); - } - - - /** - * Implementation of {@link Adapter} which simply casts objects to the - * desired type. - */ - private static class CastingAdapter implements Adapter { - private static final Adapter INSTANCE = new CastingAdapter(); - - public OlapConnection convert(Connection connection) { - return (OlapConnection) connection; - } - - public OlapStatement convert(Statement stmt) { - return (OlapStatement) stmt; - } - - public PreparedOlapStatement convert(PreparedStatement pstmt) { - return (PreparedOlapStatement) pstmt; - } - - public OlapDatabaseMetaData convert(DatabaseMetaData metadata) { - return (OlapDatabaseMetaData) metadata; - } - - public CellSet convert(ResultSet resultSet) { - return (CellSet) resultSet; - } - } -} - -// End Olap4j.java diff --git a/src/org/olap4j/OlapConnection.java b/src/org/olap4j/OlapConnection.java index c4e37e3..47f8bd9 100644 --- a/src/org/olap4j/OlapConnection.java +++ b/src/org/olap4j/OlapConnection.java @@ -1,5 +1,5 @@ /* -// $Id$ +// $Id: OlapConnection.java 16 2006-10-24 22:48:56Z jhyde $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. @@ -11,6 +11,8 @@ import org.olap4j.mdx.parser.MdxParserFactory; import org.olap4j.metadata.Schema; +import org.olap4j.metadata.Catalog; +import org.olap4j.metadata.NamedList; import java.sql.Connection; @@ -18,7 +20,7 @@ * Connection to an OLAP server. * * @author jhyde - * @version $Id$ + * @version $Id: OlapConnection.java 16 2006-10-24 22:48:56Z jhyde $ * @since Aug 22, 2006 */ public interface OlapConnection extends Connection { @@ -44,6 +46,15 @@ public interface OlapConnection extends Connection { * connection. */ Schema getSchema() throws OlapException; + + /** + * Returns a list of {@link org.olap4j.metadata.Catalog} objects which + * belong to this connection's OLAP server. + * + * @see OlapDatabaseMetaData#getCatalogs() + * @return List of Catalogs in this connection's OLAP server + */ + NamedList getCatalogs(); } // End OlapConnection.java diff --git a/src/org/olap4j/OlapDatabaseMetaData.java b/src/org/olap4j/OlapDatabaseMetaData.java index b2611e3..9c33a3f 100644 --- a/src/org/olap4j/OlapDatabaseMetaData.java +++ b/src/org/olap4j/OlapDatabaseMetaData.java @@ -9,8 +9,6 @@ */ package org.olap4j; -import org.olap4j.metadata.Database; - import java.sql.DatabaseMetaData; import java.sql.ResultSet; @@ -29,12 +27,6 @@ * @since Oct 12, 2006 */ public interface OlapDatabaseMetaData extends DatabaseMetaData { - /** - * Returns the Database, which is the root of the hierarchy - * of metadata objects. - * @return the Database - */ - Database getDatabase(); /** * Retrieves a list of descriptions of an Action. @@ -117,7 +109,7 @@ public ResultSet getCubes( String catalog, String schemaPattern, String cubeNamePattern) throws OlapException; - + /** * Retrieves a result set describing the shared and private dimensions * within a database. diff --git a/src/org/olap4j/OlapStatement.java b/src/org/olap4j/OlapStatement.java index 9f9ec88..b089f8b 100644 --- a/src/org/olap4j/OlapStatement.java +++ b/src/org/olap4j/OlapStatement.java @@ -1,5 +1,5 @@ /* -// $Id$ +// $Id: OlapStatement.java 18 2007-06-10 18:31:17Z jhyde $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. @@ -20,7 +20,7 @@ * @see PreparedOlapStatement * * @author jhyde - * @version $Id$ + * @version $Id: OlapStatement.java 18 2007-06-10 18:31:17Z jhyde $ * @since Aug 22, 2006 */ public interface OlapStatement extends Statement { diff --git a/src/org/olap4j/PreparedOlapStatement.java b/src/org/olap4j/PreparedOlapStatement.java index 250284c..3082ce1 100644 --- a/src/org/olap4j/PreparedOlapStatement.java +++ b/src/org/olap4j/PreparedOlapStatement.java @@ -1,5 +1,5 @@ /* -// $Id$ +// $Id: PreparedOlapStatement.java 17 2007-05-25 22:34:38Z jhyde $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. @@ -43,7 +43,7 @@ * @see java.sql.ResultSet * * @author jhyde - * @version $Id$ + * @version $Id: PreparedOlapStatement.java 17 2007-05-25 22:34:38Z jhyde $ * @since Aug 22, 2006 */ public interface PreparedOlapStatement diff --git a/src/org/olap4j/Todo.java b/src/org/olap4j/Todo.java index ef92abc..e0c0d28 100644 --- a/src/org/olap4j/Todo.java +++ b/src/org/olap4j/Todo.java @@ -1,5 +1,5 @@ /* -// $Id$ +// $Id: Todo.java 1 2006-09-02 14:08:27Z sgwood $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. @@ -13,7 +13,7 @@ * Reference this class as a way of flagging todo items. * * @author jhyde - * @version $Id$ + * @version $Id: Todo.java 1 2006-09-02 14:08:27Z sgwood $ * @since Aug 23, 2006 */ public class Todo { diff --git a/src/org/olap4j/mdx/CallNode.java b/src/org/olap4j/mdx/CallNode.java index b8c7ab5..e5b19ab 100644 --- a/src/org/olap4j/mdx/CallNode.java +++ b/src/org/olap4j/mdx/CallNode.java @@ -29,6 +29,7 @@ *

      36. [Gender].Properties("FORMAT_STRING"), a call to the * Properties operator, which has * {@link Syntax#Method method syntax}
      37. + * * * @author jhyde * @version $Id: //open/mondrian/src/main/mondrian/olap/FunCall.java#22 $ diff --git a/src/org/olap4j/mdx/IdentifierNode.java b/src/org/olap4j/mdx/IdentifierNode.java index 0bd2ac4..e4b0371 100644 --- a/src/org/olap4j/mdx/IdentifierNode.java +++ b/src/org/olap4j/mdx/IdentifierNode.java @@ -12,12 +12,15 @@ import org.olap4j.type.Type; import java.util.List; -import java.util.Collections; import java.util.ArrayList; +import java.util.Arrays; import java.io.PrintWriter; /** * Multi-part identifier. + * + * @version $Id: $ + * @author jhyde */ public class IdentifierNode implements ParseTreeNode { @@ -25,12 +28,14 @@ public class IdentifierNode private final List segments; /** - * Creates an identifier containing a single part. + * Creates an identifier containing one or more segments. * - * @param segment Segment, consisting of a name and quoting style + * @param segments Array of Segments, each consisting of a name and quoting + * style */ - public IdentifierNode(IdentifierNode.Segment segment) { - segments = Collections.singletonList(segment); + public IdentifierNode(IdentifierNode.Segment... segments) { + assert segments.length >= 1; + this.segments = new ArrayList(Arrays.asList(segments)); } private IdentifierNode(List segments) { @@ -54,7 +59,8 @@ public List getSegmentList() { * @return New identifier */ public IdentifierNode append(IdentifierNode.Segment segment) { - List newSegments = new ArrayList(segments); + List newSegments = + new ArrayList(segments); newSegments.add(segment); return new IdentifierNode(newSegments); } @@ -100,10 +106,25 @@ public static class Segment { public final String name; public final IdentifierNode.Quoting quoting; + /** + * Creates a segment with the given quoting. + * + * @param name Name + * @param quoting Quoting style + */ public Segment(String name, IdentifierNode.Quoting quoting) { this.name = name; this.quoting = quoting; } + + /** + * Creates a quoted segment, "[name]". + * + * @param name Name of segment + */ + public Segment(String name) { + this(name, Quoting.QUOTED); + } } public enum Quoting { diff --git a/src/org/olap4j/mdx/ParseTreeVisitor.java b/src/org/olap4j/mdx/ParseTreeVisitor.java index cd3df9c..2235e66 100644 --- a/src/org/olap4j/mdx/ParseTreeVisitor.java +++ b/src/org/olap4j/mdx/ParseTreeVisitor.java @@ -18,36 +18,36 @@ */ public interface ParseTreeVisitor { /** - * Visits a {@link SelectNode}. + * Visits a select statement. * - * @param selectNode Node representing a SELECT statement. - * @return value returned by SelectNode#accept(ParseTreeVisitor) + * @param selectNode Node representing a SELECT statement + * @see SelectNode#accept(ParseTreeVisitor) */ T visit(SelectNode selectNode); /** - * Visits an {@link AxisNode}. + * Visits an axis of a select statement. * * @see AxisNode#accept(ParseTreeVisitor) */ T visit(AxisNode axis); /** - * Visits a {@link WithMemberNode}. + * Visits a member declaration. * * @see WithMemberNode#accept(ParseTreeVisitor) */ T visit(WithMemberNode calcMemberNode); /** - * Visits a {@link WithSetNode}. + * Visits a set declaration. * * @see WithSetNode#accept(ParseTreeVisitor) */ T visit(WithSetNode calcSetNode); /** - * Visits a {@link CallNode}. + * Visits a call to an operator or function. * * @see CallNode#accept(ParseTreeVisitor) */ @@ -61,49 +61,49 @@ public interface ParseTreeVisitor { T visit(IdentifierNode id); /** - * Visits a Parameter. + * Visits a parameter. * * @see ParameterNode#accept(ParseTreeVisitor) */ T visit(ParameterNode parameterNode); /** - * Visits an DimensionNode. + * Visits a usage of a {@link org.olap4j.metadata.Dimension} in a query. * * @see DimensionNode#accept(ParseTreeVisitor) */ T visit(DimensionNode dimensionNode); /** - * Visits an HierarchyNode. + * Visits a usage of a {@link org.olap4j.metadata.Hierarchy} in a query. * * @see HierarchyNode#accept(ParseTreeVisitor) */ T visit(HierarchyNode hierarchyNode); /** - * Visits an LevelNode. + * Visits a usage of a {@link org.olap4j.metadata.Level} in a query. * * @see LevelNode#accept(ParseTreeVisitor) */ T visit(LevelNode levelExpr); /** - * Visits an MemberNode. + * Visits a usage of a {@link org.olap4j.metadata.Member} in a query. * * @see MemberNode#accept(ParseTreeVisitor) */ T visit(MemberNode memberNode); /** - * Visits an MdxLiteral. + * Visits a literal. * * @see LiteralNode#accept(ParseTreeVisitor) */ T visit(LiteralNode literalNode); /** - * Visits a {@link PropertyValueNode}. + * Visits a property-value pair. * * @see PropertyValueNode#accept(ParseTreeVisitor) */ diff --git a/src/org/olap4j/mdx/PropertyValueNode.java b/src/org/olap4j/mdx/PropertyValueNode.java index 668685e..1d2cd58 100644 --- a/src/org/olap4j/mdx/PropertyValueNode.java +++ b/src/org/olap4j/mdx/PropertyValueNode.java @@ -14,7 +14,8 @@ /** * Parse tree node representing a property-value pair. * - *

        For example, in WITH MEMBER [Measures].[Foo] AS ' [Measures].[Unit Sales] ', + *

        Property-value pairs are used to define properties of calculated members. + * For example, in WITH MEMBER [Measures].[Foo] AS ' [Measures].[Unit Sales] ', * FORMAT_STRING = 'Bold', * SOLVE_ORDER = 2 * SELECT ... diff --git a/src/org/olap4j/mdx/SelectNode.java b/src/org/olap4j/mdx/SelectNode.java index f60e344..beac96a 100644 --- a/src/org/olap4j/mdx/SelectNode.java +++ b/src/org/olap4j/mdx/SelectNode.java @@ -12,6 +12,7 @@ import org.olap4j.type.Type; import java.util.List; +import java.util.ArrayList; import java.io.PrintWriter; /** @@ -26,7 +27,7 @@ public class SelectNode implements ParseTreeNode { private final List axisList; private final AxisNode slicerAxis; private final List cellPropertyList; - private final IdentifierNode cubeName; + private IdentifierNode cubeName; /** * Creates a SelectNode. @@ -51,6 +52,15 @@ public SelectNode( this.cellPropertyList = cellPropertyList; } + public SelectNode() { + this( + new ArrayList(), + new ArrayList(), + null, + null, + new ArrayList()); + } + public T accept(ParseTreeVisitor visitor) { return visitor.visit(this); } @@ -114,6 +124,10 @@ public AxisNode getSlicerAxis() { public IdentifierNode getCubeName() { return cubeName; } + + public void setCubeName(IdentifierNode cubeName) { + this.cubeName = cubeName; + } } // End SelectNode.java diff --git a/src/org/olap4j/mdx/parser/MdxParser.java b/src/org/olap4j/mdx/parser/MdxParser.java index 8d4bebc..04c7190 100644 --- a/src/org/olap4j/mdx/parser/MdxParser.java +++ b/src/org/olap4j/mdx/parser/MdxParser.java @@ -1,5 +1,5 @@ /* -// $Id$ +// $Id: MdxParser.java 18 2007-06-10 18:31:17Z jhyde $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. @@ -23,7 +23,7 @@ * @see org.olap4j.mdx.parser.impl.DefaultMdxParserImpl * * @author jhyde - * @version $Id$ + * @version $Id: MdxParser.java 18 2007-06-10 18:31:17Z jhyde $ * @since Aug 22, 2006 */ public interface MdxParser { diff --git a/src/org/olap4j/mdx/parser/MdxParserFactory.java b/src/org/olap4j/mdx/parser/MdxParserFactory.java index 74a644a..aee922d 100644 --- a/src/org/olap4j/mdx/parser/MdxParserFactory.java +++ b/src/org/olap4j/mdx/parser/MdxParserFactory.java @@ -1,5 +1,5 @@ /* -// $Id$ +// $Id: MdxParserFactory.java 1 2006-09-02 14:08:27Z sgwood $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. @@ -15,7 +15,7 @@ * Factory for MDX parsers. * * @author jhyde - * @version $Id$ + * @version $Id: MdxParserFactory.java 1 2006-09-02 14:08:27Z sgwood $ * @since Aug 22, 2006 */ public interface MdxParserFactory { diff --git a/src/org/olap4j/mdx/parser/impl/DefaultMdxParser.cup b/src/org/olap4j/mdx/parser/impl/DefaultMdxParser.cup index f75b1e5..8f43a63 100644 --- a/src/org/olap4j/mdx/parser/impl/DefaultMdxParser.cup +++ b/src/org/olap4j/mdx/parser/impl/DefaultMdxParser.cup @@ -201,9 +201,9 @@ parser code {: int loc[] = new int[2]; scanner.getLocation(cur_token, loc); throw new RuntimeException( - "Syntax error at line " + s + - ", column " + Integer.toString(loc[0] + 1) + - ", token '" + Integer.toString(loc[1] + 1) + "'"); + "Syntax error at line " + Integer.toString(loc[0] + 1) + + ", column " + Integer.toString(loc[1] + 1) + + ", token '" + s + "'"); } else { throw new RuntimeException( "Syntax error at token '" + s + "'"); diff --git a/src/org/olap4j/mdx/parser/impl/DefaultMdxParserImpl.java b/src/org/olap4j/mdx/parser/impl/DefaultMdxParserImpl.java index df3597f..d6b35c9 100644 --- a/src/org/olap4j/mdx/parser/impl/DefaultMdxParserImpl.java +++ b/src/org/olap4j/mdx/parser/impl/DefaultMdxParserImpl.java @@ -1,5 +1,5 @@ /* -// $Id$ +// $Id: DefaultMdxParserImpl.java 18 2007-06-10 18:31:17Z jhyde $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. @@ -18,7 +18,7 @@ * Default implementation of {@link org.olap4j.mdx.parser.MdxParser MDX Parser}. * * @author jhyde - * @version $Id$ + * @version $Id: DefaultMdxParserImpl.java 18 2007-06-10 18:31:17Z jhyde $ * @since Aug 22, 2006 */ public class DefaultMdxParserImpl implements MdxParser { diff --git a/src/org/olap4j/metadata/Catalog.java b/src/org/olap4j/metadata/Catalog.java index 69c8ee2..7053527 100644 --- a/src/org/olap4j/metadata/Catalog.java +++ b/src/org/olap4j/metadata/Catalog.java @@ -10,10 +10,35 @@ package org.olap4j.metadata; import org.olap4j.OlapException; +import org.olap4j.OlapDatabaseMetaData; /** * Catalog ... * + * A Catalog is the root object in the hierarchy of metadata + * objects: + *

        + *
          + *
        • {@link org.olap4j.OlapConnection}
            + *
          • {@link Catalog}
              + *
            • {@link Schema}
                + *
              • {@link Cube}
                  + *
                • {@link Dimension}
                    + *
                  • {@link Hierarchy}
                      + *
                    • {@link Level}
                        + *
                      • {@link Member}
                      • + *
                      • {@link Property}
                      • + *
                    • + *
                  • + *
                • + *
                • {@link NamedSet}
                • + *
              • + *
              • Dimension (shared)
              • + *
            • + *
          • + *
          + *
        + * * @author jhyde * @version $Id: $ * @since Oct 24, 2006 @@ -25,17 +50,24 @@ public interface Catalog { * * @see org.olap4j.OlapDatabaseMetaData#getSchemas * @return List of Schema in this Catalog + * @throws OlapException if error occurs */ NamedList getSchemas() throws OlapException; /** - * Returns the {@link Database} this Catalog belongs to. + * Returns the name of this Catalog. * - * @return the Database this Catalog belongs to + * @return name of this Catalog */ - Database getDatabase(); - String getName(); + + /** + * Retrieves the metadata describing the OLAP server that this Catalog + * belongs to. + * + * @return metadata describing the OLAP server + */ + OlapDatabaseMetaData getMetaData(); } // End Catalog.java diff --git a/src/org/olap4j/metadata/Cube.java b/src/org/olap4j/metadata/Cube.java index 5259580..ce5fd2e 100644 --- a/src/org/olap4j/metadata/Cube.java +++ b/src/org/olap4j/metadata/Cube.java @@ -1,5 +1,5 @@ /* -// $Id$ +// $Id: Cube.java 16 2006-10-24 22:48:56Z jhyde $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. @@ -17,7 +17,7 @@ * Cube ... * * @author jhyde - * @version $Id$ + * @version $Id: Cube.java 16 2006-10-24 22:48:56Z jhyde $ * @since Aug 22, 2006 */ public interface Cube extends MetadataElement { diff --git a/src/org/olap4j/metadata/Database.java b/src/org/olap4j/metadata/Database.java deleted file mode 100644 index 86a86b3..0000000 --- a/src/org/olap4j/metadata/Database.java +++ /dev/null @@ -1,74 +0,0 @@ -/* -// $Id: $ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2006-2006 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package org.olap4j.metadata; - -import org.olap4j.OlapDatabaseMetaData; - -/** - * - * A Database is the root object in the hierarchy of metadata - * objects: - *
        - *
          - *
        • {@link Database}
            - *
          • {@link Catalog}
              - *
            • {@link Schema}
                - *
              • {@link Cube}
                  - *
                • {@link Dimension}
                    - *
                  • {@link Hierarchy}
                      - *
                    • {@link Level}
                        - *
                      • {@link Member}
                      • - *
                      • {@link Property}
                      • - *
                    • - *
                  • - *
                • - *
                • {@link NamedSet}
                • - *
              • - *
              • Dimension (shared)
              • - *
            • - *
          • - *
          - *
        - * - *

        A Database is usually accessed from a connection via its - * metadata: - *

        - * OlapConnection connection;
        - * Database database = connection.getMetaData().getDatabase(); - *
        - * - * or from a schema: - * - *
        - * OlapConnection connection;
        - * Database database = connection.getSchema().getCatalog().getDatabase(); - *
        - * - * @author jhyde - * @version $Id: $ - * @since Oct 24, 2006 - */ -public interface Database { - /** - * Retrieves a list of {@link Catalog} objects which - * belong to this Database. - * - * @see org.olap4j.OlapDatabaseMetaData#getDatabase - * @return List of Catalogs in this Database - */ - NamedList getCatalogs(); - - /** - * Retrieves the metadata describing this Database. - */ - OlapDatabaseMetaData getMetaData(); -} - -// End Database.java diff --git a/src/org/olap4j/metadata/Dimension.java b/src/org/olap4j/metadata/Dimension.java index 4c76dff..b7a8b59 100644 --- a/src/org/olap4j/metadata/Dimension.java +++ b/src/org/olap4j/metadata/Dimension.java @@ -1,5 +1,5 @@ /* -// $Id$ +// $Id: Dimension.java 18 2007-06-10 18:31:17Z jhyde $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. @@ -15,7 +15,7 @@ * Dimension ... * * @author jhyde - * @version $Id$ + * @version $Id: Dimension.java 18 2007-06-10 18:31:17Z jhyde $ * @since Aug 22, 2006 */ public interface Dimension extends MetadataElement { diff --git a/src/org/olap4j/metadata/Hierarchy.java b/src/org/olap4j/metadata/Hierarchy.java index 5054586..3ad2d0d 100644 --- a/src/org/olap4j/metadata/Hierarchy.java +++ b/src/org/olap4j/metadata/Hierarchy.java @@ -1,5 +1,5 @@ /* -// $Id$ +// $Id: Hierarchy.java 18 2007-06-10 18:31:17Z jhyde $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. @@ -13,7 +13,7 @@ * Hierarchy ... * * @author jhyde - * @version $Id$ + * @version $Id: Hierarchy.java 18 2007-06-10 18:31:17Z jhyde $ * @since Aug 23, 2006 */ public interface Hierarchy extends MetadataElement { diff --git a/src/org/olap4j/metadata/Level.java b/src/org/olap4j/metadata/Level.java index eec8b68..01ca2ab 100644 --- a/src/org/olap4j/metadata/Level.java +++ b/src/org/olap4j/metadata/Level.java @@ -1,5 +1,5 @@ /* -// $Id$ +// $Id: Level.java 18 2007-06-10 18:31:17Z jhyde $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. @@ -16,7 +16,7 @@ * all with the same attributes and at the same depth in the hierarchy. * * @author jhyde - * @version $Id$ + * @version $Id: Level.java 18 2007-06-10 18:31:17Z jhyde $ * @since Aug 23, 2006 */ public interface Level extends MetadataElement { diff --git a/src/org/olap4j/metadata/Member.java b/src/org/olap4j/metadata/Member.java index 429262c..63e089f 100644 --- a/src/org/olap4j/metadata/Member.java +++ b/src/org/olap4j/metadata/Member.java @@ -1,5 +1,5 @@ /* -// $Id$ +// $Id: Member.java 18 2007-06-10 18:31:17Z jhyde $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. @@ -18,7 +18,7 @@ * Member is a data value in an OLAP Dimension. * * @author jhyde - * @version $Id$ + * @version $Id: Member.java 18 2007-06-10 18:31:17Z jhyde $ * @since Aug 22, 2006 */ public interface Member extends MetadataElement { diff --git a/src/org/olap4j/metadata/NamedList.java b/src/org/olap4j/metadata/NamedList.java index b66715c..445a174 100644 --- a/src/org/olap4j/metadata/NamedList.java +++ b/src/org/olap4j/metadata/NamedList.java @@ -1,5 +1,5 @@ /* -// $Id$ +// $Id: NamedList.java 17 2007-05-25 22:34:38Z jhyde $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. @@ -16,7 +16,7 @@ * list by name as well as by ordinal. * * @author jhyde - * @version $Id$ + * @version $Id: NamedList.java 17 2007-05-25 22:34:38Z jhyde $ * @since Aug 22, 2006 */ public interface NamedList extends List { diff --git a/src/org/olap4j/metadata/Property.java b/src/org/olap4j/metadata/Property.java index d4f7ccb..715201e 100644 --- a/src/org/olap4j/metadata/Property.java +++ b/src/org/olap4j/metadata/Property.java @@ -1,5 +1,5 @@ /* -// $Id$ +// $Id: Property.java 18 2007-06-10 18:31:17Z jhyde $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. @@ -16,7 +16,7 @@ * {@link org.olap4j.Cell}. * * @author jhyde - * @version $Id$ + * @version $Id: Property.java 18 2007-06-10 18:31:17Z jhyde $ * @since Aug 23, 2006 */ public interface Property extends MetadataElement { diff --git a/src/org/olap4j/query/Query.java b/src/org/olap4j/query/Query.java index fe30c58..a01c8e2 100644 --- a/src/org/olap4j/query/Query.java +++ b/src/org/olap4j/query/Query.java @@ -45,7 +45,7 @@ public Query(String name, Cube cube) throws SQLException { this.name = name; this.cube = cube; this.connection = - cube.getSchema().getCatalog().getDatabase().getMetaData() + cube.getSchema().getCatalog().getMetaData() .getConnection().unwrap(OlapConnection.class); this.unused = new QueryAxis(this, null); for (Dimension dimension : cube.getDimensions()) { diff --git a/src/org/olap4j/sample/SimpleQuerySample.java b/src/org/olap4j/sample/SimpleQuerySample.java index b04df7e..04d42ad 100644 --- a/src/org/olap4j/sample/SimpleQuerySample.java +++ b/src/org/olap4j/sample/SimpleQuerySample.java @@ -12,15 +12,12 @@ import org.olap4j.*; import org.olap4j.mdx.parser.MdxParser; import org.olap4j.mdx.parser.MdxParserFactory; -import org.olap4j.mdx.SelectNode; +import org.olap4j.mdx.*; import org.olap4j.metadata.Dimension; import org.olap4j.metadata.Member; import org.olap4j.type.MemberType; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; import java.util.ArrayList; import java.util.List; @@ -55,16 +52,18 @@ void simpleStatement() Class.forName("mondrian.olap4j.Driver"); // Create connection. - OlapConnection connection = (OlapConnection) - DriverManager.getConnection("jdbc:mondrian:embedded"); + Connection connection = + DriverManager.getConnection("jdbc:mondrian:embedded"); + OlapConnection olapConnection = + connection.unwrap(OlapConnection.class); // Execute a statement. - Statement statement = connection.createStatement(); - CellSet result = Olap4j.convert( - statement.executeQuery( + OlapStatement statement = olapConnection.createStatement(); + CellSet result = + statement.executeOlapQuery( "select {[Measures].[Unit Sales]} on columns,\n" + " CrossJoin([Store].Children, [Gender].Members) on rows\n" + - "from [Sales]")); + "from [Sales]"); List cellSetAxes = result.getAxes(); @@ -130,7 +129,7 @@ void preparedStatement() throws SQLException, ClassNotFoundException { DriverManager.getConnection("jdbc:mondrian:embedded"); // Prepare a statement. - PreparedStatement statement = connection.prepareStatement( + PreparedOlapStatement statement = connection.prepareOlapStatement( "select {[Measures].[Unit Sales]} on columns,\n" + " {TopCount\n(" + " Parameter(\"Store\", [Store].[USA].[CA]).Children,\n" + @@ -139,7 +138,7 @@ void preparedStatement() throws SQLException, ClassNotFoundException { // Describe the parameters. OlapParameterMetaData parameterMetaData = - (OlapParameterMetaData) statement.getParameterMetaData(); + statement.getParameterMetaData(); // Locate the member "[Store].[USA].[WA].[Seattle]". MemberType type = (MemberType) parameterMetaData.getOlapType(1); @@ -153,7 +152,7 @@ void preparedStatement() throws SQLException, ClassNotFoundException { statement.setInt(2, 10); // Execute, and print result. - CellSet result = Olap4j.convert(statement.executeQuery()); + CellSet result = statement.executeQuery(); printResult(result); // Close the statement and connection. @@ -169,19 +168,20 @@ void statementFromParseTree() throws ClassNotFoundException, SQLException { Class.forName("mondrian.olap4j.Driver"); // Create connection. - OlapConnection connection = Olap4j.convert( - DriverManager.getConnection("jdbc:mondrian:embedded")); + Connection connection = + DriverManager.getConnection("jdbc:mondrian:embedded"); + OlapConnection olapConnection = connection.unwrap(OlapConnection.class); // Create a parser. - MdxParserFactory parserFactory = connection.getParserFactory(); - MdxParser parser = parserFactory.createMdxParser(connection); + MdxParserFactory parserFactory = olapConnection.getParserFactory(); + MdxParser parser = parserFactory.createMdxParser(olapConnection); SelectNode query = parser.parseSelect( "select {[Measures].[Unit Sales]} on columns\n" + "from [Sales]"); query.getAxisList().get(0).setNonEmpty(false); // Create statement. - OlapStatement statement = connection.createStatement(); + OlapStatement statement = olapConnection.createStatement(); CellSet cellSet = statement.executeOlapQuery(query); printResult(cellSet); } @@ -226,6 +226,47 @@ private void printResult(CellSet result) { System.out.println(); } } + + /** + * Example in "MDX query model" section of olap4j_fs.html. + * + * @param connection Connection + */ + void executeSelectNode(OlapConnection connection) { + // Create a query model. + SelectNode query = new SelectNode(); + query.setCubeName( + new IdentifierNode( + new IdentifierNode.Segment("Sales"))); + query.getAxisList().add( + new AxisNode( + false, + new CallNode( + "{}", + Syntax.Braces, + new IdentifierNode( + new IdentifierNode.Segment("Measures"), + new IdentifierNode.Segment("Unit Sales"))), + Axis.ROWS, + new ArrayList())); + + // Create a statement based upon the query model. + OlapStatement stmt; + try { + stmt = connection.createStatement(); + } catch (OlapException e) { + System.out.println("Validation failed: " + e); + return; + } + + // Execute the statement. + CellSet cset; + try { + cset = stmt.executeOlapQuery(query); + } catch (OlapException e) { + System.out.println("Execution failed: " + e); + } + } } // End SimpleQuerySample.java diff --git a/testsrc/org/olap4j/ConnectionTest.java b/testsrc/org/olap4j/ConnectionTest.java index 9fd2cb1..ca732b1 100644 --- a/testsrc/org/olap4j/ConnectionTest.java +++ b/testsrc/org/olap4j/ConnectionTest.java @@ -211,13 +211,10 @@ public void testDatabaseMetaData() throws SQLException { schemaPattern, cubeNamePattern)); - Database database = olapDatabaseMetaData.getDatabase(); - assertNotNull(database); - int k = 0; - for (Catalog catalog : database.getCatalogs()) { + for (Catalog catalog : olapConnection.getCatalogs()) { ++k; - assertEquals(catalog.getDatabase(), database); + assertEquals(catalog.getMetaData(), olapDatabaseMetaData); for (Schema schema : catalog.getSchemas()) { ++k; assertEquals(schema.getCatalog(), catalog); diff --git a/testsrc/org/olap4j/OlapTest.java b/testsrc/org/olap4j/OlapTest.java index 47a6b9d..9b52856 100644 --- a/testsrc/org/olap4j/OlapTest.java +++ b/testsrc/org/olap4j/OlapTest.java @@ -67,7 +67,7 @@ public void testModel() { // The code from here on is generic olap4j stuff // Get a list of the schemas available from this connection and dump their names - NamedList schemas = connection.getMetaData().getDatabase().getCatalogs().get("LOCALDB").getSchemas(); + NamedList schemas = connection.getCatalogs().get("LOCALDB").getSchemas(); for (Schema schema : schemas) { System.out.println("schema name="+schema.getName()); }