1.1.1

Table Of Contents
SQLFire API on page 463 provides additional information and examples for using callbacks.
Example Writer Implementation
SQLFire installs a sample writer implementation in
vFabric_SQLFire_11_bNNNNN/examples/EventCallbackWriterImpl.javam. This writer
implementation can be used to perform writes to any JDBC data source, if the appropriate driver is available in
the classpath. See the example comments for more information.
Example Listener Implementation
In this listener implementation of the EventCallBack interface, the listener checks the event type and, for
AFTER_INSERT events, multiplies each column by a factor and then inserts into a foreign table.
SYS.ADD_LISTENER on page 612 shows example code for deploying this listener to a table.
package testpackage;
public class EventCallBackListenerImpl implements EventCallback {
private String foreigntablename;
private int factor;
private Connection conn;
private PreparedStatement ps;
public EventCallBackListenerImpl() {
}
public void close() throws SQLException {
}
// The init method expects the initStr to contain the name of the
// foreign table and the factor. Eg: "emp.ftable:3"
public void init(String initStr) throws SQLException {
String[] arr = initStr.split(":");
this.foreigntablename = arr[0];
this.factor = Integer.parseInt(arr[1]);
this.conn = getConnection();
this.ps = this.conn.prepareStatement(
"insert into "+this.foreigntablename+" values(?, ?, ?)");
}
public void onEvent(Event event) throws SQLException {
if (if ((event.getType() == Type.AFTER_INSERT)) {
int size = event.getNewRow().size();
assert size == 3 : "expected the size to be 3";
List<Objects> colValues = event.getNewRow();
int one = ((Integer)colValues.get(0)).intValue() * this.factor;
int two = ((Integer)colValues.get(1)).intValue() * this.factor;
int three = ((Integer)colValues .get(2)).intValue() * this.factor;
this.ps.setInt(1, one);
this.ps.setInt(2, two);
this.ps.setInt(3, three);
this.ps.executeUpdate();
}
}
vFabric SQLFire User's Guide196
Caching Data with vFabric SQLFire