
-----------------------------------------------------------------------------
-- PORTLET_DEFINITION
-----------------------------------------------------------------------------



CREATE TABLE PORTLET_DEFINITION
(
    ID INTEGER NOT NULL,
    NAME VARCHAR(80),
    CLASS_NAME VARCHAR(255),
    APPLICATION_ID INTEGER NOT NULL,
    PORTLET_IDENTIFIER VARCHAR(80),
    EXPIRATION_CACHE VARCHAR(30),
    RESOURCE_BUNDLE VARCHAR(255),
    PREFERENCE_VALIDATOR VARCHAR(255),
    SECURITY_REF VARCHAR(40),
    PRIMARY KEY (ID)
);




-----------------------------------------------------------------------------
-- PORTLET_APPLICATION
-----------------------------------------------------------------------------



CREATE TABLE PORTLET_APPLICATION
(
    APPLICATION_ID INTEGER NOT NULL,
    APP_NAME VARCHAR(80) NOT NULL,
    APP_IDENTIFIER VARCHAR(80),
    VERSION VARCHAR(80),
    APP_TYPE INTEGER,
    CHECKSUM VARCHAR(80),
    DESCRIPTION VARCHAR(80),
    WEB_APP_ID INTEGER NOT NULL,
    SECURITY_REF VARCHAR(40),
    PRIMARY KEY (APPLICATION_ID),
    CONSTRAINT UK_APPLICATION UNIQUE (APP_NAME)
);




-----------------------------------------------------------------------------
-- WEB_APPLICATION
-----------------------------------------------------------------------------



CREATE TABLE WEB_APPLICATION
(
    ID INTEGER NOT NULL,
    CONTEXT_ROOT VARCHAR(255) NOT NULL,
    PRIMARY KEY (ID)
);




-----------------------------------------------------------------------------
-- PA_METADATA_FIELDS
-----------------------------------------------------------------------------



CREATE TABLE PA_METADATA_FIELDS
(
    ID INTEGER NOT NULL,
    OBJECT_ID INTEGER NOT NULL,
    COLUMN_VALUE TEXT NOT NULL,
    NAME VARCHAR(100) NOT NULL,
    LOCALE_STRING VARCHAR(50) NOT NULL,
    PRIMARY KEY (ID)
);




-----------------------------------------------------------------------------
-- PD_METADATA_FIELDS
-----------------------------------------------------------------------------



CREATE TABLE PD_METADATA_FIELDS
(
    ID INTEGER NOT NULL,
    OBJECT_ID INTEGER NOT NULL,
    COLUMN_VALUE TEXT NOT NULL,
    NAME VARCHAR(100) NOT NULL,
    LOCALE_STRING VARCHAR(50) NOT NULL,
    PRIMARY KEY (ID)
);




-----------------------------------------------------------------------------
-- LANGUAGE
-----------------------------------------------------------------------------



CREATE TABLE LANGUAGE
(
    ID INTEGER NOT NULL,
    PORTLET_ID INTEGER NOT NULL,
    TITLE VARCHAR(100),
    SHORT_TITLE VARCHAR(100),
    LOCALE_STRING VARCHAR(50) NOT NULL,
    KEYWORDS TEXT,
    PRIMARY KEY (ID)
);




-----------------------------------------------------------------------------
-- PORTLET_CONTENT_TYPE
-----------------------------------------------------------------------------



CREATE TABLE PORTLET_CONTENT_TYPE
(
    CONTENT_TYPE_ID INTEGER NOT NULL,
    PORTLET_ID INTEGER NOT NULL,
    CONTENT_TYPE VARCHAR(30) NOT NULL,
    MODES TEXT,
    PRIMARY KEY (CONTENT_TYPE_ID)
);




-----------------------------------------------------------------------------
-- PARAMETER
-----------------------------------------------------------------------------



CREATE TABLE PARAMETER
(
    PARAMETER_ID INTEGER NOT NULL,
    PARENT_ID INTEGER NOT NULL,
    CLASS_NAME VARCHAR(255) NOT NULL,
    NAME VARCHAR(80) NOT NULL,
    PARAMETER_VALUE TEXT NOT NULL,
    PRIMARY KEY (PARAMETER_ID)
);




