2. Objectives
• Describe Transaction Processing in Forms
• Commit Triggers and Usage
• Commit Status
• Implementing Array DML
http://ebiztechnics.blogspot.com
3. Transaction Processing
Save
Transaction (Begin)
FORM A
Block#1
Block#2
New Record
Updated Record
Deleted Record
Updated Record
Commit work;Commit work;
INSERT INTO Table1INSERT INTO Table1
UPDATE Table1UPDATE Table1
DELETE FROM Table2DELETE FROM Table2
UPDATE Table2UPDATE Table2
Transaction (End)
Action Edit
http://ebiztechnics.blogspot.com
4. Transaction Processing
Transaction processing consists of two phases:
• Post:
– Writes record changes to base tables
– Fires transactional triggers
• Commit: Performs database commit
Errors result in:
• Rollback of the database changes
• Error message
http://ebiztechnics.blogspot.com
5. Commit Sequence of Triggers
Pre-Commit
Pre-Delete
Post-Delete
Delete row
1
More
Records
http://ebiztechnics.blogspot.com
6. Commit Sequence of Triggers
Pre-Insert
Post-Insert
1
Insert
Insert row
Pre-Update
Post-Update
Update
Update row
Post-Database-Commit
Post-Forms-Commit
Finish
More
Records
More
Blocks
http://ebiztechnics.blogspot.com
7. Commit Triggers
• Pre-Commit: Fires once if form changes are made or uncommitted
changes are posted
• Pre- and Post-DML
• On-DML: Fires per record, replacing default DML on row
Use DELETE_RECORD, INSERT_RECORD, UPDATE_RECORD
built-ins
http://ebiztechnics.blogspot.com
8. Commit Triggers
• Post-Forms-Commit: Fires once even if no changes are made
• Post-Database-Commit: Fires once even if no changes are made
Note: A commit-trigger failure causes a rollback to
the savepoint.
http://ebiztechnics.blogspot.com
9. Usage of Commit Triggers
Pre-Commit
Pre-Delete
Pre-Insert
Pre-Update
Check user authorization; set up special locking
Journaling; implement foreign-key delete rule
Generate sequence numbers; journaling;
automatically generated columns; check
constraints
Journaling; implement foreign-key update rule;
auto-generated columns; check constraints
http://ebiztechnics.blogspot.com
10. Usage of Commit Triggers
On-Insert/Update/Delete
Post-Forms-Commit
Post-Database-Commit
Replace default block
DML statements
Check complex multirow
constraints
Test commit success;
test uncommitted posts
http://ebiztechnics.blogspot.com
12. Pre-Delete Trigger
• Check Before Deletion
DECLARE
CURSOR empcur IS
SELECT ’x’ FROM dept
WHERE deptno = :emp.deptno;
BEGIN
OPEN empcur;
FETCH empcur INTO :GLOBAL.x;
IF empcur%FOUND THEN
CLOSE C1;
MESSAGE(’There are employees in this dept..can not
delete’);
RAISE form_trigger_failure;
ELSE
CLOSE empcur;
END IF;
END;
http://ebiztechnics.blogspot.com
13. Assigning Sequence Nos.
• Pre-Insert Trigger
SELECT empseq.nextval
INTO :emp.empno
FROM dual;
Note: Sequence value will be visible after committing, because Pre-Insert
trigger fires after committing.
http://ebiztechnics.blogspot.com
14. Keeping an Audit Trail
• Write changes to nonbase tables.
• Gather statistics on applied changes.
Post-Insert example:
:GLOBAL.total_ins:=
TO_CHAR(TO_NUMBER(:GLOBAL.total_ins)+1);
http://ebiztechnics.blogspot.com
15. Test the success of DMLs
• SQL%FOUND
• SQL%NOTFOUND
• SQL%ROWCOUNT
UPDATE …….
SET…..
WHERE …..;
IF SQL%NOTFOUND THEN
MESSAGE(’Record does not exists’);
RAISE form_trigger_failure;
END IF;
http://ebiztechnics.blogspot.com
16. DML Statements Issued During Commit
Processing
INSERT INTO base_table (base_column, base_column,...)
VALUES (:base_item, :base_item, ...)
UPDATE base_table
SET base_column = :base_item, base_column =
:base_item, ...
WHERE ROWID = :ROWID
DELETE FROM base_table
WHERE ROWID = :ROWID
http://ebiztechnics.blogspot.com
17. DML Statements Issued During Commit
Processing
Rules:
• DML statements may fire database triggers.
• Form Builder uses and retrieves ROWID.
• The Update Changed Columns Only and Enforce Column Security
properties affect UPDATE statements.
• Locking statements are not issued.
http://ebiztechnics.blogspot.com
19. Commit Status
• What is Commit Status?
• SYSTEM.RECORD_STATUS:
– NEW
– INSERT (also caused by control items)
– QUERY
– CHANGED
• SYSTEM.BLOCK_STATUS:
– NEW (may contain records with status INSERT)
– QUERY (also possible for control block)
– CHANGED (block will be committed)
http://ebiztechnics.blogspot.com
20. Commit Status
• SYSTEM.FORM_STATUS:
– NEW
– QUERY
– CHANGED
• System variables versus built-ins for commit status
• Built-ins for getting and setting commit status:
– GET_BLOCK_PROPERTY
– GET_RECORD_PROPERTY
– SET_ RECORD _PROPERTY
http://ebiztechnics.blogspot.com
21. Commit Status
• Do not confuse commit status with validation status.
• The commit status is updated during validation.
IF :SYSTEM.BLOCK_STATUS IN (‘NEW’,’CHANGED’) THEN
COMMIT_FORM;
END IF;
CLEAR_FORM;
http://ebiztechnics.blogspot.com
22. Array DML
• Performs array inserts, updates, and deletes
• Vastly reduces network traffic
Fewer round trips (exact
number depends on array
size)
Empno Ename Job Sal
7369 SMITH CLERK 800
7499 ALLEN SALESMAN 1600
7521 WARD SALESMAN 1250
7566 JONES ANAGER 2975
7654 MARTIN SALESMAN 1250
7698 BLAKE MANAGER 2850
7782 CLARK MANAGER 2450
2 inserts
2 updates
1 delete Database
http://ebiztechnics.blogspot.com
23. Effect of Array DML on Transactional
Triggers
Array DML Size = 1 Array DML Size > 1
Fires
Fires for each
insert, update,
delete
Fires for each
insert, update,
delete
Repeated
for each
insert,
update,
delete
POST-
PRE-
DML
Fires
DML
POST-
PRE-
http://ebiztechnics.blogspot.com
24. Implementing Array DML
1. Enable the Array Processing option.
2. Specify a DML Array Size of greater than 1.
3. Specify block primary keys.
http://ebiztechnics.blogspot.com
25. Summary
• Post and commit phases
• Flow of commit processing
• DML statements issued during commit processing
• Characteristics and common uses of commit triggers
• Overriding default transaction processing
• Getting and setting the commit status
• Implementing Array DML
http://ebiztechnics.blogspot.com
Notas del editor
Note:
If a commit trigger-except for the Post Database-Commit trigger – fails, the
Transaction is rolled back to the savepoint that was set at the beginning of the current
Commit processing. This also means that earlier, not yet committed posts are not rolledback.
Note:
Locking is also needed for transaction processing. You can use the On-Lock
Trigger if you want to amend the default locking of Form Builder.
Note:
The Insert Allowed and Keyboard Navigable properties on :EMP.empno should
Be No, so that user does not enter and employee no manually.
Note:
Trigger containing base table DML can adversely affect the usual behavior of
Your form, because DML statements can cause some of the rows in the database to lock.
Note:
When the DML Array size property is grater than 1, you must specify the primary key.
Key mode can still be unique.