added new procedure to remove parties and associated records from the DB.

git-svn-id: http://locode01.ad.dom/svn/WEBMIP/trunk@3165 248e525c-4dfb-0310-94bc-949c084e9493
This commit is contained in:
mullenm
2008-01-08 15:51:07 +00:00
parent 830c016090
commit 954d42e856

View File

@@ -180,6 +180,15 @@ CREATE OR REPLACE PACKAGE mip_parties AS
p_addr_code IN addresses.code%TYPE,
p_paddr_type IN party_address_roles.rt_code%TYPE);
--
/**
REMOVE_PARTY
removes the party and all related information from the system.
%param p_prty_id - the ID of the party to remove.
*/
PROCEDURE remove_party(p_prty_id IN NUMBER);
--
END mip_parties;
/
CREATE OR REPLACE PACKAGE BODY mip_parties AS
@@ -892,5 +901,68 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS
WHERE paddr_roles.rt_code = p_paddr_type);
END expire_old_addresses;
--
/**
REMOVE_PARTY
removes the party and all related information from the system.
%param p_prty_id - the ID of the party to remove.
*/
PROCEDURE remove_party(p_prty_id IN NUMBER) IS
BEGIN
--delete all party relationships with other parties
DELETE FROM party_relationships parl
WHERE parl.from_parl_prty_id = p_prty_id;
DELETE FROM party_relationships parl
WHERE parl.to_parl_prty_id = p_prty_id;
--delete contact mechanisms
FOR cur_come IN (SELECT * FROM party_contact_mechanisms come WHERE come.prty_id = p_prty_id) LOOP
--delete the party/contact mechanism link
DELETE FROM party_contact_mechanisms come
WHERE come.prty_id = p_prty_id
AND come.come_id = cur_come.come_id;
-- delete the contact mechanism
DELETE FROM contact_mechanisms come
WHERE come.id = cur_come.come_id;
END LOOP;
--delete addresses
FOR cur_addr IN (SELECT * FROM party_addresses paddr WHERE paddr.prty_id = p_prty_id) LOOP
--delete the address roles
DELETE FROM party_address_roles paddr_role
WHERE paddr_role.paddr_prty_id = p_prty_id;
--delete the party address links
DELETE FROM party_addresses paddr
WHERE paddr.prty_id = p_prty_id
AND paddr.addr_code = cur_addr.addr_code;
END LOOP;
-- remove the passwords
DELETE FROM passwords pword
WHERE prty_id = p_prty_id;
-- remove the party roles
DELETE FROM party_roles parl
WHERE parl.prty_id = p_prty_id;
-- finally, delete the party
DELETE FROM parties prty
WHERE prty.id = p_prty_id;
-- commit the deletes
COMMIT;
-- if we have any problems then rollback
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
RAISE;
END remove_party;
END mip_parties;
/