Upload
sekhar-byna
View
1.051
Download
3
Embed Size (px)
Citation preview
Transaction Processing
http://ebiztechnics.blogspot.com
Objectives
• Describe Transaction Processing in Forms• Commit Triggers and Usage• Commit Status• Implementing Array DML
http://ebiztechnics.blogspot.com
Transaction Processing
SaveTransaction (Begin)
FORM A
Block#1
Block#2
New Record
Updated Record
Deleted Record
Updated Record
Commit work;
INSERT INTO Table1
UPDATE Table1
DELETE FROM Table2
UPDATE Table2
Transaction (End)
Action Edit
http://ebiztechnics.blogspot.com
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
Commit Sequence of Triggers
Pre-Commit
Pre-Delete
Post-Delete
Delete row
1
MoreRecords
http://ebiztechnics.blogspot.com
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
MoreRecords
MoreBlocks
http://ebiztechnics.blogspot.com
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
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
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
Usage of Commit Triggers
On-Insert/Update/Delete
Post-Forms-Commit
Post-Database-Commit
Replace default blockDML statements
Check complex multirow constraints
Test commit success;test uncommitted posts
http://ebiztechnics.blogspot.com
Update ProcessingColumnItem
QueryRollback
Data20 20
LockedQuery
Commit 30 30
30 20Update record in form
[Save] 30 20[Save]
Pre-Update 30 20Pre-Update
Row Updated 30 30 20Row updated
Post-Update 30 30 20Post-Update
http://ebiztechnics.blogspot.com
Pre-Delete Trigger• Check Before Deletion
DECLARECURSOR empcur ISSELECT ’x’ FROM dept WHERE deptno = :emp.deptno;
BEGINOPEN 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
Assigning Sequence Nos.
• Pre-Insert Trigger
SELECT empseq.nextval INTO :emp.empnoFROM dual;
Note: Sequence value will be visible after committing, because Pre-Insert trigger fires after committing.
http://ebiztechnics.blogspot.com
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
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
DML Statements Issued During Commit Processing
INSERT INTO base_table (base_column, base_column,...)VALUES (:base_item, :base_item, ...)
UPDATE base_tableSET base_column = :base_item, base_column =
:base_item, ...WHERE ROWID = :ROWID
DELETE FROM base_tableWHERE ROWID = :ROWID
http://ebiztechnics.blogspot.com
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
Overriding default transaction
On-Check-Unique
On-Column-Security
On-Commit
On-Rollback
On-Savepoint
On-Sequence-Number
CHECK_RECORD_UNIQUENESS
ENFORCE_COLUMN_SECURITY
COMMIT_FORM
ISSUE_ROLLBACK
ISSUE_SAVEPOINT
GENERATE_SEQUENCE_NUMBER
Trigger Do-the-Right-Thing Built-in
On-Logon
On-Logout
LOGON
LOGOUTTransactional TriggersFor Logging on and off
http://ebiztechnics.blogspot.com
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
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
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
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 inserts2 updates1 delete Database
http://ebiztechnics.blogspot.com
Effect of Array DML on Transactional Triggers
Array DML Size = 1 Array DML Size > 1
FiresFires for each insert, update,delete
Fires for each insert, update, delete
Repeatedfor eachinsert,update,delete
POST-
PRE-
DML
Fires
DML
POST-
PRE-
http://ebiztechnics.blogspot.com
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
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