Project

General

Profile

metacat / xmltables.sql @ 93

1
/*
2
 * xmltables.sql -- Create or replace tables for storing XML in the db
3
 *
4
 *      Purpose: creates tables needed for XML database
5
 * 
6
 *      Created: 12 September 1999
7
 *       Author: Matt Jones
8
 * Organization: National Center for Ecological Analysis and Synthesis
9
 *      Version: '$Id: xmltables.sql 93 2000-05-12 16:59:31Z bojilova $'
10
 *
11
 */
12

    
13
/*
14
 * Drop all of the objects in proper order
15
 */
16
set echo off
17

    
18
DROP SEQUENCE xml_nodes_id_seq;
19
DROP SEQUENCE xml_entity_id_seq;
20
DROP SEQUENCE xml_documents_id_seq;
21

    
22
DROP TRIGGER xml_nodes_before_insert;
23
DROP TRIGGER xml_documents_before_insert;
24
DROP TRIGGER xml_catalog_before_insert;
25

    
26
DROP TABLE xml_catalog;
27
DROP TABLE xml_documents;
28
DROP TABLE xml_nodes;
29

    
30
/* 
31
 * Nodes -- table to store XML Nodes (both elements and attributes)
32
 */
33
CREATE TABLE xml_nodes (
34
        nodeid                NUMBER(20),
35
        parentnodeid        NUMBER(20),
36
        nodeindex        NUMBER(10),
37
        nodetype        VARCHAR2(20),
38
        nodename        VARCHAR2(100),
39
        nodedata        VARCHAR2(4000),
40
        date_created        DATE,
41
        date_updated        DATE,
42
   CONSTRAINT xml_nodes_pk PRIMARY KEY (nodeid),
43
   CONSTRAINT xml_nodes_parent_fk 
44
                FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
45
);
46

    
47
CREATE SEQUENCE xml_nodes_id_seq;
48

    
49
CREATE TRIGGER xml_nodes_before_insert
50
BEFORE INSERT ON xml_nodes FOR EACH ROW
51
BEGIN
52
  SELECT xml_nodes_id_seq.nextval
53
    INTO :new.nodeid
54
    FROM dual;
55
END;
56
/
57

    
58
/* 
59
 * Documents -- table to store XML documents
60
 */
61
CREATE TABLE xml_documents (
62
        docid                NUMBER(20),
63
        rootnodeid        NUMBER(20),
64
        docname                VARCHAR2(100),
65
        doctype                VARCHAR2(100),
66
        date_created        DATE,
67
        date_updated        DATE,
68
   CONSTRAINT xml_documents_pk PRIMARY KEY (docid),
69
   CONSTRAINT xml_documents_root_fk 
70
                FOREIGN KEY (rootnodeid) REFERENCES xml_nodes
71
);
72

    
73
CREATE SEQUENCE xml_documents_id_seq;
74

    
75
CREATE TRIGGER xml_documents_before_insert
76
BEFORE INSERT ON xml_documents FOR EACH ROW
77
BEGIN
78
  SELECT xml_documents_id_seq.nextval
79
    INTO :new.docid
80
    FROM dual;
81
END;
82
/
83

    
84
/* 
85
 * XML Catalog -- table to store all external sources for XML documents
86
 */
87
CREATE TABLE xml_catalog (
88
        entity_id        NUMBER(20),
89
        entity_name        VARCHAR2(100),
90
        entity_type        VARCHAR2(20),
91
        source_doctype        VARCHAR2(100),
92
        target_doctype        VARCHAR2(100),
93
        public_id        VARCHAR2(100),
94
        system_id        VARCHAR2(1000),
95
        date_created        DATE,
96
        date_updated        DATE,
97
   CONSTRAINT xml_catalog_pk PRIMARY KEY (entity_id),
98
   CONSTRAINT xml_catalog_uk UNIQUE (entity_type, source_doctype, target_doctype, public_id)
99
);
100

    
101
CREATE SEQUENCE xml_entity_id_seq;
102

    
103
CREATE TRIGGER xml_catalog_before_insert
104
BEFORE INSERT ON xml_catalog FOR EACH ROW
105
BEGIN
106
  SELECT xml_entity_id_seq.nextval
107
    INTO :new.entity_id
108
    FROM dual;
109
END;
110
/