Defining and Referencing Calculations

The product that the CalcBuilder bean produces is a CalcStep object, which is a definition of a calculation. When the calculation definition is saved, the CalcStep object is stored in the BI Beans Catalog. Before a calculation can become part of a query, it must be loaded from the BI Beans Catalog or dynamically created.

To define a calculation, perform the following steps:

  1. Prepare an application for a CalcBuilder.

  2. Add a CalcBuilder to an application.

  3. Save the calculation in the Save Calculation panel of the CalcBuilder.

In order to evaluation a calculation, it must be applied to a query. The following code illustrates the following:


// Run the CalcBuilder private void runCalcBuilder() throws Exception { // Create our CalcBuilder CalcBuilderStepStorage calcBuilderStepStorage = new CalcBuilderStepStorage (null, m_strLookAndFeel,     null, m_query, m_metadataManager); // Set our default help provider calcBuilderStepStorage.setHelpProvider (new DefaultHelpProvider()); // Invoke the CalcBuilder try    { MDMeasure mdMeasure = (MDMeasure)calcBuilderStepStorage.invoke(); // Update the measures if a custom measure has been added if (mdMeasure != null) {    updateMeasures (mdMeasure);    } } catch (Exception e) {  // Just verify that we can retrieve the calcStep and MDMeasure even  // if saving fails  CalcStep calcStep = calcBuilderStepStorage.getCalcStep();  MDMeasure mdMeasure = calcBuilderStepStorage.getMDMeasure();  //Rethrow the exception  throw (e);  } } /** * 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
Applying a Calculation to a Query