CREATE OR REPLACE PROCEDURE SYS.UpgradeWFS_TO_2_6 IS
          wk_database_path	varchar2(100);
          wk_message		varchar2(500);
          wk_count		number := 0;
BEGIN
	wk_message := '';
	DELETE FROM SYS.INSTALL_TABLE;
	
	-------------------------------------------------------
	-- FIX JBPM_LOG
	-------------------------------------------------------
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_Log DROP CONSTRAINT FK_LOG_PARENT';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_MESSAGELOG DROP CONSTRAINT FK_TTV_MESSAGELOG_LOG';
		
		EXECUTE IMMEDIATE 'CREATE TABLE WFS.JBPM_LOG_TEMP ( 
	          ID_                   	NUMBER(19,0) NOT NULL,
	          OLD_ID					NUMBER(19,0) NULL,
	          CLASS_                	CHAR(1) NOT NULL,
	          INDEX_                	NUMBER NULL,
	          DATE_                 	TIMESTAMP(6) NULL,
	          TOKEN_                	NUMBER(19,0) NULL,
	          PARENT_               	NUMBER(19,0) NULL,
	          MESSAGE_              	VARCHAR2(4000) NULL,
	          EXCEPTION_            	VARCHAR2(4000) NULL,
	          ACTION_               	NUMBER(19,0) NULL,
	          NODE_                 	NUMBER(19,0) NULL,
	          ENTER_                	TIMESTAMP(6) NULL,
	          LEAVE_                	TIMESTAMP(6) NULL,
	          DURATION_             	NUMBER(19,0) NULL,
	          TRANSITION_           	NUMBER(19,0) NULL,
	          CHILD_                	NUMBER(19,0) NULL,
	          SOURCENODE_           	NUMBER(19,0) NULL,
	          DESTINATIONNODE_      	NUMBER(19,0) NULL,
	          VARIABLEINSTANCE_     	NUMBER(19,0) NULL,
	          OLDBYTEARRAY_         	NUMBER(19,0) NULL,
	          NEWBYTEARRAY_         	NUMBER(19,0) NULL,
	          OLDDATEVALUE_         	TIMESTAMP(6) NULL,
	          NEWDATEVALUE_         	TIMESTAMP(6) NULL,
	          OLDDOUBLEVALUE_       	FLOAT NULL,
	          NEWDOUBLEVALUE_       	FLOAT NULL,
	          OLDLONGIDCLASS_       	VARCHAR2(255) NULL,
	          OLDLONGIDVALUE_       	NUMBER(19,0) NULL,
	          NEWLONGIDCLASS_       	VARCHAR2(255) NULL,
	          NEWLONGIDVALUE_       	NUMBER(19,0) NULL,
	          OLDSTRINGIDCLASS_     	VARCHAR2(255) NULL,
	          OLDSTRINGIDVALUE_     	VARCHAR2(255) NULL,
	          NEWSTRINGIDCLASS_     	VARCHAR2(255) NULL,
	          NEWSTRINGIDVALUE_     	VARCHAR2(255) NULL,
	          OLDLONGVALUE_         	NUMBER(19,0) NULL,
	          NEWLONGVALUE_         	NUMBER(19,0) NULL,
	          OLDSTRINGVALUE_       	VARCHAR2(4000) NULL,
	          NEWSTRINGVALUE_       	VARCHAR2(4000) NULL,
	          TASKINSTANCE_         	NUMBER(19,0) NULL,
	          TASKACTORID_          	VARCHAR2(255) NULL,
	          TASKOLDACTORID_       	VARCHAR2(255) NULL,
	          SWIMLANEINSTANCE_     	NUMBER(19,0) NULL,
	          CREATEDATE            	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
	          UPDATEDATE            	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
	          RESOURCEGROUPID       	NUMBER NULL,
	          RESOURCEID            	NUMBER NULL,
	          OPERATIONALSTATUSID   	NUMBER NULL,
	          ADMINISTRATIVESTATUSID	NUMBER NULL 
	          ) TABLESPACE WFS_DATA';
	
		EXECUTE IMMEDIATE 'INSERT INTO WFS.JBPM_LOG_TEMP
		SELECT	WFS.JBPM_LOG_SEQ.NEXTVAL, ID_, CLASS_, INDEX_, DATE_, TOKEN_, PARENT_, MESSAGE_, EXCEPTION_, 
				ACTION_, NODE_, ENTER_, LEAVE_, DURATION_, TRANSITION_, CHILD_, SOURCENODE_, 
				DESTINATIONNODE_, VARIABLEINSTANCE_, OLDBYTEARRAY_, NEWBYTEARRAY_, OLDDATEVALUE_, 
				NEWDATEVALUE_, OLDDOUBLEVALUE_, NEWDOUBLEVALUE_, OLDLONGIDCLASS_, OLDLONGIDVALUE_, 
				NEWLONGIDCLASS_, NEWLONGIDVALUE_, OLDSTRINGIDCLASS_, OLDSTRINGIDVALUE_, NEWSTRINGIDCLASS_, 
				NEWSTRINGIDVALUE_, OLDLONGVALUE_, NEWLONGVALUE_, OLDSTRINGVALUE_, NEWSTRINGVALUE_, 
				TASKINSTANCE_, TASKACTORID_, TASKOLDACTORID_, SWIMLANEINSTANCE_, CREATEDATE, 
				UPDATEDATE, RESOURCEGROUPID, RESOURCEID, OPERATIONALSTATUSID, ADMINISTRATIVESTATUSID 
		FROM (
				SELECT	ID_, CLASS_, INDEX_, DATE_, TOKEN_, PARENT_, MESSAGE_, EXCEPTION_, 
						ACTION_, NODE_, ENTER_, LEAVE_, DURATION_, TRANSITION_, CHILD_, SOURCENODE_, 
						DESTINATIONNODE_, VARIABLEINSTANCE_, OLDBYTEARRAY_, NEWBYTEARRAY_, OLDDATEVALUE_, 
						NEWDATEVALUE_, OLDDOUBLEVALUE_, NEWDOUBLEVALUE_, OLDLONGIDCLASS_, OLDLONGIDVALUE_, 
						NEWLONGIDCLASS_, NEWLONGIDVALUE_, OLDSTRINGIDCLASS_, OLDSTRINGIDVALUE_, NEWSTRINGIDCLASS_, 
						NEWSTRINGIDVALUE_, OLDLONGVALUE_, NEWLONGVALUE_, OLDSTRINGVALUE_, NEWSTRINGVALUE_, 
						TASKINSTANCE_, TASKACTORID_, TASKOLDACTORID_, SWIMLANEINSTANCE_, CREATEDATE, 
						UPDATEDATE, RESOURCEGROUPID, RESOURCEID, OPERATIONALSTATUSID, ADMINISTRATIVESTATUSID 
				FROM	WFS.JBPM_LOG
				ORDER BY TOKEN_, NODE_, CLASS_) x';
			
		EXECUTE IMMEDIATE 'DROP TABLE WFS.JBPM_LOG';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_LOG_TEMP RENAME TO JBPM_LOG';
	
		-- Creating Primary Key on JBPM_LOG
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_LOG
			        		ADD ( CONSTRAINT PK_JBPM_LOG
         		 			PRIMARY KEY (ID_)
          					NOT DEFERRABLE INITIALLY IMMEDIATE
							USING INDEX
      						TABLESPACE WFS_INDEX )';
      

		-- Create index IDX_JBPM_LOG_01
		EXECUTE IMMEDIATE 'CREATE INDEX WFS.IDX_JBPM_LOG_01 
                           ON WFS.JBPM_LOG (CLASS_, NODE_, TOKEN_)
                           TABLESPACE WFS_INDEX';
                           
		EXECUTE IMMEDIATE 'CREATE INDEX WFS.IDX_JBPM_LOG_TEMP
                           ON WFS.JBPM_LOG (OLD_ID)
                           TABLESPACE WFS_INDEX';


		EXECUTE IMMEDIATE 'UPDATE	WFS.TTV_MESSAGELOG ml
							SET		LOGID = (SELECT ID_ FROM WFS.JBPM_LOG lg WHERE ml.LOGID = lg.OLD_ID)';

		EXECUTE IMMEDIATE 'DROP INDEX WFS.IDX_JBPM_LOG_TEMP';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_LOG DROP COLUMN OLD_ID';
	EXCEPTION
	  WHEN OTHERS THEN
	  wk_message := 'ERROR';
	  EXECUTE IMMEDIATE 'INSERT INTO install_table values
	   (''error in installing of application database objects:
	     Unable recreate JBPM_LOG'')';
	      GOTO bypass_install;
	END;
	
	
	
    
	-- Create Trigger TRG_JBPM_LOG_SEQ
  
	BEGIN
	
	  EXECUTE IMMEDIATE 'CREATE TRIGGER WFS.TRG_JBPM_LOG_SEQ
	                      BEFORE INSERT ON WFS.JBPM_LOG
	                      FOR EACH ROW
	                      BEGIN
	                          IF :NEW.ID_ IS NULL THEN
	                              SELECT WFS.JBPM_LOG_SEQ.NEXTVAL INTO :NEW.ID_ FROM DUAL;
	                          END IF;
	                      END;';
	
	EXCEPTION
	  WHEN OTHERS THEN
	  wk_message := 'ERROR';
	  EXECUTE IMMEDIATE 'INSERT INTO install_table values
	   (''error in installing of application database objects:
	     Unable to create trigger TRG_JBPM_LOG_SEQ'')';
	      GOTO bypass_install;
	END;
  
	-- Create Trigger TRG_JBPM_LOG_UPD
  
	BEGIN
	
	  EXECUTE IMMEDIATE 'CREATE TRIGGER WFS.TRG_JBPM_LOG_UPD
	                      BEFORE UPDATE
	                      ON WFS.JBPM_LOG
	                      FOR EACH ROW
	                      DECLARE updatedate      date;
	                      BEGIN
	                      SELECT  SYSTIMESTAMP
	                      INTO    updatedate
	                      FROM    DUAL;
	                      :NEW.UpdateDate := updatedate;
	                      END;';
	
	EXCEPTION
	  WHEN OTHERS THEN
	  wk_message := 'ERROR';
	  EXECUTE IMMEDIATE 'INSERT INTO install_table values
	   (''error in installing of application database objects:
	     Unable to create trigger TRG_JBPM_LOG_SEQ'')';
	      GOTO bypass_install;
	END;

	-- Creating Foreign Key on JBPM_LOG
    BEGIN
    
      EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_LOG ADD (
                                  CONSTRAINT JBPM_LOG#TTV_PSTATUS1 
                                          FOREIGN KEY (ADMINISTRATIVESTATUSID) 
                                          REFERENCES WFS.TTV_PROCESSSTATUS (PROCESSSTATUSID),
                                  CONSTRAINT JBPM_LOG#TTV_PSTATUS2 
                                          FOREIGN KEY (OPERATIONALSTATUSID) 
                                          REFERENCES WFS.TTV_PROCESSSTATUS (PROCESSSTATUSID),
                                  CONSTRAINT JBPM_LOG#TTV_RESOURCE 
                                          FOREIGN KEY (RESOURCEID) 
                                          REFERENCES WFS.TTV_RESOURCE (RESOURCEID),
                                  CONSTRAINT JBPM_LOG#TTV_RESOURCEGROUP 
                                          FOREIGN KEY (RESOURCEGROUPID) 
                                          REFERENCES WFS.TTV_RESOURCEGROUP (RESOURCEGROUPID),
                                  CONSTRAINT JBPM_LOG#JBPM_VARIABLEINSTANCE 
                                          FOREIGN KEY (VARIABLEINSTANCE_) 
                                          REFERENCES WFS.JBPM_VARIABLEINSTANCE (ID_),
                                  CONSTRAINT JBPM_LOG#JBPM_TRANSITION 
                                          FOREIGN KEY (TRANSITION_) 
                                          REFERENCES WFS.JBPM_TRANSITION (ID_),
                                  CONSTRAINT JBPM_LOG#JBPM_TASKINSTANCE 
                                          FOREIGN KEY (TASKINSTANCE_) 
                                          REFERENCES WFS.JBPM_TASKINSTANCE (ID_),
                                  CONSTRAINT JBPM_LOG#JBPM_SWIMLANEINSTANCE 
                                          FOREIGN KEY (SWIMLANEINSTANCE_) 
                                          REFERENCES WFS.JBPM_SWIMLANEINSTANCE (ID_),
                                  CONSTRAINT JBPM_LOG#JBPM_LOG1 
                                          FOREIGN KEY (PARENT_) 
                                          REFERENCES WFS.JBPM_LOG (ID_),
                                  CONSTRAINT JBPM_LOG#JBPM_BYTEARRAY1 
                                          FOREIGN KEY (OLDBYTEARRAY_) 
                                          REFERENCES WFS.JBPM_BYTEARRAY (ID_),
                                  CONSTRAINT JBPM_LOG#JBPM_BYTEARRAY2 
                                          FOREIGN KEY (NEWBYTEARRAY_) 
                                          REFERENCES WFS.JBPM_BYTEARRAY (ID_),
                                  CONSTRAINT JBPM_LOG#JBPM_ACTION 
                                          FOREIGN KEY (ACTION_) 
                                          REFERENCES WFS.JBPM_ACTION (ID_))';
                                          
    EXCEPTION 
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:
             Unable to create foreign Keys for JBPM_LOG'')';
        GOTO bypass_install;
        
    END;

	EXECUTE IMMEDIATE'ALTER TABLE WFS.TTV_MESSAGELOG
    					ADD ( CONSTRAINT TTV_MESSAGELOG#JBPM_LOG
						FOREIGN KEY(LOGID)
						REFERENCES WFS.JBPM_LOG(ID_)
						ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE )';
		
		-- Adding comment on JBPM_LOG table

 	--populate start state entry in existing work orders
    BEGIN
    	EXECUTE IMMEDIATE 'INSERT INTO WFS.JBPM_Log (Date_,Enter_,Leave_, Node_, Token_, Class_, Duration_, Index_)
							SELECT  pi.START_,pi.START_,pi.START_, pd.STARTSTATE_, pi.ROOTTOKEN_, ''N'', 0, -1
							FROM    WFS.JBPM_ProcessDefinition pd
							JOIN    WFS.JBPM_ProcessInstance pi
							ON(     pd.ID_ = pi.ProcessDefinition_)';
    EXCEPTION 
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:
             Unable to insert data into WFS.JBPM_Log'')';
        GOTO bypass_install;
        
    END;

	BEGIN
  
	EXECUTE IMMEDIATE 'COMMENT ON TABLE WFS.JBPM_LOG IS ''Stores process logs created by jBPM or application code during process execution
  Foreign Keys
  Token table - the token that the logs belong to
  Token table - the child token that the logs belong to
  Log table - parent/child relationship between logs
  Transition table - the transition the logs belong to
  Node table - the source node the logs belong to
  Node table - the destination node the logs belong to
  Variable Instance table - the variable instance that is referred to in the log
  Byte Array table - the old value of the byte array
  Byte Array table - the new value of the byte array
  Task Instance table - The task instance that is referred to in the log
  Swim Lane Instance table - the swimlane instance that is referred to in the log''';
  
      EXCEPTION
          WHEN OTHERS THEN
          wk_message := 'ERROR';
          EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:
             Unable to add comment on the JBPM_LOG table'')';
           GOTO bypass_install;
      END;
	--------------------------------------------------------
	-- ADD/ALTER TABLES AND THEIR PRIMARY KEYS
	--------------------------------------------------------
	
	-- Creating Table SYSTEM_RELEASE
    BEGIN
    
      EXECUTE IMMEDIATE 'create table WFS.SYSTEM_RELEASE  
                  (
                  SETTING_TYPE        	VARCHAR(50)  	 	not null,
                  SETTING_VALUE        	VARCHAR(1024)
                  )
          tablespace WFS_data
          nologging
          CACHE';
          
    EXCEPTION 
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:
             Unable to create table SYSTEM_RELEASE'')';
        GOTO bypass_install;
        
    END;
  
    -- Creating Primary Key on SYSTEM_RELEASE
    BEGIN
    
      EXECUTE IMMEDIATE 'alter table WFS.SYSTEM_RELEASE
                          add constraint PK_SYSTEM_RELEASE primary key (SETTING_TYPE)
                          using index    
                          tablespace WFS_index    
                          nologging';
                          
    EXCEPTION 
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:
             Unable to create Primary Key for SYSTEM_RELEASE'')';
        GOTO bypass_install;
        
    END;
	
	-- creating table SYSTEM_SETTINGS
    BEGIN
    
      EXECUTE IMMEDIATE 'CREATE TABLE WFS.SYSTEM_SETTINGS (
          SETTING_TYPE  VARCHAR2(25), 
          SETTING_VALUE VARCHAR2(1024)
          ) 
            TABLESPACE WFS_DATA'; 
    
    EXCEPTION
      WHEN OTHERS THEN
        
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database object:
             Unable to create table SYSTEM_SETTINGS'')';
        GOTO bypass_install;
        
    END;
    
	--CREATE TABLE WFS.TTV_SELECTOR
	BEGIN
      	EXECUTE IMMEDIATE 'CREATE TABLE WFS.TTV_SELECTOR ( 
    			SELECTIONKEY        VARCHAR2(4000) 	NOT NULL,
    			PROCESSDEFINITIONID NUMBER(19,0)   	NULL,
    			CREATEDATE          DATE		NOT NULL,
    			UPDATEDATE          DATE   		NOT NULL
				)TABLESPACE WFS_DATA';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE TABLE WFS.TTV_SELECTOR.'')';
		GOTO bypass_install;
            
    END;

	--CREATE PRIMARY KEY FOR WFS.TTV_SELECTOR
	BEGIN
  
  	    EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_SELECTOR
                               ADD ( CONSTRAINT PK_TTV_SELECTOR
                                    PRIMARY KEY (SELECTIONKEY)
                                    NOT DEFERRABLE INITIALLY IMMEDIATE
                                    USING INDEX
                                    TABLESPACE WFS_INDEX )';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE PRIMARY KEY PK_TTV_SELECTOR.'')';
		GOTO bypass_install;
            
    END;   
	
    --CREATING TABLE WFS.TTV_TRANSITIONTYPE 
    BEGIN
		EXECUTE IMMEDIATE 'CREATE TABLE WFS.TTV_TRANSITIONTYPE (
    						TRANSITIONTYPEID    NUMBER NOT NULL,
    						NAME        VARCHAR2(50) NULL,
    						CREATEDATE  TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
    						UPDATEDATE  TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL
    						)TABLESPACE WFS_DATA';
		EXECUTE IMMEDIATE 'COMMENT ON TABLE WFS.TTV_TRANSITIONTYPE IS ''Required as a result of sub-classing JBPM_TRANSITION entity''';

	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE TABLE WFS.TTV_TRANSITIONTYPE.'')';
		GOTO bypass_install;
            
    END;
    
    --CREATING Primary Key for WFS.TTV_TRANSITIONTYPE 
    BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_TRANSITIONTYPE ADD CONSTRAINT PK_TTV_TRANSITIONTYPE PRIMARY KEY (TRANSITIONTYPEID) NOT DEFERRABLE INITIALLY IMMEDIATE';
	
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE Primary Key for WFS.TTV_TRANSITIONTYPE.'')';
		GOTO bypass_install;
            
    END;
    
    --ALTERING TABLE WFS.TTV_RESOURCEGROUP
    BEGIN

		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEGROUP
							ADD (FUNCTIONALTYPE varchar2(1024)  NULL,
     							ISVISIBLE      number(1)       DEFAULT(0) NOT NULL,  
     							IMAGEPATH      varchar2(4000)  NULL)';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to ALTER TABLE WFS.TTV_RESOURCEGROUP.'')';
		GOTO bypass_install;
            
    END;

    --ALTERING TABLE WFS.TTV_RESOURCEGROUP
	BEGIN
  
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEGROUP
							MODIFY(ALLOCATIONSTRATEGYCLASSID NULL)';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to ALTER TABLE WFS.TTV_RESOURCEGROUP.'')';
		GOTO bypass_install;
            
    END;

    --ALTERING TABLE WFS.TTV_RESOURCE
	BEGIN
  
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCE
							ADD (FUNCTIONALTYPE varchar2(1024) NULL)';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to ALTER TABLE WFS.TTV_RESOURCE.'')';
		GOTO bypass_install;
            
    END;

	--ALTERING TABLE WFS.JBPM_TOKEN
	BEGIN
  
		EXECUTE IMMEDIATE ' ALTER TABLE WFS.JBPM_TOKEN
							ADD (OPERATIONALSTATUS      Number(19,0) NULL,
     							ADMINISTRATIVESTATUS   Number(19,0) NULL)';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to ALTER TABLE WFS.JBPM_TOKEN.'')';
		GOTO bypass_install;
            
    END;

    --ALTERING TABLE WFS.TTV_RESOURCETYPE
	BEGIN
  
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCETYPE
							ADD (SYSTEMID varchar2(4000)  NULL)';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to ALTER TABLE WFS.TTV_RESOURCETYPE.'')';
		GOTO bypass_install;
            
    END;
    
    --ALTERING TABLE WFS.JBPM_TRANSITION
	BEGIN
  
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TRANSITION
        				ADD ( TRANSITIONTYPEID NUMBER DEFAULT(2) NOT NULL )';
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to ALTER TABLE WFS.JBPM_TRANSITION.'')';
		GOTO bypass_install;
            
    END; 
 
    --------------------------------------------------------
	-- ADD NEW SEQUENCES
	--------------------------------------------------------

	-- recreating the WFS.TTV_RESOURCESTATUS_SEQ because it is at the wrong value.
    BEGIN
  
      EXECUTE IMMEDIATE 'DROP SEQUENCE WFS.TTV_RESOURCESTATUS_SEQ';
      EXECUTE IMMEDIATE 'CREATE SEQUENCE WFS.TTV_RESOURCESTATUS_SEQ
    						INCREMENT BY 1
    						START WITH 7
    						NOMAXVALUE
    						NOMINVALUE
    						NOCYCLE
    						NOCACHE
    						NOORDER';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE SEQUENCE .'')';
		GOTO bypass_install;
            
    END;
	
	
    --------------------------------------------------------
	-- ADD NEW TRIGGERS
	--------------------------------------------------------
	--CREATING TRG_TTV_SELECTOR_UPD FOR WFS.TTV_SELECTOR TABLE
	BEGIN
  
      EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER WFS.TRG_TTV_SELECTOR_UPD
                            BEFORE UPDATE
                            ON WFS.TTV_SELECTOR
                            FOR EACH ROW
                            BEGIN
                                :NEW.UpdateDate := sysdate;
                            END;';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE TRIGGER TRG_TTV_SELECTOR_UPD.'')';
		GOTO bypass_install;
            
    END;
   
    --CREATING TRG_TTV_SELECTOR_SEQ FOR WFS.TTV_SELECTOR TABLE
    BEGIN
  
      EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER WFS.TRG_TTV_SELECTOR_SEQ
                            BEFORE INSERT ON WFS.TTV_SELECTOR
                            FOR EACH ROW
                            BEGIN
                            
								:NEW.CreateDate := sysdate;
                                :NEW.UpdateDate := sysdate;
                            END;';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE TRIGGER TTV_SELECTOR.'')';
		GOTO bypass_install;
            
    END;

	BEGIN
  
      EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER WFS.TRG_TTV_TRANSITIONTYPE_UPD
						BEFORE UPDATE
						ON WFS.TTV_TRANSITIONTYPE
						FOR EACH ROW
						DECLARE updatedate      date;
						BEGIN
							SELECT  SYSTIMESTAMP
							INTO    updatedate
							FROM    DUAL;
							:NEW.UpdateDate := updatedate;
						END;';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE TRIGGER .'')';
		GOTO bypass_install;
            
    END;

    --CREATE TRIGGER TRG_JBPM_VARIABLEINSTANCE_SEQ
    BEGIN
      EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER WFS.TRG_JBPM_VARIABLEINSTANCE_SEQ
							BEFORE INSERT ON WFS.JBPM_VARIABLEINSTANCE
							FOR EACH ROW
							BEGIN
	
	    						IF :NEW.ID_ IS NULL THEN
	        						SELECT WFS.JBPM_VARIABLEINSTANCE_SEQ.NEXTVAL INTO :NEW.ID_ FROM DUAL;
	    						END IF;
	
	    						IF :NEW.STRINGVALUE_ IS NULL THEN
    	    						SELECT '' '' INTO :NEW.STRINGVALUE_ FROM DUAL;
    							END IF;
	
							END;';  
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE TRIGGER TRG_JBPM_VARIABLEINSTANCE_SEQ.'')';
		GOTO bypass_install;
            
    END;
    
	--CREATE TRIGGER TRG_JBPM_VARIABLEINSTANCE_UPD
	BEGIN
  
      EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER WFS.TRG_JBPM_VARIABLEINSTANCE_UPD
							BEFORE UPDATE
							ON WFS.JBPM_VARIABLEINSTANCE
							FOR EACH ROW
							BEGIN

							  SELECT SYSTIMESTAMP
							  INTO :NEW.UpdateDate
							  FROM DUAL;

							  IF :NEW.STRINGVALUE_ IS NULL THEN
							      SELECT '' ''
							      INTO :NEW.STRINGVALUE_
							      FROM DUAL;
							  END IF;

							END;';
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE TRIGGER TRG_JBPM_VARIABLEINSTANCE_UPD.'')';
		GOTO bypass_install;
            
    END;
    
	-- FIX NAME OF JBPM_VARIABLEACCESS TRG_JBPM_VARIABLEACCESS_SEQ
	BEGIN
		EXECUTE IMMEDIATE 'DROP TRIGGER WFS.TRG_JBPM_VARIABLEACCESS';
		EXECUTE IMMEDIATE 'CREATE TRIGGER WFS.TRG_JBPM_VARIABLEACCESS_SEQ
                              BEFORE INSERT ON WFS.JBPM_VARIABLEACCESS
                              FOR EACH ROW
                              BEGIN
                                  IF :NEW.ID_ IS NULL THEN
                                      SELECT WFS.JBPM_VARIABLEACCESS_SEQ.NEXTVAL INTO :NEW.ID_ FROM DUAL;
                                  END IF;
                              END;';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to FIX TRIGGER TRG_JBPM_VARIABLEACCESS_SEQ.'')';
		GOTO bypass_install;
            
    END;	
    

	--------------------------------------------------------
	-- DROP OLD INDEXES INDEXES
	--------------------------------------------------------
	-- Droping Indexes that have changed
    BEGIN
    	--EXECUTE IMMEDIATE 'DROP INDEX WFS.IDX_JBPM_LOG_01';
		EXECUTE IMMEDIATE 'DROP INDEX WFS.IDX_JBPM_VARIABLEINSTANCE_01';
		EXECUTE IMMEDIATE 'DROP INDEX WFS.IDX_JBPM_VARIABLEINSTANCE_02';
		EXECUTE IMMEDIATE 'DROP INDEX WFS.IDX_TTV_MONITOREDDRIVE';
		EXECUTE IMMEDIATE 'DROP INDEX WFS.IDX_TASK_ACTORID';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to drop old indexes.'')';
		GOTO bypass_install;
            
    END;
	--------------------------------------------------------
	-- ADD NEW INDEXES
	--------------------------------------------------------
	
	-- Creating index IX_JBPM_TASKINSTANCE_1
    BEGIN
    
      EXECUTE IMMEDIATE 'CREATE INDEX WFS.IX_JBPM_TASKINSTANCE_1
          ON WFS.JBPM_TASKINSTANCE(ACTORID_)
      tablespace WFS_INDEX';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:
             Unable to create index IX_JBPM_TASKINSTANCE_1'')';
        GOTO bypass_install;
        
    END;
    
	-- Creating index IX_TTV_MONITOREDDRIVE_1
    BEGIN
    
      EXECUTE IMMEDIATE 'create index WFS.IX_TTV_MONITOREDDRIVE_1 ON
                                  WFS.TTV_MONITOREDDRIVE (RESOURCEID,INTERNALDRIVEID)
                                  tablespace WFS_INDEX';
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:
             Unable to create index IX_TTV_MONITOREDDRIVE_1'')';
        GOTO bypass_install;
        
    END;
	
	--CREATE INDEXES FOR JBPM_PROCESSDEFINITION
	BEGIN
		EXECUTE IMMEDIATE'CREATE INDEX WFS.IDX_JBPM_PROCESSDEFINITION_01 
    						ON WFS.JBPM_PROCESSDEFINITION (NAME_)
							TABLESPACE WFS_INDEX';

		EXECUTE IMMEDIATE'CREATE INDEX WFS.IDX_JBPM_PROCESSDEFINITION_02 
    						ON WFS.JBPM_PROCESSDEFINITION (PROCESSDEFINITIONTYPEID)
							TABLESPACE WFS_INDEX';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE INDEXES for JBPM_PROCESSDEFINITION.'')';
		GOTO bypass_install;
            
    END;
    
	-- CREATE INDEX WFS.IDX_JBPM_COMMENT_02 
    BEGIN
  
		EXECUTE IMMEDIATE 'CREATE INDEX WFS.IDX_JBPM_COMMENT_02 
    						ON WFS.JBPM_COMMENT (TASKINSTANCE_)
							TABLESPACE WFS_INDEX';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE INDEX WFS.IDX_JBPM_COMMENT_02.'')';
		GOTO bypass_install;
            
    END;

	-- CREATE INDEX IDX_TTV_RESOURCETYPE_UK
    BEGIN
  
      EXECUTE IMMEDIATE 'CREATE UNIQUE INDEX WFS.IDX_TTV_RESOURCETYPE_UK
    						ON WFS.TTV_RESOURCETYPE(SYSTEMID)
							TABLESPACE WFS_INDEX';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE INDEX IDX_TTV_RESOURCETYPE_UK.'')';
		GOTO bypass_install;
            
    END;
    
	-- CREATE INDEX IDX_JBPM_VARIABLEINSTANCE_01
	BEGIN
		EXECUTE IMMEDIATE 'CREATE INDEX WFS.IDX_JBPM_VARIABLEINSTANCE_01 
    						ON WFS.JBPM_VARIABLEINSTANCE (NAME_, STRINGVALUE_)
							TABLESPACE WFS_INDEX';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE INDEX IDX_JBPM_VARIABLEINSTANCE_01.'')';
		GOTO bypass_install;
            
    END;

	-- CREATE INDEX IDX_JBPM_VARIABLEINSTANCE_02
	BEGIN
		EXECUTE IMMEDIATE 'CREATE INDEX WFS.IDX_JBPM_VARIABLEINSTANCE_02 
    						ON WFS.JBPM_VARIABLEINSTANCE (PROCESSINSTANCE_, NAME_, STRINGVALUE_, TOKENVARIABLEMAP_, CLASS_)
							TABLESPACE WFS_INDEX';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE INDEX IDX_JBPM_VARIABLEINSTANCE_02.'')';
		GOTO bypass_install;
            
    END;
    
	--------------------------------------------------------
	-- DELETES
	--------------------------------------------------------
	
	--Deleting records from WFS.ALERT_ACTIONS_HIST
	BEGIN 
		EXECUTE IMMEDIATE 'DELETE  FROM WFS.ALERT_ACTIONS_HIST
							WHERE   HIST_KEY IN (
        						SELECT  HIST_KEY
        						FROM    WFS.ALERTS_HIST
        						WHERE   IDENTIFIER IN (''Monitoring System Down'', ''Duplicate Request For Workorder''))';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to DELETE FROM WFS.ALERT_ACTIONS_HIST'')';
		GOTO bypass_install;
            
    END;

	--Deleting records from WFS.ALERTS_HIST
	BEGIN 
		EXECUTE IMMEDIATE 'DELETE  FROM WFS.ALERTS_HIST
							WHERE   IDENTIFIER IN (''Monitoring System Down'', ''Duplicate Request For Workorder'')';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to DELETE FROM WFS.ALERTS_HIST'')';
		GOTO bypass_install;
            
    END;

	--Deleting records from WFS.ALERT_ACTIONS
	BEGIN
		EXECUTE IMMEDIATE 'DELETE  FROM WFS.ALERT_ACTIONS 
							WHERE   IDENTIFIER IN (''Monitoring System Down'', ''Duplicate Request For Workorder'')';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to DELETE FROM WFS.ALERT_ACTIONS'')';
		GOTO bypass_install;
            
    END;

	--Deleting records from WFS.ALERTS
	BEGIN 
		EXECUTE IMMEDIATE 'DELETE  FROM WFS.ALERTS
							WHERE   IDENTIFIER IN (''Monitoring System Down'', ''Duplicate Request For Workorder'')';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to DELETE FROM WFS.ALERTS'')';
		GOTO bypass_install;
            
    END;

	--Deleting records from WFS.ALERT_NAMES
	BEGIN 
		EXECUTE IMMEDIATE 'DELETE  FROM  WFS.ALERT_NAMES
							WHERE   ALERT_NAME IN  (''Monitoring System Down'', ''Duplicate Request For Workorder Pattern'')';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to DELETE FROM WFS.ALERT_NAMES'')';
		GOTO bypass_install;
            
    END;
   
    --Deleting records from WFS.TTV_ACTION
	BEGIN 
		EXECUTE IMMEDIATE 'DELETE FROM WFS.TTV_ACTION WHERE name IN (''View Plugins'', ''Sort Plugins'')';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to DELETE FROM WFS.TTV_ACTION'')';
		GOTO bypass_install;
            
    END;
    
    --Deleteing records from WFS.TTV_RESOURCEGROUPMEMBERSHIP
    BEGIN
	    EXECUTE IMMEDIATE 'DELETE FROM WFS.TTV_RESOURCEGROUPMEMBERSHIP
							WHERE   RESOURCEGROUPID IN (
							            SELECT RESOURCEGROUPID 
							            FROM WFS.TTV_RESOURCEGROUP 
							            WHERE NAME IN (''Adult QC''))
							AND     RESOURCEID IN (
							            SELECT  RESOURCEID
							            FROM    WFS.TTV_RESOURCETYPE rt
							            JOIN    WFS.TTV_RESOURCE r
							            ON(     rt.RESOURCETYPEID = r.RESOURCETYPEID)
							            WHERE   rt.Name = ''Human'')';
		EXCEPTION
	      WHEN OTHERS THEN
	      
	        wk_message := 'ERROR';
	        EXECUTE IMMEDIATE 'INSERT INTO install_table values
	           (''error in installing of application database objects:  
	            Unable delete records from WFS.TTV_RESOURCEGROUPMEMBERSHIP.'')';
			GOTO bypass_install;
            
    END;
    
	--------------------------------------------------------
	-- INSERTS
	--------------------------------------------------------

	--Inserting data into WFS.TTV_DATATYPE
	BEGIN
		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_DATATYPE (DATATYPENAME) values(''url'')';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to INSERT INTO WFS.TTV_DATATYPE.'')';
		GOTO bypass_install;
            
    END;
    
	--Inserting data into WFS.TTV_PROCESSSTATUS
	BEGIN
  
		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_PROCESSSTATUS(PROCESSSTATUSID,NAME,CREATEDATE,UPDATEDATE)
							VALUES(8,''BRANCH'',sysdate,sysdate)';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to INSERT INTO WFS.TTV_PROCESSSTATUS.'')';
		GOTO bypass_install;
            
    END;
    
	--Inserting data into WFS.TTV_TRANSITIONTYPE
	BEGIN
  
		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_TRANSITIONTYPE(TRANSITIONTYPEID, NAME,CREATEDATE,UPDATEDATE)
							VALUES(1,''JBPM Standard Transition'',systimestamp,systimestamp)';

		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_TRANSITIONTYPE(TRANSITIONTYPEID, NAME,CREATEDATE,UPDATEDATE)
							VALUES(2,''TTV Transition'',systimestamp,systimestamp)';
	 EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to INSERT INTO WFS.TTV_TRANSITIONTYPE.'')';
		GOTO bypass_install;
            
    END;
    
    --Inserting data into WFS.TTV_MODULE
	BEGIN
		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_MODULE(ModuleID, NAME)
    						VALUES(WFS.TTV_MODULE_SEQ.nextval, ''Plugins'')';
	 EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to INSERT INTO WFS.TTV_MODULE.'')';
		GOTO bypass_install;
            
    END;
    
	--Inserting data into WFS.TTV_PERMISSION
	BEGIN
		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_PERMISSION(PermissionID, NAME, SECTIONNAME, MODULEID) 
   						VALUES(WFS.TTV_PERMISSION_SEQ.nextval, ''View'', ''Plugins'', (SELECT ModuleID FROM WFS.TTV_MODULE WHERE NAME = ''Plugins''))';
	 EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to INSERT INTO WFS.TTV_PERMISSION.'')';
		GOTO bypass_install;
            
    END;
    
    	--Inserting data into WFS.TTV_BIGROLEPERMISSION
	BEGIN
		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_BIGROLEPERMISSION(PERMISSIONID, BIGROLE) 
    						VALUES((SELECT PermissionID FROM WFS.TTV_PERMISSION WHERE NAME=''View'' AND SECTIONNAME=''Plugins''), ''Admin'')';
	 EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to INSERT INTO WFS.TTV_BIGROLEPERMISSION.'')';
		GOTO bypass_install;
            
    END;
    
	--Inserting data into WFS.TTV_ACTION
	BEGIN
		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_ACTION (NAME, PERMISSIONID, PATH, CREATEDATE, UPDATEDATE)
							SELECT	''Help'', 
									PERMISSIONID, 
									''help.do?method=getHelp'', 
									TO_DATE(''30/11/2007 12:00:00 AM'',''DD/MM/YYYY HH12:MI:SS PM''), 
									TO_DATE(''30/11/2007 12:00:00 AM'',''DD/MM/YYYY HH12:MI:SS PM'')
							FROM	WFS.TTV_PERMISSION
							WHERE 	NAME = ''Dashboard''';

		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_ACTION (NAME, PERMISSIONID, PATH, CREATEDATE, UPDATEDATE)
							SELECT	''View Selector Keys'', 
									PERMISSIONID, 
									''viewselectorkeys.do?method=getSelectorKeyDetails'', 
									TO_DATE(''30/11/2007 12:00:00 AM'',''DD/MM/YYYY HH12:MI:SS PM''), 
									TO_DATE(''30/11/2007 12:00:00 AM'',''DD/MM/YYYY HH12:MI:SS PM'')
							FROM	WFS.TTV_PERMISSION
							WHERE 	SECTIONNAME = ''View Work Orders''';
	
		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_ACTION (NAME, PERMISSIONID, PATH, CREATEDATE, UPDATEDATE)
							SELECT	''Add Selector Key'', 
									PERMISSIONID, 
									''viewselectorkeys.do?method=addSelectorKey'', 
									TO_DATE(''30/11/2007 12:00:00 AM'',''DD/MM/YYYY HH12:MI:SS PM''), 
									TO_DATE(''30/11/2007 12:00:00 AM'',''DD/MM/YYYY HH12:MI:SS PM'')
							FROM	WFS.TTV_PERMISSION
							WHERE 	SECTIONNAME = ''Create Work Orders''';

		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_ACTION (NAME, PERMISSIONID, PATH, CREATEDATE, UPDATEDATE)
							SELECT	''Delete Selector Key'', 
									PERMISSIONID, 
									''viewselectorkeys.do?method=deleteSelectorKey'', 
									TO_DATE(''30/11/2007 12:00:00 AM'',''DD/MM/YYYY HH12:MI:SS PM''), 
									TO_DATE(''30/11/2007 12:00:00 AM'',''DD/MM/YYYY HH12:MI:SS PM'')
							FROM	WFS.TTV_PERMISSION
							WHERE 	SECTIONNAME = ''Delete Work Orders''';
		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_ACTION (NAME, PERMISSIONID, PATH)
							VALUES (''View Resource Type Plugins'',
							(select PERMISSIONID from WFS.TTV_PERMISSION where NAME = ''View'' and SECTIONNAME = ''Plugins''),
							''plugins.do?method=getResourceTypePlugins'')';

		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_ACTION (NAME, PERMISSIONID, PATH)
							VALUES (''Sort Resource Type Plugins'',
							(select PERMISSIONID from WFS.TTV_PERMISSION where NAME = ''View'' and SECTIONNAME = ''Plugins''),
							''plugins.do?method=sortResourceTypePlugins'')';

		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_ACTION (NAME, PERMISSIONID, PATH)
							values (''View Resource Group Plugins'',
							(select PERMISSIONID from WFS.TTV_PERMISSION where NAME = ''View'' and SECTIONNAME = ''Plugins''),
							''plugins.do?method=getResourceGroupPlugins'')';

		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_ACTION (NAME, PERMISSIONID, PATH)
							values (''Sort Resource Group Plugins'',
							(select PERMISSIONID from WFS.TTV_PERMISSION where NAME = ''View'' and SECTIONNAME = ''Plugins''),
							''plugins.do?method=sortResourceGroupPlugins'')';
		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_ACTION (name, permissionid, path)
							VALUES (''Update Resource Group Queue UI Visiblity'',
							(SELECT permissionid FROM WFS.TTV_PERMISSION WHERE name = ''Modify'' and sectionname = ''Update Resources''),
							''resourceGroupQueueManagement.do?method=updateUIVisibility'')';

		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_ACTION (NAME, PERMISSIONID, PATH)
							VALUES (''Image Fetcher'',
							(select PERMISSIONID from WFS.TTV_PERMISSION where NAME = ''View'' and SECTIONNAME = ''View Work Orders''),
							''imageFetcher.do'')';
		EXCEPTION
			WHEN OTHERS THEN
      
			wk_message := 'ERROR';
			EXECUTE IMMEDIATE 'INSERT INTO install_table values
				(''error in installing of application database objects:  
				Unable to INSERT INTO WFS.TTV_ACTION.'')';
			GOTO bypass_install;
            
    END;


	--Inserting data into WFS.TTV_MENUITEM
	BEGIN
		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_MENUITEM(NAME, PERMISSIONID) 
    						VALUES(''TabbedPlugins'', WFS.TTV_PERMISSION_SEQ.currval)';
		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_MENUITEM(NAME,PERMISSIONID, CREATEDATE, UPDATEDATE) 
							VALUES(''TabbedSelectorKeysDetails'', 2, TO_DATE(''30/11/2007 12:00:00 AM'',''DD/MM/YYYY HH12:MI:SS PM''), TO_DATE(''30/11/2007 12:00:00 AM'',''DD/MM/YYYY HH12:MI:SS PM''))';
		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_MENUITEM (NAME, PERMISSIONID)
							VALUES (''TabbedResourceTypePlugins'',
								(SELECT PERMISSIONID FROM WFS.TTV_PERMISSION WHERE NAME = ''View'' and SECTIONNAME = ''Plugins''))';
		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_MENUITEM (NAME, PERMISSIONID)
							VALUES (''TabbedResourceGroupPlugins'',
								(SELECT PERMISSIONID FROM WFS.TTV_PERMISSION WHERE NAME = ''View'' and SECTIONNAME = ''Plugins''))';
		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_MENUITEM(NAME,PERMISSIONID) VALUES(''TabbedSelectorKeysDetails'',2)';
	 EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to INSERT INTO WFS.TTV_MENUITEM.'')';
		GOTO bypass_install;
            
    END;

	--Inserting data into WFS.TTV_RESOURCESTATUS
	BEGIN
		EXECUTE IMMEDIATE 'INSERT INTO WFS.TTV_RESOURCESTATUS(RESOURCESTATUSID,NAME,CREATEDATE,UPDATEDATE) 
							VALUES (WFS.TTV_RESOURCESTATUS_SEQ.nextval, ''Invalid'', sysdate, sysdate)';

	 EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to INSERT INTO WFS.TTV_RESOURCESTATUS.'')';
		GOTO bypass_install;
            
    END;
    
    --Inserting data into WFS.ALERT_NAMES
	BEGIN
    	EXECUTE IMMEDIATE 'INSERT INTO WFS.ALERT_NAMES(ALERT_NAME, PATTERN) 
    						VALUES (''Invalid License for Templates Pattern'', ''.*Invalid license for templates.*'')';
		EXECUTE IMMEDIATE 'INSERT INTO WFS.ALERT_NAMES (ALERT_NAME, PATTERN) 
							VALUES (''Template Ingest Failure Pattern'', ''.*Failed to ingest template.*'')';
	
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to INSERT INTO WFS.ALERT_NAMES.'')';
		GOTO bypass_install;
            
    END;

	--Inserting data into WFS.ALERTS
	BEGIN
		EXECUTE IMMEDIATE 'INSERT INTO WFS.ALERTS(IDENTIFIER, ALERT_NAME, THRESH_COUNT, THRESH_SECS, FREQ_COUNT, FREQ_SECS, TYPE) 
    						VALUES (''Invalid Template License'', ''Invalid License for Templates Pattern'', 1, 3600, 1, 3600, ''LOG'')';
		EXECUTE IMMEDIATE 'INSERT INTO WFS.ALERTS (IDENTIFIER, ALERT_NAME, THRESH_COUNT, THRESH_SECS, FREQ_COUNT, FREQ_SECS, TYPE) 
							VALUES (''Template Ingest Failure'', ''Template Ingest Failure Pattern'', 1, 3600, 1, 3600, ''LOG'')';
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to INSERT INTO WFS.ALERTS.'')';
		GOTO bypass_install;
            
    END;

    --Inserting data into WFS.ALERT_ACTIONS
	BEGIN
		EXECUTE IMMEDIATE 'INSERT INTO WFS.ALERT_ACTIONS(IDENTIFIER, ACTION_TYPE, DETAIL) 
    						VALUES (''Invalid Template License'', 1, ''11'')';
		EXECUTE IMMEDIATE 'INSERT INTO WFS.ALERT_ACTIONS (IDENTIFIER, ACTION_TYPE, DETAIL) 
							VALUES (''Template Ingest Failure'', 1, ''12'')';
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to INSERT INTO WFS.ALERT_ACTIONS.'')';
		GOTO bypass_install;
            
    END;

    -- Inserting into table 'SYSTEM_SETTINGS'
	BEGIN
	
		EXECUTE IMMEDIATE 'INSERT INTO wfs.SYSTEM_SETTINGS values (''RELEASE'',''2.6'')';
		
	EXCEPTION 
		WHEN OTHERS THEN
			wk_message := 'ERROR';
			EXECUTE IMMEDIATE 'INSERT INTO install_table values
			 (''error inserting SYSTEM_SETTINGS data'')';
			GOTO bypass_install;
	   
	END;
	
	-- Inserting default SYSTEM_RELEASE data
    BEGIN
    
      EXECUTE IMMEDIATE 'INSERT INTO WFS.SYSTEM_RELEASE VALUES 
                  (''RELEASE'',''2.6.0.0'')';
                  
    EXCEPTION 
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:
             Unable to insert data into SYSTEM_RELEASE'')';
        GOTO bypass_install;
        
    END;

	--------------------------------------------------------
	-- UPDATES
	--------------------------------------------------------
	
	-- FIX ACESS LEVELS IN WFS.TTV_RESOURCEGROUP
	BEGIN
	    EXECUTE IMMEDIATE 'UPDATE  WFS.TTV_RESOURCEGROUP
	    SET     ACCESSLEVELID = 0
	    WHERE   RESOURCEGROUPID = 89';
	
	    EXECUTE IMMEDIATE 'UPDATE  WFS.TTV_RESOURCEGROUP
	    SET     ACCESSLEVELID = 1
	    WHERE   RESOURCEGROUPID = 100';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to FIX ACESS LEVELS IN WFS.TTV_RESOURCEGROUP.'')';
		GOTO bypass_install;
            
    END;
    
	--Updating WFS.ttv_resourcetype setting SystemIds
	BEGIN
		EXECUTE IMMEDIATE 'UPDATE WFS.ttv_resourcetype SET systemId = ''02'' WHERE name = ''CMS''';
		EXECUTE IMMEDIATE 'UPDATE WFS.ttv_resourcetype SET systemId = ''03'' WHERE name = ''VTPS''';
		EXECUTE IMMEDIATE 'UPDATE WFS.ttv_resourcetype SET systemId = ''04'' WHERE name = ''Human''';
		EXECUTE IMMEDIATE 'UPDATE WFS.ttv_resourcetype SET systemId = ''05'' WHERE name = ''XPort SD''';
		EXECUTE IMMEDIATE 'UPDATE WFS.ttv_resourcetype SET systemId = ''06'' WHERE name = ''AMS''';
		EXECUTE IMMEDIATE 'UPDATE WFS.ttv_resourcetype SET systemId = ''07'' WHERE name = ''File Management Subsystem''';
		EXECUTE IMMEDIATE 'UPDATE WFS.ttv_resourcetype SET systemId = ''08'' WHERE name = ''Anystream''';
		EXECUTE IMMEDIATE 'UPDATE WFS.ttv_resourcetype SET systemId = ''09'' WHERE name = ''XPort Verifier''';
		EXECUTE IMMEDIATE 'UPDATE WFS.ttv_resourcetype SET systemId = ''10'' WHERE name = ''XPort IFrame''';
		EXECUTE IMMEDIATE 'UPDATE WFS.ttv_resourcetype SET systemId = ''11'' WHERE name = ''XPort HD''';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to UPDATE WFS.ttv_resourcetype.'')';
		GOTO bypass_install;
            
    END;
	
	--Updating WFS.JBPM_TRANSITION
	BEGIN
  
		EXECUTE IMMEDIATE 'UPDATE WFS.JBPM_TRANSITION
							SET TRANSITIONTYPEID = (SELECT	TRANSITIONTYPEID
                        							FROM	WFS.TTV_TRANSITIONTYPE
                        							WHERE	NAME = ''JBPM Standard Transition'')';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to UPDATE WFS.JBPM_TRANSITION.'')';
		GOTO bypass_install;
            
    END;
    
    --Updating WFS.ttv_resourcegroup
    BEGIN
  
		EXECUTE IMMEDIATE 'UPDATE wfs.ttv_resourcegroup SET isvisible = 0';
    	EXECUTE IMMEDIATE 'UPDATE wfs.ttv_resourcegroup SET isvisible = 1 WHERE resourcetypeid IN 
    						(SELECT resourcetypeid FROM wfs.ttv_resourcetype WHERE systemId IN (''03'', ''05'', ''08'', ''11''))';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to UPDATE WFS.ttv_resourcegroup.'')';
		GOTO bypass_install;
            
    END;
    
    -- Update the functional type for SD Encoders
    -- Update the functional type for HD Encoders
    -- Change all Resources and Groups of Resource Type 'XPort HD' to the new 'XPort Producer' type
    BEGIN
    	EXECUTE IMMEDIATE 'UPDATE wfs.ttv_resourcegroup set functionaltype = ''HD Encoder''
							WHERE resourcetypeid IN (SELECT resourcetypeid FROM wfs.ttv_resourcetype WHERE systemId = ''11'')';
		EXECUTE IMMEDIATE 'UPDATE wfs.ttv_resourcegroup set functionaltype = ''SD Encoder''
							WHERE resourcetypeid IN (SELECT resourcetypeid FROM wfs.ttv_resourcetype WHERE systemId = ''05'')';
		EXECUTE IMMEDIATE 'update wfs.ttv_resourcegroup set resourcetypeid = (select resourcetypeid from wfs.ttv_resourcetype where systemId = ''05'')
							where resourcetypeId = (select resourcetypeid from wfs.ttv_resourcetype where systemId = ''11'')';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to UPDATE WFS.ttv_resourcegroup.'')';
		GOTO bypass_install;
    END;
    
    -- Update the functional type for SD Encoders
    -- Update the functional type for HD Encoders
    -- Change all Resources and Groups of Resource Type 'XPort HD' to the new 'XPort Producer' type
    BEGIN
    	EXECUTE IMMEDIATE 'update wfs.ttv_resource set functionaltype = ''HD Encoder''
							WHERE resourcetypeid in (SELECT resourcetypeid from wfs.ttv_resourcetype WHERE systemId = ''11'')';
		EXECUTE IMMEDIATE 'update wfs.ttv_resource set functionaltype = ''SD Encoder''
							WHERE resourcetypeid in (SELECT resourcetypeid FROM wfs.ttv_resourcetype WHERE systemId = ''05'')';
		EXECUTE IMMEDIATE 'update wfs.ttv_resource set resourcetypeid = (select resourcetypeid from wfs.ttv_resourcetype where systemId = ''05'')
							where resourcetypeId = (select resourcetypeid from wfs.ttv_resourcetype where systemId = ''11'')';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to UPDATE WFS.ttv_resource.'')';
		GOTO bypass_install;
    END;
    
    --UPDATING WFS.ALERT_NAME
    BEGIN
    EXECUTE IMMEDIATE 'UPDATE WFS.ALERT_NAMES
						SET PATTERN = ''.*execution has failed.*''
						WHERE ALERT_NAME = ''Workorder Failed Pattern''';
	EXECUTE IMMEDIATE 'UPDATE WFS.ALERT_NAMES
						SET PATTERN = ''.*License unavailable for template.*''
						WHERE ALERT_NAME = ''Invalid License for Templates Pattern''';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to UPDATE WFS.ALERT_NAME.'')';
		GOTO bypass_install;
    END;
    
    --UPDATE JBPM_TOKEN set OPERATIONALSTATUS AND ADMINISTRATIVESTATUS
    BEGIN
    	EXECUTE IMMEDIATE 'UPDATE  WFS.JBPM_TOKEN a
							SET (a.OPERATIONALSTATUS,a.ADMINISTRATIVESTATUS)= 
						    	(SELECT OPERATIONALPROCESSSTATUSID,ADMINISTRATIVEPROCESSSTATUSID 
						    	FROM   WFS.JBPM_ProcessInstance s 
						    	WHERE  s.ID_ = a.PROCESSINSTANCE_) 
							WHERE   OPERATIONALSTATUS IS NULL AND ADMINISTRATIVESTATUS IS NULL';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to UPDATE WFS.JBPM_TOKEN.'')';
		GOTO bypass_install;
    END;
    
    --UPDATE JBPM_ProcessDefinition
    BEGIN
    	EXECUTE IMMEDIATE 'UPDATE WFS.JBPM_PROCESSDEFINITION
    						SET VERSION_ = 0';
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to UPDATE WFS.JBPM_ProcessDefinition.'')';
		GOTO bypass_install;
    END;
    
        
    -----------------------------------------------------------------
    --ADDITIONAL DELETES
    -----------------------------------------------------------------
    --Delete from ttv_resourcetype
    BEGIN
    EXECUTE IMMEDIATE 'DELETE FROM WFS.ttv_resourcetype
 						WHERE resourcetypeid = (SELECT resourcetypeid FROM wfs.ttv_resourcetype WHERE systemId = ''11'')';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to DELETE FROM ttv_resourcetype.'')';
		GOTO bypass_install;
    END;
    
    -----------------------------------------------------------------
    --CREATE FOREIGN KEYS
    -----------------------------------------------------------------
    	
    --CREATE FOREIGN KEY TTV_SELECTOR#JBPM_PROCESSDEF FOR WFS.TTV_SELECTOR
	BEGIN
  
      EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_SELECTOR
    					ADD ( CONSTRAINT TTV_SELECTOR#JBPM_PROCESSDEF
						FOREIGN KEY(PROCESSDEFINITIONID)
						REFERENCES WFS.JBPM_PROCESSDEFINITION("ID_")
						ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE )';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE FOREIGN KEY TTV_SELECTOR#JBPM_PROCESSDEF.'')';
		GOTO bypass_install;
            
    END;
    
    --CREATE FOREIGN KEYS FOR WFS.JBPM_TOKEN
	BEGIN
  
		EXECUTE IMMEDIATE ' ALTER TABLE WFS.JBPM_TOKEN
							ADD (
     						Constraint FK_TOKEN#PROCESSSTATUS_OPER
        						Foreign Key(OPERATIONALSTATUS)
       	 						References WFS.TTV_PROCESSSTATUS(PROCESSSTATUSID),
     						Constraint FK_TOKEN#PROCESSSTATUS_ADMIN
        						Foreign Key(ADMINISTRATIVESTATUS)
        						References WFS.TTV_PROCESSSTATUS(PROCESSSTATUSID))';
      
    EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to CREATE FOREIGN KEYS FOR WFS.JBPM_TOKEN.'')';
		GOTO bypass_install;
            
    END;
    
    --ADDING FOREIGN KEY FK_JBPM_TRANS_TTV_TRANSTYPE
    BEGIN
    	EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TRANSITION
    						ADD ( CONSTRAINT FK_JBPM_TRANS_TTV_TRANSTYPE
							FOREIGN KEY(TRANSITIONTYPEID)
							REFERENCES WFS.TTV_TRANSITIONTYPE(TRANSITIONTYPEID)
							ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE )'; 
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to add FOREIGN KEY FK_JBPM_TRANS_TTV_TRANSTYPE.'')';
		GOTO bypass_install;
            
    END;
