// Copyright (c) 2003, Oracle Corporation. All rights reserved. package globalExamples; import oracle.olapi.data.source.DataProvider; import oracle.olapi.data.source.Source; import oracle.olapi.data.source.NumberSource; import oracle.olapi.data.source.StringSource; import oracle.olapi.metadata.mdm.MdmAttribute; import oracle.olapi.metadata.mdm.MdmHierarchy; import oracle.olapi.metadata.mdm.MdmMeasure; import oracle.olapi.metadata.mdm.MdmPrimaryDimension; /** * Complete code for the examples that appear in the SourceConcepts.html * auxiliary file to the Source class description in the * Oracle OLAP Java API Reference. * This file uses the Context10g.java file and the CursorPrintWriter.java * file, which are in the doc/doc-files directory of the * Oracle OLAP Java API Reference directory structure. * *

* @author Oracle Corporation */ public class SourceConceptsExamples extends Object { // Objects used by more than one example private MdmHierarchy mdmTimeHier = null; private MdmHierarchy mdmProdHier = null; private MdmHierarchy mdmCustHier = null; private MdmMeasure mdmUnitCost = null; private StringSource prodHier = null; private Source prodShortDescr = null; private Source custShortDescr = null; private Source timeShortDescr = null; public SourceConceptsExamples() { } public String getDescription() { return "Examples in the SourceConcepts.html auxiliary file to the Source " + "class description in the Oracle OLAP Java API Reference."; } public void run(String [] args) { Context10g context = new Context10g(args, true); DataProvider dp = context.dp; // Get the metadata objects for the dimensions used by most of the // examples. MdmPrimaryDimension mdmProdDim = context.getMdmPrimaryDimensionByName("PRODUCT"); mdmProdHier = mdmProdDim.getDefaultHierarchy(); MdmPrimaryDimension mdmCustDim = context.getMdmPrimaryDimensionByName("CUSTOMER"); mdmCustHier = mdmCustDim.getDefaultHierarchy(); MdmPrimaryDimension mdmTimeDim = context.getMdmPrimaryDimensionByName("TIME"); mdmTimeHier = mdmTimeDim.getDefaultHierarchy(); MdmAttribute mdmProdShortDescr = mdmProdDim.getShortValueDescriptionAttribute(); prodShortDescr = mdmProdShortDescr.getSource(); MdmAttribute mdmCustShortDescr = mdmCustDim.getShortValueDescriptionAttribute(); custShortDescr = mdmCustShortDescr.getSource(); MdmAttribute mdmTimeShortDescr = mdmTimeDim.getShortValueDescriptionAttribute(); timeShortDescr = mdmTimeShortDescr.getSource(); mdmUnitCost = context.getMdmMeasureByName("UNIT_COST"); example1(context, dp); example2(context, dp); example3(context, dp); example4(context, dp); example5(context, dp); example6(context, dp); example7(context, dp); } private void example1(Context10i context, DataProvider dp) { context.println("Example 1 - Using the isSubtypeOf Method"); Source myList = dp.createListSource(new String[] { "PRODUCT_ROLLUP::FAMILY::4", // Portable PCs "PRODUCT_ROLLUP::FAMILY::5", // Desktop PCs "PRODUCT_ROLLUP::FAMILY::7", // Accessories "PRODUCT_ROLLUP::FAMILY::8"}); // Monitors prodHier = (StringSource) mdmProdHier.getSource(); // Selecting values using the selectValues shortcut Source prodSel = prodHier.selectValues(myList); // Selecting values using the full join method, from the Inputs of // a Source section. //prodSel = prodHier.join(prodHier.value(), myList, // Source.COMPARISON_RULE_SELECT, false); if (prodSel.isSubtypeOf(prodHier)) context.println("prodSel is a subtype of prodHier."); else context.println("prodSel is not a subtype of prodHier."); } private void example2(Context10i context, DataProvider dp) { context.println("Example 2 - Using the join Method To Produce a " + "Source Without an Output"); Source custValuesToSelect = dp.createListSource(new String[] {"SHIPMENTS_ROLLUP::REGION::9", // North America "SHIPMENTS_ROLLUP::REGION::10"}); // Europe Source custHier = mdmCustHier.getSource(); Source custHierValues = custHier.value(); Source custSel = custHier.join(custHierValues, custValuesToSelect, Source.COMPARISON_RULE_SELECT, false); context.commit(); context.displayResult(custSel); } private void example3(Context10i context, DataProvider dp) { context.println("Example 3 - Using the join Method To Produce a " + "Source With an Output"); // Create the same product selection as in Example 1. Source myList = dp.createListSource(new String[] { "PRODUCT_ROLLUP::FAMILY::4", // Portable PCs "PRODUCT_ROLLUP::FAMILY::5", // Desktop PCs "PRODUCT_ROLLUP::FAMILY::7", // Accessories "PRODUCT_ROLLUP::FAMILY::8"}); // Monitors Source prodHier = (StringSource) mdmProdHier.getSource(); Source prodSel = prodHier.selectValues(myList); // Create same customer selection as in Example 2. Source custValuesToSelect = dp.createListSource(new String[] {"SHIPMENTS_ROLLUP::REGION::9", // North America "SHIPMENTS_ROLLUP::REGION::10"}); // Europe Source custHier = mdmCustHier.getSource(); Source custHierValues = custHier.value(); Source custSel = custHier.join(custHierValues, custValuesToSelect, Source.COMPARISON_RULE_SELECT, false); // Join the custSel and prodSel Source objects to the short description // attribute for their hierarchies. Source prodSelDescr = prodShortDescr.joinHidden(prodSel); Source custSelDescr = custShortDescr.joinHidden(custSel); // The following are the lines from Example 3 Source custSelByProdSel = custSel.join(prodSel, dp.getEmptySource(), Source.COMPARISON_RULE_REMOVE, true); Source custSelByProdSelDescr = custSelDescr.join(prodSelDescr, dp.getEmptySource(), Source.COMPARISON_RULE_REMOVE, true); context.commit(); context.displayResult(custSelByProdSel); context.displayResult(custSelByProdSelDescr); } private void example4(Context10i context, DataProvider dp) { context.println("Example 4 - Using the join Method To Match " + "Source Objects To Inputs"); Source unitCost = mdmUnitCost.getSource(); Source prodHier = mdmProdHier.getSource(); Source timeHier = mdmTimeHier.getSource(); Source timeSel = timeHier.join(timeHier.value(), dp.createListSource(new String[] {"CALENDAR::MONTH::35", "CALENDAR::MONTH::45"}), Source.COMPARISON_RULE_SELECT, false); Source prodSel = prodHier.join(prodHier.value(), dp.createListSource(new String[] {"PRODUCT_ROLLUP::ITEM::13", "PRODUCT_ROLLUP::ITEM::14", "PRODUCT_ROLLUP::ITEM::15"}), Source.COMPARISON_RULE_SELECT, false); Source unitCostSel = unitCost.join(timeSel, dp.getEmptySource(), Source.COMPARISON_RULE_REMOVE, true) .join(prodSel, dp.getEmptySource(), Source.COMPARISON_RULE_REMOVE, true); context.commit(); context.displayResult(unitCostSel); } private void example5(Context10i context, DataProvider dp) { context.println("Example 5 - Using Shortcuts"); Source unitCost = mdmUnitCost.getSource(); StringSource timeHier = (StringSource) mdmTimeHier.getSource(); StringSource prodHier =(StringSource) mdmProdHier.getSource(); Source timeSel = timeHier.selectValues(new String[] { "CALENDAR::MONTH::35", "CALENDAR::MONTH::45"}); Source prodSel = prodHier.selectValues(new String[] { "PRODUCT_ROLLUP::ITEM::13", "PRODUCT_ROLLUP::ITEM::14", "PRODUCT_ROLLUP::ITEM::15"}); Source unitCostSel = unitCost.join(timeSel).join(prodSel); context.commit(); context.displayResult(unitCostSel); } private void example6(Context10i context, DataProvider dp) { context.println("Example 6 - Using Shortcuts"); // Create the same product selection as in Example 1. Source myList = dp.createListSource(new String[] { "PRODUCT_ROLLUP::FAMILY::4", // Portable PCs "PRODUCT_ROLLUP::FAMILY::5", // Desktop PCs "PRODUCT_ROLLUP::FAMILY::7", // Accessories "PRODUCT_ROLLUP::FAMILY::8"}); // Monitors Source pos = dp.createListSource(new int[] {2, 4}); Source myListPos = myList.position(); Source myListSel = myList.join(myListPos, pos, Source.COMPARISON_RULE_SELECT, false); // Creaating ths same selection with visible as true //Source myListSel = myList.join(myListPos, pos, // Source.COMPARISON_RULE_SELECT, true); context.commit(); context.displayResult(myListSel); } private void example7(Context10i context, DataProvider dp) { context.println("Example 7 - Matching an Input of the Base Source " + "to an Output of the Joined Source"); // Get the MdmMeasure for units MdmMeasure mdmUnits = context.getMdmMeasureByName("UNITS"); // Get the Source for the measure Source units = mdmUnits.getSource(); // Get the metadata objects for the channel dimension MdmPrimaryDimension mdmChanDim = context.getMdmPrimaryDimensionByName("CHANNEL"); MdmHierarchy mdmChanHier = mdmChanDim.getDefaultHierarchy(); // Get the Source objects for the default hierarchies of the dimensions // of the measures Source prodHier = mdmProdHier.getSource(); Source custHier = mdmCustHier.getSource(); Source timeHier = mdmTimeHier.getSource(); Source chanHier = mdmChanHier.getSource(); Source prodSel = prodHier.join(prodHier.value(), dp.createListSource(new String[] {"PRODUCT_ROLLUP::FAMILY::4", "PRODUCT_ROLLUP::FAMILY::5"}), Source.COMPARISON_RULE_SELECT, false); Source custSel = custHier.join(custHier.value(), dp.createListSource(new String[] {"SHIPMENTS_ROLLUP::REGION::9", "SHIPMENTS_ROLLUP::REGION::10"}), Source.COMPARISON_RULE_SELECT, false); Source timeSel = timeHier.join(timeHier.value(), dp.createConstantSource( "CALENDAR::YEAR::4"), Source.COMPARISON_RULE_SELECT, false); Source chanSel = chanHier.join(chanHier.value(), dp.createConstantSource( "CHANNEL_ROLLUP::CHANNEL::4"), Source.COMPARISON_RULE_SELECT, false); Source custSelByTime = custSel.join(timeSel, dp.getEmptySource(), Source.COMPARISON_RULE_REMOVE, true); Source prodByCustByTime = prodSel.join(custSelByTime, dp.getEmptySource(), Source.COMPARISON_RULE_REMOVE, true); Source selectedUnits = units.join(prodByCustByTime, dp.getEmptySource(), Source.COMPARISON_RULE_REMOVE, true) .join(chanSel, dp.getEmptySource(), Source.COMPARISON_RULE_REMOVE, true); context.commit(); context.displayResult(selectedUnits); // Get the short description attribute for the channel dimension. MdmAttribute mdmChanShortDescr = mdmChanDim.getShortValueDescriptionAttribute(); Source chanShortDescr = mdmChanShortDescr.getSource(); // Create Source objects that have the short description attributes // as the type values and the dimension selection Source objects // as outputs Source prodSelDescr = prodShortDescr.join(prodSel); Source custSelDescr = custShortDescr.join(custSel); Source timeSelDescr = timeShortDescr.join(timeSel); Source chanSelDescr = chanShortDescr.join(chanSel); // Recreate the query including the short descriptions custSelByTime = custSelDescr.join(timeSelDescr, dp.getEmptySource(), Source.COMPARISON_RULE_REMOVE, true); prodByCustByTime = prodSelDescr.join(custSelByTime, dp.getEmptySource(), Source.COMPARISON_RULE_REMOVE, true); selectedUnits = units.join(prodByCustByTime, dp.getEmptySource(), Source.COMPARISON_RULE_REMOVE, true) .join(chanSelDescr, dp.getEmptySource(), Source.COMPARISON_RULE_REMOVE, true); context.commit(); context.displayResult(selectedUnits); } public static void main(String[] args) { new SourceConceptsExamples().run(args); } }