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