Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PROCEDURE after_event (
- p_configuration_id NUMBER,
- p_session_id NUMBER,
- p_phase NUMBER
- )
- IS
- PRAGMA autonomous_transaction;
- l_configuration pkg_n2n_replication.configuration_type;
- l_is_existing NUMBER;
- l_query VARCHAR2(4000);
- BEGIN
- SELECT COUNT(1) INTO l_is_existing FROM nc_n2n_configurations conf WHERE conf.configuration_id = p_configuration_id;
- IF (l_is_existing = 0) THEN RETURN; END IF;
- l_configuration := pkg_n2n_replication.load_configuration(p_configuration_id);
- pkg_n2n_replication.refresh_mviews(p_configuration_id);
- pkg_n2n_replication.add_log_message(l_configuration, p_session_id, 'start replicating cia tables', pkg_n2n_replication.g_info_severity, 'replicate cia');
- -- check phase
- IF (p_phase = 0) THEN
- -- routine work
- pkg_n2n_replication.add_log_message(l_configuration, p_session_id, 'routine phase', pkg_n2n_replication.g_debug_severity, 'replicate cia');
- -- dependencies
- l_query :=
- 'merge into NC_CIA_DEPENDENCIES t
- using (select root_cause_ticket_id,
- object_id,
- referenced_object_id,
- rule_id
- from MV_NC_CIA_DEPENDENCIES) v
- on (t.object_id = v.object_id)
- when matched then
- update
- set t.root_cause_ticket_id = v.root_cause_ticket_id,
- t.referenced_object_id = v.referenced_object_id,
- t.rule_id = v.rule_id
- when not matched then
- insert (root_cause_ticket_id, object_id, referenced_object_id, rule_id)
- values (v.root_cause_ticket_id, v.object_id, v.referenced_object_id, v.rule_id);';
- EXECUTE IMMEDIATE l_query;
- l_query :=
- 'delete from NC_CIA_DEPENDENCIES
- where object_id not in (select object_id from MV_NC_CIA_DEPENDENCIES);';
- EXECUTE IMMEDIATE l_query;
- pkg_n2n_replication.add_log_message(l_configuration, p_session_id, 'insert/update/delete cia dependencies', pkg_n2n_replication.g_info_severity, 'replicate cia');
- -- severities
- l_query :=
- 'merge into NC_CIA_SEVERITIES t
- using (select object_id, service_level
- from MV_NC_CIA_SEVERITIES) v
- on (t.object_id = v.object_id)
- when matched then
- update
- set t.service_level = v.service_level
- when not matched then
- insert (object_id, service_level)
- values (v.object_id, v.service_level);';
- EXECUTE IMMEDIATE l_query;
- l_query :=
- 'delete from NC_CIA_SEVERITIES
- where object_id not in (select object_id from MV_NC_CIA_SEVERITIES);';
- EXECUTE IMMEDIATE l_query;
- pkg_n2n_replication.add_log_message(l_configuration, p_session_id, 'insert/update/delete cia severities', pkg_n2n_replication.g_info_severity, 'replicate cia');
- ELSIF (p_phase = 1) THEN
- -- initialization work
- l_query :=
- 'delete from NC_CIA_SEVERITIES;';
- EXECUTE IMMEDIATE l_query;
- l_query :=
- 'insert into NC_CIA_SEVERITIES (object_id, service_level)
- select object_id, service_level from MV_NC_CIA_SEVERITIES;';
- EXECUTE IMMEDIATE l_query;
- l_query :=
- 'delete from NC_CIA_DEPENDENCIES;';
- EXECUTE IMMEDIATE l_query;
- l_query :=
- 'insert into NC_CIA_DEPENDENCIES (root_cause_ticket_id, object_id, referenced_object_id, rule_id)
- select root_cause_ticket_id, object_id, referenced_object_id, rule_id from MV_NC_CIA_DEPENDENCIES;';
- EXECUTE IMMEDIATE l_query;
- pkg_n2n_replication.add_log_message(l_configuration, p_session_id, 'init phase', pkg_n2n_replication.g_debug_severity, 'replicate cia');
- END IF;
- pkg_n2n_replication.add_log_message(l_configuration, p_session_id, 'end replicating cia tables', pkg_n2n_replication.g_info_severity, 'replicate cia');
- EXCEPTION
- WHEN OTHERS THEN
- pkg_n2n_replication.add_log_message(l_configuration, p_session_id, SQLCODE||' - '||SQLERRM, pkg_n2n_replication.g_error_severity, 'replicate cia');
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement