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