--
-- ALERTS
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.ALERTS DROP CONSTRAINT FK_ALERTS_ALERT_NAMES';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.ALERTS ADD (CONSTRAINT ALERTS#ALERT_NAMES FOREIGN KEY (ALERT_NAME) REFERENCES WFS.ALERT_NAMES (ALERT_NAME)
                                                     NOT DEFERRABLE
                                                     INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for ALERTS.'')';
		GOTO bypass_install;
            
    END;

--
-- ALERT_ACTIONS
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.ALERT_ACTIONS DROP CONSTRAINT FK_ALERT_ACTIONS_ALERTS';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.ALERT_ACTIONS ADD (CONSTRAINT ALERT_ACTIONS#ALERTS FOREIGN KEY (IDENTIFIER) REFERENCES WFS.ALERTS (IDENTIFIER)
                                                              NOT DEFERRABLE
                                                              INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for ALERT_ACTIONS.'')';
		GOTO bypass_install;
            
    END;

--
-- ALERT_ACTIONS_HIST
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.ALERT_ACTIONS_HIST DROP CONSTRAINT FK_ALERTACTIONSH_ALERTSH';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.ALERT_ACTIONS_HIST ADD (CONSTRAINT ALERT_ACTIONS_HIST#ALERTS_HIST FOREIGN KEY (HIST_KEY) REFERENCES WFS.ALERTS_HIST (HIST_KEY)
                                                                             NOT DEFERRABLE
                                                                             INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for ALERT_ACTIONS_HIST.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_ACTION
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ACTION DROP CONSTRAINT FK_CRTETIMERACT_TA';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ACTION ADD (CONSTRAINT JBPM_ACTION#JBPM_ACTION1 FOREIGN KEY (TIMERACTION_) REFERENCES WFS.JBPM_ACTION (ID_)
                                                                NOT DEFERRABLE
                                                                INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ACTION DROP CONSTRAINT FK_ACTION_REFACT';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ACTION ADD (CONSTRAINT JBPM_ACTION#JBPM_ACTION2 FOREIGN KEY (REFERENCEDACTION_) REFERENCES WFS.JBPM_ACTION (ID_)
                                                                NOT DEFERRABLE
                                                                INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ACTION DROP CONSTRAINT FK_ACTION_PROCDEF';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ACTION ADD (CONSTRAINT JBPM_ACTION#JBPM_PDEFINITION FOREIGN KEY (PROCESSDEFINITION_) REFERENCES WFS.JBPM_PROCESSDEFINITION (ID_)
                                                                    NOT DEFERRABLE
                                                                    INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ACTION DROP CONSTRAINT FK_ACTION_EXPTHDL';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ACTION ADD (CONSTRAINT JBPM_ACTION#JBPM_EHANDLER FOREIGN KEY (EXCEPTIONHANDLER_) REFERENCES WFS.JBPM_EXCEPTIONHANDLER (ID_)
                                                                 NOT DEFERRABLE
                                                                 INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ACTION DROP CONSTRAINT FK_ACTION_EVENT';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ACTION ADD (CONSTRAINT JBPM_ACTION#JBPM_EVENT FOREIGN KEY (EVENT_) REFERENCES WFS.JBPM_EVENT (ID_)
                                                              NOT DEFERRABLE
                                                              INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ACTION DROP CONSTRAINT FK_ACTION_ACTNDEL';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ACTION ADD (CONSTRAINT JBPM_ACTION#JBPM_DELEGATION FOREIGN KEY (ACTIONDELEGATION_) REFERENCES WFS.JBPM_DELEGATION (ID_)
                                                                   NOT DEFERRABLE
                                                                   INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_ACTION.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_BYTEARRAY
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_BYTEARRAY DROP CONSTRAINT FK_BYTEARR_FILDEF';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_BYTEARRAY ADD (CONSTRAINT JBPM_BYTEARRAY#JBPM_MDEFINITN FOREIGN KEY (FILEDEFINITION_) REFERENCES WFS.JBPM_MODULEDEFINITION (ID_)
                                                                        NOT DEFERRABLE
                                                                        INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_BYTEARRAY.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_BYTEBLOCK
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_BYTEBLOCK DROP CONSTRAINT FK_BYTEBLOCK_FILE';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_BYTEBLOCK ADD (CONSTRAINT JBPM_BYTEBLOCK#JBPM_BYTEARRAY FOREIGN KEY (PROCESSFILE_) REFERENCES WFS.JBPM_BYTEARRAY (ID_)
                                                                        NOT DEFERRABLE
                                                                        INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_BYTEBLOCK.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_COMMENT
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_COMMENT DROP CONSTRAINT FK_COMMENT_TSK';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_COMMENT ADD (CONSTRAINT JBPM_COMMENT#JBPM_TASKINSTANCE FOREIGN KEY (TASKINSTANCE_) REFERENCES WFS.JBPM_TASKINSTANCE (ID_)
                                                                       NOT DEFERRABLE
                                                                       INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_COMMENT.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_DELEGATION
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_DELEGATION DROP CONSTRAINT FK_DELEGATION_PRCD';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_DELEGATION ADD (CONSTRAINT JBPM_DELEGATION#JBPM_PDEF FOREIGN KEY (PROCESSDEFINITION_) REFERENCES WFS.JBPM_PROCESSDEFINITION (ID_)
                                                                     NOT DEFERRABLE
                                                                     INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_DELEGATION.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_EVENT
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_EVENT DROP CONSTRAINT FK_EVENT_TRANS';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_EVENT ADD (CONSTRAINT JBPM_EVENT#JBPM_TRANSITION FOREIGN KEY (TRANSITION_) REFERENCES WFS.JBPM_TRANSITION (ID_)
                                                                 NOT DEFERRABLE
                                                                 INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_EVENT DROP CONSTRAINT FK_EVENT_TASK';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_EVENT ADD (CONSTRAINT JBPM_EVENT#JBPM_TASK FOREIGN KEY (TASK_) REFERENCES WFS.JBPM_TASK (ID_)
                                                           NOT DEFERRABLE
                                                           INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_EVENT DROP CONSTRAINT FK_EVENT_PROCDEF';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_EVENT ADD (CONSTRAINT JBPM_EVENT#JBPM_PDEFINITION FOREIGN KEY (PROCESSDEFINITION_) REFERENCES WFS.JBPM_PROCESSDEFINITION (ID_)
                                                                  NOT DEFERRABLE
                                                                  INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_EVENT.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_ID_GROUP
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ID_GROUP DROP CONSTRAINT FK_ID_GRP_PARENT';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ID_GROUP ADD (CONSTRAINT JBPM_ID_GROUP#JBPM_ID_GROUP FOREIGN KEY (PARENT_) REFERENCES WFS.JBPM_ID_GROUP (ID_)
                                                                     NOT DEFERRABLE
                                                                     INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_ID_GROUP.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_ID_MEMBERSHIP
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ID_MEMBERSHIP DROP CONSTRAINT FK_ID_MEMSHIP_USR';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ID_MEMBERSHIP ADD (CONSTRAINT JBPM_ID_MEMBERSHIP#JBPM_ID_USR FOREIGN KEY (USER_) REFERENCES WFS.JBPM_ID_USER (ID_)
                                                                             NOT DEFERRABLE
                                                                             INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ID_MEMBERSHIP DROP CONSTRAINT FK_ID_MEMSHIP_GRP';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_ID_MEMBERSHIP ADD (CONSTRAINT JBPM_ID_MEMBERSHIP#JBPM_ID_GRP FOREIGN KEY (GROUP_) REFERENCES WFS.JBPM_ID_GROUP (ID_)
                                                                             NOT DEFERRABLE
                                                                             INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_ID_MEMBERSHIP.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_MESSAGE
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_MESSAGE DROP CONSTRAINT FK_CMD_TASKINST';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_MESSAGE ADD (CONSTRAINT JBPM_MESSAGE#JBPM_TASKINSTANCE FOREIGN KEY (TASKINSTANCE_) REFERENCES WFS.JBPM_TASKINSTANCE (ID_)
                                                                       NOT DEFERRABLE
                                                                       INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_MESSAGE DROP CONSTRAINT FK_CMD_ACTION';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_MESSAGE ADD (CONSTRAINT JBPM_MESSAGE#JBPM_ACTION FOREIGN KEY (ACTION_) REFERENCES WFS.JBPM_ACTION (ID_)
                                                                 NOT DEFERRABLE
                                                                 INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_MESSAGE.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_MODULEDEFINITION
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_MODULEDEFINITION DROP CONSTRAINT FK_TSKDEF_START';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_MODULEDEFINITION ADD (CONSTRAINT JBPM_MDEFINITION#JBPM_TASK FOREIGN KEY (STARTTASK_) REFERENCES WFS.JBPM_TASK (ID_)
                                                                            NOT DEFERRABLE
                                                                            INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_MODULEDEFINITION DROP CONSTRAINT FK_MODDEF_PROCDEF';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_MODULEDEFINITION ADD (CONSTRAINT JBPM_MDEFINITION#JBPM_PDEF FOREIGN KEY (PROCESSDEFINITION_) REFERENCES WFS.JBPM_PROCESSDEFINITION (ID_)
                                                                            NOT DEFERRABLE
                                                                            INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_MODULEDEFINITION.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_MODULEINSTANCE
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_MODULEINSTANCE DROP CONSTRAINT FK_TASKMGTINST_TMD';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_MODULEINSTANCE ADD (CONSTRAINT JBPM_MINSTANCE#JBPM_MDEF FOREIGN KEY (TASKMGMTDEFINITION_) REFERENCES WFS.JBPM_MODULEDEFINITION (ID_)
                                                                        NOT DEFERRABLE
                                                                        INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_MODULEINSTANCE.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_NODE
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_NODE DROP CONSTRAINT FK_PROCST_SBPRCDEF';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_NODE ADD (CONSTRAINT JBPM_NODE#JBPM_PDEFINITION1 FOREIGN KEY (SUBPROCESSDEFINITION_) REFERENCES WFS.JBPM_PROCESSDEFINITION (ID_)
                                                                 NOT DEFERRABLE
                                                                 INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_NODE DROP CONSTRAINT FK_NODE_SUPERSTATE';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_NODE ADD (CONSTRAINT JBPM_NODE#JBPM_NODE FOREIGN KEY (SUPERSTATE_) REFERENCES WFS.JBPM_NODE (ID_)
                                                         NOT DEFERRABLE
                                                         INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_NODE DROP CONSTRAINT FK_NODE_PROCDEF';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_NODE ADD (CONSTRAINT JBPM_NODE#JBPM_PDEFINITION2 FOREIGN KEY (PROCESSDEFINITION_) REFERENCES WFS.JBPM_PROCESSDEFINITION (ID_)
                                                                 NOT DEFERRABLE
                                                                 INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_NODE DROP CONSTRAINT FK_NODE_ACTION';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_NODE ADD (CONSTRAINT JBPM_NODE#JBPM_ACTION FOREIGN KEY (ACTION_) REFERENCES WFS.JBPM_ACTION (ID_)
                                                           NOT DEFERRABLE
                                                           INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_NODE DROP CONSTRAINT FK_JBPM_NODE_TTV_RESOURCEGROUP';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_NODE ADD (CONSTRAINT JBPM_NODE#TTV_RESOURCEGROUP FOREIGN KEY (RESOURCEGROUPID) REFERENCES WFS.TTV_RESOURCEGROUP (RESOURCEGROUPID)
                                                                 NOT DEFERRABLE
                                                                 INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_NODE DROP CONSTRAINT FK_DECISION_DELEG';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_NODE ADD (CONSTRAINT JBPM_NODE#JBPM_DELEGATION FOREIGN KEY (DECISIONDELEGATION) REFERENCES WFS.JBPM_DELEGATION (ID_)
                                                               NOT DEFERRABLE
                                                               INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_NODE.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_POOLEDACTOR
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_POOLEDACTOR DROP CONSTRAINT FK_POOLEDACTOR_SLI';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_POOLEDACTOR ADD (CONSTRAINT JBPM_POOLACTR#JBPM_SLINSTANCE FOREIGN KEY (SWIMLANEINSTANCE_) REFERENCES WFS.JBPM_SWIMLANEINSTANCE (ID_)
                                                                          NOT DEFERRABLE
                                                                          INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_POOLEDACTOR.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_PROCESSDEFINITION
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_PROCESSDEFINITION DROP CONSTRAINT FK_JBPM_PROCESSDEFINITION_TYPE';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_PROCESSDEFINITION ADD (CONSTRAINT JBPM_PDEFINITION#TTV_PDEFTYPE FOREIGN KEY (PROCESSDEFINITIONTYPEID) REFERENCES WFS.TTV_PROCESSDEFINITIONTYPE (PROCESSDEFINITIONTYPEID)
                                                                                NOT DEFERRABLE
                                                                                INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_PROCESSDEFINITION.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_PROCESSINSTANCE
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_PROCESSINSTANCE DROP CONSTRAINT FK_JBPM_PROCESSINSTANCE_PRIOR';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_PROCESSINSTANCE ADD (CONSTRAINT JBPM_PINSTANCE#TTV_PPRIORITY FOREIGN KEY (PROCESSPRIORITYID) REFERENCES WFS.TTV_PROCESSPRIORITY (PROCESSPRIORITYID)
                                                                             NOT DEFERRABLE
                                                                             INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_PROCESSINSTANCE DROP CONSTRAINT FK_PROCIN_SPROCTKN';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_PROCESSINSTANCE ADD (CONSTRAINT JBPM_PINSTANCE#JBPM_TOKEN1 FOREIGN KEY (SUPERPROCESSTOKEN_) REFERENCES WFS.JBPM_TOKEN (ID_)
                                                                           NOT DEFERRABLE
                                                                           INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_PROCESSINSTANCE DROP CONSTRAINT FK_PROCIN_ROOTTKN';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_PROCESSINSTANCE ADD (CONSTRAINT JBPM_PINSTANCE#JBPM_TOKEN2 FOREIGN KEY (ROOTTOKEN_) REFERENCES WFS.JBPM_TOKEN (ID_)
                                                                           NOT DEFERRABLE
                                                                           INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_PROCESSINSTANCE DROP CONSTRAINT FK_PROCIN_PROCDEF';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_PROCESSINSTANCE ADD (CONSTRAINT JBPM_PINSTANCE#JBPM_PDEF FOREIGN KEY (PROCESSDEFINITION_) REFERENCES WFS.JBPM_PROCESSDEFINITION (ID_)
                                                                         NOT DEFERRABLE
                                                                         INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_PROCESSINSTANCE DROP CONSTRAINT FK_JBPM_PROCESSINSTANCE_OPERST';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_PROCESSINSTANCE ADD (CONSTRAINT JBPM_PINSTANCE#TTV_PSTATUS1 FOREIGN KEY (OPERATIONALPROCESSSTATUSID) REFERENCES WFS.TTV_PROCESSSTATUS (PROCESSSTATUSID)
                                                                            NOT DEFERRABLE
                                                                            INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_PROCESSINSTANCE DROP CONSTRAINT FK_JBPM_PROCESSINSTANCE_ADMST';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_PROCESSINSTANCE ADD (CONSTRAINT JBPM_PINSTANCE#TTV_PSTATUS2 FOREIGN KEY (ADMINISTRATIVEPROCESSSTATUSID) REFERENCES WFS.TTV_PROCESSSTATUS (PROCESSSTATUSID)
                                                                            NOT DEFERRABLE
                                                                            INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_PROCESSINSTANCE DROP CONSTRAINT FK_JBPM_PROCESSINSTANCE_TYPE';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_PROCESSINSTANCE ADD (CONSTRAINT JBPM_PINSTANCE#TTV_PINSTTYPE FOREIGN KEY (PROCESSINSTANCETYPEID) REFERENCES WFS.TTV_PROCESSINSTANCETYPE (PROCESSINSTANCETYPEID)
                                                                             NOT DEFERRABLE
                                                                             INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_PROCESSINSTANCE.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_RUNTIMEACTION
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_RUNTIMEACTION DROP CONSTRAINT FK_RTACTN_ACTION';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_RUNTIMEACTION ADD (CONSTRAINT JBPM_RUNTIMEACTION#JBPM_ACTION FOREIGN KEY (ACTION_) REFERENCES WFS.JBPM_ACTION (ID_)
                                                                             NOT DEFERRABLE
                                                                             INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_RUNTIMEACTION.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_SWIMLANE
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_SWIMLANE DROP CONSTRAINT FK_SWL_TSKMGMTDEF';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_SWIMLANE ADD (CONSTRAINT JBPM_SWIMLANE#JBPM_MDEFINITION FOREIGN KEY (TASKMGMTDEFINITION_) REFERENCES WFS.JBPM_MODULEDEFINITION (ID_)
                                                                        NOT DEFERRABLE
                                                                        INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_SWIMLANE DROP CONSTRAINT FK_SWL_ASSDEL';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_SWIMLANE ADD (CONSTRAINT JBPM_SWIMLANE#JBPM_DELEGATION FOREIGN KEY (ASSIGNMENTDELEGATION_) REFERENCES WFS.JBPM_DELEGATION (ID_)
                                                                       NOT DEFERRABLE
                                                                       INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_SWIMLANE.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_SWIMLANEINSTANCE
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_SWIMLANEINSTANCE DROP CONSTRAINT FK_SWIMLANEINST_TM';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_SWIMLANEINSTANCE ADD (CONSTRAINT JBPM_SLINSTANCE#JBPM_MINSTANCE FOREIGN KEY (TASKMGMTINSTANCE_) REFERENCES WFS.JBPM_MODULEINSTANCE (ID_)
                                                                                NOT DEFERRABLE
                                                                                INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_SWIMLANEINSTANCE DROP CONSTRAINT FK_SWIMLANEINST_SL';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_SWIMLANEINSTANCE ADD (CONSTRAINT JBPM_SLINSTANCE#JBPM_SWIMLANE FOREIGN KEY (SWIMLANE_) REFERENCES WFS.JBPM_SWIMLANE (ID_)
                                                                               NOT DEFERRABLE
                                                                               INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_SWIMLANEINSTANCE.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_TASK
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASK DROP CONSTRAINT FK_TSK_TSKCTRL';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASK ADD (CONSTRAINT JBPM_TASK#JBPM_TASKCONTROLLER FOREIGN KEY (TASKCONTROLLER_) REFERENCES WFS.JBPM_TASKCONTROLLER (ID_)
                                                                   NOT DEFERRABLE
                                                                   INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASK DROP CONSTRAINT FK_TASK_TASKMGTDEF';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASK ADD (CONSTRAINT JBPM_TASK#JBPM_MDEFINITION FOREIGN KEY (TASKMGMTDEFINITION_) REFERENCES WFS.JBPM_MODULEDEFINITION (ID_)
                                                                NOT DEFERRABLE
                                                                INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASK DROP CONSTRAINT FK_TASK_SWIMLANE';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASK ADD (CONSTRAINT JBPM_TASK#JBPM_SWIMLANE FOREIGN KEY (SWIMLANE_) REFERENCES WFS.JBPM_SWIMLANE (ID_)
                                                             NOT DEFERRABLE
                                                             INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASK DROP CONSTRAINT FK_TASK_PROCDEF';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASK ADD (CONSTRAINT JBPM_TASK#JBPM_PDEFINITION FOREIGN KEY (PROCESSDEFINITION_) REFERENCES WFS.JBPM_PROCESSDEFINITION (ID_)
                                                                NOT DEFERRABLE
                                                                INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASK DROP CONSTRAINT FK_TASK_ASSDEL';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASK ADD (CONSTRAINT JBPM_TASK#JBPM_DELEGATION FOREIGN KEY (ASSIGNMENTDELEGATION_) REFERENCES WFS.JBPM_DELEGATION (ID_)
                                                               NOT DEFERRABLE
                                                               INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_TASK.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_TASKACTORPOOL
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASKACTORPOOL DROP CONSTRAINT FK_TSKACTPOL_PLACT';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASKACTORPOOL ADD (CONSTRAINT JBPM_TACTRPOOL#JBPM_POOLEDACTR FOREIGN KEY (POOLEDACTOR_) REFERENCES WFS.JBPM_POOLEDACTOR (ID_)
                                                                             NOT DEFERRABLE
                                                                             INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASKACTORPOOL DROP CONSTRAINT FK_TASKACTPL_TSKI';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASKACTORPOOL ADD (CONSTRAINT JBPM_TACTRPOOL##JBPM_TINSTANCE FOREIGN KEY (TASKINSTANCE_) REFERENCES WFS.JBPM_TASKINSTANCE (ID_)
                                                                             NOT DEFERRABLE
                                                                             INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_TASKACTORPOOL.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_TASKCONTROLLER
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASKCONTROLLER DROP CONSTRAINT FK_TSKCTRL_DELEG';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASKCONTROLLER ADD (CONSTRAINT JBPM_TCONTROLR#JBPM_DELEGATION FOREIGN KEY (TASKCONTROLLERDELEGATION_) REFERENCES WFS.JBPM_DELEGATION (ID_)
                                                                              NOT DEFERRABLE
                                                                              INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_TASKCONTROLLER.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_TASKINSTANCE
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASKINSTANCE DROP CONSTRAINT FK_TASKINST_TMINST';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASKINSTANCE ADD (CONSTRAINT JBPM_TINSTANCE#JBPM_MINSTANCE FOREIGN KEY (TASKMGMTINSTANCE_) REFERENCES WFS.JBPM_MODULEINSTANCE (ID_)
                                                                           NOT DEFERRABLE
                                                                           INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASKINSTANCE DROP CONSTRAINT FK_TASKINST_TASK';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASKINSTANCE ADD (CONSTRAINT JBPM_TINSTANCE#JBPM_TASK FOREIGN KEY (TASK_) REFERENCES WFS.JBPM_TASK (ID_)
                                                                      NOT DEFERRABLE
                                                                      INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASKINSTANCE DROP CONSTRAINT FK_TASKINST_SLINST';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TASKINSTANCE ADD (CONSTRAINT JBPM_TINSTANCE#JBPM_SLINSTANCE FOREIGN KEY (SWIMLANINSTANCE_) REFERENCES WFS.JBPM_SWIMLANEINSTANCE (ID_)
                                                                            NOT DEFERRABLE
                                                                            INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_TASKINSTANCE.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_TIMER
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TIMER DROP CONSTRAINT FK_TIMER_TSKINST';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TIMER ADD (CONSTRAINT JBPM_TIMER#JBPM_TINSTANCE FOREIGN KEY (TASKINSTANCE_) REFERENCES WFS.JBPM_TASKINSTANCE (ID_)
                                                                NOT DEFERRABLE
                                                                INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TIMER DROP CONSTRAINT FK_TIMER_ACTION';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TIMER ADD (CONSTRAINT JBPM_TIMER#JBPM_ACTION FOREIGN KEY (ACTION_) REFERENCES WFS.JBPM_ACTION (ID_)
                                                             NOT DEFERRABLE
                                                             INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_TIMER.'')';
		GOTO bypass_install;
            
    END;

