Retrieving a Single Vector of Dimension Members

The purpose of this example is to create programmatically a DataAccess object that is similar to the single vector of dimension values (metadata) that is created through the user interface of the QueryBuilder bean.

The example fetches a cube that has only a single edge (the column edge) and a single layer (the Geography dimension) with three members: WORLD, BOSTON, and NEWYORK.

This example makes the following assumption: m_queryManager is a running QueryManager object.

The following code retrieves a single vector of dimension values.


//Create an empty query Query query = m_queryManager.createQuery(); //Specify that the query should fetch value, short label, and long //label metadata for each dimension value. query.setMetadataMap(null, new MetadataMap (new String[]    {MetadataMap.METADATA_VALUE, MetadataMap.METADATA_SHORTLABEL,     MetadataMap.METADATA_LONGLABEL})); //For the Geography dimension, define a member selection that includes // three members. Selection sel = new Selection("GEOGRAPHY"); MemberStep ms = new MemberStep("GEOGRAPHY"); ms.addMember("WORLD"); ms.addMember("BOSTON"); ms.addMember("NEWYORK"); sel.addStep(ms); //Apply the Geography selection to the query. query.applySelection(sel); //Initialize the query with no measures (therefore, no data) and only //the single Geography dimension at layer 0 on edge 0   //(the column edge). //The query automatically uses the Geography selection that was //applied to it above. query.initQuery(new String[] [] {{sel.getDimension()}}, null); //Get the DataAccess object by listening for the DataAvailable event //that will be fired when this QueryListener class is added to the //query as a listener. QListener ql = new QListener(); query.addQueryListener (ql); DataAccess ds = ql.getDataAccess(); //Now you can walk down just the column edge of the DataAccess //object. //The column edge extent is the number of dimension values. //There is no actual data body data. //Create a QueryListener class by extending QueryAdapter. private class QListener extends QueryAdapter {   DataAccess da = null;   public void dataAvailable(DataAvailableEvent e) {      da = e.getDataAccess();   }   public DataAccess getDataAccess() {      return da;   } }