Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 18 Functions : Indexing for More Efficient Cache Queries

Indexing for More Efficient Cache Queries
TIBCO BusinessEvents Express  This section relates to Cache OM functionality and is not relevant if you are using TIBCO BusinessEvents Express edition.
When you use Oracle Coherence as the cache provider, you can index concept and event properties to make searches faster. You can index more than one of an entity type’s properties.
The query optimization you set up is used by C_Query*() functions, and by snapshot queries, available in TIBCO BusinessEvents Event Stream Processing add-on.
You can create the indexes in the following ways.
To Create Indexes Using a Coherence Function
This method applies to the Coherence cache provider only. It is not the preferred method. It is recommended that you use the method explained in To Create an Index Using a Domain Object Override Setting.
You can create an ordered or unordered index using the following function in a startup rule function.
C_Index(String cacheName, Object property, boolean isOrdered)
where:
cacheName is a String returned by C_CacheName().
property is the object returned by the appropriate C_DatatypeAtomGetter functions, for example, C_StringAtomGetter().
isOrdered is a Boolean: set to true to order the contents of the indexed information, and set to false if you want to use an unordered index.
For example:

 
String cacheName = Coherence.C_CacheName("/Customer");
Object getter = Coherence.Extractor.C_IntAtomGetter("age");
Coherence.C_Index(cacheName, getter, true);

 
To Create an Index Using a Domain Object Override Setting
This method applies both to the TIBCO and Coherence cache providers. You can create an unordered index in the project’s Cluster Deployment Descriptor (CDD) using a domain object setting.
1.
2.
3.
In the override entry’s Properties Metadata section, check the Present in Index checkbox for the property you want to index.
4.
 
BQL Cache Queries
TIBCO BusinessEvents Express  This section relates to Cache OM functionality and is not relevant if you are using TIBCO BusinessEvents Express edition.
Enabling Explicit Tuple Format for DataGrid Fields
You can set a property in the CDD so that they are instead stored as tuples. That is, TIBCO BusinessEvents attempts to create explicit space structures for each entity type.
In Shared Nothing mode, explicit tuple format is assumed internally. You should not set this property in Shared Nothing mode.
You can still use query language queries (as explained in To Query the Cache Using BQL Queries) if entities and their properties are stored as blobs. However performance is improved if they are stored as tuples.
Only certain datatypes can be stored as tuples:
   int, long, boolean, string, datetime, contained, reference
Are stored as the equivalent TIBCO BusinessEvents DataGrid types:
   integer, long, boolean, string, calendar, long, long
If an error occurs, for example due to an unsupported datatype, the item revers to its original blob format
To Enable Explicit Tuple Format
At the cluster level, set the following field to true: "Store Properties As Individual Fields".
To Query the Cache Using BQL Queries
In order to execute the queries, you must first enable a dynamic query session.
1.
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.
3.
4.
  Query.Util.executeInDynamicQuerySession(queryString, null, true)
The function returns a list of entities from the cache.
5.
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");
    }
  }
}

 

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved