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 472 berkley
DROP SEQUENCE xml_relation_id_seq;
25 517 berkley
DROP SEQUENCE xml_replication_id_seq;
26 616 bojilova
DROP SEQUENCE accnum_uniqueid_seq;
27 72 bojilova
28 203 jones
DROP TRIGGER xml_revisions_before_insert;
29 93 bojilova
DROP TRIGGER xml_catalog_before_insert;
30 472 berkley
DROP TRIGGER xml_relation_before_insert;
31 517 berkley
DROP TRIGGER xml_replication_before_insert;
32 72 bojilova
33 123 jones
DROP TABLE xml_index;
34 414 bojilova
DROP TABLE xml_access;
35
DROP TABLE xml_revisions;
36 689 bojilova
DROP TABLE xml_relation;
37 5 jones
DROP TABLE xml_documents;
38 20 jones
DROP TABLE xml_nodes;
39 517 berkley
DROP TABLE xml_replication;
40 698 bojilova
DROP TABLE xml_catalog;
41 3 jones
42 517 berkley
/*
43
 *Replication -- table to store servers that metacat is replicated to
44
 */
45
CREATE TABLE xml_replication (
46 544 berkley
  serverid      NUMBER(20),
47
  server        VARCHAR2(512),
48
  last_checked  DATE,
49 629 berkley
  replicate     NUMBER(1),
50 544 berkley
  CONSTRAINT xml_replication_pk PRIMARY KEY (serverid)
51
);
52
53
CREATE SEQUENCE xml_replication_id_seq;
54
CREATE TRIGGER xml_replication_before_insert
55
BEFORE INSERT ON xml_replication FOR EACH ROW
56
BEGIN
57
  SELECT xml_replication_id_seq.nextval
58
    INTO :new.serverid
59
    FROM dual;
60
END;
61
/
62 517 berkley
63 629 berkley
INSERT INTO xml_replication (serverid, server, replicate) VALUES ('1', 'localhost', '0');
64 550 berkley
65 3 jones
/*
66 20 jones
 * Nodes -- table to store XML Nodes (both elements and attributes)
67 3 jones
 */
68 20 jones
CREATE TABLE xml_nodes (
69 123 jones
	nodeid		NUMBER(20),	-- the unique node id (pk)
70
	nodeindex	NUMBER(10),	-- order of nodes within parent
71
	nodetype	VARCHAR2(20),	-- type (DOCUMENT, COMMENT, PI,
72
					-- ELEMENT, ATTRIBUTE, TEXT)
73
	nodename	VARCHAR2(250),	-- the name of an element or attribute
74
	nodedata	VARCHAR2(4000), -- the data for this node (e.g.,
75
					-- for TEXT it is the content)
76
	parentnodeid	NUMBER(20),	-- index of the parent of this node
77
	rootnodeid	NUMBER(20),	-- index of the root node of this tree
78 317 bojilova
	docid		VARCHAR2(250),	-- index to the document id
79 3 jones
	date_created	DATE,
80
	date_updated	DATE,
81 20 jones
   CONSTRAINT xml_nodes_pk PRIMARY KEY (nodeid),
82 123 jones
   CONSTRAINT xml_nodes_root_fk
83
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
84 20 jones
   CONSTRAINT xml_nodes_parent_fk
85
		FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
86 3 jones
);
87
88 440 bojilova
/*
89
 * Indexes of rootnodeid & parentnodeid in xml_nodes
90
 */
91
CREATE INDEX xml_nodes_idx1 ON xml_nodes (rootnodeid);
92
CREATE INDEX xml_nodes_idx2 ON xml_nodes (parentnodeid);
93
94 20 jones
CREATE SEQUENCE xml_nodes_id_seq;
95 19 jones
96 3 jones
/*
97 698 bojilova
 * XML Catalog -- table to store all external sources for XML documents
98
 */
