Revision 72
Added by bojilova about 24 years ago
DBSAXElement.java | ||
---|---|---|
8 | 8 |
* Version: '$Id$' |
9 | 9 |
*/ |
10 | 10 |
|
11 |
package edu.ucsb.nceas.metacat; |
|
11 |
//package edu.ucsb.nceas.metacat;
|
|
12 | 12 |
|
13 | 13 |
import java.sql.*; |
14 | 14 |
import java.io.IOException; |
... | ... | |
31 | 31 |
* @param parent_id the parent id number for this element |
32 | 32 |
*/ |
33 | 33 |
public DBSAXElement (Connection conn, String tagname, |
34 |
long parent_id) { |
|
34 |
long parent_id, int nodeIndex) {
|
|
35 | 35 |
|
36 |
super(tagname, parent_id); |
|
36 |
super(tagname, parent_id, nodeIndex);
|
|
37 | 37 |
|
38 | 38 |
this.conn = conn; |
39 | 39 |
writeElementToDB(); |
... | ... | |
47 | 47 |
if (getParentID() != 0) { |
48 | 48 |
pstmt = conn.prepareStatement( |
49 | 49 |
"INSERT INTO xml_nodes (nodeid, nodetype, " + |
50 |
"nodename, parentnodeid) VALUES (null, ?, ?, ?)");
|
|
50 |
"nodename, parentnodeid, nodeindex) VALUES (null, ?, ?, ?, ?)");
|
|
51 | 51 |
} else { |
52 | 52 |
pstmt = conn.prepareStatement( |
53 | 53 |
"INSERT INTO xml_nodes (nodeid, nodetype, nodename) " + |
... | ... | |
57 | 57 |
// Bind the values to the query |
58 | 58 |
pstmt.setString(1, "ELEMENT"); |
59 | 59 |
pstmt.setString(2, getTagName()); |
60 |
//pstmt.setInt(4, null); |
|
60 | 61 |
if (getParentID() != 0) { |
61 | 62 |
pstmt.setLong(3, getParentID()); |
63 |
pstmt.setInt(4, getNodeIndex()); |
|
62 | 64 |
} |
63 | 65 |
// Do the insertion |
64 | 66 |
pstmt.execute(); |
... | ... | |
71 | 73 |
} |
72 | 74 |
} |
73 | 75 |
|
76 |
/** creates SQL code and inserts comment into DB connection */ |
|
77 |
void writeCommentToDB(String data) { |
|
78 |
try { |
|
79 |
PreparedStatement pstmt; |
|
80 |
pstmt = conn.prepareStatement( |
|
81 |
"INSERT INTO xml_nodes (nodeid, nodetype, " + |
|
82 |
"nodename, parentnodeid, nodedata) VALUES (null, ?, null, ?, ?)"); |
|
83 |
|
|
84 |
// Bind the values to the query |
|
85 |
pstmt.setString(1, "COMMENT"); |
|
86 |
pstmt.setLong(2, getElementID()); |
|
87 |
pstmt.setString(3, data); |
|
88 |
// Do the insertion |
|
89 |
pstmt.execute(); |
|
90 |
pstmt.close(); |
|
91 |
} catch (SQLException e) { |
|
92 |
System.out.println(e.getMessage()); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
74 | 96 |
/** look up the assigned element id from DB connection */ |
75 | 97 |
private long getAssignedElementID() { |
76 | 98 |
long assigned_id=0; |
Also available in: Unified diff
Included new features about writing XML documents into db
This includes writing data into db XML Catalog, document data into xml_documents,
comments into xml_nodes, added nodeindex for the order of elements by given parent element.