Project

General

Profile

Revision 1353

Added by Jing Tao almost 18 years ago

Support return field has attributes.

View differences:

src/edu/ucsb/nceas/metacat/DBQuery.java
422 422
            //pstmt.close();
423 423
            double extendedQueryStart = System.currentTimeMillis()/1000;
424 424
            String extendedQuery = qspec.printExtendedSQL(doclist.toString());
425
            MetaCatUtil.debugMessage("Extended query: "+ extendedQuery, 50);
425
            MetaCatUtil.debugMessage("Extended query: "+ extendedQuery, 30);
426 426
            pstmt = dbconn.prepareStatement(extendedQuery);
427 427
            //increase dbconnection usage count
428 428
            dbconn.increaseUsageCount(1);
......
452 452
              document.append("</param>");
453 453
  
454 454
              tableHasRows = rs.next();
455
            
455 456
              if (docListResult.containsKey(docid))
456 457
              {
457 458
                String removedelement = (String)docListResult.remove(docid);
......
466 467
            MetaCatUtil.debugMessage("Time for prepare doclistresult after"+
467 468
                                      " execute extended query: "
468 469
                                    +(docListResultEnd-extendedQueryEnd), 30);
469
          }
470
          rs.close();
471
        }
472
        pstmt.close();
470
            rs.close();
471
            pstmt.close();
472
            
473
            // get attribures return
474
            docListResult = getAttributeValueForReturn
475
                                      (qspec,docListResult, doclist.toString());
476
          }//if doclist lenght is great than zero
477
          
478
        }//if has extended query
473 479
        
480
        
474 481
        //this loop adds the relation data to the resultdoc
475 482
        //this code might be able to be added to the backtracking code above
476 483
        double startRelation = System.currentTimeMillis()/1000;
......
556 563
  }
557 564
  
558 565
  /*
566
   * A method to return search result after running a query which return
567
   * field have attribue
568
   */
569
  private Hashtable getAttributeValueForReturn(QuerySpecification squery,
570
                                               Hashtable docInformationList,
571
                                               String docList)
572
  {
573
    StringBuffer XML = null;
574
    String sql = null;
575
    DBConnection dbconn = null;
576
    PreparedStatement pstmt = null;
577
    ResultSet rs = null;
578
    int serialNumber = -1;
579
    boolean tableHasRows =false;
580
    
581
    //check the parameter
582
    if (squery == null || docList==null || docList.length() <0)
583
    {
584
      return docInformationList;
585
    }
586
    
587
    // if has attribute as return field
588
    if (squery.containAttributeReturnField())
589
    {
590
      sql = squery.printAttributeQuery(docList);
591
      try 
592
      {
593
        dbconn=DBConnectionPool.getDBConnection("DBQuery.getAttributeValue");
594
        serialNumber=dbconn.getCheckOutSerialNumber();
595
        pstmt = dbconn.prepareStatement(sql);
596
        pstmt.execute();
597
        rs = pstmt.getResultSet();
598
        tableHasRows = rs.next();
599
        while(tableHasRows) 
600
        {
601
          String docid = rs.getString(1).trim();
602
          String fieldname = rs.getString(2);
603
          String fielddata = rs.getString(3);
604
          String attirbuteName = rs.getString(4);
605
          XML = new StringBuffer();
606
  
607
          XML.append("<param name=\"");
608
          XML.append(fieldname);
609
          XML.append(QuerySpecification.ATTRIBUTESYMBOL);
610
          XML.append(attirbuteName);
611
          XML.append("\">");
612
          XML.append(fielddata);
613
          XML.append("</param>");
614
          tableHasRows = rs.next();
615
          
616
          if (docInformationList.containsKey(docid))
617
          {
618
            String removedelement = (String)docInformationList.remove(docid);
619
            docInformationList.put(docid, removedelement + XML.toString());
620
          }
621
          else
622
          {
623
            docInformationList.put(docid, XML.toString()); 
624
          }
625
        }//while
626
        rs.close();
627
        pstmt.close();
628
      }
629
      catch(Exception se)
630
      {
631
        MetaCatUtil.debugMessage("Error in DBQuery.getAttributeValue1: "
632
                                      +se.getMessage(), 30);
633
      }
634
      finally
635
      {
636
        try
637
        {
638
          pstmt.close();
639
        }//try
640
        catch (SQLException sqlE)
641
        {
642
          MetaCatUtil.debugMessage("Error in DBQuery.getAttributeValue2: "
643
                                      +sqlE.getMessage(), 30);
644
        }//catch
645
        finally
646
        {
647
          DBConnectionPool.returnDBConnection(dbconn, serialNumber);
648
        }//finally
649
      }//finally
650
    }//if
651
    return docInformationList;
652
      
653
  }
654
   
655
  
656
  /*
559 657
   * A method to create a query to get owner's docid list
560 658
   */
561 659
  private String getOwnerQuery(String owner)

Also available in: Unified diff