All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----db.idbTrigger
************************************************************ WARNING - Trigger objects are not part of the JDBC standard. Using trigger objects will make it harder to port your application to an alternative database. ************************************************************
Trigger objects provide applications with the opportunity to react to database events.
A Trigger object can be notified of changes to a specified table. Triggers on the system tables are not allowed.
When a trigger is activated, InstantDB provides the row being modified, together with the transaction ID and Connection responsible for the change. It is the responsibility of the application to ensure that a row contains sufficient information to make it uniquely identifiable (such as providing a UNIQUE column).
Constructs a new Trigger object.
Deletes this trigger.
Returns the bitmap of events that this trigger is notified of.
Returns the name of the table that this trigger is monitoring.
Callback invoked by InstantDB when a row is added to the table being monitored.
Callback invoked by InstantDB when a transaction involving the table being monitored is committed.
Callback invoked by InstantDB when a row is deleted from the table being monitored.
Callback invoked by InstantDB when a transaction involving the table being monitored is rolled back.
Callback invoked by InstantDB when a row in the table being monitored is updated.
public static final int TRIGGER_ON_UPDATE
public static final int TRIGGER_ON_DELETE
public static final int TRIGGER_ON_ADD
public static final int TRIGGER_ON_ROLLBACK
public static final int TRIGGER_ON_COMMIT
public idbTrigger(String table, int events) throws IllegalArgumentException, SQLException
Constructs a new Trigger object. The application must specify the table which this Trigger object will monitor.
The application can specify which events on the table are to be notified to the Trigger.
table
- The name of a table in the database.
events
- A bitmap of the events to trigger on.
This can be constructed by adding together one or more of the
TRIGGER_ON_xxxx event constants. Must be non-zero.
table
does not exist or
if events
is non-zero.
public String getTableName()
Returns the name of the table that this trigger is monitoring.
public int getEvents()
Returns the bitmap of events that this trigger is notified of.
public void onUpdate(Vector row, long transactionID) throws SQLException
Callback invoked by InstantDB when a row in the table being monitored is updated.
Applications should overide this method in order to handle updates. The default method does nothing.
Applications may used the supplied activeConnection
parameter to access the database and generate further modifications
to the same table or to other tables. If any exceptions
are thrown and not caught, then the current transaction will
rollback. Triggers can throw their own SQLException in order to
generate a rollback, and so reject the modification.
At the time this trigger is activated, the row affected will appear to be absent from the database.
row
- The row in the table which is being
modified. This consists of a vector of objects ordered
according to column position. Objects can be of type:
transactionID
- The transactionID of the
transaction modifying the table.
public void onAdd(Vector row, long transactionID) throws SQLException
Callback invoked by InstantDB when a row is added to the table being monitored.
Applications should overide this method in order to handle row adds. The default method does nothing.
Applications may used the supplied activeConnection
parameter to access the database and generate further modifications
to the same table or to other tables. If any exceptions
are thrown and not caught, then the current transaction will
rollback. Triggers can throw their own SQLException in order to
generate a rollback, and so reject the modification.
At the time this trigger is activated, the row will not yet have been added to the database.
row
- The row in the table which is being
modified. This consists of a vector of objects ordered
according to column position. Objects can be of type:
transactionID
- The transactionID of the
transaction modifying the table.
public void onDelete(Vector row, long transactionID) throws SQLException
Callback invoked by InstantDB when a row is deleted from the table being monitored.
Applications should overide this method in order to handle row deletes. The default method does nothing.
Applications may used the supplied activeConnection
parameter to access the database and generate further modifications
to the same table or to other tables. If any exceptions
are thrown and not caught, then the current transaction will
rollback. Triggers can throw their own SQLException in order to
generate a rollback, and so reject the modification.
At the time this trigger is activated, the row will not yet have been deleted from the database.
row
- The row in the table which is being
modified. This consists of a vector of objects ordered
according to column position. Objects can be of type:
transactionID
- The transactionID of the
transaction modifying the table.
public void onRollback(long transactionID)
Callback invoked by InstantDB when a transaction involving the table being monitored is rolled back.
Applications should overide this method in order to handle rollbacks. The default method does nothing.
If the onAdd, onUpdate and onDelete methods restrict themselves to database activity, then there is no need to override this method. However, if the application is maintaining data structures which are unknown to the database, then there is a need to inform the application when a rollback takes place. This gives the application an opportunity to make its data structures consistent with the database after the rollback.
Applications may not access the database during this method. Any attempt to do so will result in an immediate SQLException and the rollback will continue.
transactionID
- The transaction ID of the transaction
being rolled back.
public void onCommit(long transactionID)
Callback invoked by InstantDB when a transaction involving the table being monitored is committed.
Applications should overide this method in order to handle commits. The default method does nothing.
If the onAdd, onUpdate and onDelete methods restrict themselves to database activity, then there is no need to override this method. However, if the application is maintaining data structures which are unknown to the database, then there is a need to inform the application when a commit takes place. This gives the application an opportunity to note that any updated data structures are now consistent with the database.
Applications may not access the database during this method. Any attempt to do so will result in an immediate SQLException and the rollback will continue.
transactionID
- The transaction ID of the transaction
being rolled back.
public final void delete()
Deletes this trigger.
The trigger is removed from the monitored table. No further notifications will be delivered to this trigger object.
All Packages Class Hierarchy This Package Previous Next Index