-- Create User WPTB


CREATE USER WPTB IDENTIFIED BY wptb
DEFAULT TABLESPACE WFS_DATA
TEMPORARY TABLESPACE TEMP;

GRANT RESOURCE TO WPTB;

-- Create Table CONNECTIONTYPE

CREATE TABLE WPTB.TB_CONNECTIONTYPE(
	CONNECTIONTYPEID	NUMBER		NOT NULL,
	NAME			VARCHAR2(50) 	NOT NULL,
    CREATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
    UPDATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_CONNECTIONTYPE 
  ADD(CONSTRAINT PK_TB_CONNNECTIONTYPE PRIMARY KEY(CONNECTIONTYPEID)
      USING INDEX
      TABLESPACE WFS_INDEX); 

-- Create Table AdaptorType

CREATE TABLE WPTB.TB_ADAPTORTYPE(
	ADAPTORTYPEID	NUMBER		NOT NULL,
	NAME		VARCHAR2(50)	NOT NULL,
    CREATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
    UPDATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_ADAPTORTYPE
  ADD(CONSTRAINT PK_TB_ADAPTORTYPE PRIMARY KEY(ADAPTORTYPEID)
      USING INDEX
      TABLESPACE WFS_INDEX);

-- Create Table AdaptorScope

CREATE TABLE WPTB.TB_ADAPTORSCOPE(
	ADAPTORSCOPEID	NUMBER		NOT NULL,
	NAME		VARCHAR2(50)	NOT NULL,
    CREATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
    UPDATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_ADAPTORSCOPE
  ADD(CONSTRAINT PK_TB_ADAPTORSCOPE PRIMARY KEY(ADAPTORSCOPEID)
      USING INDEX
      TABLESPACE WFS_INDEX);

-- Create Table NodeDefinitionType

CREATE TABLE WPTB.TB_NODEDEFINITIONTYPE(
	NODEDEFINITIONTYPEID	NUMBER		NOT NULL,
	NAME			VARCHAR2(50)	NOT NULL,
    CREATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
    UPDATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_NODEDEFINITIONTYPE
  ADD(CONSTRAINT PK_TB_NODEDEFINITIONTYPE PRIMARY KEY(NODEDEFINITIONTYPEID)
      USING INDEX
      TABLESPACE WFS_INDEX);

-- Create Table Lock

CREATE TABLE WPTB.TB_LOCK(
	LOCKID		NUMBER		NOT NULL,
	OWNERID		VARCHAR2(50) 	NOT NULL,
	LOCKSTARTDATE	DATE		NOT NULL,
    CREATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
    UPDATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_LOCK
  ADD(CONSTRAINT PK_TB_LOCK PRIMARY KEY(LOCKID)
      USING INDEX
      TABLESPACE WFS_INDEX);

-- Create Table ProtectionKey

CREATE TABLE WPTB.TB_PROTECTIONKEY(
	PROTECTIONKEYID	NUMBER		NOT NULL,
	NAME		VARCHAR2(50)	NOT NULL,
    CREATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
    UPDATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_PROTECTIONKEY
  ADD(CONSTRAINT PK_TB_PROTECTIONKEY PRIMARY KEY(PROTECTIONKEYID)
      USING INDEX
      TABLESPACE WFS_INDEX);

ALTER TABLE WPTB.TB_PROTECTIONKEY
  ADD(CONSTRAINT UK_TB_PROTECTIONKEY UNIQUE(NAME));

-- Create Table ResourceType

CREATE TABLE WPTB.TB_RESOURCETYPE(
	RESOURCETYPEID			NUMBER 		NOT NULL,
	SYSTEMID			VARCHAR2(10)	NOT NULL UNIQUE,
	NAME				VARCHAR2(50)	NOT NULL,
	DESCRIPTION			VARCHAR2(256)	NULL,
	CONNECTIONTYPEID		NUMBER		NOT NULL,
	ADAPTORTYPEID			NUMBER 		NULL,
	ADAPTORSCOPEID			NUMBER		NULL,
	REQUIRESINITIALIZATION		NUMBER(1)	NOT NULL CHECK(REQUIRESINITIALIZATION in (0,1)),
	INITIALIZATIONSTRATEGYCLASS	VARCHAR2(256)	NULL,
	REQUIRESHEARTBEAT		NUMBER(1)	NOT NULL CHECK(REQUIRESHEARTBEAT in (0,1)),
	HEARTBEATSTRATEGYCLASS		VARCHAR2(256)	NULL,
	HEARTBEATCONNECTIONTYPEID	NUMBER		NULL,
	ADAPTORCLASSNAME		VARCHAR2(256)	NULL,
	MESSAGEIDENTIFICATIONCLASSNAME	VARCHAR2(256) NULL,
	DEFAULTPROTOCOL			VARCHAR2(50)	NULL,
	VERSION				NUMBER		NOT NULL,
	ISDIRTY				NUMBER(1)	NOT NULL CHECK(ISDIRTY in (0,1)),
        CREATEDATE     	 	        TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
        UPDATEDATE     		        TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
        MESSAGESEQUENCENUMBER		NUMBER		DEFAULT(0) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_RESOURCETYPE
  ADD(CONSTRAINT PK_TB_RESOURCETYPE PRIMARY KEY(RESOURCETYPEID)
      USING INDEX
      TABLESPACE WFS_INDEX);

ALTER TABLE WPTB.TB_RESOURCETYPE
	ADD(CONSTRAINT FK_RESOURCETYPE_CNNTYP1
	    FOREIGN KEY (CONNECTIONTYPEID) 
	    REFERENCES WPTB.TB_CONNECTIONTYPE(CONNECTIONTYPEID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE );

ALTER TABLE WPTB.TB_RESOURCETYPE
	ADD(CONSTRAINT FK_RESOURCETYPE_ADTTYP
	    FOREIGN KEY (ADAPTORTYPEID)
	    REFERENCES WPTB.TB_ADAPTORTYPE(ADAPTORTYPEID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

ALTER TABLE WPTB.TB_RESOURCETYPE
	ADD(CONSTRAINT FK_RESOURCETYPE_ADTSCP
	    FOREIGN KEY (ADAPTORSCOPEID)
	    REFERENCES WPTB.TB_ADAPTORTYPE(ADAPTORTYPEID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

ALTER TABLE WPTB.TB_RESOURCETYPE
	ADD(CONSTRAINT FK_RESOURCETYPE_CNNTYP2
	    FOREIGN KEY (HEARTBEATCONNECTIONTYPEID)
	    REFERENCES WPTB.TB_CONNECTIONTYPE(CONNECTIONTYPEID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

-- Create Table ResourceGroup

CREATE TABLE WPTB.TB_RESOURCEGROUP(
	RESOURCEGROUPID			NUMBER		NOT NULL,
	NAME				VARCHAR2(50)	NOT NULL,
	DESCRIPTION			VARCHAR2(256)	NULL,
	RESOURCETYPEID			NUMBER		NULL,
	FUNCTIONALTYPE			VARCHAR2(256)	NULL,
	ISINTERNALLYACQUIRED		NUMBER(1)	NOT NULL CHECK(ISINTERNALLYACQUIRED IN (0,1)),
	IMAGE				BLOB		NULL,
	PROTECTIONKEYID			NUMBER		NULL,
	VERSION				NUMBER		NOT NULL,
	ISDIRTY				NUMBER(1)	NOT NULL CHECK(ISDIRTY IN (0,1)),
	ALLOCATIONSTRATEGYCLASSNAME	VARCHAR2(100)	NULL,
        IMAGEFILENAME			VARCHAR2(150)	NULL,
        CREATEDATE     	                TIMESTAMP(6)    DEFAULT (SYSTIMESTAMP) NOT NULL,
        UPDATEDATE     	                TIMESTAMP(6)    DEFAULT (SYSTIMESTAMP) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_RESOURCEGROUP
  ADD(CONSTRAINT PK_TB_RESOURCEGROUP PRIMARY KEY(RESOURCEGROUPID)
      USING INDEX
      TABLESPACE WFS_INDEX);

ALTER TABLE WPTB.TB_RESOURCEGROUP
	ADD(CONSTRAINT FK_RESOURCEGROUP_RSRCTYP
	    FOREIGN KEY(RESOURCETYPEID)
	    REFERENCES WPTB.TB_RESOURCETYPE(RESOURCETYPEID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

ALTER TABLE WPTB.TB_RESOURCEGROUP
	ADD(CONSTRAINT FK_RESOURCEGROUP_PRTCKY
	    FOREIGN KEY(PROTECTIONKEYID)
	    REFERENCES WPTB.TB_PROTECTIONKEY(PROTECTIONKEYID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

-- Create Table Message

CREATE TABLE WPTB.TB_MESSAGE(
	MESSAGEID	NUMBER		NOT NULL,
	UID_		VARCHAR2(10)	NOT NULL UNIQUE,
	NAME		VARCHAR2(50)	NOT NULL,
	DESCRIPTION	VARCHAR2(256)	NULL,
	RESOURCETYPEID	NUMBER		NULL,
	ISINCOMMING	NUMBER(1)	NOT NULL CHECK(ISINCOMMING IN (0,1)),
	PROTOCOL	VARCHAR2(256)	NULL,
    CREATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
    UPDATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_MESSAGE
  ADD(CONSTRAINT PK_TB_MESSAGE PRIMARY KEY(MESSAGEID)
      USING INDEX
      TABLESPACE WFS_INDEX);

ALTER TABLE WPTB.TB_MESSAGE
	ADD(CONSTRAINT FK_MESSAGE_RSRCTYP
	    FOREIGN KEY(RESOURCETYPEID)
	    REFERENCES WPTB.TB_RESOURCETYPE(RESOURCETYPEID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

-- Create Table NodeDefinition

CREATE TABLE WPTB.TB_NODEDEFINITION(
	NODEDEFINITIONID	NUMBER		NOT NULL,
	NAME			VARCHAR2(50)	NOT NULL,
	NODEDEFINITIONTYPEID	NUMBER		NOT NULL,
	RESOURCETYPEID		NUMBER		NULL,
	XML			CLOB		NULL,
	GPDXML			CLOB		NULL,
	LOCKID		NUMBER		NULL,
    CREATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
    UPDATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_NODEDEFINITION
  ADD(CONSTRAINT PK_TB_NODEDEFINITION PRIMARY KEY(NODEDEFINITIONID)
      USING INDEX
      TABLESPACE WFS_INDEX);

ALTER TABLE WPTB.TB_NODEDEFINITION
	ADD(CONSTRAINT FK_NODEDEFINITION_NDDEFTYP
	    FOREIGN KEY(NODEDEFINITIONTYPEID)
	    REFERENCES WPTB.TB_NODEDEFINITIONTYPE(NODEDEFINITIONTYPEID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

ALTER TABLE WPTB.TB_NODEDEFINITION
	ADD(CONSTRAINT FK_NODEDEFINITION_RSRCTYP
	    FOREIGN KEY(RESOURCETYPEID)
	    REFERENCES WPTB.TB_RESOURCETYPE(RESOURCETYPEID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

ALTER TABLE WPTB.TB_NODEDEFINITION
	ADD(CONSTRAINT FK_NODEDEFINITION_LCK
	    FOREIGN KEY(LOCKID)
	    REFERENCES WPTB.TB_LOCK(LOCKID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

-- Create Table MessageNodeDefinitionNap

CREATE TABLE WPTB.TB_MESSAGENODEDEFINITIONMAP(
	MESSAGEID		NUMBER	NOT NULL,
	NODEDEFINITIONID	NUMBER 	NOT NULL,
    CREATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
    UPDATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_MESSAGENODEDEFINITIONMAP
  ADD(CONSTRAINT PK_TB_MESSAGENODEDEFINITIONMAP PRIMARY KEY(MESSAGEID, NODEDEFINITIONID)
      USING INDEX
      TABLESPACE WFS_INDEX);

ALTER TABLE WPTB.TB_MESSAGENODEDEFINITIONMAP
	ADD(CONSTRAINT FK_MSGNDDEFMP_MSG
	    FOREIGN KEY(MESSAGEID)
	    REFERENCES WPTB.TB_MESSAGE(MESSAGEID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

ALTER TABLE WPTB.TB_MESSAGENODEDEFINITIONMAP
	ADD(CONSTRAINT FK_MSGNDDEFMP_NDDEF
	    FOREIGN KEY(NODEDEFINITIONID)
	    REFERENCES WPTB.TB_NODEDEFINITION(NODEDEFINITIONID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

-- Create Table ResourceTypeParameter

CREATE TABLE WPTB.TB_RESOURCETYPEPARAMETER(
	RESOURCETYPEPARAMETERID NUMBER		NOT NULL,
        RESOURCETYPEID		NUMBER		NOT NULL,
	PARAMETERCLASS		VARCHAR2(50)	NOT NULL,
	PARAMETERNAME		VARCHAR2(50)	NOT NULL,
	VALUE			VARCHAR2(256)	NOT NULL,
    CREATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
    UPDATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_RESOURCETYPEPARAMETER
  ADD(CONSTRAINT PK_TB_RESOURCETYPEPARAMETER PRIMARY KEY(RESOURCETYPEPARAMETERID)
      USING INDEX
      TABLESPACE WFS_INDEX);

ALTER TABLE WPTB.TB_RESOURCETYPEPARAMETER
	ADD(CONSTRAINT FK_RSRCTYPPRMTR_RSRCTYP
	    FOREIGN KEY(RESOURCETYPEID)
	    REFERENCES WPTB.TB_RESOURCETYPE(RESOURCETYPEID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

CREATE UNIQUE INDEX WPTB.IDX_TB_RSRCTYPPRMTR_UK
  ON WPTB.TB_RESOURCETYPEPARAMETER(RESOURCETYPEID, PARAMETERCLASS, PARAMETERNAME)
  TABLESPACE WFS_INDEX;

-- Create Table Template

CREATE TABLE WPTB.TB_TEMPLATE(
	TEMPLATEID		NUMBER		NOT NULL,
	NAME			VARCHAR2(50)	NOT NULL,
	VERSION			NUMBER		NOT NULL,
	XML				CLOB		NULL,
	GPDXML			CLOB		NULL,
	ISDIRTY			NUMBER(1)	NOT NULL CHECK(ISDIRTY IN (0,1)),
	ISEXPORTABLE	NUMBER(1)	NOT NULL CHECK(ISEXPORTABLE IN (0,1)),
	LOCKID			NUMBER		NULL,
	ISACTIVE		NUMBER(1)	DEFAULT(1) NOT NULL CHECK(ISACTIVE IN (0,1)),
    CREATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
    UPDATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_TEMPLATE
  ADD(CONSTRAINT PKTB_TEMPLATE PRIMARY KEY(TEMPLATEID)
      USING INDEX
      TABLESPACE WFS_INDEX);

ALTER TABLE WPTB.TB_TEMPLATE
	ADD(CONSTRAINT FK_TEMPLATE_LOCK
	    FOREIGN KEY(LOCKID)
	    REFERENCES WPTB.TB_LOCK(LOCKID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

-- Create Table TemplateProtectionKeyMap

CREATE TABLE WPTB.TB_TEMPLATEPROTECTIONKEYMAP(
	PROTECTIONKEYID	NUMBER	NOT NULL,
	TEMPLATEID	NUMBER 	NOT NULL,
    CREATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
    UPDATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_TEMPLATEPROTECTIONKEYMAP
  ADD(CONSTRAINT PK_TB_TEMPLATEPROTECTIONKEYMAP PRIMARY KEY(PROTECTIONKEYID, TEMPLATEID)
      USING INDEX
      TABLESPACE WFS_INDEX);

ALTER TABLE WPTB.TB_TEMPLATEPROTECTIONKEYMAP
	ADD(CONSTRAINT FK_TMPPRTCKYMP_PRTCKY
	    FOREIGN KEY(PROTECTIONKEYID)
	    REFERENCES WPTB.TB_PROTECTIONKEY(PROTECTIONKEYID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

ALTER TABLE WPTB.TB_TEMPLATEPROTECTIONKEYMAP
	ADD(CONSTRAINT FK_TMPPRTCKYMP_TMP
	    FOREIGN KEY(TEMPLATEID)
	    REFERENCES WPTB.TB_TEMPLATE(TEMPLATEID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

-- Create Table ResourceGroupTemplateMap

CREATE TABLE WPTB.TB_RESOURCEGROUPTEMPLATEMAP(
	RESOURCEGROUPID	NUMBER	NOT NULL,
	TEMPLATEID	NUMBER 	NOT NULL,
    CREATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
    UPDATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_RESOURCEGROUPTEMPLATEMAP
  ADD(CONSTRAINT PK_TB_RESOURCEGROUPTEMPLATEMAP PRIMARY KEY(RESOURCEGROUPID, TEMPLATEID)
      USING INDEX
      TABLESPACE WFS_INDEX);

ALTER TABLE WPTB.TB_RESOURCEGROUPTEMPLATEMAP
	ADD(CONSTRAINT FK_RSRCGPTMPMP_RSRCGP
	    FOREIGN KEY(RESOURCEGROUPID)
	    REFERENCES WPTB.TB_RESOURCEGROUP(RESOURCEGROUPID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

ALTER TABLE WPTB.TB_RESOURCEGROUPTEMPLATEMAP
	ADD(CONSTRAINT FK_RSRCGPTMPMP_TMP
	    FOREIGN KEY(TEMPLATEID)
	    REFERENCES WPTB.TB_TEMPLATE(TEMPLATEID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

-- Create Table NodeDefinitionTemplateMap

CREATE TABLE WPTB.TB_NODEDEFINITIONTEMPLATEMAP(
	NODEDEFINITIONID	NUMBER	NOT NULL,
	TEMPLATEID		NUMBER 	NOT NULL,
    CREATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
    UPDATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_NODEDEFINITIONTEMPLATEMAP
  ADD(CONSTRAINT PK_TB_NDDFNTNTMPLTMP PRIMARY KEY(NODEDEFINITIONID, TEMPLATEID)
      USING INDEX
      TABLESPACE WFS_INDEX);

ALTER TABLE WPTB.TB_NODEDEFINITIONTEMPLATEMAP
	ADD(CONSTRAINT FK_NDDEFTMPMP_NDDEF
	    FOREIGN KEY(NODEDEFINITIONID)
	    REFERENCES WPTB.TB_NODEDEFINITION(NODEDEFINITIONID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

ALTER TABLE WPTB.TB_NODEDEFINITIONTEMPLATEMAP
	ADD(CONSTRAINT FK_NDDEFTMPMP_TMP
	    FOREIGN KEY(TEMPLATEID)
	    REFERENCES WPTB.TB_TEMPLATE(TEMPLATEID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

-- Create Table NodeDefinitionParentMap

CREATE TABLE WPTB.TB_NODEDEFINITIONPARENTMAP(
	NODEDEFINITIONID	NUMBER 	NOT NULL,
	NODEDEFINITIONPARENTID	NUMBER 	NOT NULL,
    CREATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL,
    UPDATEDATE     	TIMESTAMP(6) DEFAULT (SYSTIMESTAMP) NOT NULL)
TABLESPACE WFS_DATA
NOCACHE
MONITORING;

ALTER TABLE WPTB.TB_NODEDEFINITIONPARENTMAP
  ADD(CONSTRAINT PK_TB_NODEDEFINITIONPARENTMAP PRIMARY KEY(NODEDEFINITIONID, NODEDEFINITIONPARENTID)
      USING INDEX
      TABLESPACE WFS_INDEX);

ALTER TABLE WPTB.TB_NODEDEFINITIONPARENTMAP
	ADD(CONSTRAINT FK_NODEDEFINITIONPARENT_CHILD
	    FOREIGN KEY(NODEDEFINITIONID)
	    REFERENCES WPTB.TB_NODEDEFINITION(NODEDEFINITIONID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

ALTER TABLE WPTB.TB_NODEDEFINITIONPARENTMAP
	ADD(CONSTRAINT FK_NODEDEFINITIONPARENT_PARENT
	    FOREIGN KEY(NODEDEFINITIONPARENTID)
	    REFERENCES WPTB.TB_NODEDEFINITION(NODEDEFINITIONID)
	    NOT DEFERRABLE INITIALLY IMMEDIATE VALIDATE);

CREATE TRIGGER WPTB.TRG_TB_ADAPTORSCOPE_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_ADAPTORSCOPE
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                             END ;
/

CREATE TRIGGER WPTB.TRG_TB_ADAPTORTYPE_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_ADAPTORTYPE
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                            END;
/

CREATE TRIGGER WPTB.TRG_TB_CONNECTIONTYPE_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_CONNECTIONTYPE
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                            END;
/

CREATE TRIGGER WPTB.TRG_TB_LOCK_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_LOCK
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                             END;
/

CREATE TRIGGER WPTB.TRG_TB_MESSAGE_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_MESSAGE
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                             END;
/

CREATE TRIGGER WPTB.TRG_TB_MESSAGENODEDEFMAP_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_MESSAGENODEDEFINITIONMAP
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                             END;
/

CREATE TRIGGER WPTB.TRG_TB_NODEDEFINITION_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_NODEDEFINITION
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                             END;
/

CREATE TRIGGER WPTB.TRG_TB_NODEDEFPARENTMAP_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_NODEDEFINITIONPARENTMAP
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                             END;
/

CREATE TRIGGER WPTB.TRG_TB_NODEDEFTEMPLATEMAP_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_NODEDEFINITIONTEMPLATEMAP
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                             END;
/

CREATE TRIGGER WPTB.TRG_TB_NODEDEFINITIONTYPE_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_NODEDEFINITIONTYPE
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                             END;
/

CREATE TRIGGER WPTB.TRG_TB_PROTECTIONKEY_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_PROTECTIONKEY
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                             END;
/

CREATE TRIGGER WPTB.TRG_TB_RESOURCEGROUP_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_RESOURCEGROUP
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                             END;
/

CREATE TRIGGER WPTB.TRG_TB_RESGROUPTEMPLATEMAP_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_RESOURCEGROUPTEMPLATEMAP
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                             END;
/

CREATE TRIGGER WPTB.TRG_TB_RESOURCETYPE_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_RESOURCETYPE
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                             END;
/

CREATE TRIGGER WPTB.TRG_TB_RESTYPEPARAMETER_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_RESOURCETYPEPARAMETER
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                             END;
/

CREATE TRIGGER WPTB.TRG_TB_TEMPLATE_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_TEMPLATE
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                             END;
/

CREATE TRIGGER WPTB.TRG_TB_TEMPLATEPROTKEYMAP_UPD
                            BEFORE UPDATE
                            ON WPTB.TB_TEMPLATEPROTECTIONKEYMAP
                            FOR EACH ROW
                            DECLARE updatedate      date;
                            BEGIN
                            SELECT  SYSTIMESTAMP
                            INTO    updatedate
                            FROM    DUAL;
                            :NEW.UpdateDate := updatedate;
                            END;
/

CREATE SEQUENCE WPTB.TB_RESOURCETYPEPARAMETER_SEQ
    INCREMENT BY 1
    START WITH 1;

CREATE SEQUENCE WPTB.TB_RESOURCETYPE_SEQ
    INCREMENT BY 1
    START WITH 1;

CREATE SEQUENCE WPTB.TB_MESSAGE_SEQ
    INCREMENT BY 1
    START WITH 1;

CREATE SEQUENCE WPTB.TB_NODEDEFINITION_SEQ
    INCREMENT BY 1
    START WITH 1;

CREATE SEQUENCE WPTB.TB_LOCK_SEQ
    INCREMENT BY 1
    START WITH 1;

CREATE SEQUENCE WPTB.TB_TEMPLATE_SEQ
    INCREMENT BY 1
    START WITH 1;

CREATE SEQUENCE WPTB.TB_PROTECTIONKEY_SEQ
    INCREMENT BY 1
    START WITH 1;

CREATE SEQUENCE WPTB.TB_RESOURCEGROUP_SEQ
    INCREMENT BY 1
    START WITH 1;
