protected void run() throws Exception
{
println("Implementing the extract Method as a CustomModel\n");
// Get the DataProvider.
DataProvider dp = getContext().getDataProvider();
// Get the MdmMeasure objects and the Source objects for them.
MdmMeasure mdmUnitPrice = getMdmMeasure("UNIT_PRICE_AW");
MdmMeasure mdmUnitCost = getMdmMeasure("UNIT_COST_AW");
NumberSource unitPrice = (NumberSource) mdmUnitPrice.getSource();
NumberSource unitCost = (NumberSource) mdmUnitCost.getSource();
// Get the MdmPrimaryDimension objects and the default hierarchies for them.
MdmPrimaryDimension mdmProdDim = getMdmPrimaryDimension("PRODUCT_AW");
MdmPrimaryDimension mdmTimeDim = getMdmPrimaryDimension("TIME_AW");
MdmLevelHierarchy mdmProdRollup = (MdmLevelHierarchy)
mdmProdDim.getDefaultHierarchy();
MdmLevelHierarchy mdmCalendar = (MdmLevelHierarchy)
mdmTimeDim.getDefaultHierarchy();
// Get the Source objects for the hierarchies.
StringSource prodRollup = (StringSource) mdmProdRollup.getSource();
StringSource calendar = (StringSource) mdmCalendar.getSource();
// Create a Source that represents a selection of Product dimension members.
Source prodSel = prodRollup.selectValues(new String[]
{"PRODUCT_PRIMARY_AW::ITEM_AW::13",
"PRODUCT_PRIMARY_AW::ITEM_AW::14",
"PRODUCT_PRIMARY_AW::ITEM_AW::15"});
// Create a Source that is the result of a calculation involving two measures.
Source calculation = unitPrice.minus(unitCost);
// Create a Source whose element values are the Source objects for the
// measures and the calculation. The resulting Source is like a measure
// dimension.
Source sourceListSrc = dp.createListSource(new Source[] {unitPrice,
unitCost,
calculation});
// Use the extract method and then join Source objects that match the
// inputs of the Source objects in the list.
Source resultUsingExtract =
sourceListSrc.extract()
.join(sourceListSrc)
.join(prodSel)
.join(calendar, "CALENDAR_YEAR_AW::MONTH_AW::47");
// Prepare and commit the current Transaction.
prepareAndCommit();
// Create a Cursor for the query and display the values of the Cursor.
println("The values using extract method are:");
getContext().displayResult(resultUsingExtract);
// Produce the same result using a CustomModel directly.
CustomModel customModel = dp.createModel(sourceListSrc);
customModel.assign(unitPrice.getID(), unitPrice);
customModel.assign(unitCost.getID(), unitCost);
customModel.assign(calculation.getID(), calculation);
Source measValForSrc = customModel.createSolvedSource();
// Join Source objects that match the inputs of the solved Source produced by
// the CustomModel.
Source resultUsingCustomModel =
measValForSrc.join(sourceListSrc)
.join(prodSel)
.join(calendar, "CALENDAR_YEAR_AW::MONTH_AW::47");
prepareAndCommit();
println("The values of using a CustomModel directly, with the Source IDs");
println("as the qualifications are:");
getContext().displayResult(resultUsingCustomModel);
// Create a list Source that has String objects as its element values.
Source stringListSrc = dp.createListSource(new String[] {"price",
"cost",
"markup"});
// Create a CustomModel for the list Source.
CustomModel customModel2 = dp.createModel(stringListSrc);
customModel2.assign("price", unitPrice);
customModel2.assign("cost", unitCost);
customModel2.assign("markup", calculation);
Source measValForSrc2 = customModel2.createSolvedSource();