--
-- JBPM_TRANSITION
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TRANSITION DROP CONSTRAINT FK_TRANS_PROCDEF';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.JBPM_TRANSITION ADD (CONSTRAINT JBPM_TRANSITION#JBPM_PDEF FOREIGN KEY (PROCESSDEFINITION_) REFERENCES WFS.JBPM_PROCESSDEFINITION (ID_)
                                                                     NOT DEFERRABLE
                                                                     INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for JBPM_TRANSITION.'')';
		GOTO bypass_install;
            
    END;

--
-- TTV_ACTION
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_ACTION DROP CONSTRAINT FK_TTV_ACTION_PERMISSION';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_ACTION ADD (CONSTRAINT TTV_ACTION#TTV_PERMISSION FOREIGN KEY (PERMISSIONID) REFERENCES WFS.TTV_PERMISSION (PERMISSIONID)
                                                                NOT DEFERRABLE
                                                                INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for TTV_ACTION.'')';
		GOTO bypass_install;
            
    END;

--
-- TTV_MENUITEM
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_MENUITEM DROP CONSTRAINT FK_TTV_MENUITEM_PERMISSION';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_MENUITEM ADD (CONSTRAINT TTV_MENUITEM#TTV_PERMISSION FOREIGN KEY (PERMISSIONID) REFERENCES WFS.TTV_PERMISSION (PERMISSIONID)
                                                                    NOT DEFERRABLE
                                                                    INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for TTV_MENUITEM.'')';
		GOTO bypass_install;
            
    END;

