Transaction checklist signals |
A transaction checklist signal consist of adding, at store-record time, an entry to an internal list or transaction checklist of all the records that must be subjected to a transaction check at commit time. The point of making a transaction checklist at store-record time is that it makes the processing of certain transaction checks (at commit time) faster. The strategy is to keep a list of primary key values that identify the records being processed. This is efficient if these records turn out to be driving table records for a transaction check: •The transaction check can be executed faster, because the primary key values for the driving table record are known, and indexes can be used to quickly retrieve the database values needed for the check. •It is possible to merge transaction checks. If two store-record events cause a need to do a transaction check for the same driving table record, this evaluation only needs to be performed once. This type of row binding, however, is only possible if the primary key values of the driving table are known. Therefore, at store-record time, the Rules Engine attempts to find these primary key values. If these values are found, they are registered in the transaction checklist, together with the name of the constraint to be checked. In the determination of primary key values of the driving table there are four possible scenarios, that depend on both the triggering table and the constraint SQL:
If the Rules Engine can find the primary key values (scenarios 1, 2, and 3), the resulting primary key values for the driving table are substituted in the constraint test statement at commit time. If the Rules Engine can NOT find the primary key values (scenario 4), then the constraint SQL statement is sent to the database "as is", that is, without primary key substitutions. Data integrity is safeguarded, but the constraint is checked against all the data in the database.
Example 1 A business rule "A reservation cannot be booked once the scheduled tour has started" is implemented by a restrictive constraint:
The driving table of this constraint is SCHEDTOUR, because it is the first table in the FROM clause for which all primary key columns are mentioned. •If the user manipulation is also on the SCHEDTOUR table, for instance the start date of a scheduled tour is changed, then the primary key of the driving table is immediately known. •If the user manipulation is on RESERVATION, for instance a new reservation is made, then the primary key of the driving table can be determined directly via the join: st.schedtour_id = r.schedtour_id
Neither of these cases requires a constraint key query. At commit time, the primary key value of the scheduled tour is substituted in the constraint test statement:
Example 2 A business rule "Participants for a SURVIVAL tour need to be insured" is implemented by a restrictive constraint:
The driving table of this constraint is SCHEDTOUR, because it is the first table in the FROM clause for which all primary key columns are mentioned. If the user manipulation is on PARTICIPANT, for instance when a new participant is added, then a path to the driving table can be determined via:
A constraint key query is necessary in this case to retrieve the primary key values of the scheduled tours concerned.
At commit time, the primary key value of the scheduled tour (128) is substituted in the SQL for the transaction check:
Example 3 A business rule "A person must not be enrolled twice as participant on the same Scheduled Tour" is implemented by a restrictive constraint:
In this case, the constraint is sent to the database without primary key substitutions. The Rules Engine does not build a constraint key query statement if the constraint SQL statement contains a GROUP BY clause or group functions, or if the SQL statement contains no primary key references.
See also
|