Smart trigger feature
Smart Triggers in JDBC are a set of classes/interfaces that provide an ease of use capability to the Push data feature.
A smart trigger is a set of commands issued to the database that sets up a push notification when certain changes happen to data in a table. These changes are detected by a SQL query that is run after INSERT, UPDATE, or DELETE commands are executed.
Using the smart trigger feature, you can quickly watch one or more tables for changes and receive callbacks when a change is detected. Using the following JDBC API, if you make any change to the customer's table (insert/update/delete) the notify() method that you specified will get called, allowing you to see the effects of the change and take action.
/* Create a new smart trigger */ IfmxThreadedSmartTrigger push = new IfxSmartTrigger("JDBC URL to sysadmin database here"); /* Create your own callback class */ IfmxSmartTriggerCallback callback = new IfmxSmartTriggerCallback() { @Override public void notify(String json) { /*Here you can process the json from the trigger event*/ System.out.println("Trigger received! Data: " + json); } }; /* Set additional properties like the timeout or a default label */ push.label("test-label").timeout(60); /* Add one or more triggers against the table/owner/database using a SQL query */ push.addTrigger("customers", "informix", "stores_demo", "SELECT * FROM customers", "test-label-pushtest", callback); /* IfmxThreadedSmartTrigger is runnable so you can easily start it in a background thread*/ Thread t = new Thread(push); t.start(); /* you can wait on that thread or go and do other work */ j.join();
A dedicated server connection is required for using the smart trigger feature. Because of this, the IfmxSmartTrigger class uses a URL or a DataSource object for creating a new JDBC connection.
You can close or shut down the smart trigger by executing a close() method on the IfmxSmartTrigger object. This will queue-up a smooth shutdown of the session. You can also add or remove triggers anytime, as required. If the application has not started either the run() or watch() method, then the changes occur immediately. Otherwise, changes are queued until the driver receives data from the server. This will occur when any trigger is fired or when the timeout is reached.
If you want to manage the smart trigger without creating another thread, you can directly call the watch() method.
Warning: The watch() method is a blocking call and will never return unless another thread interrupts it or calls a close().
For details on all of the API's added, see the Javadoc documentation on the IfmxThreadedSmartTrigger interface.
Related links: