Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: How to trap a commit from an application?

Re: How to trap a commit from an application?

From: John K. Hinsdale <hin_at_alma.com>
Date: 6 Feb 2007 10:09:08 -0800
Message-ID: <1170785348.576158.56510@s48g2000cws.googlegroups.com>

dean wrote:
> Is there any way I can say to Oracle (9.2 or 10g) that if an
> application attempts to call commit, then throw an exception? An on-
> commit event?

You can fake it with the following Big Time Kludgy Hack, that takes advantage of the rollback behavior of DEFERRABLE constraints, described below. This will not prevent "rogue" COMMITs from 3rd parties from being issued, but it will prevent their effects, which may be good enough for you.

(1) Create a table called COMMIT_LOCKER:

      create table commit_locker ( n number not null deferrable );

(2) In your transaction do:

      alter session set constraints = deferred;
      insert into commit_locker values(null);
      ... now do more INSERT/UPDATE/DELETE (w/out COMMIT)

(3) Now the session is "booby trapped" in that any COMMIT will

   roll back all changes due to the failure of the NOT NULL on    COMMIT_LOCKER.N (4) Once YOU are satisfied that COMMIT is OK to do, issue:

      delete from commit_locker;
      commit;

This seems to work for me in the face of any "pre-committing" commands like TRUNCATE TABLE, etc.

Note that at the start of step (4) you have the option of inspecting the result of

      SELECT count(*) FROM commit_locker

which if it has one row means nobody went and tried a commit, and which if it is empty means something did a commit and rolled everything back. This knowledge may be useful to decide whether to do additional "cleanup" stuff.

But my little "there has GOT to be a better way" light is blinking. ;)

Received on Tue Feb 06 2007 - 12:09:08 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US