Project

General

Profile

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
 *    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: xmltables.sql 203 2000-06-26 10:35:05Z jones $'
13
 *
14
 */
15

    
16
/*
17
 * Drop all of the objects in proper order
18
 */
19
set echo off
20

    
21
DROP SEQUENCE xml_nodes_id_seq;
22
DROP SEQUENCE xml_revisions_id_seq;
23
DROP SEQUENCE xml_catalog_id_seq;
24

    
25
DROP TRIGGER xml_revisions_before_insert;
26
DROP TRIGGER xml_catalog_before_insert;
27

    
28
DROP TABLE xml_index;
29
DROP TABLE xml_catalog;
30
DROP TABLE xml_documents;
31
DROP TABLE xml_revisions;
32
DROP TABLE xml_nodes;
33
DROP TABLE xml_acc_numbers;
34

    
35
/* 
36
 * Nodes -- table to store XML Nodes (both elements and attributes)
37
 */
38
CREATE TABLE xml_nodes (
39
	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
	docid		VARCHAR2(55),	-- index to the document id
49
	date_created	DATE,
50
	date_updated	DATE,
51
   CONSTRAINT xml_nodes_pk PRIMARY KEY (nodeid),
52
   CONSTRAINT xml_nodes_root_fk 
53
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
54
   CONSTRAINT xml_nodes_parent_fk 
55
		FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
56
);
57

    
58
CREATE SEQUENCE xml_nodes_id_seq;
59

    
60
/* 
61
 * Documents -- table to store XML documents
62
 */
63
CREATE TABLE xml_documents (
64
	docid		VARCHAR2(250),	-- the document id #
65
	rootnodeid	NUMBER(20),	-- reference to root node of the DOM
66
	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
	date_created	DATE,
70
	date_updated	DATE,
71
   CONSTRAINT xml_documents_pk PRIMARY KEY (docid),
72
   CONSTRAINT xml_documents_root_fk 
73
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes
74
);
75

    
76
/* 
77
 * 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
 * XML Catalog -- table to store all external sources for XML documents
107
 */
108
CREATE TABLE xml_catalog (
109
	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
);
119

    
120
CREATE SEQUENCE xml_catalog_id_seq;
121

    
122
CREATE TRIGGER xml_catalog_before_insert
123
BEFORE INSERT ON xml_catalog FOR EACH ROW
124
BEGIN
125
  SELECT xml_catalog_id_seq.nextval
126
    INTO :new.catalog_id
127
    FROM dual;
128
END;
129
/
130

    
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
	path		VARCHAR2(200),	-- precomputed path through tree
138
   CONSTRAINT xml_index_pk PRIMARY KEY (nodeid,path),
139
   CONSTRAINT xml_nodes_fk FOREIGN KEY (nodeid) REFERENCES xml_nodes
140
);
141

    
142
/* 
143
 * Index of the paths in xml_index 
144
 */
145
CREATE INDEX xml_index_idx1 ON xml_index (path);
146

    
147
/* 
148
 * table to store unique Accession # for every document in 2 parts
149
 */
150
CREATE TABLE xml_acc_numbers (
151
	global_name	VARCHAR2(32),	-- first part of acc #
152
	local_id	NUMBER(20),	-- second part - unique in global name
153
   CONSTRAINT xml_acc_numbers_pk PRIMARY KEY (global_name, local_id)
154
);
(7-7/7)