CREATE OR REPLACE PACKAGE my_commit
/*----------------------------------------------------------------
||
|| Overview: use my_commit.perform_commit in place of a direct
|| call to the COMMIT; statement. This will give you
|| more flexibility when testing your code, since
|| you can disable your commit processing with a
|| call to my_commit.turn_off.
||
|| You can also turn on tracing so that whenever you
|| call perform_commit, a trace of that action will
|| be displayed with DBMS_OUTPUT.PUT_LINE.
||
----------------------------------------------------------------*/
IS
/* Control committing; turned ON by default. */
PROCEDURE turn_on;
PROCEDURE turn_off;
FUNCTION committing
RETURN BOOLEAN;
/* Commit substitute */
PROCEDURE perform_commit (context_in IN VARCHAR2 := NULL);
/* Incremental commit processing */
PROCEDURE init_counter;
PROCEDURE increment_and_commit (context_in IN VARCHAR2 := NULL);
PROCEDURE commit_after (count_in IN INTEGER);
/* Tracing commit execution */
PROCEDURE trace_on;
PROCEDURE trace_off;
FUNCTION tracing
RETURN BOOLEAN;
END my_commit;
Package created.
CREATE OR REPLACE PACKAGE BODY my_commit
IS
g_do_commit BOOLEAN := TRUE;
g_commit_after INTEGER := 1;
g_counter INTEGER := 0;
g_trc BOOLEAN := FALSE;
PROCEDURE commit_after (count_in IN INTEGER)
IS
BEGIN
g_commit_after := NVL (count_in, 1);
END;
PROCEDURE turn_on
IS
BEGIN
g_do_commit := TRUE;
END;
PROCEDURE turn_off
IS
BEGIN
g_do_commit := FALSE;
END;
FUNCTION committing
RETURN BOOLEAN
IS
BEGIN
RETURN g_do_commit;
END;
PROCEDURE trace_on
IS
BEGIN
g_trc := TRUE;
END;
PROCEDURE trace_off
IS
BEGIN
g_trc := FALSE;
END;
FUNCTION tracing
RETURN BOOLEAN
IS
BEGIN
RETURN g_trc;
END;
PROCEDURE trace_action (context_in IN VARCHAR2, message_in IN VARCHAR2)
IS
BEGIN
DBMS_OUTPUT.put_line ( 'my_commit trace: '
|| context_in
|| ' - '
|| message_in
);
END trace_action;
/* my_commit version of COMMIT */
PROCEDURE perform_commit (context_in IN VARCHAR2 := NULL)
IS
BEGIN
trace_action ('perform_commit'
, CASE
WHEN committing ()
THEN '*COMMIT ENABLED*'
ELSE '*COMMIT DISABLED*'
END
|| ' '
|| context_in
);
IF committing ()
THEN
COMMIT;
END IF;
END;
PROCEDURE init_counter
IS
BEGIN
g_counter := 0;
END;
PROCEDURE increment_and_commit (context_in IN VARCHAR2 := NULL)
IS
BEGIN
trace_action ('increment_and_commit', context_in);
IF g_commit_after <= g_counter AND g_commit_after > 0
THEN
perform_commit (context_in);
init_counter;
ELSE
g_counter := g_counter + 1;
END IF;
END;
END my_commit;
Package Body created.