Dynamic Query Agent Sessions

You can dynamically start a collocated query agent session from an inference agent and make queries, using startup and preprocessor rule functions.

executeInDynamicQuerySession

The following function is used in the inference agent's preprocessor. It enables you to execute a query in the dynamic query agent session (without the need for collocated query agent),, and use the results:

Query.Util.executeInDynamicQuerySession(queryString, mapOfParameters, true);

The is an example showing how you might use this rule function:

void rulefunction Inference.RuleFunctions.MyPreProcessor {
       attribute {
   validity = ACTION;
}
scope {
   Events.AccountOperations request;
}
body {
   String queryString = "select acc" +
      " from /Concepts/Account as acc" +
      " where acc.Status = \"Normal\"";
   Object resultList = Query.Util.executeInDynamicQuerySession(queryString, null, true);
   int size = Query.Util.sizeOfList(resultList);
   System.debugOut("Result list has " + size + " items");
   
   for(int i = 0;  i < size; i = i + 1){
      Object row = Query.Util.removeFromList(resultList, 0);
      Concepts.Account acc = row;
      System.debugOut("  Result row: " + acc);
      }
   }
}

executeInQuerySession

The following rule functions executes the SQL string synchronously in the collocated query and returns the results:

Query.Util.executeInQuerySession(String querySessionName, String sqlString, Object mapOfParameters, boolean reuse)
		

invokeFunctionInQuerySession

The following rule function invokes a rule function in another query session/agent and needs a collocated query agent. The name of the query session/agent, which is deployed in the same processing unit, is provided as a parameter:

Query.Util.invokeFunctionInQuerySession(String querySessionName, String queryRuleFunctionUri, Object[] parameters)