--
-- TTV_MESSAGELOG
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_MESSAGELOG DROP CONSTRAINT FK_TTV_MESSAGELOG_RESOURCE';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_MESSAGELOG ADD (CONSTRAINT TTV_MESSAGELOG#TTV_RESOURCE FOREIGN KEY (RESOURCEID) REFERENCES WFS.TTV_RESOURCE (RESOURCEID)
                                                                      NOT DEFERRABLE
                                                                      INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for TTV_MESSAGELOG.'')';
		GOTO bypass_install;
            
    END;

--
-- TTV_MONITOREDDRIVE
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_MONITOREDDRIVE DROP CONSTRAINT FK_TTV_MONITOREDDRIVE_STATUS';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_MONITOREDDRIVE ADD (CONSTRAINT TTV_MDRIVE#TTV_MDRIVESTATUS FOREIGN KEY (CURRENTDRIVESTATUSID) REFERENCES WFS.TTV_MONITOREDDRIVESTATUS (MONITOREDDRIVESTATUSID)
                                                                          NOT DEFERRABLE
                                                                          INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_MONITOREDDRIVE DROP CONSTRAINT FK_TTV_MONITOREDDRIVE_RES';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_MONITOREDDRIVE ADD (CONSTRAINT TTV_MDRIVE#TTV_RESOURCE FOREIGN KEY (RESOURCEID) REFERENCES WFS.TTV_RESOURCE (RESOURCEID)
                                                                      NOT DEFERRABLE
                                                                      INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for TTV_MONITOREDDRIVE.'')';
		GOTO bypass_install;
            
    END;

