Subject | Autonomous Transaction Routines |
---|---|
Author | Adriano dos Santos Fernandes |
Post date | 2007-11-01T10:07:10Z |
Autonomous transaction is a procedure/trigger flag meaning that the
routine runs in an independent transaction.
When one explicitly calls an autonomous procedure or the engine calls an
autonomous trigger, a new transaction with same TPB of the current
transaction is created to execute the routine.
If the routine terminates due to exception, this transaction is rolled back.
Otherwise it's automatically committed.
================
Usage:
1) Autonomous triggers may be used to log (in non-external tables)
tentatives (that may have failled) to change/insert/delete records.
2) ON CONNECT trigger may call an autonomous procedure to log (in
non-external tables) rejected access
to connect to databases.
ON CONNECT trigger already can throw exceptions and reject logons, but
with the exception the transaction
is rolled back and the log doesn't survive.
3) Notify events to other processes without lose the transaction context.
A autonomous procedure may update the database and call POST_EVENT.
Withing the COMMIT, the events will be delivered.
================
Syntax:
CREATE PROCEDURE <name> [ <input and output arguments> ]
[ AUTONOMOUS TRANSACTION ]
AS
BEGIN
...
END
CREATE TRIGGER <name>
[ ACTIVE ] [ POSITION <n> ] ... [ AUTONOMOUS TRANSACTION ]
AS
BEGIN
...
END
================
ODS storage:
Use RDB$FLAGS of RDB$TRIGGERS and add a column RDB$FLAGS to RDB$PROCEDURES.
Use same bit mask for both tables.
Adriano
routine runs in an independent transaction.
When one explicitly calls an autonomous procedure or the engine calls an
autonomous trigger, a new transaction with same TPB of the current
transaction is created to execute the routine.
If the routine terminates due to exception, this transaction is rolled back.
Otherwise it's automatically committed.
================
Usage:
1) Autonomous triggers may be used to log (in non-external tables)
tentatives (that may have failled) to change/insert/delete records.
2) ON CONNECT trigger may call an autonomous procedure to log (in
non-external tables) rejected access
to connect to databases.
ON CONNECT trigger already can throw exceptions and reject logons, but
with the exception the transaction
is rolled back and the log doesn't survive.
3) Notify events to other processes without lose the transaction context.
A autonomous procedure may update the database and call POST_EVENT.
Withing the COMMIT, the events will be delivered.
================
Syntax:
CREATE PROCEDURE <name> [ <input and output arguments> ]
[ AUTONOMOUS TRANSACTION ]
AS
BEGIN
...
END
CREATE TRIGGER <name>
[ ACTIVE ] [ POSITION <n> ] ... [ AUTONOMOUS TRANSACTION ]
AS
BEGIN
...
END
================
ODS storage:
Use RDB$FLAGS of RDB$TRIGGERS and add a column RDB$FLAGS to RDB$PROCEDURES.
Use same bit mask for both tables.
Adriano