Query the Cache Using BQL Queries
In order to execute the queries, you must first enable a dynamic query session.
- 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
- 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.
- Add another rule function. Configure it as an event preprocessor (in the CDD file).
- In the event preprocessor function, create a query string that selects entities from the cache. You can use any valid BQL query.
- Use the query string in the following function:
Query.Util.executeInDynamicQuerySession(queryString, null, true)
The function returns a list of entities from the cache.
- 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.
Native Querying with Apache Ignite as a Cache Provider
You can use the native querying for Apache Ignite as cache provider to improve query performace. In this case, the tables must be present internally. To use native querying, prefix the usual query with the native-query:
string. For example, replace the SELECT age, count FROM /Concepts/Common/Customer;
query with native-query: SELECT age, count FROM be_gen_Concepts_Common_Customer;
query.
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"); } } }