Helper events for creating DataViews
The CMF provides helper events to make it easier to create DataViews of com.apama.utils.Params events.
The com.apama.utils.SingleParamsDataView event lets you create a DataView that contains the contents of a single com.apama.utils.Params event. It creates a two-column DataView that contains a row for each key/value pair from the supplied Params event. Actions defined in the SingleParamsDataView event let you update the contents of the DataView, as well as overwrite or clear the contents, or remove the DataView.
The SingleParamsDataView event type definition is as follows:
event SingleParamsDataView {
action create(Params display, context mainContext, Params config);
action update(Params display);
action clear();
action onSpawn();
action delete();
}
The config argument to the create() action can contain the following parameters:
Parameter | Description | Default | Type |
NAME | Name of the DataView you want to create. | No default. Required. | string |
DESCRIPTION | Description of the DataView being created. | Value of the NAME parameter | string |
KEY_COLUMN_TITLE | Title for the key column. | "Key" | string |
VALUE_COLUMN_TITLE | Title for the value column. | "Value" | string |
OVERWRITE | Execution of the update() action overwrites content. | true | boolean |
OWNER | Owner of items in the DataView. | "*" (all users) | string |
The code below provides an example of how to use the SingleParamsDataView event to create and update a DataView.
using com.apama.utils.SingleParamDataView;
using com.apama.utils.Params;
...
integer count := 0;
Params display := new Params;
display.addParam("Key", "Value");
display.addParam("Count", count.toString());
Params config := new Params;
config.addParam((new SingleParamsDataViewConsts).NAME, "Test Params Dataview");
SingleParamDataView dv := new SingleParamDataView;
dv.create(display, mainContext, config);
// Auto update it every 10 seconds
on all wait (10.0) {
count := count +1;
display.addParam("Count", count.toString());
dv.update(display);
}
The com.apama.utils.MultipleParamsDataView event lets you create a DataView that contains the contents of multiple com.apama.utils.Params events that conform to a schema. The MultipleParamsDataView event creates a DataView with columns that match a com.apama.utils.ParamsSchema event. Each row represents a Params events that matches the ParamsSchema event. By default, every field in the schema is a key field but you can specify key fields to identify unique rows. You pass Params events to MultipleParamsDataView events to add, update or delete selected rows.
The MultipleParamDataView event type definition is as follows:
event MultipleParamsDataView {
action create(ParamsSchema schema, context mainContext, Params config);
action addOrUpdate(Params params);
action remove(Params params);
action clear();
action onSpawn();
action delete();
}
The config argument to the create() action can contain the following parameters:
Parameter | Description | Default | Type |
NAME | Name of the DataView you want to create. | No default. Required. | string |
DESCRIPTION | Description of the DataView being created. | Value of the NAME parameter | string |
KEY_FIELDS | Sequence of fields the DataView uses as the key. Key fields are used to identify unique items/rows in the DataView. | All fields. | sequence<string> |
OWNER | Owner of items in the DataView. | "*" (all users) | string |
The code below provides an example of how to use the MultipleParamsDataView event to create and update a DataView.
using com.apama.utils.Params;
using com.apama.utils.ParamsSchema;
using com.apama.utils.MultipleParamsDataView;
using com.apama.utils.MultipleParamsDataViewConsts;
...
ParamsSchema schema := new ParamsSchema;
schema.addItemMinimal("Name","string","","The Name");
schema.addItemMinimal("Count","integer","0","Count");
Params config := new Params;
config.addParam((new MultipleParamsDataViewConsts).NAME,
"Test Params Dataview");
// Set 'Name' to be the key field:
config.addParam((new MultipleParamsDataViewConsts).KEY_FIELDS, "['Name']");
// Create the DataView
MultiParamDataView dv := new MultiParamDataView;
dv.create(schema, mainContext, config);
// Add a row
integer count := 0;
Params display := new Params;
display.addParam("Name", "Test");
display.addParam("Count", count.toString());
dv.addOrUpdate(display);
// Auto update it every 10 seconds
on all wait (10.0) {
count := count +1;
display.addParam("Count", count.toString());
dv.update(display);
}
See the ApamaDoc for details about the com.apama.utils.SingleParamsDataView and com.apama.utils.MultipleParamsDataView events.