--
connect &METADATAOWNER/&METADATAPASSWORD@&TNSALIAS
--
--  Create the package to handle events related to contentType 'image/jpeg'
--
CREATE OR REPLACE PACKAGE IMAGE_EVENT_MANAGER
as
  procedure handlePostCreate(EVENT dbms_xevent.XDBRepositoryEvent);
  procedure handlePreDelete(EVENT dbms_xevent.XDBRepositoryEvent);
end;
/
show errors
--
create or replace public synonym IMAGE_EVENT_MANAGER for IMAGE_EVENT_MANAGER
/
CREATE OR REPLACE PACKAGE BODY IMAGE_EVENT_MANAGER
as
--
PROCEDURE handlePostCreate(event dbms_xevent.XDBRepositoryEvent)
IS
   Payload xmltype;
BEGIN
  xdb_asynchronous_events.enqueue_event(xdb_utilities.serializeEvent(event));
END handlePostCreate;
--
PROCEDURE handlePreDelete(event dbms_xevent.XDBRepositoryEvent)
IS
  RESOURCE_PATH   VARCHAR2(700);
  repositoryEvent DBMS_XEVENT.XDBEVENT;
  XMLREF          REF XMLType := null;
BEGIN
  repositoryEvent := dbms_xevent.getXDBEvent(event);
  RESOURCE_PATH   := dbms_xevent.getName(dbms_xevent.getPath(event));        
  
  -- dbms_xdb.purgeResourceMetadata(RESOURCE_PATH);
  
  select ref(m)
    into XMLREF
    from RESOURCE_VIEW r, IMAGE_METADATA_TABLE m
   where r.RESID = M.RESID
     and equals_path(res,RESOURCE_PATH) = 1;
 
  dbms_xdb.deleteResourceMetadata(RESOURCE_PATH,XMLREF);
EXCEPTION
  when no_data_found then
    null;
  
END handlePreDelete;
--
END IMAGE_EVENT_MANAGER;
/
show errors
--
grant execute on IMAGE_EVENT_MANAGER to public
/
desc IMAGE_EVENT_MANAGER
--
disconnect
--
