Project

General

Profile

« Previous | Next » 

Revision 3211

Added by berkley about 17 years ago

adding changes to make paged query results possible

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
562 562
                // aware of session expiration on every request
563 563
            } else {
564 564
                HttpSession sess = request.getSession(true);
565
                logMetacat.info("session.isnew: " + sess.isNew() + "    params.hassessid: " + params.containsKey("sessionid"));
565 566
                if (sess.isNew() && !params.containsKey("sessionid")) {
566 567
                    // session expired or has not been stored b/w user requests
567 568
                    logMetacat.info(
568 569
                            "The session is new or no sessionid is assigned. The user is public");
569 570
                    username = "public";
570 571
                    sess.setAttribute("username", username);
572
                    sess_id = (String)sess.getId();
573
                              sess.setAttribute("sessionid", sess_id);
574
                    sessionHash.put(sess_id, sess);
571 575
                } else {
572 576
                    logMetacat.info("The session is either old or "
573 577
                            + "has sessionid parameter");
......
582 586
                                sess = (HttpSession) sessionHash.get(sess_id);
583 587
                            }
584 588
                        } else {
585
                            // we already store the session in login, so we
586
                            // don't need here
587
                            /*
588
                             * logMetacat.info("in no sessionid
589
                             * parameter ", 40); sess_id =
590
                             * (String)sess.getId();
591
                             * logMetacat.info("storing the session id "
592
                             * + sess_id + " which has username " +
593
                             * sess.getAttribute("username") + " into session
594
                             * hash in handleGetOrPost method", 35);
595
                             */
589
                          //this makes sure there is a session object for public sessions
590
                          sess_id = sess.getId();
591
                          sessionHash.put(sess_id, sess);
596 592
                        }
597 593
                    } catch (IllegalStateException ise) {
598 594
                        logMetacat.error(
......
608 604
                    groupnames = (String[]) sess.getAttribute("groupnames");
609 605
                    name = (String) sess.getAttribute("name");
610 606
                }
607
                
608
                logMetacat.info("&*&*&*&*&*&*&*&*&*&*&*&*&*&*&&*&*SESSIONID1: " + sess_id);
611 609

  
612 610
                //make user user username should be public
613 611
                if (username == null || (username.trim().equals(""))) {
src/edu/ucsb/nceas/metacat/DBQuery.java
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
src/edu/ucsb/nceas/metacat/QueryTerm.java
292 292
     */
293 293
    public static String useNestedStatements(String pathexpr)
294 294
    {
295
      System.out.println("pathexpr: " + pathexpr);
295 296
        StringBuffer nestedStmts = new StringBuffer();
296 297
        Vector nodes = new Vector();
297 298
        String path = pathexpr;

Also available in: Unified diff