Revision 3247
Added by berkley over 17 years ago
src/edu/ucsb/nceas/metacat/DBQuery.java | ||
---|---|---|
386 | 386 |
cachedQuerySpec = (QuerySpecification)sess.getAttribute("query"); |
387 | 387 |
} |
388 | 388 |
|
389 |
/*if(cachedQuerySpec != null && |
|
390 |
cachedQuerySpec.printSQL(false).equals(qspec.printSQL(false))) |
|
391 |
{ //use the cached resultset if the query was the same as the last |
|
392 |
MetacatResultSet mrs = (MetacatResultSet)sess.getAttribute("results"); |
|
393 |
logMetacat.warn("#############Using cached query results."); |
|
394 |
//if the query is the same and the session contains the query |
|
395 |
//results, return those instead of rerunning the query |
|
396 |
if(mrs != null) |
|
397 |
{ //print and return the cached buffer |
|
398 |
StringBuffer pagedResultBuffer = getPagedResult(mrs, pagestart, |
|
399 |
pagesize); |
|
400 |
if(out != null) |
|
401 |
{ |
|
402 |
out.println("<?xml version=\"1.0\"?>\n"); |
|
403 |
out.println("<resultset>\n"); |
|
404 |
out.println(" <query>" + xmlquery + "</query>\n"); |
|
405 |
out.println(pagedResultBuffer.toString()); |
|
406 |
out.println("\n</resultset>\n"); |
|
407 |
} |
|
408 |
String returnString = "<?xml version=\"1.0\"?>\n"; |
|
409 |
returnString += "<resultset>\n"; |
|
410 |
returnString += " <query>" + xmlquery + "</query>\n"; |
|
411 |
returnString += pagedResultBuffer.toString(); |
|
412 |
returnString += "\n</resultset>\n"; |
|
413 |
return new StringBuffer(returnString); |
|
414 |
} |
|
415 |
}*/ |
|
416 |
|
|
417 |
//no cached results...go on with a normal query |
|
418 |
|
|
419 | 389 |
resultset.append("<?xml version=\"1.0\"?>\n"); |
420 | 390 |
resultset.append("<resultset>\n"); |
421 | 391 |
resultset.append(" <query>" + xmlquery + "</query>"); |
... | ... | |
468 | 438 |
out.println(closeRestultset); |
469 | 439 |
} |
470 | 440 |
|
471 |
/*try |
|
472 |
{ |
|
473 |
//cache the query result and the query |
|
474 |
logMetacat.warn("#################Caching query and resultset"); |
|
475 |
sess.setAttribute("query", qspec); |
|
476 |
MetacatResultSet mrs = new MetacatResultSet(resultset.toString()); |
|
477 |
sess.setAttribute("results", mrs); |
|
478 |
StringBuffer pagedResultBuffer = getPagedResult(mrs, pagestart, pagesize); |
|
479 |
String returnString = "<?xml version=\"1.0\"?>\n"; |
|
480 |
returnString += "<resultset>\n"; |
|
481 |
returnString += " <query>" + xmlquery + "</query>\n"; |
|
482 |
returnString += pagedResultBuffer.toString(); |
|
483 |
returnString += "\n</resultset>\n"; |
|
484 |
return new StringBuffer(returnString); |
|
485 |
|
|
486 |
} |
|
487 |
catch(Exception e) |
|
488 |
{ |
|
489 |
logMetacat.error("Could not parse resultset: " + e.getMessage()); |
|
490 |
//e.printStackTrace(); |
|
491 |
}*/ |
|
492 |
|
|
493 | 441 |
//default to returning the whole resultset |
494 | 442 |
return resultset; |
495 | 443 |
}//createResultDocuments |
... | ... | |
585 | 533 |
logMetacat.warn("Time to execute query: " |
586 | 534 |
+ (queryExecuteTime - startTime)); |
587 | 535 |
|
588 |
boolean tableHasRows; |
|
536 |
boolean tableHasRows = rs.next();
|
|
589 | 537 |
|
590 |
//if(pagestart == 0) |
|
591 |
//{ //if we're on page 0 then move to the first record |
|
592 |
tableHasRows = rs.next(); |
|
593 |
//} |
|
594 |
|
|
595 |
/*for(int z=0; z<pagesize * pagestart; z++) |
|
596 |
{ //move to the start page |
|
597 |
logMetacat.warn("############moving to: " + z); |
|
598 |
tableHasRows = rs.next(); |
|
599 |
if(!tableHasRows) |
|
600 |
{ |
|
601 |
break; |
|
602 |
} |
|
603 |
}*/ |
|
604 |
|
|
605 | 538 |
if(pagesize == 0) |
606 | 539 |
{ //this makes sure we get all results if there is no paging |
607 | 540 |
pagesize = 99999; |
... | ... | |
783 | 716 |
logMetacat.warn("currentIndex: " + currentIndex); |
784 | 717 |
if(currentIndex >= ((pagesize * pagestart) + pagesize)) |
785 | 718 |
{ |
786 |
logMetacat.warn("docListResult: " + docListResult.toString()); |
|
787 | 719 |
ResultDocumentSet pagedResultsHash = new ResultDocumentSet(); |
788 | 720 |
for(int i=pagesize*pagestart; i<docListResult.size(); i++) |
789 | 721 |
{ |
... | ... | |
801 | 733 |
} |
802 | 734 |
}//while |
803 | 735 |
|
804 |
//subset the docListResult by pages |
|
805 |
/*Hashtable pagedResultsHash = new Hashtable(); |
|
806 |
Enumeration keys = docListResult.keys(); |
|
807 |
if(pagesize != 0) |
|
808 |
{ |
|
809 |
for(int z=0; z<pagesize * pagestart; z++) |
|
810 |
{ //move to the start page |
|
811 |
logMetacat.warn("############moving to: " + z); |
|
812 |
keys.nextElement(); |
|
813 |
} |
|
814 |
|
|
815 |
for(int z=pagestart * pagesize; z<(pagesize * pagestart) + pagesize; z++) |
|
816 |
{ |
|
817 |
try |
|
818 |
{ |
|
819 |
logMetacat.warn("############hashing result: " + z); |
|
820 |
String key = (String)keys.nextElement(); |
|
821 |
pagedResultsHash.put(key, docListResult.get(key)); |
|
822 |
} |
|
823 |
catch(java.util.NoSuchElementException nsee) |
|
824 |
{ |
|
825 |
break; |
|
826 |
} |
|
827 |
} |
|
828 |
docListResult = pagedResultsHash; |
|
829 |
}*/ |
|
830 |
|
|
831 | 736 |
rs.close(); |
832 | 737 |
pstmt.close(); |
833 | 738 |
//if docListResult is not empty, it need to be sent. |
Also available in: Unified diff
removed a bunch of commented out code