-----------------------------------------------------------------------------
-- PORTLET_ENTITY
-----------------------------------------------------------------------------



CREATE TABLE PORTLET_ENTITY
(
    PEID INTEGER NOT NULL,
    ID VARCHAR(255) NOT NULL,
    APP_NAME VARCHAR(255) NOT NULL,
    PORTLET_NAME VARCHAR(255) NOT NULL,
    PRIMARY KEY (PEID),
    CONSTRAINT UK_ENTITY_ID UNIQUE (ID)
);




-----------------------------------------------------------------------------
-- SECURITY_ROLE_REFERENCE
-----------------------------------------------------------------------------



CREATE TABLE SECURITY_ROLE_REFERENCE
(
    ID INTEGER NOT NULL,
    PORTLET_DEFINITION_ID INTEGER NOT NULL,
    ROLE_NAME VARCHAR(150) NOT NULL,
    ROLE_LINK VARCHAR(150),
    PRIMARY KEY (ID)
);




-----------------------------------------------------------------------------
-- SECURITY_ROLE
-----------------------------------------------------------------------------



CREATE TABLE SECURITY_ROLE
(
    ID INTEGER NOT NULL,
    WEB_APPLICATION_ID INTEGER NOT NULL,
    ROLE_NAME VARCHAR(150) NOT NULL,
    DESCRIPTION VARCHAR(150),
    PRIMARY KEY (ID)
);




-----------------------------------------------------------------------------
-- USER_ATTRIBUTE_REF
-----------------------------------------------------------------------------



CREATE TABLE USER_ATTRIBUTE_REF
(
    ID INTEGER NOT NULL,
    APPLICATION_ID INTEGER NOT NULL,
    NAME VARCHAR(150),
    NAME_LINK VARCHAR(150),
    PRIMARY KEY (ID)
);




-----------------------------------------------------------------------------
-- USER_ATTRIBUTE
-----------------------------------------------------------------------------



CREATE TABLE USER_ATTRIBUTE
(
    ID INTEGER NOT NULL,
    APPLICATION_ID INTEGER NOT NULL,
    NAME VARCHAR(150),
    DESCRIPTION VARCHAR(150),
    PRIMARY KEY (ID)
);




-----------------------------------------------------------------------------
-- JETSPEED_SERVICE
-----------------------------------------------------------------------------



CREATE TABLE JETSPEED_SERVICE
(
    ID INTEGER NOT NULL,
    APPLICATION_ID INTEGER NOT NULL,
    NAME VARCHAR(150),
    PRIMARY KEY (ID)
);




-----------------------------------------------------------------------------
-- LOCALIZED_DESCRIPTION
-----------------------------------------------------------------------------



CREATE TABLE LOCALIZED_DESCRIPTION
(
    ID INTEGER NOT NULL,
    OBJECT_ID INTEGER NOT NULL,
    CLASS_NAME VARCHAR(255) NOT NULL,
    DESCRIPTION TEXT NOT NULL,
    LOCALE_STRING VARCHAR(50) NOT NULL,
    PRIMARY KEY (ID)
);




-----------------------------------------------------------------------------
-- LOCALIZED_DISPLAY_NAME
-----------------------------------------------------------------------------



CREATE TABLE LOCALIZED_DISPLAY_NAME
(
    ID INTEGER NOT NULL,
    OBJECT_ID INTEGER NOT NULL,
    CLASS_NAME VARCHAR(255),
    DISPLAY_NAME TEXT NOT NULL,
    LOCALE_STRING VARCHAR(50) NOT NULL,
    PRIMARY KEY (ID)
);




-----------------------------------------------------------------------------
-- CUSTOM_PORTLET_MODE
-----------------------------------------------------------------------------



CREATE TABLE CUSTOM_PORTLET_MODE
(
    ID INTEGER NOT NULL,
    APPLICATION_ID INTEGER NOT NULL,
    CUSTOM_NAME VARCHAR(150) NOT NULL,
    MAPPED_NAME VARCHAR(150),
    DESCRIPTION TEXT,
    PRIMARY KEY (ID)
);




-----------------------------------------------------------------------------
-- CUSTOM_WINDOW_STATE
-----------------------------------------------------------------------------



