Revision 453
Added by berkley over 23 years ago
DBQuery.java | ||
---|---|---|
121 | 121 |
* |
122 | 122 |
* @param xmlquery the xml serialization of the query (@see pathquery.dtd) |
123 | 123 |
*/ |
124 |
public Hashtable findDocuments(Reader xmlquery, String user, String group) { |
|
124 |
public Hashtable findDocuments(Reader xmlquery, String user, String group) |
|
125 |
//throws Exception |
|
126 |
{ |
|
125 | 127 |
Hashtable docListResult = new Hashtable(); |
126 | 128 |
PreparedStatement pstmt; |
127 | 129 |
String docid = null; |
... | ... | |
132 | 134 |
String updateDate = null; |
133 | 135 |
String fieldname = null; |
134 | 136 |
String fielddata = null; |
137 |
String relation = null; |
|
135 | 138 |
StringBuffer document = null; |
136 | 139 |
|
137 | 140 |
try { |
... | ... | |
215 | 218 |
} |
216 | 219 |
} |
217 | 220 |
} |
221 |
|
|
222 |
pstmt = conn.prepareStatement(qspec.printPackageSQL()); |
|
223 |
pstmt.execute(); |
|
224 |
rs = pstmt.getResultSet(); |
|
225 |
tableHasRows = rs.next(); |
|
226 |
String[][] relations = new String[2000][3]; |
|
227 |
int relLength=0; |
|
228 |
while(tableHasRows) |
|
229 |
{ |
|
230 |
relations[relLength][0] = rs.getString(1).trim(); |
|
231 |
relations[relLength][1] = rs.getString(2).trim(); |
|
232 |
relations[relLength][2] = rs.getString(3).trim(); |
|
233 |
relLength++; |
|
234 |
|
|
235 |
//this get's direct relations from the data. i.e. those relations |
|
236 |
//where the docid of the current document is in the subject tag. |
|
237 |
|
|
238 |
docid = rs.getString(1); |
|
239 |
metacatURL murl = new metacatURL(docid); |
|
240 |
if(murl.getURLType().equals("metacat")) |
|
241 |
{//we only want to process metacat urls here. |
|
242 |
String[] tempparam = murl.getParam(0); |
|
243 |
if(tempparam[0].equals("docid")) |
|
244 |
{ |
|
245 |
docid = tempparam[1]; |
|
246 |
document = new StringBuffer(); |
|
247 |
document.append("<relation>"); |
|
248 |
document.append("<relationtype>").append(rs.getString(2)); |
|
249 |
document.append("</relationtype>"); |
|
250 |
document.append("<relationdoc>").append(rs.getString(3)); |
|
251 |
document.append("</relationdoc>"); |
|
252 |
document.append("</relation>"); |
|
253 |
tableHasRows = rs.next(); |
|
254 |
if(docListResult.containsKey(docid)) |
|
255 |
{ |
|
256 |
String removedelement = (String)docListResult.remove(docid); |
|
257 |
docListResult.put(docid, removedelement + document.toString()); |
|
258 |
} |
|
259 |
else |
|
260 |
{ |
|
261 |
docListResult.put(docid, document.toString()); |
|
262 |
} |
|
263 |
} |
|
264 |
else |
|
265 |
{ |
|
266 |
//throw new Exception("Error in url. The first parameter must " + |
|
267 |
// "be the docid."); |
|
268 |
System.err.println("DBQuery: error in url"); |
|
269 |
} |
|
270 |
} |
|
271 |
} |
|
272 |
|
|
273 |
//this loop handles transitive relations. i.e. if two relation tags |
|
274 |
//both have the same object then the subject of each are related. |
|
275 |
for(int i=0; i<relLength; i++) |
|
276 |
{ |
|
277 |
for(int j=0; j<relLength; j++) |
|
278 |
{ |
|
279 |
if(i != j) |
|
280 |
{ |
|
281 |
if(relations[i][2].equals(relations[j][2])) |
|
282 |
{//the objects are the same. |
|
283 |
metacatURL murl = new metacatURL(relations[i][0]); |
|
284 |
//relations[i][0] contains the docid of document that |
|
285 |
//the new document is related to. |
|
286 |
String[] tempparam = murl.getParam(0); |
|
287 |
if(tempparam[0].equals("docid")) |
|
288 |
{ |
|
289 |
docid = tempparam[1]; |
|
290 |
document = new StringBuffer(); |
|
291 |
document.append("<relation>"); |
|
292 |
document.append("<relationtype>").append(relations[j][1]); |
|
293 |
document.append("</relationtype>"); |
|
294 |
document.append("<relationdoc>").append(relations[j][0]); |
|
295 |
//the relation is to the subject of the new document |
|
296 |
//instead of the object. |
|
297 |
// direct relation transitive relation |
|
298 |
// |-----------------| |-----------------| |
|
299 |
// subject -> (object = object) -> subject |
|
300 |
document.append("</relationdoc>"); |
|
301 |
document.append("</relation>"); |
|
302 |
if(docListResult.containsKey(docid)) |
|
303 |
{ |
|
304 |
String removedelement = (String)docListResult.remove(docid); |
|
305 |
docListResult.put(docid, removedelement + |
|
306 |
document.toString()); |
|
307 |
} |
|
308 |
else |
|
309 |
{ |
|
310 |
docListResult.put(docid, document.toString()); |
|
311 |
} |
|
312 |
} |
|
313 |
} |
|
314 |
} |
|
315 |
} |
|
316 |
} |
|
317 |
|
|
218 | 318 |
pstmt.close(); |
219 | 319 |
} catch (SQLException e) { |
220 | 320 |
System.err.println("Error getting id: " + e.getMessage()); |
... | ... | |
595 | 695 |
|
596 | 696 |
/** |
597 | 697 |
* '$Log$ |
698 |
* 'Revision 1.19 2000/09/12 17:37:07 bojilova |
|
699 |
* 'added check from "read" permission on "query" and "squery" actions |
|
700 |
* 'for connected user or for "public" connection |
|
701 |
* ' |
|
598 | 702 |
* 'Revision 1.18 2000/09/05 20:50:56 berkley |
599 | 703 |
* 'Added a method called getNodeContent which retrieves the content of a node in a document. If there are more than one nodes with the same name returned, it returns an array with all of the data. |
600 | 704 |
* ' |
Also available in: Unified diff
Added functionality for package specifications. metacatservlet now contains a new action called getrelateddocument that handles retrieving related documents using the metacatURL specification (metacatURL.java). DBQuery contains new code in runQuery that embeds relation tags in the returned hashtable describing the documents related to each docid. querySpecification contains a new method which prints the sql that does the relation query.