52 |
52 |
|
53 |
53 |
import javax.servlet.ServletOutputStream;
|
54 |
54 |
import javax.servlet.http.HttpServletResponse;
|
|
55 |
import javax.servlet.http.HttpSession;
|
55 |
56 |
|
56 |
57 |
import org.apache.log4j.Logger;
|
57 |
58 |
|
... | ... | |
257 |
258 |
String user, String[] groups,
|
258 |
259 |
String sessionid, boolean useXMLIndex)
|
259 |
260 |
{
|
|
261 |
int pagesize = 0;
|
|
262 |
int pagestart = 0;
|
|
263 |
|
|
264 |
if(params.containsKey("pagesize") && params.containsKey("pagestart"))
|
|
265 |
{
|
|
266 |
String pagesizeStr = ((String[])params.get("pagesize"))[0];
|
|
267 |
String pagestartStr = ((String[])params.get("pagestart"))[0];
|
|
268 |
if(pagesizeStr != null && pagestartStr != null)
|
|
269 |
{
|
|
270 |
pagesize = (new Integer(pagesizeStr)).intValue();
|
|
271 |
pagestart = (new Integer(pagestartStr)).intValue();
|
|
272 |
}
|
|
273 |
}
|
|
274 |
|
260 |
275 |
// get query and qformat
|
261 |
276 |
String xmlquery = ((String[])params.get("query"))[0];
|
262 |
277 |
|
|
278 |
logMetacat.warn("SESSIONID: " + sessionid);
|
263 |
279 |
logMetacat.warn("xmlquery: " + xmlquery);
|
264 |
280 |
String qformat = ((String[])params.get("qformat"))[0];
|
265 |
281 |
logMetacat.warn("qformat: " + qformat);
|
... | ... | |
288 |
304 |
{
|
289 |
305 |
//xml format
|
290 |
306 |
response.setContentType("text/xml");
|
291 |
|
createResultDocument(xmlquery, qspec, out, user, groups, useXMLIndex);
|
|
307 |
createResultDocument(xmlquery, qspec, out, user, groups, useXMLIndex,
|
|
308 |
pagesize, pagestart, sessionid);
|
292 |
309 |
}//if
|
293 |
310 |
else
|
294 |
311 |
{
|
... | ... | |
296 |
313 |
response.setContentType("text/html");
|
297 |
314 |
PrintWriter nonout = null;
|
298 |
315 |
StringBuffer xml = createResultDocument(xmlquery, qspec, nonout, user,
|
299 |
|
groups, useXMLIndex);
|
|
316 |
groups, useXMLIndex, pagesize,
|
|
317 |
pagestart, sessionid);
|
300 |
318 |
|
301 |
319 |
//transfer the xml to html
|
302 |
320 |
try
|
... | ... | |
305 |
323 |
DBTransform trans = new DBTransform();
|
306 |
324 |
response.setContentType("text/html");
|
307 |
325 |
|
308 |
|
// if the user is a moderator, then pass a param to the
|
|
326 |
// if the user is a moderator, then pass a param to the
|
309 |
327 |
// xsl specifying the fact
|
310 |
328 |
if(MetaCatUtil.isModerator(user, groups)){
|
311 |
329 |
params.put("isModerator", new String[] {"true"});
|
... | ... | |
336 |
354 |
QuerySpecification qspec,
|
337 |
355 |
PrintWriter out,
|
338 |
356 |
String user, String[] groups,
|
339 |
|
boolean useXMLIndex)
|
|
357 |
boolean useXMLIndex, int pagesize,
|
|
358 |
int pagestart, String sessionid)
|
340 |
359 |
{
|
341 |
360 |
DBConnection dbconn = null;
|
342 |
361 |
int serialNumber = -1;
|
... | ... | |
361 |
380 |
//print out the search result
|
362 |
381 |
// search the doc list
|
363 |
382 |
resultset = findResultDoclist(qspec, resultset, out, user, groups,
|
364 |
|
dbconn, useXMLIndex);
|
|
383 |
dbconn, useXMLIndex, pagesize, pagestart,
|
|
384 |
sessionid);
|
365 |
385 |
|
366 |
386 |
|
367 |
387 |
|
... | ... | |
406 |
426 |
StringBuffer resultsetBuffer,
|
407 |
427 |
PrintWriter out,
|
408 |
428 |
String user, String[]groups,
|
409 |
|
DBConnection dbconn, boolean useXMLIndex )
|
|
429 |
DBConnection dbconn, boolean useXMLIndex,
|
|
430 |
int pagesize, int pagestart, String sessionid)
|
410 |
431 |
throws Exception
|
411 |
432 |
{
|
|
433 |
/*
|
|
434 |
if pagesize != 0 then we need to process the query results in pages
|
|
435 |
1) check to see what the sessionid is: look in MetacatServlet.getSessionHash()
|
|
436 |
2) lookup the sessionid and the query in the paged_results table
|
|
437 |
3) if there is already a page result for the session and query get that
|
|
438 |
result and look at what our pagesize and pagestart is to get the next
|
|
439 |
pagesize results
|
|
440 |
4) if there is not a cached result, do the query, put the result in the
|
|
441 |
cache under the correct sessionid and return 0..pagesize results
|
|
442 |
5) when the session expires or is logged out, delete the cached queryresults
|
412 |
443 |
|
|
444 |
|
|
445 |
paged_results
|
|
446 |
-------------
|
|
447 |
sessionid (PK) (String)
|
|
448 |
query (String)
|
|
449 |
resultset (String)
|
|
450 |
|
|
451 |
*/
|
|
452 |
Hashtable sessionHash = MetaCatServlet.getSessionHash();
|
|
453 |
HttpSession sess = (HttpSession)sessionHash.get(sessionid);
|
|
454 |
//now we have the session object, so we can cache the query there.
|
|
455 |
|
413 |
456 |
int offset = 1;
|
414 |
457 |
// this is a hack for offset
|
415 |
458 |
if (out == null)
|
... | ... | |
482 |
525 |
|
483 |
526 |
double startTime = System.currentTimeMillis() / 1000;
|
484 |
527 |
pstmt = dbconn.prepareStatement(query);
|
485 |
|
|
|
528 |
|
486 |
529 |
// Execute the SQL query using the JDBC connection
|
487 |
530 |
pstmt.execute();
|
488 |
531 |
ResultSet rs = pstmt.getResultSet();
|
|
532 |
|
489 |
533 |
double queryExecuteTime = System.currentTimeMillis() / 1000;
|
|
534 |
logMetacat.warn("Pagesize: " + pstmt.getFetchSize());
|
490 |
535 |
logMetacat.warn("Time for execute query: "
|
491 |
536 |
+ (queryExecuteTime - startTime));
|
492 |
537 |
boolean tableHasRows = rs.next();
|
... | ... | |
1516 |
1561 |
ignoredParams.add("site");
|
1517 |
1562 |
ignoredParams.add("operator");
|
1518 |
1563 |
ignoredParams.add("sessionid");
|
|
1564 |
ignoredParams.add("pagesize");
|
|
1565 |
ignoredParams.add("pagestart");
|
1519 |
1566 |
|
1520 |
1567 |
// Also ignore parameters listed in the properties file
|
1521 |
1568 |
// so that they can be passed through to stylesheets
|
adding changes to make paged query results possible