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 177 2000-06-20 01:42:11Z jones $'
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_catalog_id_seq;
23

    
24
DROP TRIGGER xml_catalog_before_insert;
25

    
26
DROP TABLE xml_index;
27
DROP TABLE xml_catalog;
28
DROP TABLE xml_documents;
29
DROP TABLE xml_nodes;
30
DROP TABLE xml_acc_numbers;
31

    
32
/* 
33
 * Nodes -- table to store XML Nodes (both elements and attributes)
34
 */
35
CREATE TABLE xml_nodes (
36
	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
	docid		VARCHAR2(55),	-- index to the document id
46
	date_created	DATE,
47
	date_updated	DATE,
48
   CONSTRAINT xml_nodes_pk PRIMARY KEY (nodeid),
49
   CONSTRAINT xml_nodes_root_fk 
50
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
51
   CONSTRAINT xml_nodes_parent_fk 
52
		FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
53
);
54

    
55
CREATE SEQUENCE xml_nodes_id_seq;
56

    
57
/* 
58
 * Documents -- table to store XML documents
59
 */
60
CREATE TABLE xml_documents (
61
	docid		VARCHAR2(250),	-- the document id #
62
	rootnodeid	NUMBER(20),	-- reference to root node of the DOM
63
	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
	date_created	DATE,
67
	date_updated	DATE,
68
   CONSTRAINT xml_documents_pk PRIMARY KEY (docid),
69
   CONSTRAINT xml_documents_root_fk 
70
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes
71
);
72

    
73
/* 
74
 * XML Catalog -- table to store all external sources for XML documents
75
 */
76
CREATE TABLE xml_catalog (
77
	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
);
87

    
88
CREATE SEQUENCE xml_catalog_id_seq;
89

    
90
CREATE TRIGGER xml_catalog_before_insert
91
BEFORE INSERT ON xml_catalog FOR EACH ROW
92
BEGIN
93
  SELECT xml_catalog_id_seq.nextval
94
    INTO :new.catalog_id
95
    FROM dual;
96
END;
97
/
98

    
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
	path		VARCHAR2(200),	-- precomputed path through tree
106
   CONSTRAINT xml_index_pk PRIMARY KEY (nodeid,path),
107
   CONSTRAINT xml_nodes_fk FOREIGN KEY (nodeid) REFERENCES xml_nodes
108
);
109

    
110
/* 
111
 * Index of the paths in xml_index 
112
 */
113
CREATE INDEX xml_index_idx1 ON xml_index (path);
114

    
115
/* 
116
 * 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
	local_id	NUMBER(20),	-- second part - unique in global name
121
   CONSTRAINT xml_acc_numbers_pk PRIMARY KEY (global_name, local_id)
122
);
(6-6/6)