How to retrieve SQL query of QaaWS using BO Java RE SDK

QaaWS is stored as Webi document on the server

To check that QaaWS is represented as Webi document, you can open Query Builder and run the following SQL:

SELECT * FROM CI_APPOBJECTS WHERE SI_KIND='QaaWS'

The property SI_FILES describes the location of the files corresponding to QaaWS and it is actually the WID file:

The following code prints queries for all QaaWS found in CMS:

IInfoObjects objs = infoStore.query("SELECT * FROM CI_APPOBJECTS WHERE SI_KIND='QaaWS'");
System.out.println("Number of QaaWS found: " + objs.size());
for (Object obj : objs) {
   IInfoObject infoObj = (IInfoObject)obj;
   System.out.println("------ " + infoObj.getTitle() + " ------");
   DocumentInstance widoc = wiRepEngine.openDocument(infoObj.getID());
   printQuery(widoc);
   widoc.closeDocument();
}

The function printing SQL of Webi document

public static void printQuery(DocumentInstance widoc) {
   DataProviders dps = widoc.getDataProviders();
   for (int i = 0; i < dps.getCount(); ++i) {
      DataProvider dp = (DataProvider)dps.getItem(i);
      if (dp instanceof SQLDataProvider) {
         SQLDataProvider sdp = (SQLDataProvider)dp;
         ArrayList<TreeNode> nodes = getListOfTreeNodes(sdp.getSQLContainer(), true);
         for (TreeNode node : nodes) {
            if (node instanceof SQLSelectStatement) {
               SQLSelectStatement query = (SQLSelectStatement)node;
               System.out.println(query.getSQL());
            }
         }
      }
   }
}

Auxiliary functions

The following function finds the list of all nodes in the tree. It might be more convenient then writing recursion:

public static ArrayList<TreeNode> getListOfTreeNodes(TreeNode root, boolean onlyLeaves) {
   ArrayList<TreeNode> nodes = new ArrayList<TreeNode>();
   treeNodeTraversal(root, nodes, onlyLeaves);
   return nodes;
}

private static void treeNodeTraversal(TreeNode node,
   ArrayList<TreeNode> nodes,
   boolean onlyLeaves)
{
   if (!onlyLeaves || node.isLeaf()) {
      nodes.add(node);
   }
   for (int i = 0; i < node.getChildCount(); ++i) {
      treeNodeTraversal(node.getChildAt(i), nodes, onlyLeaves);
   }
}

Source Code

Leave a 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