Purging data provider queries using BO RE Java SDK

Before copying webi documents from test to production environment it might be useful to clean up document queries.

The following function

  • purges data providers queries,
  • removes saved prompt values, and
  • regenerates queries.
public static void purgeQueries(DocumentInstance widoc) {
   DataProviders dps = widoc.getDataProviders();
   for (int i = 0; i < dps.getCount(); ++i) {
      DataProvider dp = (DataProvider)dps.getItem(i);
      if (dp instanceof SQLDataProvider) {
         System.out.println("Data provider: " + dp.getName());
         SQLDataProvider sdp = (SQLDataProvider)dp;
         sdp.purge(true); // true means purge prompt values
         sdp.generateQuery();
         sdp.resetSQL();
      }
   }
}

The code is very simple but I use this functionality most often.

More Information

Getting started with BO RE Java SDK
Package com.businessobjects.rebean.wi.*

3 thoughts on “Purging data provider queries using BO RE Java SDK

  1. Balaji

    Hi,
    Can you pls provide me this code in and JSP SDK format so that I can use this in our BO plant.

    Your help will be really great and I was looking for this kind long time

    Thanks
    Balaji Karunakaran

    Like

    Reply
  2. Balaji

    Hi bukhantsov,

    Can you plsssss help me out to redefind this purge code to run in Eclipse

    Thanks
    Balaji Karunakaran

    ———————-
    package org.BK.javatool;

    import com.businessobjects.rebean.wi.DataProvider;
    import com.businessobjects.rebean.wi.DataProviders;
    import com.businessobjects.rebean.wi.DocumentInstance;
    import com.businessobjects.rebean.wi.ObjectQualification;
    import com.businessobjects.rebean.wi.ReportDictionary;
    import com.businessobjects.rebean.wi.ReportEngine;
    import com.businessobjects.rebean.wi.ReportEngines;
    import com.businessobjects.rebean.wi.SQLDataProvider;
    import com.businessobjects.rebean.wi.VariableExpression;
    import com.crystaldecisions.sdk.exception.SDKException;
    import com.crystaldecisions.sdk.framework.CrystalEnterprise;
    import com.crystaldecisions.sdk.framework.IEnterpriseSession;
    import com.crystaldecisions.sdk.framework.ISessionMgr;
    import com.crystaldecisions.sdk.occa.infostore.IInfoObject;
    import com.crystaldecisions.sdk.occa.infostore.IInfoObjects;
    import com.crystaldecisions.sdk.occa.infostore.IInfoStore;

    public class SDKBO {

    public static void main(String[] args) {
    IEnterpriseSession enterpriseSession = null;
    ReportEngines reportEngines = null;
    try {
    System.out.println(“Connecting…”);
    ISessionMgr sessionMgr = CrystalEnterprise.getSessionMgr();
    enterpriseSession = sessionMgr.logon(“Administrator”, “”,
    “Coq3bobjapp01:7400”, “secEnterprise”);
    reportEngines = (ReportEngines) enterpriseSession
    .getService(“ReportEngines”);
    ReportEngine wiRepEngine = (ReportEngine) reportEngines
    .getService(ReportEngines.ReportEngineType.WI_REPORT_ENGINE);
    IInfoStore infoStore = (IInfoStore) enterpriseSession
    .getService(“InfoStore”);
    String query = “select SI_NAME, SI_ID from CI_INFOOBJECTS ”
    + “where SI_KIND = ‘Webi’ and SI_INSTANCE=0”;
    IInfoObjects infoObjects = (IInfoObjects) infoStore.query(query);
    for (Object object : infoObjects) {
    IInfoObject infoObject = (IInfoObject) object;
    String path = getInfoObjectPath(infoObject);
    if (path.startsWith(“/”)) {
    DocumentInstance widoc = wiRepEngine
    .openDocument(infoObject.getID());
    String doc = infoObject.getTitle();
    System.out.println(path + “/” + doc);
    printDocumentVariables(widoc);
    //addReplaceVariable(widoc, “VERSION”, “=\”12.00.18.00\””);
    //purgeQueries(widoc);
    widoc.closeDocument();
    }
    }
    } catch (SDKException ex) {
    ex.printStackTrace();
    } finally {
    if (reportEngines != null)
    reportEngines.close();
    if (enterpriseSession != null)
    enterpriseSession.logoff();
    }
    System.out.println(“Finished!”);
    }

    public static void purgeQueries(DocumentInstance widoc) {
    DataProviders dps = widoc.getDataProviders();
    for (int i = 0; i < dps.getCount(); ++i) {
    DataProvider dp = (DataProvider) dps.getItem(i);
    if (dp instanceof SQLDataProvider) {
    System.out.println("Data provider: " + dp.getName());
    SQLDataProvider sdp = (SQLDataProvider) dp;
    sdp.purge(true); // true means purge prompt values
    sdp.generateQuery();
    sdp.resetSQL();
    }
    }
    )

    Like

    Reply

Leave a Reply to Balaji Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s