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 690 2001-01-31 18:49:18Z bojilova $'
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
DROP SEQUENCE xml_relation_id_seq;
25
DROP SEQUENCE xml_replication_id_seq;
26
DROP SEQUENCE accnum_uniqueid_seq;
27

    
28
DROP TRIGGER xml_revisions_before_insert;
29
DROP TRIGGER xml_catalog_before_insert;
30
DROP TRIGGER xml_relation_before_insert;
31
DROP TRIGGER xml_replication_before_insert;
32

    
33
DROP TABLE xml_index;
34
DROP TABLE xml_catalog;
35
DROP TABLE xml_access;
36
DROP TABLE xml_revisions;
37
DROP TABLE xml_relation;
38
DROP TABLE xml_documents;
39
DROP TABLE xml_nodes;
40
DROP TABLE xml_replication;
41

    
42
/*
43
 *Replication -- table to store servers that metacat is replicated to
44
 */
45
CREATE TABLE xml_replication (
46
  serverid      NUMBER(20),
47
  server        VARCHAR2(512),
48
  last_checked  DATE,
49
  replicate     NUMBER(1), 
50
  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

    
63
INSERT INTO xml_replication (serverid, server, replicate) VALUES ('1', 'localhost', '0');
64

    
65
/* 
66
 * Nodes -- table to store XML Nodes (both elements and attributes)
67
 */
68
CREATE TABLE xml_nodes (
69
	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
	docid		VARCHAR2(250),	-- index to the document id
79
	date_created	DATE,
80
	date_updated	DATE,
81
   CONSTRAINT xml_nodes_pk PRIMARY KEY (nodeid),
82
   CONSTRAINT xml_nodes_root_fk 
83
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
84
   CONSTRAINT xml_nodes_parent_fk 
85
		FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
86
);
87

    
88
/* 
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
CREATE SEQUENCE xml_nodes_id_seq;
95

    
96
/* 
97
 * Documents -- table to store XML documents
98
 */
99
CREATE TABLE xml_documents (
100
	docid		VARCHAR2(250),	-- the document id #
101
	rootnodeid	NUMBER(20),	-- reference to root node of the DOM
102
	docname		VARCHAR2(100),	-- usually the root element name
103
	doctype		VARCHAR2(100),	-- public id indicating document type
104
	user_owner	VARCHAR2(100),	-- the user owned the document
105
	user_updated	VARCHAR2(100),	-- the user updated the document
106
	server_location NUMBER(20),	-- the server on which this document resides
107
	rev NUMBER(10)	DEFAULT 1,	--the revision number of the document
108
	date_created	DATE,
109
	date_updated	DATE,
110
	public_access	NUMBER(1) DEFAULT 1, -- flag for public access
111
   CONSTRAINT xml_documents_pk PRIMARY KEY (docid),
112
   CONSTRAINT xml_documents_rep_fk
113
    		FOREIGN KEY (server_location) REFERENCES xml_replication, 
114
   CONSTRAINT xml_documents_root_fk 
115
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes
116
);
117

    
118
/* 
119
 * Index of <docid,doctype> in xml_document
120
 */
121
CREATE INDEX xml_documents_idx1 ON xml_documents (docid, doctype);
122

    
123
/* 
124
 * ACL -- table to store ACL for XML documents by principals
125
 */
126
CREATE TABLE xml_access (
127
	docid		VARCHAR2(250),	-- the document id #
128
	accessfileid	VARCHAR2(250),	-- the document id # for the access file
129
	principal_name	VARCHAR2(100),	-- name of user, group, etc.
130
	permission	NUMBER(1),	-- "read", "write", "all"
131
	perm_type	VARCHAR2(32),	-- "allowed" or "denied"
132
	perm_order	VARCHAR2(32),	-- "allow first" or "deny first"
133
	begin_time	DATE,		-- the time that permission begins
134
	end_time	DATE,		-- the time that permission ends
135
	ticket_count	NUMBER(5),	-- ticket counter for that permission
136
   CONSTRAINT xml_access_ck CHECK (begin_time < end_time),
137
   CONSTRAINT xml_access_accessfileid_fk 
138
		FOREIGN KEY (accessfileid) REFERENCES xml_documents
139
);
140

    
141
/* 
142
 * Revised Documents -- table to store XML documents saved after an UPDATE
143
 *                    or DELETE
144
 */
145
CREATE TABLE xml_revisions (
146
	revisionid	NUMBER(20),	-- the revision number we are saving
147
	docid		VARCHAR2(250),	-- the document id #
148
	rootnodeid	NUMBER(20),	-- reference to root node of the DOM
149
	docname		VARCHAR2(100),	-- usually the root element name
150
	doctype		VARCHAR2(100),	-- public id indicating document type
151
	user_owner	VARCHAR2(100),
152
	user_updated	VARCHAR2(100),
153
	server_location NUMBER(20),
154
	rev		NUMBER(10),
155
	date_created	DATE,
156
	date_updated	DATE,
157
   CONSTRAINT xml_revisions_pk PRIMARY KEY (revisionid),
158
   CONSTRAINT xml_revisions_rep_fk
159
		FOREIGN KEY (server_location) REFERENCES xml_replication,
160
   CONSTRAINT xml_revisions_root_fk 
161
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes
162
);
163

    
164
CREATE SEQUENCE xml_revisions_id_seq;
165

    
166
CREATE TRIGGER xml_revisions_before_insert
167
BEFORE INSERT ON xml_revisions FOR EACH ROW
168
BEGIN
169
  SELECT xml_revisions_id_seq.nextval
170
    INTO :new.revisionid
171
    FROM dual;
172
END;
173
/
174

    
175
/* 
176
 * XML Catalog -- table to store all external sources for XML documents
177
 */
178
CREATE TABLE xml_catalog (
179
	catalog_id	NUMBER(20),	-- the id for this catalog entry
180
	entry_type	VARCHAR2(500),	-- the type of this catalog entry
181
					-- (e.g., DTD, XSD, XSL)
182
	source_doctype	VARCHAR2(500),	-- the source public_id for transforms
183
	target_doctype	VARCHAR2(500),	-- the target public_id for transforms
184
	public_id	VARCHAR2(500),	-- the unique id for this type
185
	system_id	VARCHAR2(1000),	-- the local location of the object
186
   CONSTRAINT xml_catalog_pk PRIMARY KEY (catalog_id),
187
   CONSTRAINT xml_catalog_uk UNIQUE 
188
		(entry_type, source_doctype, target_doctype, public_id)
189
);
190

    
191
CREATE SEQUENCE xml_catalog_id_seq;
192

    
193
CREATE TRIGGER xml_catalog_before_insert
194
BEFORE INSERT ON xml_catalog FOR EACH ROW
195
BEGIN
196
  SELECT xml_catalog_id_seq.nextval
197
    INTO :new.catalog_id
198
    FROM dual;
199
END;
200
/
201

    
202
/* 
203
 * Index of Nodes -- table to store precomputed paths through tree for 
204
 * quick searching in structured searches
205
 */
206
CREATE TABLE xml_index (
207
	nodeid		NUMBER(20),	-- the unique node id
208
	path		VARCHAR2(200),	-- precomputed path through tree
209
	docid		VARCHAR2(250),	-- index to the document id
210
	doctype		VARCHAR2(100),	-- public id indicating document type
211
        parentnodeid    NUMBER(20),     -- id of the parent of the node represented
212
					-- by this row
213
   CONSTRAINT xml_index_pk PRIMARY KEY (nodeid,path),
214
   CONSTRAINT xml_index_nodeid_fk FOREIGN KEY (nodeid) REFERENCES xml_nodes,
215
   CONSTRAINT xml_index_docid_fk 
216
		FOREIGN KEY (docid) REFERENCES xml_documents
217
);
218

    
219
/* 
220
 * Index of the paths in xml_index 
221
 */
222
CREATE INDEX xml_index_idx1 ON xml_index (path);
223

    
224
/* 
225
 * Sequence to get uniqueID for Accession #
226
 */
227
CREATE SEQUENCE accnum_uniqueid_seq;
228

    
229
CREATE TABLE xml_relation (
230
	relationid    NUMBER(20) PRIMARY KEY, -- unique id
231
	docid         VARCHAR2(250) ,         -- the docid of the package file
232
	                                      -- that this relation came from
233
	subject       VARCHAR2(512) NOT NULL, -- the subject of the relation
234
	subdoctype    VARCHAR2(128),         	-- the doctype of the subject
235
	relationship  VARCHAR2(128)  NOT NULL,-- the relationship type
236
	object        VARCHAR2(512) NOT NULL, -- the object of the relation
237
	objdoctype    VARCHAR2(128),          -- the doctype of the object
238
	CONSTRAINT xml_relation_uk UNIQUE (subject, relationship, object),
239
	CONSTRAINT xml_relation_docid_fk 
240
		FOREIGN KEY (docid) REFERENCES xml_documents
241
  );
242

    
243
CREATE SEQUENCE xml_relation_id_seq;
244
  
245
CREATE TRIGGER xml_relation_before_insert
246
BEFORE INSERT ON xml_relation FOR EACH ROW
247
BEGIN
248
  SELECT xml_relation_id_seq.nextval
249
    INTO :new.relationid
250
    FROM dual;
251
END;
252
/
253

    
(11-11/11)