--
-- TTV_MONITOREDDRIVEHISTORY
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_MONITOREDDRIVEHISTORY DROP CONSTRAINT FK_TTV_MONDRIVEHISTORY_DRIVE';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_MONITOREDDRIVEHISTORY ADD (CONSTRAINT TTV_MDRIVEHIST#TTV_MDRIVE FOREIGN KEY (MONITOREDDRIVEID) REFERENCES WFS.TTV_MONITOREDDRIVE (MONITOREDDRIVEID)
                                                                               NOT DEFERRABLE
                                                                               INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for TTV_MONITOREDDRIVEHISTORY.'')';
		GOTO bypass_install;
            
    END;

--
-- TTV_PERMISSION
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_PERMISSION DROP CONSTRAINT FK_TTV_PERMISSION_MODULE';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_PERMISSION ADD (CONSTRAINT TTV_PERMISSION#TTV_MODULE FOREIGN KEY (MODULEID) REFERENCES WFS.TTV_MODULE (MODULEID)
                                                                    NOT DEFERRABLE
                                                                    INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for TTV_PERMISSION.'')';
		GOTO bypass_install;
            
    END;

--
-- TTV_PROCDEFACCESSLEVEL
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_PROCDEFACCESSLEVEL DROP CONSTRAINT FK_TTV_PROCDEFACCESSLEVEL_ACC';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_PROCDEFACCESSLEVEL ADD (CONSTRAINT TTV_PROCDEFALEVEL#TTV_ALEVEL FOREIGN KEY (ACCESSLEVELID) REFERENCES WFS.TTV_ACCESSLEVEL (ACCESSLEVELID)
                                                                               NOT DEFERRABLE
                                                                               INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_PROCDEFACCESSLEVEL DROP CONSTRAINT FK_TTV_PROCDEFACCESSLEVEL_PROC';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_PROCDEFACCESSLEVEL ADD (CONSTRAINT TTV_PDEFALEVEL#JBPM_PDEF FOREIGN KEY (PROCESSDEFINITIONID) REFERENCES WFS.JBPM_PROCESSDEFINITION (ID_)
                                                                           NOT DEFERRABLE
                                                                           INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for TTV_PROCDEFACCESSLEVEL.'')';
		GOTO bypass_install;
            
    END;

