--
-- A hint submitted by a user: Oracle DB MUST be created as "shared" and the 
-- job_queue_processes parameter  must be greater than 2
-- However, these settings are pretty much standard after any
-- Oracle install, so most users need not worry about this.
--
-- Many other users (including the primary author of Quartz) have had success
-- runing in dedicated mode, so only consider the above as a hint ;-)
--

delete from AD74A_fired_triggers;
delete from AD74A_simple_triggers;
delete from AD74A_simprop_triggers;
delete from AD74A_cron_triggers;
delete from AD74A_blob_triggers;
delete from AD74A_triggers;
delete from AD74A_job_details;
delete from AD74A_calendars;
delete from AD74A_paused_trigger_grps;
delete from AD74A_locks;
delete from AD74A_scheduler_state;

drop table AD74A_calendars;
drop table AD74A_fired_triggers;
drop table AD74A_blob_triggers;
drop table AD74A_cron_triggers;
drop table AD74A_simple_triggers;
drop table AD74A_simprop_triggers;
drop table AD74A_triggers;
drop table AD74A_job_details;
drop table AD74A_paused_trigger_grps;
drop table AD74A_locks;
drop table AD74A_scheduler_state;

PROMPT 'AD74A_job_details';
CREATE TABLE AD74A_job_details
  (
    SCHED_NAME VARCHAR2(120) NOT NULL,
    JOB_NAME  VARCHAR2(200) NOT NULL,
    JOB_GROUP VARCHAR2(200) NOT NULL,
    DESCRIPTION VARCHAR2(250) NULL,
    JOB_CLASS_NAME   VARCHAR2(250) NOT NULL, 
    IS_DURABLE VARCHAR2(1) NOT NULL,
    IS_NONCONCURRENT VARCHAR2(1) NOT NULL,
    IS_UPDATE_DATA VARCHAR2(1) NOT NULL,
    REQUESTS_RECOVERY VARCHAR2(1) NOT NULL,
    JOB_DATA BLOB NULL,
    CONSTRAINT AD74A_JOB_DETAILS_PK PRIMARY KEY (SCHED_NAME,JOB_NAME,JOB_GROUP)
) TABLESPACE AD7401E00;
PROMPT 'AD74A_triggers';
CREATE TABLE AD74A_triggers
  (
    SCHED_NAME VARCHAR2(120) NOT NULL,
    TRIGGER_NAME VARCHAR2(200) NOT NULL,
    TRIGGER_GROUP VARCHAR2(200) NOT NULL,
    JOB_NAME  VARCHAR2(200) NOT NULL, 
    JOB_GROUP VARCHAR2(200) NOT NULL,
    DESCRIPTION VARCHAR2(250) NULL,
    NEXT_FIRE_TIME NUMBER(13) NULL,
    PREV_FIRE_TIME NUMBER(13) NULL,
    PRIORITY NUMBER(13) NULL,
    TRIGGER_STATE VARCHAR2(16) NOT NULL,
    TRIGGER_TYPE VARCHAR2(8) NOT NULL,
    START_TIME NUMBER(13) NOT NULL,
    END_TIME NUMBER(13) NULL,
    CALENDAR_NAME VARCHAR2(200) NULL,
    MISFIRE_INSTR NUMBER(2) NULL,
    JOB_DATA BLOB NULL,
    CONSTRAINT AD74A_TRIGGERS_PK PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
    CONSTRAINT AD74A_TRIGGER_TO_JOBS_FK FOREIGN KEY (SCHED_NAME,JOB_NAME,JOB_GROUP) 
      REFERENCES AD74A_JOB_DETAILS(SCHED_NAME,JOB_NAME,JOB_GROUP) 
) TABLESPACE AD7401E00;
PROMPT 'AD74A_simple_triggers';
CREATE TABLE AD74A_simple_triggers
  (
    SCHED_NAME VARCHAR2(120) NOT NULL,
    TRIGGER_NAME VARCHAR2(200) NOT NULL,
    TRIGGER_GROUP VARCHAR2(200) NOT NULL,
    REPEAT_COUNT NUMBER(7) NOT NULL,
    REPEAT_INTERVAL NUMBER(12) NOT NULL,
    TIMES_TRIGGERED NUMBER(10) NOT NULL,
    CONSTRAINT AD74A_SIMPLE_TRIG_PK PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
    CONSTRAINT AD74A_SIMPLE_TRIG_TO_TRIG_FK FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) 
	REFERENCES AD74A_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
) TABLESPACE AD7401E00;
PROMPT 'AD74A_cron_triggers';
CREATE TABLE AD74A_cron_triggers
  (
    SCHED_NAME VARCHAR2(120) NOT NULL,
    TRIGGER_NAME VARCHAR2(200) NOT NULL,
    TRIGGER_GROUP VARCHAR2(200) NOT NULL,
    CRON_EXPRESSION VARCHAR2(120) NOT NULL,
    TIME_ZONE_ID VARCHAR2(80),
    CONSTRAINT AD74A_CRON_TRIG_PK PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
    CONSTRAINT AD74A_CRON_TRIG_TO_TRIG_FK FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) 
      REFERENCES AD74A_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
) TABLESPACE AD7401E00;
PROMPT 'AD74A_simprop_triggers';
CREATE TABLE AD74A_simprop_triggers
  (          
    SCHED_NAME VARCHAR2(120) NOT NULL,
    TRIGGER_NAME VARCHAR2(200) NOT NULL,
    TRIGGER_GROUP VARCHAR2(200) NOT NULL,
    STR_PROP_1 VARCHAR2(512) NULL,
    STR_PROP_2 VARCHAR2(512) NULL,
    STR_PROP_3 VARCHAR2(512) NULL,
    INT_PROP_1 NUMBER(10) NULL,
    INT_PROP_2 NUMBER(10) NULL,
    LONG_PROP_1 NUMBER(13) NULL,
    LONG_PROP_2 NUMBER(13) NULL,
    DEC_PROP_1 NUMERIC(13,4) NULL,
    DEC_PROP_2 NUMERIC(13,4) NULL,
    BOOL_PROP_1 VARCHAR2(1) NULL,
    BOOL_PROP_2 VARCHAR2(1) NULL,
    CONSTRAINT AD74A_SIMPROP_TRIG_PK PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
    CONSTRAINT AD74A_SIMPROP_TRIG_TO_TRIG_FK FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) 
      REFERENCES AD74A_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
) TABLESPACE AD7401E00;
PROMPT 'AD74A_blob_triggers';
CREATE TABLE AD74A_blob_triggers
  (
    SCHED_NAME VARCHAR2(120) NOT NULL,
    TRIGGER_NAME VARCHAR2(200) NOT NULL,
    TRIGGER_GROUP VARCHAR2(200) NOT NULL,
    BLOB_DATA BLOB NULL,
    CONSTRAINT AD74A_BLOB_TRIG_PK PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
    CONSTRAINT AD74A_BLOB_TRIG_TO_TRIG_FK FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) 
        REFERENCES AD74A_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
) TABLESPACE AD7401E00;
PROMPT 'AD74A_calendars';
CREATE TABLE AD74A_calendars
  (
    SCHED_NAME VARCHAR2(120) NOT NULL,
    CALENDAR_NAME  VARCHAR2(200) NOT NULL, 
    CALENDAR BLOB NOT NULL,
    CONSTRAINT AD74A_CALENDARS_PK PRIMARY KEY (SCHED_NAME,CALENDAR_NAME)
) TABLESPACE AD7401E00;
PROMPT 'AD74A_paused_trigger_grps';
CREATE TABLE AD74A_paused_trigger_grps
  (
    SCHED_NAME VARCHAR2(120) NOT NULL,
    TRIGGER_GROUP  VARCHAR2(200) NOT NULL, 
    CONSTRAINT AD74A_PAUSED_TRIG_GRPS_PK PRIMARY KEY (SCHED_NAME,TRIGGER_GROUP)
) TABLESPACE AD7401E00;
PROMPT 'AD74A_fired_triggers';
CREATE TABLE AD74A_fired_triggers 
  (
    SCHED_NAME VARCHAR2(120) NOT NULL,
    ENTRY_ID VARCHAR2(95) NOT NULL,
    TRIGGER_NAME VARCHAR2(200) NOT NULL,
    TRIGGER_GROUP VARCHAR2(200) NOT NULL,
    INSTANCE_NAME VARCHAR2(200) NOT NULL,
    FIRED_TIME NUMBER(13) NOT NULL,
    SCHED_TIME NUMBER(13) NOT NULL,
    PRIORITY NUMBER(13) NOT NULL,
    STATE VARCHAR2(16) NOT NULL,
    JOB_NAME VARCHAR2(200) NULL,
    JOB_GROUP VARCHAR2(200) NULL,
    IS_NONCONCURRENT VARCHAR2(1) NULL,
    REQUESTS_RECOVERY VARCHAR2(1) NULL,
    CONSTRAINT AD74A_FIRED_TRIGGER_PK PRIMARY KEY (SCHED_NAME,ENTRY_ID)
) TABLESPACE AD7401E00;
PROMPT 'AD74A_scheduler_state';
CREATE TABLE AD74A_scheduler_state 
  (
    SCHED_NAME VARCHAR2(120) NOT NULL,
    INSTANCE_NAME VARCHAR2(200) NOT NULL,
    LAST_CHECKIN_TIME NUMBER(13) NOT NULL,
    CHECKIN_INTERVAL NUMBER(13) NOT NULL,
    CONSTRAINT AD74A_SCHEDULER_STATE_PK PRIMARY KEY (SCHED_NAME,INSTANCE_NAME)
) TABLESPACE AD7401E00;
PROMPT 'AD74A_locks';
CREATE TABLE AD74A_locks
  (
    SCHED_NAME VARCHAR2(120) NOT NULL,
    LOCK_NAME  VARCHAR2(40) NOT NULL, 
    CONSTRAINT AD74A_LOCKS_PK PRIMARY KEY (SCHED_NAME,LOCK_NAME)
) TABLESPACE AD7401E00;

