Revision 3221
Added by berkley about 17 years ago
DBQuery.java | ||
---|---|---|
358 | 358 |
private StringBuffer getPagedResult(MetacatResultSet mrs, int pagestart, |
359 | 359 |
int pagesize) |
360 | 360 |
{ |
361 |
logMetacat.warn(mrs.toString()); |
|
361 |
//logMetacat.warn(mrs.toString());
|
|
362 | 362 |
if(pagesize == 0) |
363 | 363 |
{ //if pagesize is 0 then we return the whole resultset |
364 | 364 |
return new StringBuffer(mrs.toString()); |
... | ... | |
422 | 422 |
cachedQuerySpec.printSQL(false).equals(qspec.printSQL(false))) |
423 | 423 |
{ //use the cached resultset if the query was the same as the last |
424 | 424 |
MetacatResultSet mrs = (MetacatResultSet)sess.getAttribute("results"); |
425 |
logMetacat.info("Using cached query results"); |
|
425 |
logMetacat.info("Using cached query results.");
|
|
426 | 426 |
//if the query is the same and the session contains the query |
427 | 427 |
//results, return those instead of rerunning the query |
428 | 428 |
if(mrs != null) |
... | ... | |
470 | 470 |
resultset = findResultDoclist(qspec, resultset, out, user, groups, |
471 | 471 |
dbconn, useXMLIndex, pagesize, pagestart, |
472 | 472 |
sessionid); |
473 |
|
|
474 | 473 |
} //try |
475 | 474 |
catch (IOException ioe) |
476 | 475 |
{ |
... | ... | |
501 | 500 |
out.println(closeRestultset); |
502 | 501 |
} |
503 | 502 |
|
504 |
//create a DOM to cache |
|
505 | 503 |
try |
506 | 504 |
{ |
507 |
|
|
508 | 505 |
//cache the query result and the query |
509 | 506 |
logMetacat.info("Caching query and resultset"); |
510 | 507 |
sess.setAttribute("query", qspec); |
511 |
MetacatResultSet mrs = processAndCacheResults(resultset.toString(), sess);
|
|
508 |
MetacatResultSet mrs = new MetacatResultSet(resultset.toString());
|
|
512 | 509 |
sess.setAttribute("results", mrs); |
513 | 510 |
StringBuffer pagedResultBuffer = getPagedResult(mrs, pagestart, pagesize); |
514 | 511 |
String returnString = "<?xml version=\"1.0\"?>\n"; |
... | ... | |
520 | 517 |
} |
521 | 518 |
catch(Exception e) |
522 | 519 |
{ |
523 |
logMetacat.error("################Could not parse resultset: " + e.getMessage()); |
|
520 |
logMetacat.error("Could not parse resultset: " + e.getMessage()); |
|
521 |
//e.printStackTrace(); |
|
524 | 522 |
} |
525 | 523 |
|
524 |
//default to returning the whole resultset |
|
526 | 525 |
return resultset; |
527 | 526 |
}//createResultDocuments |
528 | 527 |
|
529 |
/** |
|
530 |
* parse the dom of the resultset into a MetacatResultSet object so it can |
|
531 |
* be cached in a reasonable way |
|
532 |
*/ |
|
533 |
private MetacatResultSet processAndCacheResults(String resultset, HttpSession sess) |
|
534 |
throws Exception |
|
535 |
{ |
|
536 |
StringReader sreader = new StringReader(resultset.toString()); |
|
537 |
InputSource inputsource = new InputSource(sreader); |
|
538 |
logMetacat.warn("processing DOM"); |
|
539 |
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputsource); |
|
540 |
//got the dom, now process it into an MRS |
|
541 |
MetacatResultSet mrs = new MetacatResultSet(doc); |
|
542 |
return mrs; |
|
543 |
} |
|
544 |
|
|
545 | 528 |
/* |
546 | 529 |
* Find the doc list which match the query |
547 | 530 |
*/ |
Also available in: Unified diff
paging now works well. sped up the caching by using SAX instead of DOM parsing. it seems fast. need some other people to test for me though. the two params needed are 'pagesize' and 'pagestart'. I haven't updated any of the web interfaces to use this, so if you want to try it, you'll have to type in the url the old fashioned way