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 123 jones
DROP SEQUENCE xml_catalog_id_seq;
23 72 bojilova
24 93 bojilova
DROP TRIGGER xml_catalog_before_insert;
25 72 bojilova
26 123 jones
DROP TABLE xml_index;
27 72 bojilova
DROP TABLE xml_catalog;
28 5 jones
DROP TABLE xml_documents;
29 20 jones
DROP TABLE xml_nodes;
30 163 bojilova
DROP TABLE xml_acc_numbers;
31 3 jones
32
/*
33 20 jones
 * Nodes -- table to store XML Nodes (both elements and attributes)
34 3 jones
 */
35 20 jones
CREATE TABLE xml_nodes (
36 123 jones
	nodeid		NUMBER(20),	-- the unique node id (pk)
37
	nodeindex	NUMBER(10),	-- order of nodes within parent
38
	nodetype	VARCHAR2(20),	-- type (DOCUMENT, COMMENT, PI,
39
					-- ELEMENT, ATTRIBUTE, TEXT)
40
	nodename	VARCHAR2(250),	-- the name of an element or attribute
41
	nodedata	VARCHAR2(4000), -- the data for this node (e.g.,
42
					-- for TEXT it is the content)
43
	parentnodeid	NUMBER(20),	-- index of the parent of this node
44
	rootnodeid	NUMBER(20),	-- index of the root node of this tree
45 163 bojilova
	docid		VARCHAR2(55),	-- index to the document id
46 3 jones
	date_created	DATE,
47
	date_updated	DATE,
48 20 jones
   CONSTRAINT xml_nodes_pk PRIMARY KEY (nodeid),
49 123 jones
   CONSTRAINT xml_nodes_root_fk
50
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
51 20 jones
   CONSTRAINT xml_nodes_parent_fk
52
		FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
53 3 jones
);
54
55 20 jones
CREATE SEQUENCE xml_nodes_id_seq;
56 19 jones
57 3 jones
/*
58 72 bojilova
 * Documents -- table to store XML documents
59 5 jones
 */
60
CREATE TABLE xml_documents (
61 165 jones
	docid		VARCHAR2(250),	-- the document id #
62
	rootnodeid	NUMBER(20),	-- reference to root node of the DOM
63 123 jones
	docname		VARCHAR2(100),	-- usually the root element name
64
	doctype		VARCHAR2(100),	-- public id indicating document type
65
	doctitle	VARCHAR2(1000),	-- title of document if exists
66 5 jones
	date_created	DATE,
67
	date_updated	DATE,
68
   CONSTRAINT xml_documents_pk PRIMARY KEY (docid),
69
   CONSTRAINT xml_documents_root_fk
70 20 jones
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes
71 5 jones
);
72
73 72 bojilova
/*
74 93 bojilova
 * XML Catalog -- table to store all external sources for XML documents
75 72 bojilova
 */
76
CREATE TABLE xml_catalog (
77 123 jones
	catalog_id	NUMBER(20),	-- the id for this catalog entry
78
	entry_type	VARCHAR2(500),	-- the type of this catalog entry
79
					-- (e.g., DTD, XSD, XSL)
80
	source_doctype	VARCHAR2(500),	-- the source public_id for transforms
81
	target_doctype	VARCHAR2(500),	-- the target public_id for transforms
82
	public_id	VARCHAR2(500),	-- the unique id for this type
83
	system_id	VARCHAR2(1000),	-- the local location of the object
84
   CONSTRAINT xml_catalog_pk PRIMARY KEY (catalog_id)
85
   -- CONSTRAINT xml_catalog_uk UNIQUE (entry_type, source_doctype, target_doctype, public_id)
86 72 bojilova
);
87
88 123 jones
CREATE SEQUENCE xml_catalog_id_seq;
89 72 bojilova
90 93 bojilova
CREATE TRIGGER xml_catalog_before_insert
91
BEFORE INSERT ON xml_catalog FOR EACH ROW
92 72 bojilova
BEGIN
93 123 jones
  SELECT xml_catalog_id_seq.nextval
94
    INTO :new.catalog_id
95 72 bojilova
    FROM dual;
96
END;
97
/
98 123 jones
99
/*
100
 * Index of Nodes -- table to store precomputed paths through tree for
101
 * quick searching in structured searches
102
 */
103
CREATE TABLE xml_index (
104
	nodeid		NUMBER(20),	-- the unique node id
105 177 jones
	path		VARCHAR2(200),	-- precomputed path through tree
106 123 jones
   CONSTRAINT xml_index_pk PRIMARY KEY (nodeid,path),
107
   CONSTRAINT xml_nodes_fk FOREIGN KEY (nodeid) REFERENCES xml_nodes
108
);
109 163 bojilova
110
/*
111 177 jones
 * Index of the paths in xml_index
112
 */
113
CREATE INDEX xml_index_idx1 ON xml_index (path);
114
115
/*
116 163 bojilova
 * table to store unique Accession # for every document in 2 parts
117
 */
118
CREATE TABLE xml_acc_numbers (
119
	global_name	VARCHAR2(32),	-- first part of acc #
120 166 jones
	local_id	NUMBER(20),	-- second part - unique in global name
121 163 bojilova
   CONSTRAINT xml_acc_numbers_pk PRIMARY KEY (global_name, local_id)
122
);