Defining a Query Using QueryBuilder

To define a query using the QueryBuilder, use the following steps:

Notice that this procedure does not require that you apply selections to the Query object. When the QueryBuilder runs, it applies the user's selections to the Query object. However, you can choose to initialize the QueryBuilder by applying a selection to the Query object before running the QueryBuilder.

Example: Defining a query using the QueryBuilder

The following code provides an example of defining a query using the QueryBuilder.


//m_metadataMgr is an existing MetadataManager object //m_qb is an existing QueryBuilder object // //strSalesMeasure is the unique identifier for the Sales measure //strMeasureDim is the unique identifier for the Dimension measure //strTimeDim is the unique identifier for the Time dimension //strProductDim is the unique identifier for the Product dimension //strGeogDim is the unique identifier for the Geography dimension //strChannelDim is the unique identifier for the Channel dimension // //Create a QueryManager and specify the metadata to use. QueryManager m_QueryManager = new QueryManager (); m_QueryManager.setMetadataManager (m_metadataMgr); // //Create an empty Query using the QueryManager factory method Query m_query = m_QueryManager.createQuery (); // //Define arrays to specify the dimension layout //that will be used to initialize the query. String [] [] dimensions = new String [3] []; //Row edge of the query dimensions [0] = new String [2]; dimensions [0] [0] = strTimeDim; dimensions [0] [1] = strMeasureDim; //Column edge of the query dimensions [1] = new String [1]; dimensions [1] [0] = strProductDim; //Page edge of the query dimensions [2] = new String [2]; dimensions [2] [0] = strGeogDim; dimensions [2] [1] = strChannelDim; //Specify the Sales measures String [] measures = new String[1]; measures [0] = strSalesMeasure; // //Initialize the Query object //Since the second parameter of this method is not Null, //the query uses the specified dimension layout. m_query.initCubeQuery (measures, dimensions);   // //Tell the QueryBuilder about the Query object. //Note: Query implements the QueryContext interface in order to //provide QueryAccess objects that let QueryBuilder work with //available and selected selections. The QueryContext cast is //necessary when QueryBuilder references a Query object. m_qb.setQueryContext ((QueryContext) m_query); // //Run the QueryBuilder. m_qb.run ();