--
-- TTV_PROCESSINSTANCENOTE
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_PROCESSINSTANCENOTE DROP CONSTRAINT FK_TTV_PROCESSINSTNOTE_PROC';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_PROCESSINSTANCENOTE ADD (CONSTRAINT TTV_PINSTANCENOTE#JBPM_PINST FOREIGN KEY (PROCESSINSTANCEID) REFERENCES WFS.JBPM_PROCESSINSTANCE (ID_)
                                                                                NOT DEFERRABLE
                                                                                INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for TTV_PROCESSINSTANCENOTE.'')';
		GOTO bypass_install;
            
    END;

--
-- TTV_RESOURCE
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCE DROP CONSTRAINT FK_TTV_RESOURCE_TYPE';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCE ADD (CONSTRAINT TTV_RESOURCE#TTV_RTYPE FOREIGN KEY (RESOURCETYPEID) REFERENCES WFS.TTV_RESOURCETYPE (RESOURCETYPEID)
                                                               NOT DEFERRABLE
                                                               INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCE DROP CONSTRAINT FK_TTV_RESOURCE_OPERRESSTAT';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCE ADD (CONSTRAINT TTV_RESOURCE#TTV_RSTATUS1 FOREIGN KEY (OPERATIONALRESOURCESTATUSID) REFERENCES WFS.TTV_RESOURCESTATUS (RESOURCESTATUSID)
                                                                  NOT DEFERRABLE
                                                                  INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCE DROP CONSTRAINT FK_TTV_RESOURCE_ADMRESSTAT';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCE ADD (CONSTRAINT TTV_RESOURCE#TTV_RSTATUS2 FOREIGN KEY (ADMINISTRATIVERESOURCESTATUSID) REFERENCES WFS.TTV_RESOURCESTATUS (RESOURCESTATUSID)
                                                                  NOT DEFERRABLE
                                                                  INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for TTV_RESOURCE.'')';
		GOTO bypass_install;
            
    END;

