Applying a Calculation to a Query

Before you can use a calculation in a query, it must be loaded from the BI Beans Catalog or dynamically created. To load a calculation (including all of its dependent calculations) from the BI Beans Catalog, one of the following actions must occur:

Note: When a CalcStep in a selection is applied to a query, then the CalcStep is evaluated. To evaluate a CalcStep object in a selection, a Query object creates a corresponding CalcStepEvaluator object. Evaluation of a CalcStep object is the process of translating a calculation's definition into the appropriate OLAP API source.

The following code example shows how a calculation that has been wrapped in a MetadataManager MDMeasure can be added to a query:


/** *  Updates the measures based on the specified MDMeasure. * *  @param mdMeasure a MDMeasure value that represents the *          measure to add. *  @throws  InvalidStepArgException, SelectionException, QueryException or *          MetadataManagerException  if measures could not be updated */ private void updateMeasures (MDMeasure mdMeasure)  throws InvalidStepArgException, SelectionException, QueryException, MetadataManagerException { // Update the panel if a calculation has been added if (mdMeasure != null) {  //Create a queryAccess in order to update query  QueryAccess queryAccess = m_query.createQueryAccess(); // Retrieve the name of the measure dimension String strMeasureDimension =    queryAccess.getMeasureDimension(LayerMetadataMap.LAYER_METADATA_NAME); // Retrieve the selection associated with the measure dimension Selection selection =    queryAccess.getSelection (strMeasureDimension); // Verify that the selection is non-null if (selection != null) { // Retrieve the members associated with the step MemberStep step = (MemberStep)selection.getStep(0); Vector members = step.getMembers(); // Retrieve the current measure list String[] newMeasures = new String [members.size() + 1]; for (int i=0; i < members.size(); i++)    {     newMeasures[i] = (String)members.elementAt(i);    } // Add our new custom measure newMeasures[members.size()] = mdMeasure.getUniqueID(); members.addElement (mdMeasure.getUniqueID()); step.setMembers (members); // Set the action to be ADD for inserting a MemberStep. step.setAction(oracle.dss.selection.step.Step.SELECT); // Remove all steps from this selection. selection.removeAllSteps(); // Add our newly created step which includes our new custom // measure selection.addStep(step); // Attempt to update the query with the new measure selection m_query.applySelection (selection);     }   } }

Adding a CalcBuilder to an Application
Defining and Referencing Calculations