Open topic with navigation

TIBCO BusinessEvents® Enterprise Edition 6.3.1

# Query the Cache Using BQL Queries

To run the queries, you must first enable a dynamic query session.

Note:

- The term BQL is an acronym indicating the TIBCO BusinessEvents Event Stream Processing query language.
- This is the only method that works with Legacy ActiveSpaces.

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 the 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.

## Ungrouping Query Results

By default, TIBCO BusinessEvents tries to club the calls to the Callback rulefunction when multiple events qualify for a callback at the same time. For example, a query that counts the arriving events may callback with counts like 300, 303, 308 instead of 300, 301, 302 and so on.

To disable such grouping and to trigger a Callback rulefunction for each event, set the `be.query.max.coalesce.results` property to `0` in the CDD file at query agent level.

## Example Rule Function for a Legacy ActiveSpaces Cache

The following example preprocessor rule function code shows the techniques used for querying a Legacy ActiveSpaces 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");
        }
      }
    }

Subtopics

Did you find this helpful?

YesNo
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO BusinessEvents® Enterprise Edition

Copyright © 2004-2024. Cloud Software Group, Inc. All Rights Reserved.