Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved


Chapter 7 Coding Considerations for Event, Location, and Derived Value Rules : Coding Event Rules

Coding Event Rules
Using the event rule feature, you can associate business rules and policies with the definition of a table. These rules are run whenever data in the table is manipulated. You can code two types of event rules:
Validation rule
A validation rule is used when the table is being modified. It checks the validity of modified values of fields in the table.
Trigger rule
A trigger rule causes additional processing to take place when a table is accessed. For example, it can be used to create an audit trail, or maintain a one-to-one relationship between two tables.
These rules run based on defined accesses. All the rules that apply to a specific access are executed in the order in which they are entered in the event rule section.
Conditions for Validation Rules
The following conditions apply to the coding of a validation rule:
The rule must be a function. A successful validation must return Y. An unsuccessful validation can return any non-Y value. It is recommended that the rule return either N or a message explaining why the validation was not successful.
The validation must explicitly handle its own exceptions. If a validation does not handle an exception, the transaction that caused the validation is terminated.
Conditions for Trigger Rules
Trigger rules can be nested up to a maximum depth of five accesses. For example, an access to one table can trigger access to another table, which in turn can trigger access to another table, and so on. The following restrictions apply to the coding of a trigger rule:
It must explicitly handle its own exceptions. If a trigger does not handle an exception, the transaction that caused the trigger is terminated.
It should not contain COMMIT or ROLLBACK statements. If you need to explicitly keep changes to data, start a new transaction using the EXECUTE statement.
When are Locks Released?
Locks taken by an event rule are released at the end of the transaction in which it is running.
Search Path
The search path for the application invoking the event rule determines the search path for the event rule. Because the Table Editor on the developer’s workbench has a search path of S (system library), when you are accessing the table from the workbench you must execute the shareable tools STEBROWSE or STE to browse or edit a table using an event rule. For more information about these tools, refer to TIBCO Object Service Broker Shareable Tools.
Sample Set of Event Rules
The sample table has two event rules defined, DELETEMPNO and VALIDEMPNO. The following illustrations show the coding of these rules.
Sample Trigger Rule
The first rule, DELETEMPNO, inserts data into the table @DELETEMPNO when an occurrence is deleted from the @EMPLOYEES table.

DELETEMPNO;
_
_ ---------------------------------------------------------------------------
_ ------------------------------------------------------------+--------------
_ @DELETEMPNO.EMPNO = @EMPLOYEES.EMPNO; | 1
_ INSERT @DELETEMPNO; | 2
_ ---------------------------------------------------------------------------

 
Sample Validation Rule
The second rule, VALIDEMPNO, determines if an employee number entered in as data to the table is below an accepted numeric limit. It returns a message to the screen if the supplied value is invalid.

VALIDEMPNO;
_
_ ---------------------------------------------------------------------------
_ @EMPLOYEES.EMPNO <= 9999; | Y N
_ ------------------------------------------------------------+--------------
_ RETURN(’The value for EMPNO must be greater than 9999’); | 1
_ RETURN(’Y’); | 1
_ ---------------------------------------------------------------------------

 
Event Rule Processing Across Nodes
An event rule running on a local node can access data on a remote node. An event rule running on a remote node as the result of a remote data access can only access data on the same node. The following illustration shows the valid and invalid accesses.

Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved