Humble Trader

Monday, September 04, 2006

Get HTML - ctl_get_html_b.sql

-- ------------------------------------------------------------------------- --
-- --
-- Title: ctl_get_html_b.sql --
-- Author: Steve Roach --
-- --
-- Description: Container for all procedures and functions relating to --
-- interacting with the CTL objects for the get_html --
-- sub-system. --
-- --
-- ------------------------------------------------------------------------- --

-- Package body definition.
CREATE OR REPLACE PACKAGE BODY ctl_get_html
AS
PROCEDURE init_html_page_access
(
p_web_page IN VARCHAR2
,p_run_no IN NUMBER
)
IS
BEGIN
-- Create HTML Page Access row.
INSERT INTO html_page_access
(
run_no
,html_page_name
,status
,start_tsp
)
VALUES
(
p_run_no
,p_web_page
,'FETCHING'
,SYSDATE
);
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20001,
'ctl_gen_html.init_html_page_access Error: ' || SQLERRM ||
'. p_web_page = ' || p_web_page || ', p_run_no = ' || p_run_no ||
'.');
END init_html_page_access;

PROCEDURE html_page_access_update_status
(
p_run_no IN NUMBER
,p_new_status IN VARCHAR2
)
IS
l_old_status VARCHAR2(30);

e_status_not_allowed EXCEPTION;
BEGIN
-- Get the current status.
SELECT status
INTO l_old_status
FROM html_page_access
WHERE run_no = p_run_no;

CASE p_new_status
WHEN 'FETCHED'
THEN
IF l_old_status != 'FETCHING'
THEN
RAISE e_status_not_allowed;
END IF;
WHEN 'PARSING'
THEN
IF l_old_status != 'FETCHED'
THEN
RAISE e_status_not_allowed;
END IF;
WHEN 'PARSED'
THEN
IF l_old_status != 'PARSING'
THEN
RAISE e_status_not_allowed;
END IF;
WHEN 'FAILED'
THEN
NULL;
ELSE
RAISE e_status_not_allowed;
END CASE;

UPDATE html_page_access
SET status = p_new_status
WHERE run_no = p_run_no;

EXCEPTION
WHEN e_status_not_allowed THEN
RAISE_APPLICATION_ERROR(-20001,
'ctl_gen_html.html_page_access_update_status Error. ' ||
p_new_status || ' cannot follow ' || l_old_status || '.');
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20001,
'ctl_gen_html.html_page_access_update_status Error: ' || SQLERRM ||
'. p_run_no = ' || p_run_no || ', p_new_status = ' ||
p_new_status || '.');
END html_page_access_update_status;

PROCEDURE init_html_parse_passes
(
p_parse_run_no IN NUMBER
,p_raw_run_no IN NUMBER
)
IS
BEGIN
html_page_access_update_status(p_raw_run_no, 'PARSING');

-- Create HTML Parse Passes row.
INSERT INTO html_parse_passes
(
parse_run_no
,raw_run_no
,status
,start_tsp
)
VALUES
(
p_parse_run_no
,p_raw_run_no
,'PARSING'
,SYSDATE
);
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20001,
'ctl_gen_html.init_html_parse_passes Error: ' || SQLERRM ||
'. p_parse_run_no = ' || p_parse_run_no || ', p_raw_run_no = ' ||
p_raw_run_no || '.');
END init_html_parse_passes;

PROCEDURE html_parse_passes_update_stat
(
p_parse_run_no IN NUMBER
,p_raw_run_no IN NUMBER
,p_new_status IN VARCHAR2
)
IS
l_old_status VARCHAR2(30);

e_status_not_allowed EXCEPTION;
BEGIN
-- Get the current status.
SELECT status
INTO l_old_status
FROM html_parse_passes
WHERE parse_run_no = p_parse_run_no
AND raw_run_no = p_raw_run_no;

CASE p_new_status
WHEN 'PARSED'
THEN
IF l_old_status != 'PARSING'
THEN
RAISE e_status_not_allowed;
END IF;
WHEN 'FAILED'
THEN
NULL;
ELSE
RAISE e_status_not_allowed;
END CASE;

UPDATE html_parse_passes
SET status = p_new_status
WHERE parse_run_no = p_parse_run_no
AND raw_run_no = p_raw_run_no;

EXCEPTION
WHEN e_status_not_allowed THEN
RAISE_APPLICATION_ERROR(-20001,
'ctl_gen_html.html_parse_passes_update_stat Error. ' ||
p_new_status || ' cannot follow ' || l_old_status || '.');
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20001,
'ctl_gen_html.html_parse_passes_update_stat Error: ' || SQLERRM ||
'. p_parse_run_no = ' || p_parse_run_no || ', p_raw_run_no = ' ||
p_raw_run_no || ', p_new_status = ' || p_new_status || '.');
END html_parse_passes_update_stat;
END ctl_get_html;
/
SHOW ERRORS

0 Comments:

Post a Comment

<< Home