Query the Cache Using BQL Queries

In order to execute the queries, you must first enable a dynamic query session.

Note:
  • This method relates to Cache OM functionality and is not relevant if you are using TIBCO BusinessEvents Express edition.
  • This method of querying a cache requires use of the TIBCO BusinessEvents Event Stream Processing add-on product.
  • The term BQL is an acronym indicating the TIBCO BusinessEvents Event Stream Processing query language.
  • This is the only method that works with TIBCO BusinessEvents DataGrid.
  • For the Coherence cache provider you can also use the methods explained in TIBCO BusinessEvents Architect’s Guide.

Procedure

  1. Add a rule function in the inference agent that contains the following function: Query.Util.startDynamicQuerySession().

    Configure this as a startup rule function (in the CDD file). For more on dynamic query sessions see TIBCO BusinessEvents Event Stream Processing Query Developer’s Guide.

  2. Add another rule function. Configure it as an event preprocessor (in the CDD file).
  3. In the event preprocessor function, create a query string that selects entities from the cache. You can use any valid BQL query.
  4. Use the query string in the following function:
      Query.Util.executeInDynamicQuerySession(queryString, null, true)

    The function returns a list of entities from the cache.

  5. Use the list returned as needed. For example, iterate over the list and load the entities, as shown in the following example.
    Note: You can also do cache lookups using @id and @extId attributes.

Example Rule Function for a TIBCO BusinessEvents DataGrid Cache

The following example preprocessor rule function code shows the techniques used for querying a TIBCO BusinessEvents DataGrid cache. You can then use standard functions to work with the entities returned by the query.

/**
 * @description
 */
void rulefunction RuleFunctions.InputEventPreprocessor {
  attribute {
    validity = ACTION;
  }
  scope {
    
    Events.InputEvent inputevent;
  }
  body {
    System.debugOut("Now starting InputEventPreprocessor");
    
    Concepts.Misc misc = Instance.getByExtId("misc");
    String[] EXTIDS_COLLECTION = Instance.PropertyArray.toArrayString(misc.EXTID_LIST);
    String queryString =
              "select c" +
              "\n from /Concepts/TestConcept as c" +
              "\n where c@extId in"
              + "(\""
              + EXTIDS_COLLECTION[0]
              + "\", \"" + EXTIDS_COLLECTION[1]
              + "\", \"" + EXTIDS_COLLECTION[2]
              + "\", \"" + EXTIDS_COLLECTION[3]
              + "\", \"" + EXTIDS_COLLECTION[4]
              + "\")";
    System.debugOut("Executing query: \n" + queryString);    
    Object resultList = Query.Util.executeInDynamicQuerySession(queryString, null, true);
    System.debugOut("Query returned: " + Query.Util.sizeOfList(resultList) + " rows");
    
    while(Query.Util.sizeOfList(resultList) > 0){
      Concepts.TestConcept c = Query.Util.removeFromList(resultList, 0);
      Cluster.DataGrid.CacheLoadEntity(c);
      
      System.debugOut("Now loading concept " + c + " in the pre-processor");
    }
  }
}