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 163 2000-06-15 19:01:11Z 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_catalog_id_seq;
23
DROP SEQUENCE xml_documents_id_seq;
24

    
25
DROP TRIGGER xml_nodes_before_insert;
26
DROP TRIGGER xml_documents_before_insert;
27
DROP TRIGGER xml_catalog_before_insert;
28

    
29
DROP TABLE xml_index;
30
DROP TABLE xml_catalog;
31
DROP TABLE xml_documents;
32
DROP TABLE xml_nodes;
33
DROP TABLE xml_acc_numbers;
34

    
35
/* 
36
 * Nodes -- table to store XML Nodes (both elements and attributes)
37
 */
38
CREATE TABLE xml_nodes (
39
	nodeid		NUMBER(20),	-- the unique node id (pk)
40
	nodeindex	NUMBER(10),	-- order of nodes within parent
41
	nodetype	VARCHAR2(20),	-- type (DOCUMENT, COMMENT, PI,
42
					-- ELEMENT, ATTRIBUTE, TEXT)
43
	nodename	VARCHAR2(250),	-- the name of an element or attribute
44
	nodedata	VARCHAR2(4000), -- the data for this node (e.g., 
45
					-- for TEXT it is the content)
46
	parentnodeid	NUMBER(20),	-- index of the parent of this node
47
	rootnodeid	NUMBER(20),	-- index of the root node of this tree
48
	docid		VARCHAR2(55),	-- index to the document id
49
	date_created	DATE,
50
	date_updated	DATE,
51
   CONSTRAINT xml_nodes_pk PRIMARY KEY (nodeid),
52
   CONSTRAINT xml_nodes_root_fk 
53
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
54
   CONSTRAINT xml_nodes_parent_fk 
55
		FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
56
);
57

    
58
CREATE SEQUENCE xml_nodes_id_seq;
59

    
60
CREATE TRIGGER xml_nodes_before_insert
61
BEFORE INSERT ON xml_nodes FOR EACH ROW
62
BEGIN
63
  SELECT xml_nodes_id_seq.nextval
64
    INTO :new.nodeid
65
    FROM dual;
66
END;
67
/
68

    
69
/* 
70
 * Documents -- table to store XML documents
71
 */
72
CREATE TABLE xml_documents (
73
	docid		VARCHAR2(55),	-- the document id #
74
	rootnodeid	NUMBER(20),	-- refernce to the root node of the DOM
75
	docname		VARCHAR2(100),	-- usually the root element name
76
	doctype		VARCHAR2(100),	-- public id indicating document type
77
	doctitle	VARCHAR2(1000),	-- title of document if exists
78
	date_created	DATE,
79
	date_updated	DATE,
80
   CONSTRAINT xml_documents_pk PRIMARY KEY (docid),
81
   CONSTRAINT xml_documents_root_fk 
82
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes
83
);
84

    
85
/* 
86
 * XML Catalog -- table to store all external sources for XML documents
87
 */
88
CREATE TABLE xml_catalog (
89
	catalog_id	NUMBER(20),	-- the id for this catalog entry
90
	entry_type	VARCHAR2(500),	-- the type of this catalog entry
91
					-- (e.g., DTD, XSD, XSL)
92
	source_doctype	VARCHAR2(500),	-- the source public_id for transforms
93
	target_doctype	VARCHAR2(500),	-- the target public_id for transforms
94
	public_id	VARCHAR2(500),	-- the unique id for this type
95
	system_id	VARCHAR2(1000),	-- the local location of the object
96
   CONSTRAINT xml_catalog_pk PRIMARY KEY (catalog_id)
97
   -- CONSTRAINT xml_catalog_uk UNIQUE (entry_type, source_doctype, target_doctype, public_id)
98
);
99

    
100
CREATE SEQUENCE xml_catalog_id_seq;
101

    
102
CREATE TRIGGER xml_catalog_before_insert
103
BEFORE INSERT ON xml_catalog FOR EACH ROW
104
BEGIN
105
  SELECT xml_catalog_id_seq.nextval
106
    INTO :new.catalog_id
107
    FROM dual;
108
END;
109
/
110

    
111
/* 
112
 * Index of Nodes -- table to store precomputed paths through tree for 
113
 * quick searching in structured searches
114
 */
115
CREATE TABLE xml_index (
116
	nodeid		NUMBER(20),	-- the unique node id
117
	path		VARCHAR2(20),	-- precomputed path through tree
118
   CONSTRAINT xml_index_pk PRIMARY KEY (nodeid,path),
119
   CONSTRAINT xml_nodes_fk FOREIGN KEY (nodeid) REFERENCES xml_nodes
120
);
121

    
122
/* 
123
 * table to store unique Accession # for every document in 2 parts
124
 */
125
CREATE TABLE xml_acc_numbers (
126
	global_name	VARCHAR2(32),	-- first part of acc #
127
	local_id	NUMBER(20),	-- second part - unique inside global name
128
   CONSTRAINT xml_acc_numbers_pk PRIMARY KEY (global_name, local_id)
129
);
(6-6/6)