Oracle9i OLAP Developer's Guide to the OLAP API Release 2 (9.2) Part Number A95297-01 |
|
Discovering the Available Metadata, 8 of 8
The sample code that follows is a simple Java program called SampleMetadataDiscoverer
. The program discovers the metadata objects that are under the root MdmSchema
of any data store. The program's output lists the names and related objects for the MdmMeasure
and MdmDimension
objects in the root MdmSchema
and its subschemas.
After presenting the program code, this topic presents the output of the program when it is run against a data store that consists of the Sales History relational schema, which is provided with the Oracle installation. In the OLAP metadata, the Sales History schema is represented as the SH_CAT measure folder. Through an OLAP API connection, the SH_CAT measure folder maps to an MdmSchema
that is also called SH_CAT
.
The SampleMetadataDiscoverer
program includes one piece of code that is specific to the SH_CAT
MdmSchema
. This code gets the primary Source
for an MdmDimension
for which the return value of the getName
method is PRODUCTS_DIM.
In most cases, an application will not search for a metadata object using its internal name (such as PRODUCTS_DIM), and it will not use the System.out.println
method to produce output. However, this sample code uses these techniques because they offer the advantage of simplicity.
To establish a connection, this program calls a hypothetical method called connectOnLab1
on a hypothetical class called MyConnection
. To close the connection, the program calls a method called MyConnection.closeConnection
. The code for these methods is not shown here, but the procedure for connecting is described in Chapter 3, "Connecting to a Data Store".
package mytestpackage; import com.sun.java.util.collections.ArrayList; import com.sun.java.util.collections.List; import com.sun.java.util.collections.Iterator; import oracle.express.mdm.*; import oracle.olapi.metadata.MetadataObject; import oracle.olapi.data.source.Source; import oracle.express.olapi.data.full.ExpressDataProvider; public class SampleMetadataDiscoverer { static final int TERSE = 0; static final int VERBOSE = 1; public SampleMetadataDiscoverer(){ } public static void main(String[] args) { // Connect through JDBC to a database on Lab1 // and get a DataProvider (see Chapter 3) ExpressDataProvider dp = MyConnection.connectOnLab1(); // Create an MdmMetadataProvider MdmMetadataProvider mp = null; mp = (MdmMetadataProvider) dp.getDefaultMetadataProvider(); // Get metadata info about the root MdmSchema and its subschemas MdmSchema root = null; try { root = mp.getRootSchema(); System.out.println("***Root MdmSchema: " + root.getName()); MdmDimension measureDim = root.getMeasureDimension(); System.out.println("******Measure MdmDimension: " + measureDim.getName()); getSchemaInfo(root, TERSE); } catch (Exception e) { System.out.println("***Exception encountered : " + e.toString()); } // Make a Source object out of the PRODUCTS_DIM MdmDimension System.out.println("***Making a Source object for PRODUCTS_DIM"); MdmDimension mdmProductDim = null; try { List rootDims = root.getDimensions(); Iterator rootDimIter = rootDims.iterator(); while (mdmProductDim == null && rootDimIter.hasNext()) { MdmDimension aDim = (MdmDimension) rootDimIter.next(); if (aDim.getName().equals("PRODUCTS_DIM")) mdmProductDim = aDim; } Source product = mdmProductDim.getSource(); System.out.println("******Made the Source"); } catch (Exception e) { System.out.println("******Exception encountered : " + e.toString()); } // Close the connection MyConnection.closeConnection(conn); } // ********************************************************* // Method for getting info about an MdmSchema public static void getSchemaInfo(MdmSchema schema, int outputStyle) { System.out.println("***Schema: " + schema.getName()); // Get the MdmSchema's dimension info MdmDimension oneDim = null; try { List dims = schema.getDimensions(); Iterator dimIter = dims.iterator(); System.out.println(" "); System.out.println("********************************************"); System.out.println(" "); while (dimIter.hasNext()) { oneDim = (MdmDimension) dimIter.next(); getDimInfo(oneDim, outputStyle); System.out.println(" "); System.out.println("********************************************"); System.out.println(" "); } } catch (Exception e) { System.out.println("******Exception encountered : " + e.toString()); } // Get the MdmSchema's measure info MdmMeasure oneMeasure = null; try { List measures = schema.getMeasures(); Iterator measIter = measures.iterator(); while (measIter.hasNext()) { oneMeasure = (MdmMeasure) measIter.next(); getMeasureInfo(oneMeasure, outputStyle); System.out.println(" "); System.out.println(" "); } } catch (Exception e) { System.out.println("******Exception encountered : " + e.toString()); } // Get the MdmSchema's subschema info MdmSchema oneSchema = null; try { List subSchemas = schema.getSubSchemas(); Iterator subSchemaIter = subSchemas.iterator(); while (subSchemaIter.hasNext()) { oneSchema = (MdmSchema) subSchemaIter.next(); getSchemaInfo(oneSchema, VERBOSE); } } catch (Exception e) { System.out.println("***Exception encountered : " + e.toString()); } } // ********************************************************* // Method for getting info about an MdmDimension public static void getDimInfo(MdmDimension dim, int outputStyle) { System.out.println("******MdmDimension Name: " + dim.getName()); System.out.println("*********Description: " + dim.getDescription()); if (outputStyle == VERBOSE) { // Get MdmDimensionMemberType for the MdmDimension try { MdmDimensionMemberType dimMemberType = dim.getMemberType(); if (dimMemberType instanceof MdmStandardMemberType) System.out.println("*********Member Type: MdmStandardMemberType"); if (dimMemberType instanceof MdmTimeMemberType) System.out.println("*********Member Type: MdmTimeMemberType"); if (dimMemberType instanceof MdmMeasureMemberType) System.out.println("*********Member Type: MdmMeasureMemberType"); } catch (Exception e) { System.out.println("***Exception encountered : " + e.toString()); } // Get attributes of the MdmDimension try { List attributes = dim.getAttributes(); Iterator attrIter = attributes.iterator(); while (attrIter.hasNext()) System.out.println("*********Attribute: " + ((MdmAttribute) attrIter.next()).getName()); } catch (Exception e) { System.out.println("***Exception encountered : " + e.toString()); } // Get concrete class and hierarchy type of the MdmDimension String kindOfDim = null; try { if (dim instanceof MdmListDimension) { kindOfDim = "ListDim"; System.out.println("*********" + dim.getName() + " is an MdmListDimension"); } else if (dim instanceof MdmHierarchy) switch(((MdmHierarchy) dim).getHierarchyType()) { case (MdmHierarchy.UNION_HIERARCHY): kindOfDim = "UnionHier"; System.out.println("*********" + dim.getName() + " is a union MdmHierarchy"); break; case (MdmHierarchy.LEVEL_HIERARCHY): kindOfDim = "LevelHier"; System.out.println("*********" + dim.getName() + " is a level MdmHierarchy"); break; case (MdmHierarchy.VALUE_HIERARCHY): kindOfDim = "ValueHier"; System.out.println("*********" + dim.getName() + " is a value MdmHierarchy"); break; } else { kindOfDim = "Level"; System.out.println("*********" + dim.getName() + " is an MdmLevel"); } } catch (Exception e) { System.out.println("***Exception encountered : " + e.toString()); } // For level MdmHierarchy, get parent, ancestors, and region attributes if (kindOfDim.equals("LevelHier")) { System.out.println("*********Parent attribute: " + ((MdmHierarchicalDimension) dim).getParentRelation().getName()); System.out.println("*********Ancestors attribute: " + ((MdmHierarchicalDimension) dim).getAncestorsRelation().getName()); System.out.println("*********Region attribute: " + ((MdmUnionDimensionDefinition) dim.getDefinition()) .getRegionAttribute().getName()); } // Get the MdmDimensionDefinition for the MdmDimension MdmDimensionDefinition dimDef = dim.getDefinition(); // For union or level MdmHierarchy, list the regions and default hierarchy if ((kindOfDim.equals("UnionHier")) || (kindOfDim.equals("LevelHier"))) { try { System.out.println(" "); System.out.println("*********The following are the regions of " + dim.getName()); List regions = ((MdmUnionDimensionDefinition)dimDef).getRegions(); Iterator regIter = regions.iterator(); while (regIter.hasNext()) { MdmDimension oneRegion = (MdmDimension) regIter.next(); System.out.println("************" + oneRegion.getName()); if (oneRegion.hasMdmTag(MdmMetadataProvider.DEFAULT_HIERARCHY_TAG)) System.out.println("***************(The " + oneRegion.getName() + " region is the default MdmHierarchy)"); } } catch (Exception e) { System.out.println("***Exception encountered : " + e.toString()); } } // For union or level MdmHierarchy, get region info if ((kindOfDim.equals("UnionHier")) || (kindOfDim.equals("LevelHier"))) { try { System.out.println(" "); System.out.println("*********Information about the regions of " + dim.getName() + ":"); List regions = ((MdmUnionDimensionDefinition)dimDef).getRegions(); Iterator regIter = regions.iterator(); while (regIter.hasNext()) { MdmDimension oneRegion = (MdmDimension) regIter.next(); getDimInfo(oneRegion, VERBOSE); } } catch (Exception e) { System.out.println("***Exception encountered : " + e.toString()); } } } System.out.println(" "); } // ********************************************************* // Method for getting info about an MdmMeasure public static void getMeasureInfo(MdmMeasure measure, int outputStyle) { System.out.println("******Measure: " + measure.getName()); if (outputStyle == VERBOSE) { // Get the dimensions of the MdmMeasure try { List mDims = measure.getDimensions(); Iterator mDimIter = mDims.iterator(); while (mDimIter.hasNext()) System.out.println("*********Dimension of the Measure: " + ((MdmDimension) mDimIter.next()).getName()); } catch (Exception e) { System.out.println("******Exception encountered : " + e.toString()); } } } }
The output from the sample program consists of text lines produced by Java statements such as the following one.
System.out.println("***Root MdmSchema: " + root.getName());
The code uses the getName
method because its return value is brief. An alternative would be to use the getDescription
method, but the output would be more verbose.
When the program is run on the Sales History schema, the output includes the following items:
MdmSchema
, which is ROOT.MdmDimension
for the root MdmSchema
. The name is MEASUREDIMENSION.MdmDimension
objects in the root MdmSchema
.MdmDimension
and MdmMeasure
objects in the SH_CAT MdmSchema
.
Because the SH_CAT
MdmSchema
is the only subschema under the root MdmSchema
, its MdmDimension
objects are identical to those in the root.
Source
for the MdmDimension
that has the name PRODUCTS_DIM.Here is the output. In order to conserve space, some blank lines have been omitted.
***Root MdmSchema: ROOT ******Measure MdmDimension: MEASUREDIMENSION ***Schema: ROOT ******************************************** ******MdmDimension Name: CHANNELS_DIM *********Description: Channel Values ********************************************** ******MdmDimension Name: CUSTOMERS_DIM *********Description: Customer Dimension Values ********************************************** ******MdmDimension Name: PRODUCTS_DIM *********Description: Product Dimension Values ********************************************** ******MdmDimension Name: PROMOTIONS_DIM *********Description: Promotion Values ********************************************** ******MdmDimension Name: TIMES_DIM *********Description: Time Dimension Values ********************************************** ***Subschema: SH_CAT ***Schema: SH_CAT ******************************************** ******MdmDimension Name: CHANNELS_DIM *********Description: Channel Values *********Member Type: MdmStandardMemberType *********Attribute: Long Description *********Attribute: Short Description *********CHANNELS_DIM is a union MdmHierarchy *********The following are the regions of CHANNELS_DIM ************CHANNEL_ROLLUP ***************(The CHANNEL_ROLLUP region is the default MdmHierarchy) *********Information about the regions of CHANNELS_DIM: ******MdmDimension Name: CHANNEL_ROLLUP *********Description: Standard Channels *********Member Type: MdmStandardMemberType *********CHANNEL_ROLLUP is a level MdmHierarchy *********Parent attribute: PARENTRELATION *********Ancestors attribute: ANCESTORSRELATION *********Region attribute: LEVELRELATION *********The following are the regions of CHANNEL_ROLLUP ************CHANNEL_TOTAL ************CHANNEL_CLASS ************CHANNEL *********Information about the regions of CHANNEL_ROLLUP: ******MdmDimension Name: CHANNEL_TOTAL *********Description: Channel Total for the standard hierarchy *********Member Type: MdmStandardMemberType *********CHANNEL_TOTAL is an MdmLevel ******MdmDimension Name: CHANNEL_CLASS *********Description: Channel Class level of the standard hierarchy *********Member Type: MdmStandardMemberType *********CHANNEL_CLASS is an MdmLevel ******MdmDimension Name: CHANNEL *********Description: Channel level of the standard hierarchy *********Member Type: MdmStandardMemberType *********CHANNEL is an MdmLevel ********************************************** ******MdmDimension Name: CUSTOMERS_DIM *********Description: Customer Dimension Values *********Member Type: MdmStandardMemberType *********Attribute: Long Description *********Attribute: Short Description *********Attribute: First Name *********Attribute: Last Name *********Attribute: Gender *********Attribute: Marital Status *********Attribute: Year of Birth *********Attribute: Income Level *********Attribute: Credit Limit *********Attribute: Street Address *********Attribute: Postal Code *********Attribute: Phone Number *********Attribute: E-mail *********CUSTOMERS_DIM is a union MdmHierarchy *********The following are the regions of CUSTOMERS_DIM ************GEOG_ROLLUP ***************(The GEOG_ROLLUP region is the default MdmHierarchy) ************CUST_ROLLUP *********Information about the regions of CUSTOMERS_DIM: ******MdmDimension Name: GEOG_ROLLUP *********Description: Standard *********Member Type: MdmStandardMemberType *********GEOG_ROLLUP is a level MdmHierarchy *********Parent attribute: PARENTRELATION *********Ancestors attribute: ANCESTORSRELATION *********Region attribute: LEVELRELATION *********The following are the regions of GEOG_ROLLUP ************GEOG_TOTAL ************REGION ************SUBREGION ************COUNTRY ************STATE ************CITY ************CUSTOMER *********Information about the regions of GEOG_ROLLUP: ******MdmDimension Name: GEOG_TOTAL *********Description: Geography Total for the standard CUSTOMER hierarchy *********Member Type: MdmStandardMemberType *********GEOG_TOTAL is an MdmLevel ******MdmDimension Name: REGION *********Description: Region level of the standard CUSTOMER hierarchy *********Member Type: MdmStandardMemberType *********REGION is an MdmLevel ******MdmDimension Name: SUBREGION *********Description: Subregion level of the standard CUSTOMER hierarchy *********Member Type: MdmStandardMemberType *********SUBREGION is an MdmLevel ******MdmDimension Name: COUNTRY *********Description: Country level of the standard CUSTOMER hierarchy *********Member Type: MdmStandardMemberType *********COUNTRY is an MdmLevel ******MdmDimension Name: STATE *********Description: State level of the standard CUSTOMER hierarchy *********Member Type: MdmStandardMemberType *********STATE is an MdmLevel ******MdmDimension Name: CITY *********Description: City level of the standard CUSTOMER hierarchy *********Member Type: MdmStandardMemberType *********CITY is an MdmLevel ******MdmDimension Name: CUSTOMER *********Description: Customer level of standard CUSTOMER hierarchy *********Member Type: MdmStandardMemberType *********CUSTOMER is an MdmLevel ******MdmDimension Name: CUST_ROLLUP *********Description: Standard *********Member Type: MdmStandardMemberType *********CUST_ROLLUP is a level MdmHierarchy *********Parent attribute: PARENTRELATION *********Ancestors attribute: ANCESTORSRELATION *********Region attribute: LEVELRELATION *********The following are the regions of CUST_ROLLUP ************CUST_TOTAL ************STATE ************CITY ************CUSTOMER *********Information about the regions of CUST_ROLLUP: ******MdmDimension Name: CUST_TOTAL *********Description: Customer Total for the standard CUSTOMER hierarchy *********Member Type: MdmStandardMemberType *********CUST_TOTAL is an MdmLevel ******MdmDimension Name: STATE *********Description: State level of the standard CUSTOMER hierarchy *********Member Type: MdmStandardMemberType *********STATE is an MdmLevel ******MdmDimension Name: CITY *********Description: City level of the standard CUSTOMER hierarchy *********Member Type: MdmStandardMemberType *********CITY is an MdmLevel ******MdmDimension Name: CUSTOMER *********Description: Customer level of standard CUSTOMER hierarchy *********Member Type: MdmStandardMemberType *********CUSTOMER is an MdmLevel ********************************************** ******MdmDimension Name: PRODUCTS_DIM *********Description: Product Dimension Values *********Member Type: MdmStandardMemberType *********Attribute: Long Description *********Attribute: Short Description *********PRODUCTS_DIM is a union MdmHierarchy *********The following are the regions of PRODUCTS_DIM ************PROD_ROLLUP ***************(The PROD_ROLLUP region is the default MdmHierarchy) *********Information about the regions of PRODUCTS_DIM: ******MdmDimension Name: PROD_ROLLUP *********Description: Standard *********Member Type: MdmStandardMemberType *********PROD_ROLLUP is a level MdmHierarchy *********Parent attribute: PARENTRELATION *********Ancestors attribute: ANCESTORSRELATION *********Region attribute: LEVELRELATION *********The following are the regions of PROD_ROLLUP ************PROD_TOTAL ************CATEGORY ************SUBCATEGORY ************PRODUCT *********Information about the regions of PROD_ROLLUP: ******MdmDimension Name: PROD_TOTAL *********Description: Product Total for the standard PRODUCT hierarchy *********Member Type: MdmStandardMemberType *********PROD_TOTAL is an MdmLevel ******MdmDimension Name: CATEGORY *********Description: Category level of standard PRODUCT hierarchy *********Member Type: MdmStandardMemberType *********CATEGORY is an MdmLevel ******MdmDimension Name: SUBCATEGORY *********Description: Sub-category level of standard PRODUCT hierarchy *********Member Type: MdmStandardMemberType *********SUBCATEGORY is an MdmLevel ******MdmDimension Name: PRODUCT *********Description: Product level of standard PRODUCT hierarchy *********Member Type: MdmStandardMemberType *********PRODUCT is an MdmLevel ********************************************** ******MdmDimension Name: PROMOTIONS_DIM *********Description: Promotion Values *********Member Type: MdmStandardMemberType *********Attribute: Long Description *********Attribute: Short Description *********PROMOTIONS_DIM is a union MdmHierarchy *********The following are the regions of PROMOTIONS_DIM ************PROMO_ROLLUP ***************(The PROMO_ROLLUP region is the default MdmHierarchy) *********Information about the regions of PROMOTIONS_DIM: ******MdmDimension Name: PROMO_ROLLUP *********Description: Standard Promotions *********Member Type: MdmStandardMemberType *********PROMO_ROLLUP is a level MdmHierarchy *********Parent attribute: PARENTRELATION *********Ancestors attribute: ANCESTORSRELATION *********Region attribute: LEVELRELATION *********The following are the regions of PROMO_ROLLUP ************PROMO_TOTAL ************CATEGORY ************SUBCATEGORY ************PROMO *********Information about the regions of PROMO_ROLLUP: ******MdmDimension Name: PROMO_TOTAL *********Description: Promotions Total for the standard PROMOTION hierarchy *********Member Type: MdmStandardMemberType *********PROMO_TOTAL is an MdmLevel ******MdmDimension Name: CATEGORY *********Description: Category level of the standard PROMOTION hierarchy *********Member Type: MdmStandardMemberType *********CATEGORY is an MdmLevel ******MdmDimension Name: SUBCATEGORY *********Description: Sub-category level of the standard PROMOTION hierarchy *********Member Type: MdmStandardMemberType *********SUBCATEGORY is an MdmLevel ******MdmDimension Name: PROMO *********Description: Promotion level of the standard PROMOTION hierarchy *********Member Type: MdmStandardMemberType *********PROMO is an MdmLevel ********************************************** ******MdmDimension Name: TIMES_DIM *********Description: Time Dimension Values *********Member Type: MdmStandardMemberType *********Attribute: Long Description *********Attribute: Short Description *********Attribute: Period Number *********Attribute: Period Number of Days *********Attribute: Period End Date *********TIMES_DIM is a union MdmHierarchy *********The following are the regions of TIMES_DIM ************CAL_ROLLUP ***************(The CAL_ROLLUP region is the default MdmHierarchy) ************FIS_ROLLUP *********Information about the regions of TIMES_DIM: ******MdmDimension Name: CAL_ROLLUP *********Description: Calendar *********Member Type: MdmStandardMemberType *********CAL_ROLLUP is a level MdmHierarchy *********Parent attribute: PARENTRELATION *********Ancestors attribute: ANCESTORSRELATION *********Region attribute: LEVELRELATION *********The following are the regions of CAL_ROLLUP ************YEAR ************QUARTER ************MONTH ************DAY *********Information about the regions of CAL_ROLLUP: ******MdmDimension Name: YEAR *********Description: Year level of the Calendar hierarchy *********Member Type: MdmStandardMemberType *********YEAR is an MdmLevel ******MdmDimension Name: QUARTER *********Description: Quarter level of the Calendar hierarchy *********Member Type: MdmStandardMemberType *********QUARTER is an MdmLevel ******MdmDimension Name: MONTH *********Description: Month level of the Calendar hierarchy *********Member Type: MdmStandardMemberType *********MONTH is an MdmLevel ******MdmDimension Name: DAY *********Description: Day level of the Calendar hierarchy *********Member Type: MdmStandardMemberType *********DAY is an MdmLevel ******MdmDimension Name: FIS_ROLLUP *********Description: Fiscal *********Member Type: MdmStandardMemberType *********FIS_ROLLUP is a level MdmHierarchy *********Parent attribute: PARENTRELATION *********Ancestors attribute: ANCESTORSRELATION *********Region attribute: LEVELRELATION *********The following are the regions of FIS_ROLLUP ************FIS_YEAR ************FIS_QUARTER ************FIS_MONTH ************FIS_WEEK ************DAY *********Information about the regions of FIS_ROLLUP: ******MdmDimension Name: FIS_YEAR *********Description: Year level of the Fiscal hierarchy *********Member Type: MdmStandardMemberType *********FIS_YEAR is an MdmLevel ******MdmDimension Name: FIS_QUARTER *********Description: Quarter level of the Fiscal hierarchy *********Member Type: MdmStandardMemberType *********FIS_QUARTER is an MdmLevel ******MdmDimension Name: FIS_MONTH *********Description: Month level of the Fiscal hierarchy *********Member Type: MdmStandardMemberType *********FIS_MONTH is an MdmLevel ******MdmDimension Name: FIS_WEEK *********Description: Week level of the Fiscal hierarchy *********Member Type: MdmStandardMemberType *********FIS_WEEK is an MdmLevel ******MdmDimension Name: DAY *********Description: Day level of the Calendar hierarchy *********Member Type: MdmStandardMemberType *********DAY is an MdmLevel ********************************************** ******Measure: SALES_QUANTITY *********Dimension of the Measure: CHANNELS_DIM *********Dimension of the Measure: CUSTOMERS_DIM *********Dimension of the Measure: PRODUCTS_DIM *********Dimension of the Measure: PROMOTIONS_DIM *********Dimension of the Measure: TIMES_DIM ******Measure: SALES_AMOUNT *********Dimension of the Measure: CHANNELS_DIM *********Dimension of the Measure: CUSTOMERS_DIM *********Dimension of the Measure: PRODUCTS_DIM *********Dimension of the Measure: PROMOTIONS_DIM *********Dimension of the Measure: TIMES_DIM ******Measure: UNIT_PRICE *********Dimension of the Measure: PRODUCTS_DIM *********Dimension of the Measure: TIMES_DIM ******Measure: UNIT_COST *********Dimension of the Measure: PRODUCTS_DIM *********Dimension of the Measure: TIMES_DIM ***Making a Source object for PRODUCTS_DIM ******Made the Source
|
Copyright © 2000, 2002 Oracle Corporation. All Rights Reserved. |
|