Rem  Copyright (c) Oracle Corporation 2014. All Rights Reserved.
Rem
Rem    NAME
Rem      ords_update_registry.sql
Rem
Rem    DESCRIPTION
Rem      This script updates the registy for the Oracle REST Data Services (ORDS).
Rem      Do not invoke this script directly.  If you are doing a manual installation, use ords_manual_install.sql
Rem
Rem    NOTES
Rem      Assumes user with SYSDBA privilege is connected.
Rem
Rem    REQUIREMENTS
Rem      - Oracle Database Release 11.1 or later
Rem
Rem    Arguments:
Rem      1  : Installation Type:  1 - Fresh Install, 2 - Upgrade
Rem      2  : Version installed for ORDS
Rem
Rem    MODIFIED    (MM/DD/YYYY)
Rem     epaglina    01/28/2014 - Created.
Rem
Rem

set define '^'
set verify off
set termout on
set autocommit off
-- set serveroutput on

define INSTALLTYPE  = '^1'
define CURRVERSION  = '^2'

whenever sqlerror exit sql.sqlcode

alter session set current_schema = SYS;

begin

    if '^INSTALLTYPE' = '1' then
       dbms_registry.loaded('ORDS','^CURRVERSION');
    elsif '^INSTALLTYPE' = '2' then
        if dbms_registry.status('ORDS') = 'UPGRADING' then
            dbms_registry.upgraded('ORDS','^CURRVERSION');
        else 
            -- ORDS Not been previously registered.        
            dbms_registry.loaded('ORDS','^CURRVERSION');
        end if;
    end if;


   dbms_output.put_line('INFO: ' || to_char(sysdate,'HH24:MI:SS') || ' Validating objects for Oracle REST Data Services.');
   validate_ords;

   if dbms_registry.is_valid('ORDS') = 1 then
      dbms_output.put_line('INFO: ' || to_char(sysdate,'HH24:MI:SS') || ' Completed registration process for Oracle REST Data Services.');
   else
      dbms_output.put_line('ERROR: ' || to_char(sysdate,'HH24:MI:SS') || ' Registration status for ORDS is invalid.');
      raise_application_error(-20006, 'ERROR: Validating objects failed.');
   end if;
   
end;
/

