Rem  Copyright (c) Oracle Corporation 2014. All Rights Reserved.
Rem
Rem    NAME
Rem      ords_start_registry.sql
Rem
Rem    DESCRIPTION
Rem      This script starts the registration 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  : Schema name for Oracle Rest Data Services (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 ORDSSCHEMA   = '^2'

whenever sqlerror exit sql.sqlcode

begin
   sys.dbms_output.put_line('INFO: ' || to_char(sysdate,'HH24:MI:SS') || ' Start registration process for Oracle REST Data Services.');

   -- loading registry with component id, component name, validation procedure, schema name
   if ^INSTALLTYPE = 1 then
      sys.dbms_registry.loading('ORDS','Oracle REST Data Services','validate_ords', '^ORDSSCHEMA');

    elsif ^INSTALLTYPE = '2' then        
        if sys.dbms_registry.is_valid('ORDS') is not null then
            sys.dbms_registry.upgrading('ORDS','Oracle REST Data Services','validate_ords', '^ORDSSCHEMA');
        else 
            -- ORDS Not Registered.
            sys.dbms_registry.loading('ORDS','Oracle REST Data Services','validate_ords', '^ORDSSCHEMA');
        end if;
    end if;
   
end;
/