--
-- TTV_RESOURCEGROUP
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEGROUP DROP CONSTRAINT FK_TTV_RESOURCEGROUP_ACCESS';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEGROUP ADD (CONSTRAINT TTV_RESOURCEGROUP#TTV_ALEVEL FOREIGN KEY (ACCESSLEVELID) REFERENCES WFS.TTV_ACCESSLEVEL (ACCESSLEVELID)
                                                                          NOT DEFERRABLE
                                                                          INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEGROUP DROP CONSTRAINT FK_TTV_RESOURCEGROUP_ALLOCST';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEGROUP ADD (CONSTRAINT TTV_RESOURCEGROUP#TTV_SGYCLASS FOREIGN KEY (ALLOCATIONSTRATEGYCLASSID) REFERENCES WFS.TTV_STRATEGYCLASS (STRATEGYCLASSID)
                                                                            NOT DEFERRABLE
                                                                            INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEGROUP DROP CONSTRAINT FK_TTV_RESOURCEGROUP_RESTYPE';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEGROUP ADD (CONSTRAINT TTV_RESOURCEGROUP#TTV_RTYPE FOREIGN KEY (RESOURCETYPEID) REFERENCES WFS.TTV_RESOURCETYPE (RESOURCETYPEID)
                                                                         NOT DEFERRABLE
                                                                         INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for TTV_RESOURCEGROUP.'')';
		GOTO bypass_install;
            
    END;

