24 |
24 |
private Connection conn;
|
25 |
25 |
|
26 |
26 |
/**
|
27 |
|
* Construct a new element instance
|
|
27 |
* Construct a new node instance for DOCUMENT nodes
|
28 |
28 |
*
|
29 |
29 |
* @param conn the JDBC Connection to which all information is written
|
30 |
|
* @param tagname the name of the element
|
31 |
|
* @param parent_id the parent id number for this element
|
|
30 |
* @param tagname the name of the node
|
32 |
31 |
*/
|
|
32 |
public DBSAXElement (Connection conn, String tagname) {
|
|
33 |
super(tagname);
|
|
34 |
this.conn = conn;
|
|
35 |
writeChildNodeToDB("DOCUMENT", tagname, null);
|
|
36 |
setNodeID(getAssignedNodeID());
|
|
37 |
}
|
|
38 |
|
|
39 |
/**
|
|
40 |
* Construct a new node instance for ELEMENT nodes
|
|
41 |
*
|
|
42 |
* @param conn the JDBC Connection to which all information is written
|
|
43 |
* @param tagname the name of the node
|
|
44 |
* @param parentNode the parent node for this node being created
|
|
45 |
*/
|
33 |
46 |
public DBSAXElement (Connection conn, String tagname,
|
34 |
|
long parent_id, int nodeIndex) {
|
|
47 |
DBSAXElement parentNode) {
|
35 |
48 |
|
36 |
|
super(tagname, parent_id, nodeIndex);
|
37 |
|
|
|
49 |
super(tagname);
|
|
50 |
setParentID(parentNode.getNodeID());
|
|
51 |
setNodeIndex(parentNode.incChildNum());
|
38 |
52 |
this.conn = conn;
|
39 |
|
if (getParentID() != 0) {
|
40 |
|
writeChildNodeToDB("ELEMENT", getTagName(), null, getNodeIndex());
|
41 |
|
} else {
|
42 |
|
writeChildNodeToDB("DOCUMENT", getTagName(), null, 0);
|
43 |
|
}
|
44 |
|
|
|
53 |
writeChildNodeToDB("ELEMENT", getTagName(), null);
|
45 |
54 |
setNodeID(getAssignedNodeID());
|
46 |
55 |
}
|
47 |
56 |
|
48 |
57 |
/** creates SQL code and inserts new node into DB connection */
|
49 |
58 |
public void writeChildNodeToDB(String nodetype, String nodename,
|
50 |
|
String data, int nodeIndex) {
|
|
59 |
String data) {
|
51 |
60 |
try {
|
52 |
61 |
PreparedStatement pstmt;
|
53 |
62 |
if (nodetype == "DOCUMENT") {
|
... | ... | |
69 |
78 |
if (nodetype != "DOCUMENT") {
|
70 |
79 |
if (nodetype == "ELEMENT") {
|
71 |
80 |
pstmt.setLong(3, getParentID());
|
|
81 |
pstmt.setString(4, data);
|
|
82 |
pstmt.setInt(5, getNodeIndex());
|
72 |
83 |
} else {
|
73 |
84 |
pstmt.setLong(3, getNodeID());
|
|
85 |
pstmt.setString(4, data);
|
|
86 |
pstmt.setInt(5, incChildNum());
|
74 |
87 |
}
|
75 |
|
pstmt.setString(4, data);
|
76 |
|
pstmt.setInt(5, nodeIndex);
|
77 |
88 |
}
|
78 |
89 |
// Do the insertion
|
79 |
90 |
pstmt.execute();
|
... | ... | |
81 |
92 |
} catch (SQLException e) {
|
82 |
93 |
System.err.println("Error inserting node: (" + nodetype + ", " +
|
83 |
94 |
nodename + ", " +
|
84 |
|
data + ", " +
|
85 |
|
nodeIndex + ")" );
|
86 |
|
|
|
95 |
data + ")" );
|
87 |
96 |
System.err.println(e.getMessage());
|
88 |
97 |
}
|
89 |
98 |
}
|
... | ... | |
137 |
146 |
// Enter the attribute in the hash table
|
138 |
147 |
super.setAttribute(attName, attValue);
|
139 |
148 |
|
140 |
|
writeChildNodeToDB("ATTRIBUTE", attName, attValue, 0);
|
141 |
149 |
// And enter the attribute in the database
|
|
150 |
writeChildNodeToDB("ATTRIBUTE", attName, attValue);
|
142 |
151 |
} else {
|
143 |
152 |
System.err.println("Attribute name must not be null!");
|
144 |
153 |
}
|
rearranged API for incrementing the node index within the parent node