Writing JavaScript Filters
The JavaScript interface to the replicator enables filters to be written using standard JavaScript with a complete object-based interface to the internal Java objects and classes that make up the THL data.
For more information on the Rhino JavaScript implementation, see "Rhino"
The basic structure of a JavaScript filter is as follows:
// Prepare the filter and setup structures
prepare()
{
}
// Perform the filter process; function is called for each event in the THL
filter(event)
{
// Get the array of DBMSData objects
data = event.getData();
// Iterate over the individual DBMSData objects
for(i=0;i<data.size();i++)
{
// Get a single DBMSData object
d = data.get(i);
// Process a Statement Event; event type is identified by comparing the object class type
if (d = instanceof com.continuent.tungsten.replicator.dbms.StatementData)
{
// Do statement processing
}
else if (d = instanceof com.continuent.tungsten.replicator.dbms.RowChangeData)
{
// Get an array of all the row changes
rows = data.get(i).getRowChanges();
// Iterate over row changes
for(j=0;j<rows.size();j++)
{
// Get the single row change
rowchange = rows.get(j);
// Identify the row change type
if (rowchange.getAction() == "INSERT")
{
}
....
}
}
}
}
The following sections will examine the different data structures, functions, and information available when processing these individual events.