Revision 149
Added by bojilova over 24 years ago
src/edu/ucsb/nceas/metacat/DBSAXHandler.java | ||
---|---|---|
33 | 33 |
|
34 | 34 |
static int elementNo = 0; |
35 | 35 |
static String docname = null; |
36 |
//private String docID; |
|
37 |
//private String rootNodeID; |
|
36 | 38 |
private String doctype; |
37 | 39 |
private String systemid; |
38 | 40 |
private boolean debug = false; |
... | ... | |
40 | 42 |
private Stack nodeStack; |
41 | 43 |
private Connection conn = null; |
42 | 44 |
private DBSAXDocument currentDocument; |
45 |
private DBSAXNode rootNode; |
|
43 | 46 |
|
44 | 47 |
/** Construct an instance of the handler class |
45 | 48 |
* |
... | ... | |
63 | 66 |
System.out.println("start Document"); |
64 | 67 |
} |
65 | 68 |
// Create the document node represantation as root |
66 |
DBSAXNode documentNode = new DBSAXNode(conn, docname);
|
|
69 |
rootNode = new DBSAXNode(conn, docname);
|
|
67 | 70 |
// Add the node to the stack, so that any text data can be |
68 | 71 |
// added as it is encountered |
69 |
nodeStack.push(documentNode);
|
|
72 |
nodeStack.push(rootNode);
|
|
70 | 73 |
} |
71 | 74 |
|
72 | 75 |
/** SAX Handler that receives notification of end of the document */ |
... | ... | |
139 | 142 |
} else if (doctype == null) { |
140 | 143 |
doctype = DBEntityResolver.doctype; |
141 | 144 |
} |
142 |
DBSAXNode documentNode = (DBSAXNode)nodeStack.peek(); |
|
143 |
documentNode.writeNodename(docname); |
|
144 |
currentDocument = new DBSAXDocument(conn, documentNode.getNodeID(), |
|
145 |
//DBSAXNode documentNode = (DBSAXNode)nodeStack.peek(); |
|
146 |
rootNode.writeNodename(docname); |
|
147 |
rootNode.writeRootNodeID(rootNode.getNodeID()); |
|
148 |
currentDocument = new DBSAXDocument(conn, rootNode.getNodeID(), |
|
145 | 149 |
docname, doctype); |
150 |
rootNode.writeDocID(currentDocument.getDocID()); |
|
146 | 151 |
} |
147 | 152 |
|
148 | 153 |
// Create the current node representation |
149 |
currentNode = new DBSAXNode(conn, localName, parentNode); |
|
154 |
currentNode = new DBSAXNode(conn, localName, parentNode, rootNode, currentDocument);
|
|
150 | 155 |
|
151 | 156 |
// Add all of the attributes |
152 | 157 |
for (int i=0; i<atts.getLength(); i++) |
src/edu/ucsb/nceas/metacat/DBSAXDocument.java | ||
---|---|---|
87 | 87 |
} |
88 | 88 |
} |
89 | 89 |
|
90 |
/** look up the assigned doc id from DB connection */ |
|
91 |
public long getDocID() { |
|
92 |
long doc_id=0; |
|
93 |
Statement stmt; |
|
94 |
try { |
|
95 |
stmt = conn.createStatement(); |
|
96 |
stmt.execute("SELECT xml_documents_id_seq.currval FROM dual"); |
|
97 |
ResultSet rs = stmt.getResultSet(); |
|
98 |
boolean tableHasRows = rs.next(); |
|
99 |
if (tableHasRows) { |
|
100 |
doc_id = rs.getLong(1); |
|
101 |
} |
|
102 |
stmt.close(); |
|
103 |
} catch (SQLException e) { |
|
104 |
System.out.println("Error getting id: " + e.getMessage()); |
|
105 |
} |
|
106 |
|
|
107 |
// assign the new ID number |
|
108 |
return doc_id; |
|
109 |
} |
|
110 |
|
|
90 | 111 |
/** |
91 | 112 |
* Get the document title |
92 | 113 |
*/ |
src/edu/ucsb/nceas/metacat/DBSAXNode.java | ||
---|---|---|
34 | 34 |
this.conn = conn; |
35 | 35 |
writeChildNodeToDB("DOCUMENT", tagname, null); |
36 | 36 |
setNodeID(getAssignedNodeID()); |
37 |
setRootNodeID(getNodeID()); |
|
37 | 38 |
} |
38 | 39 |
|
39 | 40 |
/** |
... | ... | |
44 | 45 |
* @param parentNode the parent node for this node being created |
45 | 46 |
*/ |
46 | 47 |
public DBSAXNode (Connection conn, String tagname, |
47 |
DBSAXNode parentNode) {
|
|
48 |
DBSAXNode parentNode, DBSAXNode rootNode, DBSAXDocument currentDocument) {
|
|
48 | 49 |
|
49 | 50 |
super(tagname); |
50 | 51 |
setParentID(parentNode.getNodeID()); |
52 |
setRootNodeID(rootNode.getNodeID()); |
|
53 |
setDocID(currentDocument.getDocID()); |
|
51 | 54 |
setNodeIndex(parentNode.incChildNum()); |
52 | 55 |
this.conn = conn; |
53 | 56 |
writeChildNodeToDB("ELEMENT", getTagName(), null); |
... | ... | |
68 | 71 |
pstmt = conn.prepareStatement( |
69 | 72 |
"INSERT INTO xml_nodes " + |
70 | 73 |
"(nodeid, nodetype, nodename, " + |
71 |
"parentnodeid, nodedata, nodeindex) " + |
|
72 |
"VALUES (null, ?, ?, ?, ?, ?)"); |
|
74 |
"parentnodeid, rootnodeid, docid, nodedata, nodeindex) " +
|
|
75 |
"VALUES (null, ?, ?, ?, ?, ?, ?, ?)");
|
|
73 | 76 |
} |
74 | 77 |
|
75 | 78 |
// Bind the values to the query |
... | ... | |
78 | 81 |
if (nodetype != "DOCUMENT") { |
79 | 82 |
if (nodetype == "ELEMENT") { |
80 | 83 |
pstmt.setLong(3, getParentID()); |
81 |
pstmt.setString(4, data); |
|
82 |
pstmt.setInt(5, getNodeIndex()); |
|
84 |
pstmt.setLong(4, getRootNodeID()); |
|
85 |
pstmt.setLong(5, getDocID()); |
|
86 |
pstmt.setString(6, data); |
|
87 |
pstmt.setInt(7, getNodeIndex()); |
|
83 | 88 |
} else { |
84 | 89 |
pstmt.setLong(3, getNodeID()); |
85 |
pstmt.setString(4, data); |
|
86 |
pstmt.setInt(5, incChildNum()); |
|
90 |
if (nodetype == "COMMENT") |
|
91 |
System.out.println(getDocID()); |
|
92 |
pstmt.setLong(4, getRootNodeID()); |
|
93 |
pstmt.setLong(5, getDocID()); |
|
94 |
pstmt.setString(6, data); |
|
95 |
pstmt.setInt(7, incChildNum()); |
|
87 | 96 |
} |
88 | 97 |
} |
89 | 98 |
// Do the insertion |
... | ... | |
119 | 128 |
} |
120 | 129 |
} |
121 | 130 |
|
131 |
/** |
|
132 |
* creates SQL code to put root node id for the document node |
|
133 |
* into DB connection |
|
134 |
*/ |
|
135 |
public void writeRootNodeID(long rootnode_id) { |
|
136 |
try { |
|
137 |
PreparedStatement pstmt; |
|
138 |
pstmt = conn.prepareStatement( |
|
139 |
"UPDATE xml_nodes set rootnodeid = ? " + |
|
140 |
"WHERE nodeid = ?"); |
|
141 |
|
|
142 |
// Bind the values to the query |
|
143 |
pstmt.setLong(1, rootnode_id); |
|
144 |
pstmt.setLong(2, getNodeID()); |
|
145 |
// Do the insertion |
|
146 |
pstmt.execute(); |
|
147 |
pstmt.close(); |
|
148 |
} catch (SQLException e) { |
|
149 |
System.out.println(e.getMessage()); |
|
150 |
} |
|
151 |
} |
|
152 |
/** |
|
153 |
* creates SQL code to put doc ID for the document node and for comment/PI nodes under document node |
|
154 |
* into DB connection |
|
155 |
*/ |
|
156 |
public void writeDocID(long doc_id) { |
|
157 |
try { |
|
158 |
PreparedStatement pstmt; |
|
159 |
pstmt = conn.prepareStatement( |
|
160 |
"UPDATE xml_nodes set docid = ? " + |
|
161 |
"WHERE nodeid = ?"); |
|
162 |
|
|
163 |
// Bind the values to the query |
|
164 |
pstmt.setLong(1, doc_id); |
|
165 |
pstmt.setLong(2, getNodeID()); |
|
166 |
// Do the insertion |
|
167 |
pstmt.execute(); |
|
168 |
pstmt.close(); |
|
169 |
|
|
170 |
// for comments and PI on the top |
|
171 |
pstmt = conn.prepareStatement( |
|
172 |
"UPDATE xml_nodes set docid = ? " + |
|
173 |
"WHERE parentnodeid = ?"); |
|
174 |
// Bind the values to the query |
|
175 |
pstmt.setLong(1, doc_id); |
|
176 |
pstmt.setLong(2, getNodeID()); |
|
177 |
// Do the insertion |
|
178 |
pstmt.execute(); |
|
179 |
pstmt.close(); |
|
180 |
} catch (SQLException e) { |
|
181 |
System.out.println(e.getMessage()); |
|
182 |
} |
|
183 |
} |
|
184 |
|
|
122 | 185 |
/** look up the assigned node id from DB connection */ |
123 | 186 |
private long getAssignedNodeID() { |
124 | 187 |
long assigned_id=0; |
src/edu/ucsb/nceas/metacat/BasicNode.java | ||
---|---|---|
21 | 21 |
private long node_id; |
22 | 22 |
private String tagname; |
23 | 23 |
private long parent_id; |
24 |
private long rootnode_id; |
|
25 |
private long doc_id; |
|
24 | 26 |
private Hashtable attributes; |
25 | 27 |
private int childNum; |
26 | 28 |
private int nodeIndex; |
... | ... | |
110 | 112 |
this.parent_id = parent_id; |
111 | 113 |
} |
112 | 114 |
|
115 |
/** Get the root node id of this node */ |
|
116 |
public long getRootNodeID() |
|
117 |
{ |
|
118 |
return rootnode_id; |
|
119 |
} |
|
120 |
|
|
121 |
/** Set the root node id of this node */ |
|
122 |
public void setRootNodeID(long rootnode_id) |
|
123 |
{ |
|
124 |
this.rootnode_id = rootnode_id; |
|
125 |
} |
|
126 |
|
|
127 |
/** Get the doc id of this node */ |
|
128 |
public long getDocID() |
|
129 |
{ |
|
130 |
return doc_id; |
|
131 |
} |
|
132 |
|
|
133 |
/** Set the doc id of this node */ |
|
134 |
public void setDocID(long doc_id) |
|
135 |
{ |
|
136 |
this.doc_id = doc_id; |
|
137 |
} |
|
138 |
|
|
113 | 139 |
/** Get the name of this node */ |
114 | 140 |
public String getTagName() |
115 | 141 |
{ |
Also available in: Unified diff
assign rootnodeid, docid for every node in xml_nodes table by given document