--
connect &METADATAOWNER/&METADATAPASSWORD@&TNSALIAS
--
set serveroutput on
--
column config_path format a64
--
-- Remove any links to the Configuration Document
--
declare
   cursor findPaths (targetPath varchar2) is
   select path 
     from path_view p, resource_view r
    where p.resid = r.resid
      and equals_path(r.res,targetPath) = 1
      and p.path <> targetPath;
begin
  for p in findPaths(:RES_CONFIG_PATH) loop
    dbms_xdb.deleteResource(p.PATH);
  end loop;
  commit;
end;
/
--
-- DeRegister the Repository Level Resource Configuration for Image Metadata
--
declare
   configid number(2) := null;
begin
  select config_id - 1
    into configId
    from (
           select rownum config_id, column_value config_path
             from table( dbms_resConfig.getRepositoryResConfigPaths() )
         )
   where config_path = :RES_CONFIG_PATH;

  dbms_resConfig.deleteRepositoryResConfig(configid);
  commit;

  dbms_output.put_line('Deleted Repository Configuration Document #' || configid); 

exception
  when no_data_found then 
    null;
end;
/
drop package IMAGE_EVENT_MANAGER
/
disconnect
--
