Some business rules are implemented directly in the data model. An example is a rule that each Customer must have a registered Bank Account that is implemented by declaring, in the Customer table, a column Bank Account with the attribute Mandatory = Yes.
Many business rules in USoft, however, are defined by SQL statements that are technically referrred to in USoft Definer as constraints. Below are 2 examples.
Example Rule 1
A Customer cannot withdraw money if their account is overdrawn or the account has been frozen.
The precise conditions are: the sum of the TRANSACTIONS is less than 0 or the ACCOUNT_STATUS is Blocked.
Implementation:
SELECT '' RESTRICT
FROM account a
WHERE 0 >
(
SELECT SUM( t.txn_amount )
FROM transaction t
WHERE a.account_id = t.account_id
)
OR a.account_status = 'BLOCKED'
This business rule is a restrictive type of constraint. It affects two database objects. This rule would ensure that the situation (described above) would never be possible.
This business rule is checked regardless how these transactions enter the system (e.g. direct entry, background process, or batch process).
Also, this business rule is checked regardless of how the rule is broken (e.g. adding a new transaction, changing the amount of any transaction, or setting the account to frozen).
Example Rule 2
Customers are charged an ATM transaction fee of $1.00. If the customer has generated more than 10 ATM transactions since the last statement, ATM transaction fees would be waived.
Implementation:
INSERT INTO transaction_fee
(
account_id
, txn_amoun
, txn_date
, txn_fee_id
)
SELECT account_id
, 1
, SYSDATE
, 1
FROM transaction t
WHERE OLD( txn_id ) IS NULL
AND 10 >
(
SELECT COUNT(*)
FROM transaction_fee tf, account a
WHERE tf.txn_date > a.last_statement_date
AND tf_account_id = a.account_id
AND tf_account_id = t.account_id
)
This Rule is behavioral, corrective. If a transaction is generated, then the Rule will check to see if 10 transaction fees have already been created since the last statement date. If less than 10 have been created, the Rule will create a new transaction fee to go along with the transaction the user has just entered.
|