Revision 3307
Added by Jing Tao over 17 years ago
src/edu/ucsb/nceas/metacat/DBQuery.java | ||
---|---|---|
568 | 568 |
updateDate = rs.getString(5); |
569 | 569 |
rev = rs.getInt(6); |
570 | 570 |
|
571 |
// if there are returndocs to match, backtracking can be performed |
|
572 |
// otherwise, just return the document that was hit |
|
573 |
Vector returndocVec = qspec.getReturnDocList(); |
|
574 |
if (returndocVec.size() != 0 && !returndocVec.contains(doctype) |
|
575 |
&& !qspec.isPercentageSearch()) |
|
576 |
{ |
|
577 |
logMetacat.info("Back tracing now..."); |
|
578 |
String sep = MetaCatUtil.getOption("accNumSeparator"); |
|
579 |
StringBuffer btBuf = new StringBuffer(); |
|
580 |
btBuf.append("select docid from xml_relation where "); |
|
581 |
|
|
582 |
//build the doctype list for the backtracking sql statement |
|
583 |
btBuf.append("packagetype in ("); |
|
584 |
for (int i = 0; i < returndocVec.size(); i++) |
|
585 |
{ |
|
586 |
btBuf.append("'").append((String) returndocVec.get(i)).append("'"); |
|
587 |
if (i != (returndocVec.size() - 1)) |
|
588 |
{ |
|
589 |
btBuf.append(", "); |
|
590 |
} |
|
591 |
} |
|
592 |
btBuf.append(") "); |
|
593 |
btBuf.append("and (subject like '"); |
|
594 |
btBuf.append(docid).append("'"); |
|
595 |
btBuf.append("or object like '"); |
|
596 |
btBuf.append(docid).append("')"); |
|
597 |
|
|
598 |
PreparedStatement npstmt = dbconn.prepareStatement(btBuf.toString()); |
|
599 |
//should incease usage count |
|
600 |
dbconn.increaseUsageCount(1); |
|
601 |
npstmt.execute(); |
|
602 |
ResultSet btrs = npstmt.getResultSet(); |
|
603 |
boolean hasBtRows = btrs.next(); |
|
604 |
//Hashtable list = new Hashtable(); |
|
605 |
while (hasBtRows) |
|
606 |
{ |
|
607 |
//there was a backtrackable document found |
|
608 |
DocumentImpl xmldoc = null; |
|
609 |
String packageDocid = btrs.getString(1); |
|
610 |
logMetacat.info("Getting document for docid: " |
|
611 |
+ packageDocid); |
|
612 |
try |
|
613 |
{ |
|
614 |
// THIS CONSTRUCTOR BUILDS THE WHOLE XML doc not |
|
615 |
// needed here |
|
616 |
// xmldoc = new DocumentImpl(dbconn, packageDocid); |
|
617 |
// thus use the following to get the doc info only |
|
618 |
// xmldoc = new DocumentImpl(dbconn); |
|
619 |
String accNumber = packageDocid + MetaCatUtil.getOption("accNumSeparator") + |
|
620 |
DBUtil.getLatestRevisionInDocumentTable(packageDocid); |
|
621 |
xmldoc = new DocumentImpl(accNumber, false); |
|
622 |
if (xmldoc == null) |
|
623 |
{ |
|
624 |
logMetacat.info("Document was null for: " |
|
625 |
+ packageDocid); |
|
626 |
} |
|
627 |
} |
|
628 |
catch (Exception e) |
|
629 |
{ |
|
630 |
System.out.println("Error getting document in " |
|
631 |
+ "DBQuery.findDocuments: " |
|
632 |
+ e.getMessage()); |
|
633 |
} |
|
634 |
|
|
635 |
String docid_org = xmldoc.getDocID(); |
|
636 |
if (docid_org == null) |
|
637 |
{ |
|
638 |
logMetacat.info("Docid_org was null."); |
|
639 |
hasBtRows = btrs.next(); |
|
640 |
continue; |
|
641 |
} |
|
642 |
docid = docid_org.trim(); |
|
643 |
/*if (list.containsKey(docid)) |
|
644 |
{ |
|
645 |
logMetacat.info("DocumentResultSet already has docid "+docid+" and skip it"); |
|
646 |
hasBtRows = btrs.next(); |
|
647 |
continue; |
|
648 |
}*/ |
|
649 |
docname = xmldoc.getDocname(); |
|
650 |
doctype = xmldoc.getDoctype(); |
|
651 |
createDate = xmldoc.getCreateDate(); |
|
652 |
updateDate = xmldoc.getUpdateDate(); |
|
653 |
rev = xmldoc.getRev(); |
|
654 |
document = new StringBuffer(); |
|
655 |
|
|
656 |
String completeDocid = docid |
|
657 |
+ MetaCatUtil.getOption("accNumSeparator"); |
|
658 |
completeDocid += rev; |
|
659 |
document.append("<docid>").append(completeDocid); |
|
660 |
document.append("</docid>"); |
|
661 |
if (docname != null) |
|
662 |
{ |
|
663 |
document.append("<docname>" + docname + "</docname>"); |
|
664 |
} |
|
665 |
if (doctype != null) |
|
666 |
{ |
|
667 |
document.append("<doctype>" + doctype + "</doctype>"); |
|
668 |
} |
|
669 |
if (createDate != null) |
|
670 |
{ |
|
671 |
document.append("<createdate>" + createDate + "</createdate>"); |
|
672 |
} |
|
673 |
if (updateDate != null) |
|
674 |
{ |
|
675 |
document.append("<updatedate>" + updateDate+ "</updatedate>"); |
|
676 |
} |
|
677 |
// Store the document id and the root node id |
|
678 |
docListResult.addResultDocument( |
|
679 |
new ResultDocument(docid, (String) document.toString())); |
|
680 |
currentIndex++; |
|
681 |
//list.put(docid, docid); |
|
682 |
logMetacat.info("$$$$$$$real result: " + docid); |
|
683 |
count++; |
|
684 |
|
|
685 |
// Get the next package document linked to our hit |
|
686 |
hasBtRows = btrs.next(); |
|
687 |
}//while |
|
688 |
npstmt.close(); |
|
689 |
btrs.close(); |
|
690 |
} |
|
691 |
else if (returndocVec.size() == 0 || returndocVec.contains(doctype)) |
|
571 |
Vector returndocVec = qspec.getReturnDocList(); |
|
572 |
if (returndocVec.size() == 0 || returndocVec.contains(doctype)) |
|
692 | 573 |
{ |
693 | 574 |
logMetacat.info("NOT Back tracing now..."); |
694 | 575 |
document = new StringBuffer(); |
Also available in: Unified diff
Get rid of back tracing part