DROP TABLE BPEL_ACTIVITY_RECOVERY;
DROP TABLE BPEL_CORRELATION_PROP;
DROP TABLE BPEL_CORRELATION_SET;
DROP TABLE BPEL_CORRELATOR;
DROP TABLE BPEL_CORRELATOR_MESSAGE_CKEY;
DROP TABLE BPEL_EVENT;
DROP TABLE BPEL_FAULT;
DROP TABLE BPEL_INSTANCE;
DROP TABLE BPEL_MESSAGE;
DROP TABLE BPEL_MESSAGE_EXCHANGE;
DROP TABLE BPEL_MEX_PROPS;
DROP TABLE BPEL_PLINK_VAL;
DROP TABLE BPEL_PROCESS;
DROP TABLE BPEL_PROCESS_CONF;
DROP TABLE BPEL_PROCESS_PROPERTY;
DROP TABLE BPEL_SCOPE;
DROP TABLE BPEL_SELECTORS;
DROP TABLE BPEL_UNMATCHED;
DROP TABLE BPEL_XML_DATA;
DROP TABLE LARGE_DATA;
DROP TABLE VAR_PROPERTY;
DROP generator hibernate_sequence;

COMMIT;

create table BPEL_ACTIVITY_RECOVERY (ID numeric(18,0) not null, PIID numeric(18,0), AID numeric(18,0), CHANNEL varchar(255), REASON varchar(255), DATE_TIME timestamp, LDATA_ID numeric(18,0), ACTIONS varchar(255), RETRIES integer, INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
create table BPEL_CORRELATION_PROP (ID numeric(18,0) not null, NAME varchar(255), NAMESPACE varchar(255), "VALUE" varchar(255), CORR_SET_ID numeric(18,0), INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
create table BPEL_CORRELATION_SET (ID numeric(18,0) not null, "VALUE" varchar(255), CORR_SET_NAME varchar(255), SCOPE_ID numeric(18,0), PIID numeric(18,0), PROCESS_ID numeric(18,0), INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
create table BPEL_CORRELATOR (ID numeric(18,0) not null, CID varchar(255), PROCESS_ID numeric(18,0), INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
create table BPEL_CORRELATOR_MESSAGE_CKEY (ID numeric(18,0) not null, CKEY varchar(255), CORRELATOR_MESSAGE_ID numeric(18,0), INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
create table BPEL_EVENT (ID numeric(18,0) not null, IID numeric(18,0), PID numeric(18,0), TSTAMP timestamp, TYPE varchar(255), DETAIL blob sub_type 1, LDATA_ID numeric(18,0), SID numeric(18,0), INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
create table BPEL_FAULT (ID numeric(18,0) not null, FAULTNAME varchar(255), LDATA_ID numeric(18,0), EXPLANATION varchar(255), LINENO integer, AID integer, INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
create table BPEL_INSTANCE (ID numeric(18,0) not null, INSTANTIATING_CORRELATOR numeric(18,0), FAULT numeric(18,0), JACOB_STATE numeric(18,0), PREVIOUS_STATE smallint, PROCESS_ID numeric(18,0), STATE smallint, LAST_ACTIVE_DT timestamp, SEQUENCE numeric(18,0), FAILURE_COUNT integer, FAILURE_DT timestamp, INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
create table BPEL_MESSAGE (ID numeric(18,0) not null, MEX numeric(18,0), TYPE varchar(255), DATA numeric(18,0), INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
create table BPEL_MESSAGE_EXCHANGE (ID numeric(18,0) not null, PORT_TYPE varchar(255), CHANNEL_NAME varchar(255), CLIENTKEY varchar(255), LDATA_EPR_ID numeric(18,0), LDATA_CEPR_ID numeric(18,0), REQUEST numeric(18,0), RESPONSE numeric(18,0), INSERT_DT timestamp, OPERATION varchar(255), STATE varchar(255), PROCESS numeric(18,0), PIID numeric(18,0), DIR char(1), PLINK_MODELID integer, PATTERN varchar(255), CORR_STATUS varchar(255), FAULT_TYPE varchar(255), FAULT_EXPL varchar(255), CALLEE varchar(255), PARTNERLINK numeric(18,0), INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
create table BPEL_MEX_PROPS (MEX numeric(18,0) not null, "VALUE" varchar(8000), NAME varchar(255) not null, primary key (MEX, NAME));
create table BPEL_PLINK_VAL (ID numeric(18,0) not null, PARTNER_LINK varchar(100) not null, PARTNERROLE varchar(100), MYROLE_EPR numeric(18,0), PARTNERROLE_EPR numeric(18,0), PROCESS numeric(18,0), SCOPE numeric(18,0), SVCNAME varchar(255), MYROLE varchar(100), MODELID integer, MYSESSIONID varchar(255), PARTNERSESSIONID varchar(255), INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
create table BPEL_PROCESS (ID numeric(18,0) not null, PROCID varchar(255) not null unique, deployer varchar(255), deploydate timestamp, type_name varchar(255), type_ns varchar(255), version integer, RETIRED smallint, "ACTIVE" smallint, INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
create table BPEL_PROCESS_CONF (ID numeric(18,0) not null, PROCID varchar(255) not null unique, deployer varchar(255), deploydate timestamp, type_name varchar(255), type_ns varchar(255), version integer, "ACTIVE" smallint, primary key (ID));
create table BPEL_PROCESS_PROPERTY (ID numeric(18,0) not null, PROPNAME varchar(255), PROPNS varchar(255), SIMPLE_CNT varchar(255), MIXED_CNT blob sub_type 1, PROCESS_ID numeric(18,0), primary key (ID));
create table BPEL_SCOPE (ID numeric(18,0) not null, PIID numeric(18,0), PARENT_SCOPE_ID numeric(18,0), STATE varchar(255) not null, NAME varchar(255) not null, MODELID integer, INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
create table BPEL_SELECTORS (ID numeric(18,0) not null, PIID numeric(18,0) not null, SELGRPID varchar(255) not null, IDX integer not null, CORRELATION_KEY varchar(255) not null, CORRELATOR numeric(18,0) not null, INSERT_TIME timestamp, MLOCK integer not null, primary key (ID), unique (CORRELATION_KEY, CORRELATOR));
create table BPEL_UNMATCHED (ID numeric(18,0) not null, MEX numeric(18,0) not null, CORRELATION_KEY varchar(255), CORRELATOR numeric(18,0) not null, INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
create table BPEL_XML_DATA (ID numeric(18,0) not null, LDATA_ID numeric(18,0), NAME varchar(255) not null, SCOPE_ID numeric(18,0), PIID numeric(18,0), IS_SIMPLE_TYPE smallint, INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
create table LARGE_DATA (ID numeric(18,0) not null, BIN_DATA blob, INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
create table VAR_PROPERTY (ID numeric(18,0) not null, XML_DATA_ID numeric(18,0), PROP_VALUE varchar(255), PROP_NAME varchar(255) not null, INSERT_TIME timestamp, MLOCK integer not null, primary key (ID));
-- alter table BPEL_ACTIVITY_RECOVERY add constraint FK94D24A7BEBD59315 foreign key (LDATA_ID) references LARGE_DATA;
-- alter table BPEL_ACTIVITY_RECOVERY add constraint FK94D24A7BA821BBE1 foreign key (PIID) references BPEL_INSTANCE;
-- alter table BPEL_CORRELATION_PROP add constraint FK4EC9DDAA4D0B7982 foreign key (CORR_SET_ID) references BPEL_CORRELATION_SET;
-- alter table BPEL_CORRELATION_SET add constraint FKB838191BA821BBE1 foreign key (PIID) references BPEL_INSTANCE;
-- alter table BPEL_CORRELATION_SET add constraint FKB838191B6D49C363 foreign key (SCOPE_ID) references BPEL_SCOPE;
-- alter table BPEL_CORRELATION_SET add constraint FKB838191BE15A2343 foreign key (PROCESS_ID) references BPEL_PROCESS;
create index IDX_CORRELATOR_CID on BPEL_CORRELATOR (CID);
-- alter table BPEL_CORRELATOR add constraint FKF50EFA33E15A2343 foreign key (PROCESS_ID) references BPEL_PROCESS;
create index IDX_BPEL_CORRTOR_MESSAGE_CKEY on BPEL_CORRELATOR_MESSAGE_CKEY (CKEY);
-- alter table BPEL_CORRELATOR_MESSAGE_CKEY add constraint FK8997F700EEFA7470 foreign key (CORRELATOR_MESSAGE_ID) references BPEL_UNMATCHED;
-- alter table BPEL_EVENT add constraint FKAA6D6730EBD59315 foreign key (LDATA_ID) references LARGE_DATA;
-- alter table BPEL_EVENT add constraint FKAA6D6730A7EED251 foreign key (IID) references BPEL_INSTANCE;
-- alter table BPEL_EVENT add constraint FKAA6D6730C831CBE3 foreign key (PID) references BPEL_PROCESS;
-- alter table BPEL_FAULT add constraint FKAA722EB8EBD59315 foreign key (LDATA_ID) references LARGE_DATA;
-- alter table BPEL_INSTANCE add constraint FKE1DED41FDD43DBE1 foreign key (INSTANTIATING_CORRELATOR) references BPEL_CORRELATOR;
-- alter table BPEL_INSTANCE add constraint FKE1DED41F433A5462 foreign key (JACOB_STATE) references LARGE_DATA;
-- alter table BPEL_INSTANCE add constraint FKE1DED41F1F3C9CB7 foreign key (FAULT) references BPEL_FAULT;
-- alter table BPEL_INSTANCE add constraint FKE1DED41FE15A2343 foreign key (PROCESS_ID) references BPEL_PROCESS;
-- alter table BPEL_MESSAGE add constraint FK4FA7231DCA00A413 foreign key (MEX) references BPEL_MESSAGE_EXCHANGE;
-- alter table BPEL_MESSAGE add constraint FK4FA7231DC3002ADB foreign key (DATA) references LARGE_DATA;
-- alter table BPEL_MESSAGE_EXCHANGE add constraint FKBDA6BD0561AB335E foreign key (LDATA_CEPR_ID) references LARGE_DATA;
-- alter table BPEL_MESSAGE_EXCHANGE add constraint FKBDA6BD05BBA250D foreign key (PARTNERLINK) references BPEL_PLINK_VAL;
-- alter table BPEL_MESSAGE_EXCHANGE add constraint FKBDA6BD05A821BBE1 foreign key (PIID) references BPEL_INSTANCE;
-- alter table BPEL_MESSAGE_EXCHANGE add constraint FKBDA6BD059A69FCAD foreign key (LDATA_EPR_ID) references LARGE_DATA;
-- alter table BPEL_MESSAGE_EXCHANGE add constraint FKBDA6BD05B5BD38C7 foreign key (PROCESS) references BPEL_PROCESS;
-- alter table BPEL_MESSAGE_EXCHANGE add constraint FKBDA6BD05FF451031 foreign key (RESPONSE) references BPEL_MESSAGE;
-- alter table BPEL_MESSAGE_EXCHANGE add constraint FKBDA6BD0554DCEE7F foreign key (REQUEST) references BPEL_MESSAGE;
-- alter table BPEL_MEX_PROPS add constraint FK203CAFC7CA00A413 foreign key (MEX) references BPEL_MESSAGE_EXCHANGE;
-- alter table BPEL_PLINK_VAL add constraint FK7D71E742CA8FEABB foreign key (MYROLE_EPR) references LARGE_DATA;
-- alter table BPEL_PLINK_VAL add constraint FK7D71E74290D95ED1 foreign key (SCOPE) references BPEL_SCOPE;
-- alter table BPEL_PLINK_VAL add constraint FK7D71E742B5BD38C7 foreign key (PROCESS) references BPEL_PROCESS;
-- alter table BPEL_PLINK_VAL add constraint FK7D71E742AC89DDD7 foreign key (PARTNERROLE_EPR) references LARGE_DATA;
-- alter table BPEL_PROCESS_PROPERTY add constraint FK4690A34F5F2D4DD4 foreign key (PROCESS_ID) references BPEL_PROCESS_CONF;
-- alter table BPEL_SCOPE add constraint FKAB2A32EAA821BBE1 foreign key (PIID) references BPEL_INSTANCE;
-- alter table BPEL_SCOPE add constraint FKAB2A32EA42B20B58 foreign key (PARENT_SCOPE_ID) references BPEL_SCOPE;
create index IDX_SELECTOR_CORRELATOR on BPEL_SELECTORS (CORRELATOR);
create index IDX_SELECTOR_CKEY on BPEL_SELECTORS (CORRELATION_KEY);
create index IDX_SELECTOR_SELGRPID on BPEL_SELECTORS (SELGRPID);
-- alter table BPEL_SELECTORS add constraint FKF1F83A0AA821BBE1 foreign key (PIID) references BPEL_INSTANCE;
-- alter table BPEL_SELECTORS add constraint FKF1F83A0A875201C9 foreign key (CORRELATOR) references BPEL_CORRELATOR;
create index IDX_UNMATCHED_CKEY on BPEL_UNMATCHED (CORRELATION_KEY);
create index IDX_UNMATCHED_CORRELATOR on BPEL_UNMATCHED (CORRELATOR);
-- alter table BPEL_UNMATCHED add constraint FKF0663E01CA00A413 foreign key (MEX) references BPEL_MESSAGE_EXCHANGE;
-- alter table BPEL_UNMATCHED add constraint FKF0663E01875201C9 foreign key (CORRELATOR) references BPEL_CORRELATOR;
-- alter table BPEL_XML_DATA add constraint FKB7D47E7CEBD59315 foreign key (LDATA_ID) references LARGE_DATA;
-- alter table BPEL_XML_DATA add constraint FKB7D47E7CA821BBE1 foreign key (PIID) references BPEL_INSTANCE;
-- alter table BPEL_XML_DATA add constraint FKB7D47E7C6D49C363 foreign key (SCOPE_ID) references BPEL_SCOPE;
-- alter table VAR_PROPERTY add constraint FK9C1E2C0DA48E25F2 foreign key (XML_DATA_ID) references BPEL_XML_DATA;
create generator hibernate_sequence;

COMMIT;

-- Firebird DB script submitted by Leonardo Alves

DROP TABLE QRTZ_JOB_LISTENERS;
DROP TABLE QRTZ_TRIGGER_LISTENERS;
DROP TABLE QRTZ_FIRED_TRIGGERS;
DROP TABLE QRTZ_PAUSED_TRIGGER_GRPS;
DROP TABLE QRTZ_SCHEDULER_STATE;
DROP TABLE QRTZ_LOCKS;
DROP TABLE QRTZ_SIMPLE_TRIGGERS;
DROP TABLE QRTZ_CRON_TRIGGERS;
DROP TABLE QRTZ_BLOB_TRIGGERS;
DROP TABLE QRTZ_TRIGGERS;
DROP TABLE QRTZ_JOB_DETAILS;
DROP TABLE QRTZ_CALENDARS;

COMMIT;

CREATE TABLE QRTZ_JOB_DETAILS (
    JOB_NAME VARCHAR(60) NOT NULL,
    JOB_GROUP VARCHAR(60) NOT NULL,
    DESCRIPTION VARCHAR(120),
    JOB_CLASS_NAME VARCHAR(128) NOT NULL,
    IS_DURABLE VARCHAR(1) NOT NULL,
    IS_VOLATILE VARCHAR(1) NOT NULL,
    IS_STATEFUL VARCHAR(1) NOT NULL,
    REQUESTS_RECOVERY VARCHAR(1) NOT NULL,
    JOB_DATA BLOB,
    CONSTRAINT PK_QRTZ_JOB_DETAILS PRIMARY KEY (JOB_NAME,JOB_GROUP)
);

CREATE TABLE QRTZ_JOB_LISTENERS (
    JOB_NAME VARCHAR(60) NOT NULL,
    JOB_GROUP VARCHAR(60) NOT NULL,
    JOB_LISTENER VARCHAR(60) NOT NULL,
    CONSTRAINT PK_QRTZ_JOB_LST PRIMARY KEY (JOB_NAME,JOB_GROUP,JOB_LISTENER),
    CONSTRAINT FK_QRTZ_JOB_LST_1 FOREIGN KEY (JOB_NAME,JOB_GROUP)
    REFERENCES QRTZ_JOB_DETAILS(JOB_NAME,JOB_GROUP)
);

CREATE TABLE QRTZ_TRIGGERS (
    TRIGGER_NAME VARCHAR(60) NOT NULL,
    TRIGGER_GROUP VARCHAR(60) NOT NULL,
    JOB_NAME VARCHAR(60) NOT NULL,
    JOB_GROUP VARCHAR(60) NOT NULL,
    IS_VOLATILE VARCHAR(1) NOT NULL,
    DESCRIPTION VARCHAR(120),
    NEXT_FIRE_TIME BIGINT,
    PREV_FIRE_TIME BIGINT,
    TRIGGER_STATE VARCHAR(16) NOT NULL,
    TRIGGER_TYPE VARCHAR(8) NOT NULL,
    START_TIME BIGINT NOT NULL,
    END_TIME BIGINT,
    CALENDAR_NAME VARCHAR(60),
    MISFIRE_INSTR SMALLINT,
    CONSTRAINT PK_QRTZ_TRIGGERS PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP),
    CONSTRAINT FK_QRTZ_TRIGGERS_1 FOREIGN KEY (JOB_NAME,JOB_GROUP)
    REFERENCES QRTZ_JOB_DETAILS(JOB_NAME,JOB_GROUP)
);

CREATE TABLE QRTZ_SIMPLE_TRIGGERS (
    TRIGGER_NAME VARCHAR(60) NOT NULL,
    TRIGGER_GROUP VARCHAR(60) NOT NULL,
    REPEAT_COUNT BIGINT NOT NULL,
    REPEAT_INTERVAL BIGINT NOT NULL,
    TIMES_TRIGGERED BIGINT NOT NULL,
    CONSTRAINT PK_QRTZ_SIMPLE_TRIGGERS PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP),
    CONSTRAINT FK_QRTZ_SIMPLE_TRIGGERS_1 FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP)
    REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP)
);

CREATE TABLE QRTZ_CRON_TRIGGERS (
    TRIGGER_NAME VARCHAR(60) NOT NULL,
    TRIGGER_GROUP VARCHAR(60) NOT NULL,
    CRON_EXPRESSION VARCHAR(60) NOT NULL,
    TIME_ZONE_ID VARCHAR(60),
    CONSTRAINT PK_QRTZ_SIMPLE_TRG PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP),
    CONSTRAINT FK_QRTZ_SIMPLE_TRG_1 FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP)
    REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP)
);

CREATE TABLE QRTZ_BLOB_TRIGGERS (
    TRIGGER_NAME VARCHAR(60) NOT NULL,
    TRIGGER_GROUP VARCHAR(60) NOT NULL,
    BLOB_DATA BLOB,
    CONSTRAINT PK_QRTZ_BLOB_TRIGGERS PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP),
    CONSTRAINT FK_QRTZ_BLOB_TRIGGERS_1 FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP)
        REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP)
);

CREATE TABLE QRTZ_TRIGGER_LISTENERS (
    TRIGGER_NAME VARCHAR(60) NOT NULL,
    TRIGGER_GROUP VARCHAR(60) NOT NULL,
    TRIGGER_LISTENER VARCHAR(60) NOT NULL,
    CONSTRAINT PK_QRTZ_TRIGGER_LST PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP,TRIGGER_LISTENER),
    CONSTRAINT FK_QRTZ_TRIGGER_LST_1 FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP)
    REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP)
);

CREATE TABLE QRTZ_CALENDARS (
    CALENDAR_NAME VARCHAR(60) NOT NULL,
    CALENDAR BLOB NOT NULL,
    CONSTRAINT PK_QRTZ_CALENDARS PRIMARY KEY (CALENDAR_NAME)
);

CREATE TABLE QRTZ_PAUSED_TRIGGER_GRPS (
    TRIGGER_GROUP VARCHAR(60) NOT NULL,
    CONSTRAINT PK_QRTZ_PAUSED_TRIGGER_GRPS PRIMARY KEY (TRIGGER_GROUP)
);

CREATE TABLE QRTZ_FIRED_TRIGGERS (
    ENTRY_ID VARCHAR(95) NOT NULL,
    TRIGGER_NAME VARCHAR(60) NOT NULL,
    TRIGGER_GROUP VARCHAR(60) NOT NULL,
    IS_VOLATILE VARCHAR(1) NOT NULL,
    INSTANCE_NAME VARCHAR(60) NOT NULL,
    FIRED_TIME BIGINT NOT NULL,
    STATE VARCHAR(16) NOT NULL,
    JOB_NAME VARCHAR(60),
    JOB_GROUP VARCHAR(60),
    IS_STATEFUL VARCHAR(1),
    REQUESTS_RECOVERY VARCHAR(1),
    CONSTRAINT PK_QRTZ_FIRED_TRIGGERS PRIMARY KEY (ENTRY_ID)
);

CREATE TABLE QRTZ_SCHEDULER_STATE (
    INSTANCE_NAME VARCHAR(60) NOT NULL,
    LAST_CHECKIN_TIME BIGINT NOT NULL,
    CHECKIN_INTERVAL BIGINT NOT NULL,
    RECOVERER VARCHAR(60),
    CONSTRAINT PK_QRTZ_SCHEDULER_STATE PRIMARY KEY (INSTANCE_NAME)
);

CREATE TABLE QRTZ_LOCKS (
    LOCK_NAME VARCHAR(40) NOT NULL,
    CONSTRAINT PK_QRTZ_LOCKS PRIMARY KEY (LOCK_NAME)
);

COMMIT;

INSERT INTO QRTZ_LOCKS VALUES('TRIGGER_ACCESS');
INSERT INTO QRTZ_LOCKS VALUES('JOB_ACCESS');
INSERT INTO QRTZ_LOCKS VALUES('CALENDAR_ACCESS');
INSERT INTO QRTZ_LOCKS VALUES('STATE_ACCESS');
INSERT INTO QRTZ_LOCKS VALUES('MISFIRE_ACCESS');

COMMIT;