--
-- TTV_RESOURCEGROUPMEMBERSHIP
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEGROUPMEMBERSHIP DROP CONSTRAINT FK_TTV_RESMEMB_GROUP';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEGROUPMEMBERSHIP ADD (CONSTRAINT TTV_RGRPMBRSHIP#TTV_RGROUP FOREIGN KEY (RESOURCEGROUPID) REFERENCES WFS.TTV_RESOURCEGROUP (RESOURCEGROUPID)
                                                                                  NOT DEFERRABLE
                                                                                  INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEGROUPMEMBERSHIP DROP CONSTRAINT FK_TTV_RESMEMB_RESOURCE';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEGROUPMEMBERSHIP ADD (CONSTRAINT TTV_RGRPMBRSHIP#TTV_RESOURCE FOREIGN KEY (RESOURCEID) REFERENCES WFS.TTV_RESOURCE (RESOURCEID)
                                                                                    NOT DEFERRABLE
                                                                                    INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for TTV_RESOURCEGROUPMEMBERSHIP.'')';
		GOTO bypass_install;
            
    END;

--
-- TTV_RESOURCEGROUPQUEUEITEM
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEGROUPQUEUEITEM DROP CONSTRAINT FK_TTV_RESOURCEGROUPQ_RESGRP';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEGROUPQUEUEITEM ADD (CONSTRAINT TTV_RGROUPQITEM#TTV_RGROUP FOREIGN KEY (RESOURCEGROUPID) REFERENCES WFS.TTV_RESOURCEGROUP (RESOURCEGROUPID)
                                                                                 NOT DEFERRABLE
                                                                                 INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEGROUPQUEUEITEM DROP CONSTRAINT FK_TTV_RESOURCEGROUPQ_TOKEN';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEGROUPQUEUEITEM ADD (CONSTRAINT TTV_RGROUPQUEUEITEM#JBPM_TOKEN FOREIGN KEY (TOKENID) REFERENCES WFS.JBPM_TOKEN (ID_)
                                                                                     NOT DEFERRABLE
                                                                                     INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for TTV_RESOURCEGROUPQUEUEITEM.'')';
		GOTO bypass_install;
            
    END;

--
-- TTV_RESOURCETYPE
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCETYPE DROP CONSTRAINT FK_TTV_RESOURCETYPE_INITSTRAT';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCETYPE ADD (CONSTRAINT TTV_RESOURCETYPE#TTV_SGYCLASS1 FOREIGN KEY (INITIALIZATIONSTRATEGYCLASSID) REFERENCES WFS.TTV_STRATEGYCLASS (STRATEGYCLASSID)
                                                                           NOT DEFERRABLE
                                                                           INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCETYPE DROP CONSTRAINT FK_TTV_RESOURCETYPE_HRTSTRAT';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCETYPE ADD (CONSTRAINT TTV_RESOURCETYPE#TTV_SGYCLASS2 FOREIGN KEY (HEARTBEATSTRATEGYCLASSID) REFERENCES WFS.TTV_STRATEGYCLASS (STRATEGYCLASSID)
                                                                           NOT DEFERRABLE
                                                                           INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCETYPE DROP CONSTRAINT FK_TTV_RESOURCETYPE_HRTCONTYP';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCETYPE ADD (CONSTRAINT TTV_RESOURCETYPE#TTV_CTYPE1 FOREIGN KEY (HEARTBEATCONNECTIONTYPEID) REFERENCES WFS.TTV_CONNECTIONTYPE (CONNECTIONTYPEID)
                                                                        NOT DEFERRABLE
                                                                        INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCETYPE DROP CONSTRAINT FK_TTV_RESOURCETYPE_RESCONTYP';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCETYPE ADD (CONSTRAINT TTV_RESOURCETYPE#TTV_CTYPE2 FOREIGN KEY (RESOURCECONNECTIONTYPEID) REFERENCES WFS.TTV_CONNECTIONTYPE (CONNECTIONTYPEID)
                                                                        NOT DEFERRABLE
                                                                        INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for TTV_RESOURCETYPE.'')';
		GOTO bypass_install;
            
    END;

--
-- TTV_RESOURCEUSAGEHISTORY
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEUSAGEHISTORY DROP CONSTRAINT FK_TTV_RESUSAGEHIST_GROUP';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEUSAGEHISTORY ADD (CONSTRAINT TTV_RUSAGEHIST#TTV_RGROUP FOREIGN KEY (RESOURCEGROUPID) REFERENCES WFS.TTV_RESOURCEGROUP (RESOURCEGROUPID)
                                                                              NOT DEFERRABLE
                                                                              INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEUSAGEHISTORY DROP CONSTRAINT FK_TTV_RESUSEHIST_RES';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEUSAGEHISTORY ADD (CONSTRAINT TTV_RUSAGEHIST#TTV_RESOURCE FOREIGN KEY (RESOURCEID) REFERENCES WFS.TTV_RESOURCE (RESOURCEID)
                                                                                NOT DEFERRABLE
                                                                                INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEUSAGEHISTORY DROP CONSTRAINT FK_TTV_RESUSEHIST_PROCINST';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEUSAGEHISTORY ADD (CONSTRAINT TTV_RUSAGEHIST#JBPM_PINSTANCE FOREIGN KEY (PROCESSINSTANCEID) REFERENCES WFS.JBPM_PROCESSINSTANCE (ID_)
                                                                                  NOT DEFERRABLE
                                                                                  INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEUSAGEHISTORY DROP CONSTRAINT FK_TTV_RESUSEHIST_NODE';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_RESOURCEUSAGEHISTORY ADD (CONSTRAINT TTV_RUSAGEHIST#JBPM_NODE FOREIGN KEY (NODEID) REFERENCES WFS.JBPM_NODE (ID_)
                                                                             NOT DEFERRABLE
                                                                             INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for TTV_RESOURCEUSAGEHISTORY.'')';
		GOTO bypass_install;
            
    END;

--
-- TTV_STRATEGYCLASS
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_STRATEGYCLASS DROP CONSTRAINT FK_TTV_STRATEGYCLASS_TYPE';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_STRATEGYCLASS ADD (CONSTRAINT TTV_SGYCLASS#TTV_SGYCLASSTYPE FOREIGN KEY (STRATEGYCLASSTYPEID) REFERENCES WFS.TTV_STRATEGYCLASSTYPE (STRATEGYCLASSTYPEID)
                                                                           NOT DEFERRABLE
                                                                           INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for TTV_STRATEGYCLASS.'')';
		GOTO bypass_install;
            
    END;

--
-- TTV_TOKENRESOURCE
-- 
	BEGIN
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_TOKENRESOURCE DROP CONSTRAINT FK_TTV_TOKENRESOURCE_GROUP';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_TOKENRESOURCE ADD (CONSTRAINT TTV_TOKENRESOURCE#TTV_RGROUP FOREIGN KEY (RESOURCEGROUPID) REFERENCES WFS.TTV_RESOURCEGROUP (RESOURCEGROUPID)
                                                                          NOT DEFERRABLE
                                                                          INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_TOKENRESOURCE DROP CONSTRAINT FK_TTV_TOKENRESOURCE_RES';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_TOKENRESOURCE ADD (CONSTRAINT TTV_TOKENRESOURCE#TTV_RESOURCE FOREIGN KEY (RESOURCEID) REFERENCES WFS.TTV_RESOURCE (RESOURCEID)
                                                                            NOT DEFERRABLE
                                                                            INITIALLY IMMEDIATE)';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_TOKENRESOURCE DROP CONSTRAINT FK_TTV_TOKENRESOURCE_TOKEN';
		EXECUTE IMMEDIATE 'ALTER TABLE WFS.TTV_TOKENRESOURCE ADD (CONSTRAINT TTV_TOKENRESOURCE#JBPM_TOKEN FOREIGN KEY (TOKENID) REFERENCES WFS.JBPM_TOKEN (ID_)
                                                                          NOT DEFERRABLE
                                                                          INITIALLY IMMEDIATE)';
	EXCEPTION
      WHEN OTHERS THEN
      
        wk_message := 'ERROR';
        EXECUTE IMMEDIATE 'INSERT INTO install_table values
           (''error in installing of application database objects:  
            Unable to Alter Foreign Keys for TTV_TOKENRESOURCE.'')';
		GOTO bypass_install;
            
    END;
	
	<<bypass_install>>
	
	  COMMIT;
	  
	  IF wk_message = 'ERROR' THEN
	  
	     NULL;
	     
	  ELSE
	  
	     EXECUTE IMMEDIATE 'INSERT INTO install_table values
	   (''Installation completed SUCCESSFULLY'')';
	    COMMIT; 
	  END IF;

END;
/
