Project

General

Profile

1 81 bojilova
/*
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 123 jones
 *    Copyright: 2000 Regents of the University of California and the
10
 *               National Center for Ecological Analysis and Synthesis
11
 *  For Details: http://www.nceas.ucsb.edu/
12
 *    File Info: '$Id$'
13 2 jones
 *
14
 */
15
16 5 jones
/*
17 19 jones
 * Drop all of the objects in proper order
18 2 jones
 */
19 72 bojilova
set echo off
20
21 20 jones
DROP SEQUENCE xml_nodes_id_seq;
22 203 jones
DROP SEQUENCE xml_revisions_id_seq;
23 123 jones
DROP SEQUENCE xml_catalog_id_seq;
24 72 bojilova
25 203 jones
DROP TRIGGER xml_revisions_before_insert;
26 93 bojilova
DROP TRIGGER xml_catalog_before_insert;
27 72 bojilova
28 123 jones
DROP TABLE xml_index;
29 72 bojilova
DROP TABLE xml_catalog;
30 5 jones
DROP TABLE xml_documents;
31 203 jones
DROP TABLE xml_revisions;
32 20 jones
DROP TABLE xml_nodes;
33 163 bojilova
DROP TABLE xml_acc_numbers;
34 3 jones
35
/*
36 20 jones
 * Nodes -- table to store XML Nodes (both elements and attributes)
37 3 jones
 */
38 20 jones
CREATE TABLE xml_nodes (
39 123 jones
	nodeid		NUMBER(20),	-- the unique node id (pk)
40
	nodeindex	NUMBER(10),	-- order of nodes within parent
41
	nodetype	VARCHAR2(20),	-- type (DOCUMENT, COMMENT, PI,
42
					-- ELEMENT, ATTRIBUTE, TEXT)
43
	nodename	VARCHAR2(250),	-- the name of an element or attribute
44
	nodedata	VARCHAR2(4000), -- the data for this node (e.g.,
45
					-- for TEXT it is the content)
46
	parentnodeid	NUMBER(20),	-- index of the parent of this node
47
	rootnodeid	NUMBER(20),	-- index of the root node of this tree
48 317 bojilova
	docid		VARCHAR2(250),	-- index to the document id
49 3 jones
	date_created	DATE,
50
	date_updated	DATE,
51 20 jones
   CONSTRAINT xml_nodes_pk PRIMARY KEY (nodeid),
52 123 jones
   CONSTRAINT xml_nodes_root_fk
53
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
54 20 jones
   CONSTRAINT xml_nodes_parent_fk
55
		FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
56 3 jones
);
57
58 20 jones
CREATE SEQUENCE xml_nodes_id_seq;
59 19 jones
60 3 jones
/*
61 72 bojilova
 * Documents -- table to store XML documents
62 5 jones
 */
63
CREATE TABLE xml_documents (
64 165 jones
	docid		VARCHAR2(250),	-- the document id #
65
	rootnodeid	NUMBER(20),	-- reference to root node of the DOM
66 123 jones
	docname		VARCHAR2(100),	-- usually the root element name
67
	doctype		VARCHAR2(100),	-- public id indicating document type
68
	doctitle	VARCHAR2(1000),	-- title of document if exists
69 5 jones
	date_created	DATE,
70
	date_updated	DATE,
71
   CONSTRAINT xml_documents_pk PRIMARY KEY (docid),
72
   CONSTRAINT xml_documents_root_fk
73 20 jones
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes
74 5 jones
);
75
76 72 bojilova
/*
77 203 jones
 * Revised Documents -- table to store XML documents saved after an UPDATE
78
 *                    or DELETE
79
 */
80
CREATE TABLE xml_revisions (
81
	revisionid	NUMBER(20),	-- the revision number we are saving
82
	docid		VARCHAR2(250),	-- the document id #
83
	rootnodeid	NUMBER(20),	-- reference to root node of the DOM
84
	docname		VARCHAR2(100),	-- usually the root element name
85
	doctype		VARCHAR2(100),	-- public id indicating document type
86
	doctitle	VARCHAR2(1000),	-- title of document if exists
87
	date_created	DATE,
88
	date_updated	DATE,
89
   CONSTRAINT xml_revisions_pk PRIMARY KEY (revisionid),
90
   CONSTRAINT xml_revisions_root_fk
91
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes
92
);
93
94
CREATE SEQUENCE xml_revisions_id_seq;
95
96
CREATE TRIGGER xml_revisions_before_insert
97
BEFORE INSERT ON xml_revisions FOR EACH ROW
98
BEGIN
99
  SELECT xml_revisions_id_seq.nextval
100
    INTO :new.revisionid
101
    FROM dual;
102
END;
103
/
104
105
/*
106 93 bojilova
 * XML Catalog -- table to store all external sources for XML documents
107 72 bojilova
 */
108
CREATE TABLE xml_catalog (
109 123 jones
	catalog_id	NUMBER(20),	-- the id for this catalog entry
110
	entry_type	VARCHAR2(500),	-- the type of this catalog entry
111
					-- (e.g., DTD, XSD, XSL)
112
	source_doctype	VARCHAR2(500),	-- the source public_id for transforms
113
	target_doctype	VARCHAR2(500),	-- the target public_id for transforms
114
	public_id	VARCHAR2(500),	-- the unique id for this type
115
	system_id	VARCHAR2(1000),	-- the local location of the object
116
   CONSTRAINT xml_catalog_pk PRIMARY KEY (catalog_id)
117
   -- CONSTRAINT xml_catalog_uk UNIQUE (entry_type, source_doctype, target_doctype, public_id)
118 72 bojilova
);
119
120 123 jones
CREATE SEQUENCE xml_catalog_id_seq;
121 72 bojilova
122 93 bojilova
CREATE TRIGGER xml_catalog_before_insert
123
BEFORE INSERT ON xml_catalog FOR EACH ROW
124 72 bojilova
BEGIN
125 123 jones
  SELECT xml_catalog_id_seq.nextval
126
    INTO :new.catalog_id
127 72 bojilova
    FROM dual;
128
END;
129
/
130 123 jones
131
/*
132
 * Index of Nodes -- table to store precomputed paths through tree for
133
 * quick searching in structured searches
134
 */
135
CREATE TABLE xml_index (
136
	nodeid		NUMBER(20),	-- the unique node id
137 177 jones
	path		VARCHAR2(200),	-- precomputed path through tree
138 317 bojilova
	docid		VARCHAR2(250),	-- index to the document id
139
	doctype		VARCHAR2(100),	-- public id indicating document type
140 123 jones
   CONSTRAINT xml_index_pk PRIMARY KEY (nodeid,path),
141 317 bojilova
   CONSTRAINT xml_index_nodeid_fk FOREIGN KEY (nodeid) REFERENCES xml_nodes,
142
   CONSTRAINT xml_index_docid_fk
143
		FOREIGN KEY (docid) REFERENCES xml_documents
144 123 jones
);
145 163 bojilova
146
/*
147 177 jones
 * Index of the paths in xml_index
148
 */
149
CREATE INDEX xml_index_idx1 ON xml_index (path);
150
151
/*
152 163 bojilova
 * table to store unique Accession # for every document in 2 parts
153
 */
154
CREATE TABLE xml_acc_numbers (
155
	global_name	VARCHAR2(32),	-- first part of acc #
156 166 jones
	local_id	NUMBER(20),	-- second part - unique in global name
157 163 bojilova
   CONSTRAINT xml_acc_numbers_pk PRIMARY KEY (global_name, local_id)
158
);