MicroStrategy ONE

Setting Extended Properties for a Data Mart Table

The following code sample illustrates how to set extended properties for a data mart. It includes code for setting properties for an existing data mart report, as well as code for setting properties at the same time that you are defining the data mart.

Code sample

 public void testConvertToDatamart() throws Exception{

 

   //Create a report bean instance

   ReportBean rb = getReportBean("SimpleReport");

   rb.collectData();

   WebReportInstance inst = rb.getReportInstance();

 

   //access the datamart info and indicate that the instance should

   //be associated with a datamart if it is not already

   WebDatamart datamart = inst.getDatamartInfo(true);

   WebObjectInfo dbInstance=null;

 

   //Choose the appropriate db role; Set the connection information for the datamart table.

   WebFolder sl = factory.getObjectSource().getAvailableDBRoles();

   for(int i=0;i<sl.size();i++){

     if(sl.get(i).getName().equals("Tutorial Data")){

       dbInstance = (WebObjectInfo)sl.get(i);

       break;

     }

   }

 

   if(dbInstance==null){

     dbInstance = sl.get(1);

   }

   datamart.setDBRole(dbInstance);

 

   //access the table information

   WebDatamartTable table = datamart.getTable();

 

   //set table name and properties, in this case specifying that new table info

   //should replace existing info rather than be appended to it.

   table.setName("custom",false);

   table.setAppendToTable(false);

 

   //check to see if the report has previously been defined as a data mart report

   WebPropertySet wps=datamart.getProperties();

   if(wps!=null){

     //set extended properties for an existing data mart report

     wps.getItemByName("Table Prefix").setValue("myTable_");

   }

   else{

     //set extended properties for a report that is being defined as a data

     //mart report -that is, a report that is not yet a data mart report

     inst.setProperty(EnumDSSXMLReportObjects.DssXmlReportObjectDatamart,"DatamartProperties","Table Prefix","myTable_");

   }

 

   //Apply the changes to the data mart report, including setting the extended property

   //and saving the report as a data mart report if required

   rb.getReportInstance().getReportManipulator().applyChanges();

   rb.collectData();

   rb.getReportInstance().setSaveAsDisplayMode(EnumDSSXMLDisplayMode.DssXmlDisplayModeDatamart);

   WebObjectInfo oInfo=rb.getObjectInfo():

   oInfo.populate();

   WebFolder parent=oInfo.getParent();

   rb.getReportInstance().saveAs(parent,"DatamartSavedFromWeb2");

 }