99
CREATE TABLE xml_catalog (
100
	catalog_id	NUMBER(20),	-- the id for this catalog entry
101
	entry_type	VARCHAR2(500),	-- the type of this catalog entry
102
					-- (e.g., DTD, XSD, XSL)
103
	source_doctype	VARCHAR2(500),	-- the source public_id for transforms
104
	target_doctype	VARCHAR2(500),	-- the target public_id for transforms
105
	public_id	VARCHAR2(500),	-- the unique id for this type
106
	system_id	VARCHAR2(1000),	-- the local location of the object
107
   CONSTRAINT xml_catalog_pk PRIMARY KEY (catalog_id),
108
   CONSTRAINT xml_catalog_uk UNIQUE
109
		(entry_type, source_doctype, target_doctype, public_id)
110
);
111
112
CREATE SEQUENCE xml_catalog_id_seq;
113
114
CREATE TRIGGER xml_catalog_before_insert
115
BEFORE INSERT ON xml_catalog FOR EACH ROW
116
BEGIN
117
  SELECT xml_catalog_id_seq.nextval
118
    INTO :new.catalog_id
119
    FROM dual;
120
END;
121
/
122
123
/*
124 72 bojilova
 * Documents -- table to store XML documents
125 5 jones
 */
126
CREATE TABLE xml_documents (
127 165 jones
	docid		VARCHAR2(250),	-- the document id #
128
	rootnodeid	NUMBER(20),	-- reference to root node of the DOM
129 123 jones
	docname		VARCHAR2(100),	-- usually the root element name
130
	doctype		VARCHAR2(100),	-- public id indicating document type
131 414 bojilova
	user_owner	VARCHAR2(100),	-- the user owned the document
132
	user_updated	VARCHAR2(100),	-- the user updated the document
133 689 bojilova
	server_location NUMBER(20),	-- the server on which this document resides
134 698 bojilova
	rev 		NUMBER(10) DEFAULT 1,--the revision number of the document
135 5 jones
	date_created	DATE,
136
	date_updated	DATE,
137 698 bojilova
	public_access	NUMBER(1),	-- flag for public access
138
        catalog_id      NUMBER(20),	-- reference to xml_catalog
139 5 jones
   CONSTRAINT xml_documents_pk PRIMARY KEY (docid),
140 544 berkley
   CONSTRAINT xml_documents_rep_fk
141 689 bojilova
    		FOREIGN KEY (server_location) REFERENCES xml_replication,
142 5 jones
   CONSTRAINT xml_documents_root_fk
143 698 bojilova
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
144
   CONSTRAINT xml_documents_catalog_fk
145
		FOREIGN KEY (catalog_id) REFERENCES xml_catalog
146 5 jones
);
147
148 72 bojilova
/*
149 440 bojilova
 * Index of <docid,doctype> in xml_document
150
 */
151
CREATE INDEX xml_documents_idx1 ON xml_documents (docid, doctype);
152
153
/*
154 203 jones
 * Revised Documents -- table to store XML documents saved after an UPDATE
155
 *                    or DELETE
156
 */
157
CREATE TABLE xml_revisions (
158
	revisionid	NUMBER(20),	-- the revision number we are saving
159
	docid		VARCHAR2(250),	-- the document id #
160
	rootnodeid	NUMBER(20),	-- reference to root node of the DOM
161
	docname		VARCHAR2(100),	-- usually the root element name
162
	doctype		VARCHAR2(100),	-- public id indicating document type
163 414 bojilova
	user_owner	VARCHAR2(100),
164
	user_updated	VARCHAR2(100),
165 556 bojilova
	server_location NUMBER(20),
166 689 bojilova
	rev		NUMBER(10),
167 203 jones
	date_created	DATE,
168
	date_updated	DATE,
169 698 bojilova
	public_access	NUMBER(1),	-- flag for public access
170
        catalog_id      NUMBER(20),	-- reference to xml_catalog
171 203 jones
   CONSTRAINT xml_revisions_pk PRIMARY KEY (revisionid),
172 552 berkley
   CONSTRAINT xml_revisions_rep_fk
173 689 bojilova
		FOREIGN KEY (server_location) REFERENCES xml_replication,
174 203 jones
   CONSTRAINT xml_revisions_root_fk
175 698 bojilova
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
176
   CONSTRAINT xml_revisions_catalog_fk
177
		FOREIGN KEY (catalog_id) REFERENCES xml_catalog
178 203 jones
);
179
180
CREATE SEQUENCE xml_revisions_id_seq;
181
182
CREATE TRIGGER xml_revisions_before_insert
183
BEFORE INSERT ON xml_revisions FOR EACH ROW
184
BEGIN
185
  SELECT xml_revisions_id_seq.nextval
