20 |
20 |
*/
|
21 |
21 |
public class DBSAXDocument {
|
22 |
22 |
|
23 |
|
private Connection conn;
|
|
23 |
private Connection conn;
|
24 |
24 |
private long rootnodeid;
|
25 |
25 |
private String docname;
|
26 |
26 |
private String doctype;
|
|
27 |
private String doctitle;
|
|
28 |
private long docid;
|
27 |
29 |
|
28 |
30 |
/**
|
29 |
31 |
* Construct a new document instance
|
... | ... | |
65 |
67 |
// Do the insertion
|
66 |
68 |
pstmt.execute();
|
67 |
69 |
pstmt.close();
|
|
70 |
|
|
71 |
long assigned_id=0;
|
|
72 |
Statement stmt;
|
|
73 |
stmt = conn.createStatement();
|
|
74 |
stmt.execute("SELECT xml_documents_id_seq.currval FROM dual");
|
|
75 |
ResultSet rs = stmt.getResultSet();
|
|
76 |
boolean tableHasRows = rs.next();
|
|
77 |
if (tableHasRows) {
|
|
78 |
assigned_id = rs.getLong(1);
|
|
79 |
this.docid = assigned_id;
|
|
80 |
}
|
|
81 |
stmt.close();
|
|
82 |
|
68 |
83 |
conn.commit();
|
69 |
84 |
conn.setAutoCommit(true);
|
70 |
85 |
} catch (SQLException e) {
|
... | ... | |
72 |
87 |
}
|
73 |
88 |
}
|
74 |
89 |
|
|
90 |
/**
|
|
91 |
* Get the document title
|
|
92 |
*/
|
|
93 |
public String getTitle() {
|
|
94 |
return doctitle;
|
|
95 |
}
|
|
96 |
|
|
97 |
/**
|
|
98 |
* Set the document title
|
|
99 |
*
|
|
100 |
* @param title the new title for the document
|
|
101 |
*/
|
|
102 |
public void setTitle( String title ) {
|
|
103 |
this.doctitle = title;
|
|
104 |
try {
|
|
105 |
PreparedStatement pstmt;
|
|
106 |
pstmt = conn.prepareStatement(
|
|
107 |
"UPDATE xml_documents " +
|
|
108 |
" SET doctitle = ? " +
|
|
109 |
"WHERE docid = ?");
|
|
110 |
|
|
111 |
// Bind the values to the query
|
|
112 |
pstmt.setString(1, doctitle);
|
|
113 |
pstmt.setLong(2, docid);
|
|
114 |
|
|
115 |
// Do the insertion
|
|
116 |
pstmt.execute();
|
|
117 |
pstmt.close();
|
|
118 |
} catch (SQLException e) {
|
|
119 |
System.out.println(e.getMessage());
|
|
120 |
}
|
|
121 |
}
|
|
122 |
|
|
123 |
/**
|
|
124 |
* Look up the title of the first child element named "title"
|
|
125 |
* and record it as the document title
|
|
126 |
*/
|
|
127 |
public void setTitleFromChildElement() {
|
|
128 |
String title = null;
|
|
129 |
long assigned_id=0;
|
|
130 |
PreparedStatement pstmt;
|
|
131 |
try {
|
|
132 |
pstmt = conn.prepareStatement(
|
|
133 |
"SELECT nodedata FROM xml_nodes " +
|
|
134 |
"WHERE nodetype = 'TEXT' " +
|
|
135 |
"AND parentnodeid IN " +
|
|
136 |
"(SELECT nodeid FROM xml_nodes " +
|
|
137 |
"WHERE nodename = 'title' " +
|
|
138 |
"START WITH nodeid = ? " +
|
|
139 |
"CONNECT BY PRIOR nodeid = parentnodeid)");
|
|
140 |
/*
|
|
141 |
"SELECT nodeid " +
|
|
142 |
"FROM xml_nodes " +
|
|
143 |
"START WITH nodeid = ? " +
|
|
144 |
"CONNECT BY PRIOR nodeid = parentnodeid " +
|
|
145 |
"AND PRIOR nodename = 'title' " );
|
|
146 |
|
|
147 |
pstmt = conn.prepareStatement("SELECT nodedata " +
|
|
148 |
"FROM xml_nodes " +
|
|
149 |
"WHERE nodetype = 'TEXT' " +
|
|
150 |
" AND nodeid in " +
|
|
151 |
"(SELECT nodeid FROM xml_nodes " +
|
|
152 |
" WHERE nodename = 'title' " +
|
|
153 |
" START WITH nodeid = ? " +
|
|
154 |
" CONNECT BY PRIOR nodeid = parentnodeid ");
|
|
155 |
*/
|
|
156 |
|
|
157 |
// Bind the values to the query
|
|
158 |
pstmt.setLong(1, rootnodeid);
|
|
159 |
|
|
160 |
pstmt.execute();
|
|
161 |
ResultSet rs = pstmt.getResultSet();
|
|
162 |
boolean tableHasRows = rs.next();
|
|
163 |
if (tableHasRows) {
|
|
164 |
title = rs.getString(1);
|
|
165 |
}
|
|
166 |
pstmt.close();
|
|
167 |
} catch (SQLException e) {
|
|
168 |
System.out.println("Error getting id: " + e.getMessage());
|
|
169 |
}
|
|
170 |
|
|
171 |
// assign the new title
|
|
172 |
this.setTitle(title);
|
|
173 |
}
|
75 |
174 |
}
|
reincorporated Title registration code for documents