TIBCO BusinessEvents (BE) - How to access and update a table on external Ignite data grid

TIBCO BusinessEvents (BE) - How to access and update a table on external Ignite data grid

book

Article ID: KB0071393

calendar_today

Updated On:

Products Versions
TIBCO BusinessEvents Enterprise Edition 6.x

Description

TIBCO BusinessEvents (BE) - How to access and update a table on external Ignite data grid.

Issue/Introduction

How to access and update a table on external Ignite data grid

Environment

All Operating Systems

Resolution

A sample project is available with TIBCO BE installation under $BE_HOME/examples/standard/ActiveSpaces. The sample includes a startup RuleFunction to connect to an AS2.4 grid "startup()" and to an Ignite data grid "StartUpIgnite()".

To connect with the sample to an external Ignite data grid, copy the existing CDD, update the startup RuleFunction and modify the connect details for the Ignite grid in the startup RuleFunction "StartUpIgnite()". 
Here table created with catalog function "Store.Container.Ignite.createCacheConfig()".

When you create the table with a JDBC tool from outside BE then it is required that the table name and cache name be set to the same name in current version.
A CR BE-31676 raised for the issue.

Sample SQL to create a table with table and cache name "TestTable1":
CREATE TABLE DEFAULT.TestTable1 (
    id1 long,
    Name VARCHAR,
    PRIMARY KEY (id1)
 ) WITH "CACHE_NAME=TestTable1";

It is necessary to configure the primary index of the external table in the Startup RuleFunction with the "Store.Container.Ignite.setContainerKeyField()" catalog function, even if the table has already been created by an external JDBC tool.

In the project, you have to use certain catalog functions to update or query data from the external Ignite data grid, depending on where the table was created.

1. Table created with a JDBC tool
It is required to use catalog function "Store.executeUpdate()" to be able to update and load rows by an SQL query.
Row's created or updated with catalog function "Store.put()" will not be returned by an SQL executed in an JDBC tool or with catalog function "Store.query()".
The rows created with an SQL statement and "Store.put()" are stored in a different format and all rows returned only when query the cache with IgniteAdvisor tool.

2. Table created with BE catalog function  "Store.Container.Ignite.createContainer" 
Here it is required to update the table data with BE catalog functions "Store.put()".
An SQL insert will fail in the JDBC tool, because the JDBC driver has not returned and displayed all required columns.

Sample BE code to create a table:
String sTableName="TestTable1";
String sIgniteURL="localhost:47500..47505";
Object oCacheCfg = Store.Container.Ignite.createCacheConfig(sTableName, "Default");
Store.Container.Ignite.setAtomicityMode(oCacheCfg, "TRANSACTIONAL");
Object oFieldsMap = Collections.Map.createLinkedHashMap();
Collections.Map.put(oFieldsMap, "id1", "java.lang.Long");
Collections.Map.put(oFieldsMap, "Name", "java.lang.String");

Object oQueryEntity = Store.Container.Ignite.createQueryEntity(sTableName, oFieldsMap);
Store.Container.Ignite.setQueryEntity(oCacheCfg, oQueryEntity);
Store.Container.Ignite.createContainer(sIgniteURL, sTableName, oCacheCfg);

Collections.Map.deleteMap(oFieldsMap);

// set primary index
Store.open(sIgniteURL,sTableName);
Store.Container.Ignite.setContainerKeyField(sIgniteURL, sTableName, "id1");

Sample Put operation:
String sTableName="TestTable1";
String sIgniteURL="localhost:47500..47505";
Store.open(sIgniteURL,sTableName);
Object oItem = Store.Item.create(sIgniteURL,sTableName);
Store.Item.setLong(oItem,"id1",1);
Store.Item.setString(oItem,"Name","Test");

Store.put(sIgniteURL,sTableName,oItem);
Store.Item.destroy(oItem);