186
    INTO :new.revisionid
187
    FROM dual;
188
END;
189
/
190
191
/*
192 698 bojilova
 * ACL -- table to store ACL for XML documents by principals
193 72 bojilova
 */
194 698 bojilova
CREATE TABLE xml_access (
195
	docid		VARCHAR2(250),	-- the document id #
196
	accessfileid	VARCHAR2(250),	-- the document id # for the access file
197
	principal_name	VARCHAR2(100),	-- name of user, group, etc.
198
	permission	NUMBER(1),	-- "read", "write", "all"
199
	perm_type	VARCHAR2(32),	-- "allowed" or "denied"
200
	perm_order	VARCHAR2(32),	-- "allow first" or "deny first"
201
	begin_time	DATE,		-- the time that permission begins
202
	end_time	DATE,		-- the time that permission ends
203
	ticket_count	NUMBER(5),	-- ticket counter for that permission
204
   CONSTRAINT xml_access_ck CHECK (begin_time < end_time),
205
   CONSTRAINT xml_access_accessfileid_fk
206
		FOREIGN KEY (accessfileid) REFERENCES xml_documents
207 72 bojilova
);
208
209 123 jones
/*
210
 * Index of Nodes -- table to store precomputed paths through tree for
211
 * quick searching in structured searches
212
 */
213
CREATE TABLE xml_index (
214
	nodeid		NUMBER(20),	-- the unique node id
215 177 jones
	path		VARCHAR2(200),	-- precomputed path through tree
216 317 bojilova
	docid		VARCHAR2(250),	-- index to the document id
217
	doctype		VARCHAR2(100),	-- public id indicating document type
218 689 bojilova
        parentnodeid    NUMBER(20),     -- id of the parent of the node represented
219
					-- by this row
220 123 jones
   CONSTRAINT xml_index_pk PRIMARY KEY (nodeid,path),
221 317 bojilova
   CONSTRAINT xml_index_nodeid_fk FOREIGN KEY (nodeid) REFERENCES xml_nodes,
222
   CONSTRAINT xml_index_docid_fk
223
		FOREIGN KEY (docid) REFERENCES xml_documents
224 123 jones
);
225 163 bojilova
226
/*
227 177 jones
 * Index of the paths in xml_index
228
 */
229
CREATE INDEX xml_index_idx1 ON xml_index (path);
230
231
/*
232 616 bojilova
 * Sequence to get uniqueID for Accession #
233 163 bojilova
 */
234 616 bojilova
CREATE SEQUENCE accnum_uniqueid_seq;
235 472 berkley
236
CREATE TABLE xml_relation (
237 689 bojilova
	relationid    NUMBER(20) PRIMARY KEY, -- unique id
238
	docid         VARCHAR2(250) ,         -- the docid of the package file
239
	                                      -- that this relation came from
240
	subject       VARCHAR2(512) NOT NULL, -- the subject of the relation
241
	subdoctype    VARCHAR2(128),         	-- the doctype of the subject
242
	relationship  VARCHAR2(128)  NOT NULL,-- the relationship type
243
	object        VARCHAR2(512) NOT NULL, -- the object of the relation
244
	objdoctype    VARCHAR2(128),          -- the doctype of the object
245
	CONSTRAINT xml_relation_uk UNIQUE (subject, relationship, object),
246
	CONSTRAINT xml_relation_docid_fk
247
		FOREIGN KEY (docid) REFERENCES xml_documents
248 472 berkley
  );
249
250
CREATE SEQUENCE xml_relation_id_seq;
251
252
CREATE TRIGGER xml_relation_before_insert
253
BEFORE INSERT ON xml_relation FOR EACH ROW
254
BEGIN
255
  SELECT xml_relation_id_seq.nextval
256
    INTO :new.relationid
257
    FROM dual;
258
END;
259
/