Revision 2069
Added by Matt Jones about 20 years ago
QuerySpecification.java | ||
---|---|---|
808 | 808 |
|
809 | 809 |
/** |
810 | 810 |
* This method prints sql based upon the <returnfield> tag in the |
811 |
* pathquery document. This allows for customization of the returned fields |
|
811 |
* pathquery document. This allows for customization of the returned fields. |
|
812 |
* If the boolean useXMLIndex paramter is false, it uses a recursive query on |
|
813 |
* xml_nodes to find the fields to be included by their path expression, and |
|
814 |
* avoids the use of the xml_index table. |
|
812 | 815 |
* |
816 |
* @param doclist |
|
817 |
* the list of document ids to search by |
|
818 |
* @param unaccessableNodePair |
|
819 |
* the node pair(start id and end id) which this user could not |
|
820 |
* access it |
|
821 |
* @param useXMLIndex a boolean flag indicating whether to search using xml_index |
|
822 |
*/ |
|
823 |
public String printExtendedSQL(String doclist, |
|
824 |
Hashtable unaccessableNodePair, boolean useXMLIndex) |
|
825 |
{ |
|
826 |
if (useXMLIndex) { |
|
827 |
return printExtendedSQL(doclist, unaccessableNodePair); |
|
828 |
} else { |
|
829 |
StringBuffer self = new StringBuffer(); |
|
830 |
|
|
831 |
boolean firstfield = true; |
|
832 |
//put the returnfields into the query |
|
833 |
//the for loop allows for multiple fields |
|
834 |
for (int i = 0; i < returnFieldList.size(); i++) { |
|
835 |
if (firstfield) { |
|
836 |
firstfield = false; |
|
837 |
self.append("("); |
|
838 |
} else { |
|
839 |
self.append(" UNION ("); |
|
840 |
} |
|
841 |
String path = (String) returnFieldList.elementAt(i); |
|
842 |
self.append("select xml_nodes.docid, "); |
|
843 |
self.append("'"+ path + "' as path, "); |
|
844 |
self.append("xml_nodes.nodedata, "); |
|
845 |
self.append("xml_nodes.parentnodeid "); |
|
846 |
self.append("from xml_nodes, xml_documents "); |
|
847 |
self.append("where parentnodeid IN "); |
|
848 |
self.append(QueryTerm.useNestedStatements(path)); |
|
849 |
|
|
850 |
self.append(" AND xml_nodes.docid in ("); |
|
851 |
self.append(doclist); |
|
852 |
self.append(")"); |
|
853 |
self.append(" AND xml_nodes.nodetype = 'TEXT'"); |
|
854 |
self.append(" AND xml_nodes.rootnodeid = xml_documents.rootnodeid"); |
|
855 |
|
|
856 |
// add control part for extended query |
|
857 |
Enumeration en = unaccessableNodePair.keys(); |
|
858 |
|
|
859 |
while (en.hasMoreElements()) { |
|
860 |
// Get control pairs in object |
|
861 |
Long startNodeIdObject = (Long) en.nextElement(); |
|
862 |
Long endNodeIdObject = (Long) unaccessableNodePair |
|
863 |
.get(startNodeIdObject); |
|
864 |
// change it to long |
|
865 |
long startNodeId = startNodeIdObject.longValue(); |
|
866 |
long endNodeId = endNodeIdObject.longValue(); |
|
867 |
// add into query |
|
868 |
self.append(" AND( xml_nodes.nodeid < "); |
|
869 |
self.append(startNodeId); |
|
870 |
self.append(" OR xml_nodes.nodeid > "); |
|
871 |
self.append(endNodeId); |
|
872 |
self.append(")"); |
|
873 |
} |
|
874 |
self.append(")"); |
|
875 |
} |
|
876 |
|
|
877 |
return self.toString(); |
|
878 |
} |
|
879 |
} |
|
880 |
|
|
881 |
/** |
|
882 |
* This method prints sql based upon the <returnfield> tag in the |
|
883 |
* pathquery document. This allows for customization of the returned fields. |
|
884 |
* It uses the xml_index table and so assumes that this table has been |
|
885 |
* built. |
|
886 |
* |
|
813 | 887 |
* @param doclist |
814 | 888 |
* the list of document ids to search by |
815 | 889 |
* @param unaccessableNodePair |
816 | 890 |
* the node pair(start id and end id) which this user could not |
817 | 891 |
* access it |
818 | 892 |
*/ |
819 |
public String printExtendedSQL(String doclist, |
|
893 |
public String printExtendedSQL(String doclist,
|
|
820 | 894 |
Hashtable unaccessableNodePair) |
821 | 895 |
{ |
822 | 896 |
StringBuffer self = new StringBuffer(); |
Also available in: Unified diff
Created new printExtendedSQL function that can get the extended
return fields using only xml_nodes and not xml_index. One
step closer to eliminating the dependence ofn xml_index.