
-----------------------------------------------------------------------------
-- 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)
);

ALTER TABLE PORTLET_DEFINITION
    ADD 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),
    UNIQUE (APP_NAME)
);

ALTER TABLE PORTLET_APPLICATION
    ADD PRIMARY KEY (APPLICATION_ID) ;



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

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

ALTER TABLE WEB_APPLICATION
    ADD PRIMARY KEY (ID) ;



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

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

ALTER TABLE PA_METADATA_FIELDS
    ADD PRIMARY KEY (ID) ;



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

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

ALTER TABLE PD_METADATA_FIELDS
    ADD 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 LONG VARCHAR
);

ALTER TABLE LANGUAGE
    ADD 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 LONG VARCHAR
);

ALTER TABLE PORTLET_CONTENT_TYPE
    ADD 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 LONG VARCHAR NOT NULL
);

ALTER TABLE PARAMETER
    ADD 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,
    UNIQUE (ID)
);

ALTER TABLE PORTLET_ENTITY
    ADD PRIMARY KEY (PEID) ;



-----------------------------------------------------------------------------
-- 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)
);

ALTER TABLE SECURITY_ROLE_REFERENCE
    ADD 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)
);

ALTER TABLE SECURITY_ROLE
    ADD 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)
);

ALTER TABLE USER_ATTRIBUTE_REF
    ADD PRIMARY KEY (ID) ;



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

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

ALTER TABLE USER_ATTRIBUTE
    ADD PRIMARY KEY (ID) ;



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

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

ALTER TABLE JETSPEED_SERVICE
    ADD 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 LONG VARCHAR NOT NULL,
    LOCALE_STRING VARCHAR(50) NOT NULL
);

ALTER TABLE LOCALIZED_DESCRIPTION
    ADD 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 LONG VARCHAR NOT NULL,
    LOCALE_STRING VARCHAR(50) NOT NULL
);

ALTER TABLE LOCALIZED_DISPLAY_NAME
    ADD 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 LONG VARCHAR
);

ALTER TABLE CUSTOM_PORTLET_MODE
    ADD 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 LONG VARCHAR
);

ALTER TABLE CUSTOM_WINDOW_STATE
    ADD PRIMARY KEY (ID) ;





ALTER TABLE PA_METADATA_FIELDS
    FOREIGN KEY FK_PA_METADATA_FIELDS_1 (OBJECT_ID)
    REFERENCES PORTLET_APPLICATION (APPLICATION_ID)
;


ALTER TABLE PD_METADATA_FIELDS
    FOREIGN KEY FK_PD_METADATA_FIELDS_1 (OBJECT_ID)
    REFERENCES PORTLET_DEFINITION (ID)
;








ALTER TABLE USER_ATTRIBUTE_REF
    FOREIGN KEY FK_USER_ATTRIBUTE_REF_1 (APPLICATION_ID)
    REFERENCES PORTLET_APPLICATION (APPLICATION_ID)
;


ALTER TABLE USER_ATTRIBUTE
    FOREIGN KEY FK_USER_ATTRIBUTE_1 (APPLICATION_ID)
    REFERENCES PORTLET_APPLICATION (APPLICATION_ID)
;





ALTER TABLE CUSTOM_PORTLET_MODE
    FOREIGN KEY FK_CUSTOM_PORTLET_MODE_1 (APPLICATION_ID)
    REFERENCES PORTLET_APPLICATION (APPLICATION_ID)
;


ALTER TABLE CUSTOM_WINDOW_STATE
    FOREIGN KEY FK_CUSTOM_WINDOW_STATE_1 (APPLICATION_ID)
    REFERENCES PORTLET_APPLICATION (APPLICATION_ID)
;


