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 123 2000-06-07 00:44:37Z 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
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

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

    
57
CREATE SEQUENCE xml_nodes_id_seq;
58

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

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

    
84
CREATE SEQUENCE xml_documents_id_seq;
85

    
86
CREATE TRIGGER xml_documents_before_insert
87
BEFORE INSERT ON xml_documents FOR EACH ROW
88
BEGIN
89
  SELECT xml_documents_id_seq.nextval
90
    INTO :new.docid
91
    FROM dual;
92
END;
93
/
94

    
95
/* 
96
 * XML Catalog -- table to store all external sources for XML documents
97
 */
98
CREATE TABLE xml_catalog (
99
	catalog_id	NUMBER(20),	-- the id for this catalog entry
100
	entry_type	VARCHAR2(500),	-- the type of this catalog entry
101
					-- (e.g., DTD, XSD, XSL)
102
	source_doctype	VARCHAR2(500),	-- the source public_id for transforms
103
	target_doctype	VARCHAR2(500),	-- the target public_id for transforms
104
	public_id	VARCHAR2(500),	-- the unique id for this type
105
	system_id	VARCHAR2(1000),	-- the local location of the object
106
   CONSTRAINT xml_catalog_pk PRIMARY KEY (catalog_id)
107
   -- CONSTRAINT xml_catalog_uk UNIQUE (entry_type, source_doctype, target_doctype, public_id)
108
);
109

    
110
CREATE SEQUENCE xml_catalog_id_seq;
111

    
112
CREATE TRIGGER xml_catalog_before_insert
113
BEFORE INSERT ON xml_catalog FOR EACH ROW
114
BEGIN
115
  SELECT xml_catalog_id_seq.nextval
116
    INTO :new.catalog_id
117
    FROM dual;
118
END;
119
/
120

    
121
/* 
122
 * Index of Nodes -- table to store precomputed paths through tree for 
123
 * quick searching in structured searches
124
 */
125
CREATE TABLE xml_index (
126
	nodeid		NUMBER(20),	-- the unique node id
127
	path		VARCHAR2(20),	-- precomputed path through tree
128
   CONSTRAINT xml_index_pk PRIMARY KEY (nodeid,path),
129
   CONSTRAINT xml_nodes_fk FOREIGN KEY (nodeid) REFERENCES xml_nodes
130
);
(6-6/6)