Triggers
In Javra IDE, Triggers are invoked on performing write and delete action to the program / table. They are used also for maintaining referential integrity. There are two types of triggers:
- Default Triggers
- Logical Triggers
Default triggers are used for write and delete operation to any table. Trigger program for all the tables, call the Default trigger programs x/xxxxtwrite.p for write operation and x/xxxxtdel.p for delete operation of a table. Generally, these triggers audit the history of a table during add, update, and delete events. Additional trigger logics are written in logical trigger files in the format x/xxxxlwrite.p for write trigger and x/xxxxldel.p for delete trigger.

Above figure demonstrates an example of write trigger (using customer table). The figure also illustrates how the trigger distinguishes the update actions performed by old records, and application (if any) and executes the old trigger, in this case customer-w.p. If the update is from X/E Files, it executes the custlwrite.p.
The write database trigger for table customer has the following format:
trigger procedure for write of customer old buffer o-customer.
run x/xxxxtwrite.p (input buffer customer:handle,
input buffer o-customer:handle,
source-procedure:handle) no-error.
if error-status:error then
return error return-value.
Here the write trigger performs the following steps
- Runs a logical write trigger
- Checks if it is a new record, then fills default values.
- Records it into an audit table.
- Updates the audit fields.
- For each widget it performs Field validation of mandatory and dynamic and Runs the field trigger in logical trigger.
- Runs p-commit.
Similarly, the delete database trigger for table customer has the following format:
trigger procedure for delete of customer.
run x/xxxxtdel.p (input buffer customer:handle,
input source-procedure:handle) no-error.
if error-status:error then
return error return-value.
Here the delete trigger performs the following tasks
- Runs a logical delete trigger.
- Checks if it can be deleted.
- Performs cascading deletes.
- Creates a deleted record.
- Create audit record.
Related Topics