Project

General

Profile

1 72 bojilova
source_doctype, public_id, /*
2 2 jones
 * 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$'
10
 *
11
 */
12
13 5 jones
/*
14 19 jones
 * Drop all of the objects in proper order
15 2 jones
 */
16 72 bojilova
set echo off
17
18 20 jones
DROP SEQUENCE xml_nodes_id_seq;
19 72 bojilova
DROP SEQUENCE xml_entity_id_seq;
20
DROP SEQUENCE xml_documents_id_seq;
21
22 20 jones
DROP TRIGGER xml_nodes_before_insert;
23 72 bojilova
DROP TRIGGER xml_documents_before_insert;
24
DROP TRIGGER xml_cat_entities_before_insert;
25
26
DROP TABLE xml_catalog_entities;
27
DROP TABLE xml_catalog;
28 5 jones
DROP TABLE xml_documents;
29 20 jones
DROP TABLE xml_nodes;
30 3 jones
31
/*
32 20 jones
 * Nodes -- table to store XML Nodes (both elements and attributes)
33 3 jones
 */
34 20 jones
CREATE TABLE xml_nodes (
35 3 jones
	nodeid		NUMBER(20),
36 10 jones
	parentnodeid	NUMBER(20),
37 72 bojilova
	nodeindex	NUMBER(10),
38
	nodetype	VARCHAR2(20),
39
	nodename	VARCHAR2(100),
40 76 jones
	nodedata	VARCHAR2(4000),
41 3 jones
	date_created	DATE,
42
	date_updated	DATE,
43 20 jones
   CONSTRAINT xml_nodes_pk PRIMARY KEY (nodeid),
44
   CONSTRAINT xml_nodes_parent_fk
45
		FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
46 3 jones
);
47
48 20 jones
CREATE SEQUENCE xml_nodes_id_seq;
49 19 jones
50 20 jones
CREATE TRIGGER xml_nodes_before_insert
51
BEFORE INSERT ON xml_nodes FOR EACH ROW
52 19 jones
BEGIN
53 20 jones
  SELECT xml_nodes_id_seq.nextval
54 19 jones
    INTO :new.nodeid
55
    FROM dual;
56
END;
57
/
58
59 3 jones
/*
60 72 bojilova
 * Documents -- table to store XML documents
61 5 jones
 */
62
CREATE TABLE xml_documents (
63
	docid		NUMBER(20),
64
	rootnodeid	NUMBER(20),
65 72 bojilova
	docname		VARCHAR2(100),
66
	doctype		VARCHAR2(100),
67 5 jones
	date_created	DATE,
68
	date_updated	DATE,
69
   CONSTRAINT xml_documents_pk PRIMARY KEY (docid),
70
   CONSTRAINT xml_documents_root_fk
71 20 jones
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes
72 5 jones
);
73
74 72 bojilova
CREATE SEQUENCE xml_documents_id_seq;
75
76
CREATE TRIGGER xml_documents_before_insert
77
BEFORE INSERT ON xml_documents FOR EACH ROW
78
BEGIN
79
  SELECT xml_documents_id_seq.nextval
80
    INTO :new.docid
81
    FROM dual;
82
END;
83
/
84
85
/*
86
 * XML Catalog -- tables to store all external sources for XML documents
87
 */
88
CREATE TABLE xml_catalog (
89
	doctype		VARCHAR2(100),
90
	date_created	DATE,
91
	date_updated	DATE,
92
   CONSTRAINT xml_catalog_pk PRIMARY KEY (doctype)
93
);
94
95
CREATE TABLE xml_catalog_entities (
96
	entity_id	NUMBER(20),
97
	entity_name	VARCHAR2(100),
98
	entity_type	VARCHAR2(20),
99
	source_doctype	VARCHAR2(100),
100
	target_doctype	VARCHAR2(100),
101
	public_id	VARCHAR2(100),
102
	system_id	VARCHAR2(1000),
103
	date_created	DATE,
104
	date_updated	DATE,
105
   CONSTRAINT xml_catalog_entities_pk PRIMARY KEY (entity_id),
106
   CONSTRAINT xml_catalog_entities_uk UNIQUE (entity_type, source_doctype, target_doctype, public_id),
107
   CONSTRAINT xml_source_catalog_fk FOREIGN KEY (source_doctype) REFERENCES xml_catalog,
108
   CONSTRAINT xml_target_catalog_fk FOREIGN KEY (target_doctype) REFERENCES xml_catalog
109
);
110
111
CREATE SEQUENCE xml_entity_id_seq;
112
113
CREATE TRIGGER xml_cat_entities_before_insert
114
BEFORE INSERT ON xml_catalog_entities FOR EACH ROW
115
BEGIN
116
  SELECT xml_entity_id_seq.nextval
117
    INTO :new.entity_id
118
    FROM dual;
119
END;
120
/