CREATE TABLE CUSTOM_WINDOW_STATE
(
    ID INTEGER NOT NULL,
    APPLICATION_ID INTEGER NOT NULL,
    CUSTOM_NAME VARCHAR(150) NOT NULL,
    MAPPED_NAME VARCHAR(150),
    DESCRIPTION TEXT,
    PRIMARY KEY (ID)
);




----------------------------------------------------------------------
-- CUSTOM_WINDOW_STATE                                                      
----------------------------------------------------------------------


----------------------------------------------------------------------
-- PORTLET_DEFINITION                                                      
----------------------------------------------------------------------


----------------------------------------------------------------------
-- PORTLET_APPLICATION                                                      
----------------------------------------------------------------------


----------------------------------------------------------------------
-- WEB_APPLICATION                                                      
----------------------------------------------------------------------

ALTER TABLE PA_METADATA_FIELDS
    ADD CONSTRAINT FK_PA_METADATA_FIELDS_1 FOREIGN KEY (OBJECT_ID)
    REFERENCES PORTLET_APPLICATION (APPLICATION_ID)
    ON DELETE CASCADE 
;

----------------------------------------------------------------------
-- PA_METADATA_FIELDS                                                      
----------------------------------------------------------------------

ALTER TABLE PD_METADATA_FIELDS
    ADD CONSTRAINT FK_PD_METADATA_FIELDS_1 FOREIGN KEY (OBJECT_ID)
    REFERENCES PORTLET_DEFINITION (ID)
    ON DELETE CASCADE 
;

----------------------------------------------------------------------
-- PD_METADATA_FIELDS                                                      
----------------------------------------------------------------------


----------------------------------------------------------------------
-- LANGUAGE                                                      
----------------------------------------------------------------------


----------------------------------------------------------------------
-- PORTLET_CONTENT_TYPE                                                      
----------------------------------------------------------------------


----------------------------------------------------------------------
-- PARAMETER                                                      
----------------------------------------------------------------------


----------------------------------------------------------------------
-- PORTLET_ENTITY                                                      
----------------------------------------------------------------------


----------------------------------------------------------------------
-- SECURITY_ROLE_REFERENCE                                                      
----------------------------------------------------------------------


----------------------------------------------------------------------
-- SECURITY_ROLE                                                      
----------------------------------------------------------------------

ALTER TABLE USER_ATTRIBUTE_REF
    ADD CONSTRAINT FK_USER_ATTRIBUTE_REF_1 FOREIGN KEY (APPLICATION_ID)
    REFERENCES PORTLET_APPLICATION (APPLICATION_ID)
    ON DELETE CASCADE 
;

----------------------------------------------------------------------
-- USER_ATTRIBUTE_REF                                                      
----------------------------------------------------------------------

ALTER TABLE USER_ATTRIBUTE
    ADD CONSTRAINT FK_USER_ATTRIBUTE_1 FOREIGN KEY (APPLICATION_ID)
    REFERENCES PORTLET_APPLICATION (APPLICATION_ID)
    ON DELETE CASCADE 
;

----------------------------------------------------------------------
-- USER_ATTRIBUTE                                                      
----------------------------------------------------------------------


----------------------------------------------------------------------
-- JETSPEED_SERVICE                                                      
----------------------------------------------------------------------


----------------------------------------------------------------------
-- LOCALIZED_DESCRIPTION                                                      
----------------------------------------------------------------------


----------------------------------------------------------------------
-- LOCALIZED_DISPLAY_NAME                                                      
----------------------------------------------------------------------

ALTER TABLE CUSTOM_PORTLET_MODE
    ADD CONSTRAINT FK_CUSTOM_PORTLET_MODE_1 FOREIGN KEY (APPLICATION_ID)
    REFERENCES PORTLET_APPLICATION (APPLICATION_ID)
    ON DELETE CASCADE 
;

----------------------------------------------------------------------
-- CUSTOM_PORTLET_MODE                                                      
----------------------------------------------------------------------

ALTER TABLE CUSTOM_WINDOW_STATE
    ADD CONSTRAINT FK_CUSTOM_WINDOW_STATE_1 FOREIGN KEY (APPLICATION_ID)
    REFERENCES PORTLET_APPLICATION (APPLICATION_ID)
    ON DELETE CASCADE 
;
