25
Transaction Processing http:// ebiztechnics.blogspot.com

Oracle Forms : Transnational Triggers

Embed Size (px)

Citation preview

Page 1: Oracle Forms : Transnational Triggers

Transaction Processing

http://ebiztechnics.blogspot.com

Page 2: Oracle Forms : Transnational Triggers

Objectives

• Describe Transaction Processing in Forms• Commit Triggers and Usage• Commit Status• Implementing Array DML

http://ebiztechnics.blogspot.com

Page 3: Oracle Forms : Transnational Triggers

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

Page 4: Oracle Forms : Transnational Triggers

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

Page 5: Oracle Forms : Transnational Triggers

Commit Sequence of Triggers

Pre-Commit

Pre-Delete

Post-Delete

Delete row

1

MoreRecords

http://ebiztechnics.blogspot.com

Page 6: Oracle Forms : Transnational Triggers

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

Page 7: Oracle Forms : Transnational Triggers

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

Page 8: Oracle Forms : Transnational Triggers

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

Page 9: Oracle Forms : Transnational Triggers

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

Page 10: Oracle Forms : Transnational Triggers

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

Page 11: Oracle Forms : Transnational Triggers

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

Page 12: Oracle Forms : Transnational Triggers

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

Page 13: Oracle Forms : Transnational Triggers

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

Page 14: Oracle Forms : Transnational Triggers

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

Page 15: Oracle Forms : Transnational Triggers

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

Page 16: Oracle Forms : Transnational Triggers

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

Page 17: Oracle Forms : Transnational Triggers

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

Page 18: Oracle Forms : Transnational Triggers

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

Page 19: Oracle Forms : Transnational Triggers

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

Page 20: Oracle Forms : Transnational Triggers

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

Page 21: Oracle Forms : Transnational Triggers

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

Page 22: Oracle Forms : Transnational Triggers

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

Page 23: Oracle Forms : Transnational Triggers

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

Page 24: Oracle Forms : Transnational Triggers

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

Page 25: Oracle Forms : Transnational Triggers

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