create index idx_AD74A_j_req_recovery on AD74A_job_details(SCHED_NAME,REQUESTS_RECOVERY) TABLESPACE "AD7402E00";
create index idx_AD74A_j_grp on AD74A_job_details(SCHED_NAME,JOB_GROUP) TABLESPACE "AD7402E00";

create index idx_AD74A_t_j on AD74A_triggers(SCHED_NAME,JOB_NAME,JOB_GROUP) TABLESPACE "AD7402E00";
create index idx_AD74A_t_jg on AD74A_triggers(SCHED_NAME,JOB_GROUP) TABLESPACE "AD7402E00";
create index idx_AD74A_t_c on AD74A_triggers(SCHED_NAME,CALENDAR_NAME) TABLESPACE "AD7402E00";
create index idx_AD74A_t_g on AD74A_triggers(SCHED_NAME,TRIGGER_GROUP) TABLESPACE "AD7402E00";
create index idx_AD74A_t_state on AD74A_triggers(SCHED_NAME,TRIGGER_STATE) TABLESPACE "AD7402E00";
create index idx_AD74A_t_n_state on AD74A_triggers(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP,TRIGGER_STATE) TABLESPACE "AD7402E00";
create index idx_AD74A_t_n_g_state on AD74A_triggers(SCHED_NAME,TRIGGER_GROUP,TRIGGER_STATE) TABLESPACE "AD7402E00";
create index idx_AD74A_t_next_fire_time on AD74A_triggers(SCHED_NAME,NEXT_FIRE_TIME) TABLESPACE "AD7402E00";
create index idx_AD74A_t_nft_st on AD74A_triggers(SCHED_NAME,TRIGGER_STATE,NEXT_FIRE_TIME) TABLESPACE "AD7402E00";
create index idx_AD74A_t_nft_misfire on AD74A_triggers(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME) TABLESPACE "AD7402E00";
create index idx_AD74A_t_nft_st_misfire on AD74A_triggers(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_STATE) TABLESPACE "AD7402E00";
create index idx_AD74A_t_nft_st_misfire_grp on AD74A_triggers(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_GROUP,TRIGGER_STATE) TABLESPACE "AD7402E00";

create index idx_AD74A_ft_trig_inst_name on AD74A_fired_triggers(SCHED_NAME,INSTANCE_NAME) TABLESPACE "AD7402E00";
create index idx_AD74A_inst_job_req_rcvry on AD74A_fired_triggers(SCHED_NAME,INSTANCE_NAME,REQUESTS_RECOVERY) TABLESPACE "AD7402E00";
create index idx_AD74A_ft_j_g on AD74A_fired_triggers(SCHED_NAME,JOB_NAME,JOB_GROUP) TABLESPACE "AD7402E00";
create index idx_AD74A_ft_jg on AD74A_fired_triggers(SCHED_NAME,JOB_GROUP) TABLESPACE "AD7402E00";
create index idx_AD74A_ft_t_g on AD74A_fired_triggers(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) TABLESPACE "AD7402E00";
create index idx_AD74A_ft_tg on AD74A_fired_triggers(SCHED_NAME,TRIGGER_GROUP) TABLESPACE "AD7402E00";

COMMIT;
