Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2004 Regents of the University of California and the
4
 *             National Center for Ecological Analysis and Synthesis
5
 *
6
 *   '$Author: sgarg $'
7
 *     '$Date: 2005-09-07 16:51:20 -0700 (Wed, 07 Sep 2005) $'
8
 * '$Revision: 2567 $'
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
 */
24
 
25

    
26
/**
27
 * Create the xml_path_index table
28
 */
29

    
30
CREATE SEQUENCE xml_path_index_id_seq;
31
CREATE TABLE xml_path_index (
32
        nodeid          NUMBER(20),     -- the unique node id
33
        docid           VARCHAR2(250),  -- index to the document id
34
        path            VARCHAR2(1000), -- precomputed path through tree
35
	nodedata        VARCHAR2(4000), -- the data for this node (e.g.,
36
                                        -- for TEXT it is the content)
37
        nodedatanumerical NUMBER,       -- the data for this node if
38
                                        -- it is a number
39
        parentnodeid    NUMBER(20),     -- index of the parent of this node
40

    
41
   CONSTRAINT xml_path_index_pk PRIMARY KEY (nodeid),
42
   CONSTRAINT xml_path_index_docid_fk
43
                FOREIGN KEY (docid) REFERENCES xml_documents
44
);
45
                                                                                                                                                             
46
CREATE TRIGGER xml_path_index_before_insert
47
BEFORE INSERT ON xml_path_index FOR EACH ROW
48
BEGIN
49
  SELECT xml_path_index_id_seq.nextval
50
    INTO :new.nodeid
51
    FROM dual;
52
END;
53
/
54

    
55

    
56
/*
57
 * Index of the path, nodedata, nodedatanumerical in xml_path_index
58
 */
59
CREATE INDEX xml_path_index_idx1 ON xml_path_index (path);
60
CREATE INDEX xml_path_index_idx2 ON xml_path_index (nodedata);
61
CREATE INDEX xml_path_index_idx3 ON xml_path_index (nodedatanumerical);
62

    
63

    
64

    
65
/**
66
 * Create the xml_nodes_revisions table
67
 * to store nodes from xml_nodes which 
68
 * are of old revisions and deleted document
69
 */
70

    
71
CREATE TABLE xml_nodes_revisions (
72
        nodeid          NUMBER(20),     -- the unique node id (pk)
73
        nodeindex       NUMBER(10),     -- order of nodes within parent
74
        nodetype        VARCHAR2(20),   -- type (DOCUMENT, COMMENT, PI,
75
                                        -- ELEMENT, ATTRIBUTE, TEXT)
76
        nodename        VARCHAR2(250),  -- the name of an element or attribute
77
        nodeprefix      VARCHAR2(50),   -- the namespace prefix of an element
78
                                        -- or attribute
79
        nodedata        VARCHAR2(4000), -- the data for this node (e.g.,
80
                                        -- for TEXT it is the content)
81
        parentnodeid    NUMBER(20),     -- index of the parent of this node
82
        rootnodeid      NUMBER(20),     -- index of the root node of this tree
83
        docid           VARCHAR2(250),  -- index to the document id
84
        date_created    DATE,
85
        date_updated    DATE,
86
        nodedatanumerical NUMBER,       -- the data for this node if
87
                                        -- it is a number
88
   CONSTRAINT xml_nodes_revisions_pk PRIMARY KEY (nodeid),
89
   CONSTRAINT xml_nodes_revisions_root_fk
90
                FOREIGN KEY (rootnodeid) REFERENCES xml_nodes_revisions,
91
   CONSTRAINT xml_nodes_revisions_parent_fk
92
                FOREIGN KEY (parentnodeid) REFERENCES xml_nodes_revisions
93
);
94

    
95

    
96
/**
97
 * Indexes of rootnodeid, parentnodeid, and nodename in xml_nodes_revision
98
 */
99
CREATE INDEX xml_nodes_revisions_idx1 ON xml_nodes_revisions (rootnodeid);
100
CREATE INDEX xml_nodes_revisions_idx2 ON xml_nodes_revisions (parentnodeid);
101
CREATE INDEX xml_nodes_revisions_idx3 ON xml_nodes_revisions (nodename);
102

    
103

    
104
/**
105
 * Drop the constraint from xml_revisions which points to xml_nodes
106
 */
107
ALTER TABLE xml_revisions DROP CONSTRAINT xml_revisions_root_fk;
108

    
109

    
110
/**
111
 * Copy the nodes from xml_nodes to xml_nodes_revisions for old revisions
112
 * of the documents and deleted documents
113
 */
114
INSERT INTO xml_nodes_revisions (nodeid, nodeindex, nodetype,
115
nodename, nodeprefix, nodedata, parentnodeid, rootnodeid,
116
docid, date_created, date_updated, nodedatanumerical)
117
SELECT * FROM xml_nodes WHERE rootnodeid NOT IN
118
(SELECT rootnodeid from xml_documents where rootnodeid is not NULL);
119

    
120

    
121
/**
122
 * Create the key constraint in xml_revisions which points to 
123
 * xml_nodes_revisions
124
 */
125
ALTER TABLE xml_revisions ADD CONSTRAINT xml_revisions_root_fk
126
 FOREIGN KEY (rootnodeid) REFERENCES xml_nodes_revisions (nodeid);
127
 
128

    
129
/**
130
 * Delete the records from xml_index table which point to old revisions in xml_index
131
 * This is possible for documents for which the indexing thread failed during UPDATE
132
 */
133

    
134
DELETE FROM xml_index WHERE nodeid IN (SELECT nodeid FROM xml_nodes WHERE
135
rootnodeid NOT IN (SELECT rootnodeid FROM xml_documents WHERE rootnodeid IS NOT NULL)); 
136

    
137
/**
138
 * Delete the records from xml_nodes which were transfered to xml_nodes_revisions 
139
 */
140
DELETE FROM xml_nodes WHERE rootnodeid NOT IN
141
(SELECT rootnodeid from xml_documents where rootnodeid is not NULL);
(23-23/28)