Oracle® OLAP Java API Reference
10g Release 1 (10.1)    B10994-01


Example Oracle OLAP Java API Programs

The Oracle OLAP Java API Reference and Oracle OLAP Developer's Guide to the OLAP API contain many examples of the use of OLAP API classes and their methods. Those examples are usually not complete programs.

This document contains links to complete programs that contain the code from the examples. The programs use the OLAP Catalog metadata objects for the Global schema. You can add these programs to your Java development environment and run them if the programs can connect to an Oracle Database instance with the OLAP option that has the Global schema and its OLAP Catalog metadata.

Most of the programs use the Context10g and CursorPrintWriter classes. Those classes connect to the Oracle database, get metadata objects, and display the results of the queries that the examples create. Copy the Context10g.java and CursorPrintWriter.java files and any of the following example programs to your Java development environment.

The SampleMetadataDiscoverer10g.java program does not use the Context10g program. Instead, it uses the MyConnection10g.java class to make a connection to an Oracle Database instance.

The programs that connect to the database use command line arguments that specify the server and the database instance to which you want to connect, and the username and password to use for the connection. See the comments in the Context10g or the MyConnection10g.java files for information on the command line arguments required.

Examples in the Oracle OLAP Java API Reference

The following file has the complete code for the examples that appear in the Source Concepts and Examples document that is referenced in the description of the Source class. SourceConceptsExamples.java

Examples in the Oracle OLAP Developer's Guide to the OLAP API

The examples that appear in the Oracle OLAP Developer's Guide to the OLAP API are in the following files, which are listed by chapter.

Chapter 1, Introduction to the OLAP API

This chapter does not have any examples.

Chapter 2, Understanding OLAP API Metadata

File Name Example
ElementsOfMdmAttribute.java A program that creates a custom MdmAttribute for product colors and retrieves the data displayed in the table in the "Elements of an MdmAttribute" section.
GettingDataTypeOfMdmSource.java Example 2-1, Getting the Data Type of an MdmSource.
GettingTypeOfMdmSource.java Example 2-2, Getting the Type of an MdmSource.

Chapter 3, Connecting to a Data Store

The code for most of the examples in this chapter is used in the Context10g.java and the MyConnection10g.java programs to create a connection to an Oracle Database instance. The complete code for Example 3-5 and Example 3-6 is in the following files.

File Name Example
GettingExistingConnection.java Example 3-5, Getting an Existing Connection.
ExecutingDMLCommands.java Example 3-6, Executing DML Commands.

Chapter 4, Discovering the Available Metadata

The following files are the program which is Example 4-9, Discovering the OLAP Catalog Metadata, and a class it uses to connect to an Oracle Database instance.

File Name Example
SampleMetadataDiscoverer10g.java Example 4-9, Discovering the OLAP Catalog Metadata.
MyConnection10g.java Class used by SampleMetadataDiscoverer10g to make the connection to an Oracle Database instance.

Chapter 5, Working with Metadata Mapping Objects

File Name Example
GettingColumnsForLevel.java Example 5-1, Getting the Columns for an MtmLevelHierarchyMap.
GettingColumnsForMeasure.java Example 5-3, Getting the Columns for an MdmMeasure.
CreatingCustomMeasure.java Example 5-4, Creating A Custom Measure.

Chapter 6, Understanding Source Objects

File Name Example
UnderstandingSourceObjects.java The following examples, and two informal examples, are implemented as methods of this class:
Example 6-1, Getting the Data Type of a Source.
Example 6-2, Using the isSubtypeOf Method.
Example 6-3, Using the join Method To Produce a Source Without an Output.
Example 6-4, Using the join Method To Produce a Source With an Output.
Example 6-5, Using the join Method To Match Source Objects To Inputs.
Example 6-6, Using Shortcuts.
Example 6-7, Matching the Base Source to an Input of the Joined Source.
Example 6-8, Matching an Input of the Base Source to an Output of the Joined Source.
Example 6-9, Matching the Inputs of a Measure and Producing Outputs.
UsingParamSourceWithMeasDim.java Example 6-10, Using a Parameterized Source With a Measure Dimension.

Chapter 7, Making Queries Using Source Objects

File Name Example
MakingQueriesExamples.java The following examples are implemented as methods of this class:
Example 7-1, Controlling Input-to-Source Matching With the alias Method.
Example 7-2, Using the distinct Method.
Example 7-3, Using the extract Method.
Example 7-4, Using COMPARISON_RULE_REMOVE.
Example 7-5, Using COMPARISON_RULE_DESCENDING.
Example 7-6, Selecting the First and Last Time Elements.
Example 7-8, Selecting a Subset of the Elements of a Source.
Example 7-11, Hierarchical Sorting by Measure Value.
SortingHierarchicallyByAttribute.java Example 7-7, Sorting Products Hierarchically By Color.
CreatingCubeAndPivotingEdges.java Example 7-9, Creating a Cube and Pivoting Its Edges.
DrillingInHierarchy.java Example 7-10, Drilling in a Hierarchy.
GettingShareOfUnits.java Example 7-12, Getting the Share of Units Sold.
RankingProductsByUnitsSold.java Example 7-13, Ranking Products by Units Sold.
UsingLagMethod.java Example 7-14, Using the Lag Method.
UsingMovingTotalMethod.java Example 7-15, Using the movingTotal Method.
SelectingRangeWithNumberParam.java Example 7-16, Selecting a Range With NumberParameter Objects.

Chapter 8, Using a TransactionProvider

File Name Example
TransactionExamples.java The following examples are implemented as methods of this class:
Example 8-1, Rolling Back a Transaction.
Example 8-2, Using Child Transaction Objects.

Chapter 9, Understanding Cursor Classes and Objects

File Name Example
CursorConceptsExamples.java The following examples, and an informal example, are implemented as methods of this class:
Example 9-1, Creating the querySource Query.
Example 9-2, Setting the CompoundCursor Position and Getting the Current Values.
Example 9-3, Positions in an Asymmetric Query.

Chapter 10, Retrieving Query Results

File Name Example
RetrievingQueryResults.java The following examples are implemented as methods of this class:
Example 10-1, Creating a Cursor.
Example 10-2, Getting a Single Value from a ValueCursor.
Example 10-3, Getting All of the Values from a ValueCursor.
Example 10-4, Getting ValueCursor Objects from a CompoundCursor example.
Example 10-5, Getting Values from a CompoundCursor with Nested Outputs example.
Example 10-6, Navigating For a Table View.
Example 10-7, Navigating For a Crosstab View Without Pages.
Example 10-8, Navigating For a Crosstab View With Pages.
Example 10-9, Getting CursorSpecification Objects from a CursorManagerSpecification.
Example 10-10, Specifying the Calculation of the Extent of a Cursor.
Example 10-11, Specifying the Calculation of Starting and Ending Positions in a Parent.
Example 10-12, Calculating the Span of the Positions in the Parent of a Value.
Example 10-13, Specifying a Fetch Size.

Chapter 11, Creating Dynamic Queries

Example 11-1 in this chapter is the TopBottomTemplate class. Example 11-2 and Example 11-3 are inner classes of TopBottomTemplate.

File Name Example
TopBottomTemplate.java Example 11-1, Implementing a Template.
Example 11-2, Implementing a MetadataState.
Example 11-3, Implementing a SourceGenerator.
TopBottomTest.java Example 11-4, Getting the Source Produced by the Template.

<nobr>Copyright © 2002, 2003, Oracle.<wbr> All Rights Reserved.</nobr>