Revision 2474
Added by sgarg over 19 years ago
src/edu/ucsb/nceas/metacat/QuerySpecification.java | ||
---|---|---|
661 | 661 |
returnFieldList.add(inputString); |
662 | 662 |
containsExtendedSQL = true; |
663 | 663 |
} else { |
664 |
|
|
664 |
|
|
665 | 665 |
if ( inputString.startsWith(ATTRIBUTESYMBOL) ) { |
666 |
|
|
666 |
|
|
667 | 667 |
// case where the return field is solely an attribute |
668 | 668 |
MetaCatUtil.debugMessage("QuerySpecification.handleReturnField(): " , 35); |
669 | 669 |
MetaCatUtil.debugMessage(" there are *only* attributes in the XPATH statement" , 35); |
... | ... | |
940 | 940 |
StringBuffer self = new StringBuffer(); |
941 | 941 |
|
942 | 942 |
// test if the are elements in the return fields |
943 |
if ( returnFieldList.size() != 0 ) { |
|
944 |
self.append("select xml_nodes.docid, xml_index.path, xml_nodes.nodedata, "); |
|
945 |
self.append("xml_nodes.parentnodeid "); |
|
946 |
self.append("from xml_index, xml_nodes where xml_index.nodeid="); |
|
947 |
self.append("xml_nodes.parentnodeid and (xml_index.path like '"); |
|
943 |
if ( returnFieldList.size() == 0 ) { |
|
944 |
return null; |
|
945 |
} |
|
946 |
self.append("select xml_nodes.docid, xml_index.path, xml_nodes.nodedata, "); |
|
947 |
self.append("xml_nodes.parentnodeid "); |
|
948 |
self.append("from xml_index, xml_nodes where xml_index.nodeid="); |
|
949 |
self.append("xml_nodes.parentnodeid and (xml_index.path like '"); |
|
948 | 950 |
|
949 |
boolean firstfield = true;
|
|
950 |
//put the returnfields into the query
|
|
951 |
//the for loop allows for multiple fields
|
|
952 |
for (int i = 0; i < returnFieldList.size(); i++) {
|
|
951 |
boolean firstfield = true; |
|
952 |
//put the returnfields into the query |
|
953 |
//the for loop allows for multiple fields |
|
954 |
for (int i = 0; i < returnFieldList.size(); i++) { |
|
953 | 955 |
if (firstfield) { |
954 |
firstfield = false; |
|
955 |
self.append((String) returnFieldList.elementAt(i)); |
|
956 |
self.append("' "); |
|
956 |
firstfield = false;
|
|
957 |
self.append((String) returnFieldList.elementAt(i));
|
|
958 |
self.append("' ");
|
|
957 | 959 |
} else { |
958 |
self.append("or xml_index.path like '"); |
|
959 |
self.append((String) returnFieldList.elementAt(i)); |
|
960 |
self.append("' "); |
|
960 |
self.append("or xml_index.path like '");
|
|
961 |
self.append((String) returnFieldList.elementAt(i));
|
|
962 |
self.append("' ");
|
|
961 | 963 |
} |
962 |
}
|
|
963 |
self.append(") AND xml_nodes.docid in (");
|
|
964 |
self.append(doclist);
|
|
965 |
self.append(") AND xml_nodes.nodetype = 'TEXT'");
|
|
964 |
} |
|
965 |
self.append(") AND xml_nodes.docid in ("); |
|
966 |
self.append(doclist); |
|
967 |
self.append(") AND xml_nodes.nodetype = 'TEXT'"); |
|
966 | 968 |
|
967 |
addAccessRestrictionSQL(unaccessableNodePair, self);
|
|
969 |
addAccessRestrictionSQL(unaccessableNodePair, self); |
|
968 | 970 |
|
969 |
} |
|
970 |
|
|
971 |
// test if there are attributes in the return fields |
|
972 |
if ( containsAttributeReturnField() ) { |
|
973 |
MetaCatUtil.debugMessage("QuerySpecification.printExtendedSQL: " + |
|
974 |
"Attributes *are* in the returnfields\n", 35); |
|
975 |
// append the attribute query |
|
976 |
self.append(printAttributeQuery(doclist)); |
|
977 |
} |
|
978 |
|
|
979 | 971 |
return self.toString(); |
980 | 972 |
} |
981 | 973 |
|
... | ... | |
1001 | 993 |
String rfield = ""; |
1002 | 994 |
if(tempIt.hasNext()){ |
1003 | 995 |
String element = (String)tempIt.next(); |
1004 |
if(element != null) {
|
|
1005 |
rfield +=element;
|
|
996 |
if(element != null) { |
|
997 |
rfield +=element; |
|
1006 | 998 |
} |
1007 | 999 |
} |
1008 | 1000 |
if(tempIt.hasNext()){ |
1009 | 1001 |
String attribute = (String)tempIt.next(); |
1010 |
if(attribute != null) {
|
|
1011 |
rfield = rfield + "@" + attribute;
|
|
1002 |
if(attribute != null) { |
|
1003 |
rfield = rfield + "@" + attribute; |
|
1012 | 1004 |
} |
1013 | 1005 |
} |
1014 | 1006 |
tempVector.add(rfield); |
... | ... | |
1141 | 1133 |
self.append(returnPath); |
1142 | 1134 |
self.append("' AND "); |
1143 | 1135 |
}else { |
1144 |
MetaCatUtil.debugMessage("QuerySpecification.printAttributeQuery: "
|
|
1136 |
MetaCatUtil.debugMessage("QuerySpecification.printAttributeQuery: " |
|
1145 | 1137 |
+ "returnPath is: " + returnPath, 30); |
1146 | 1138 |
} |
1147 | 1139 |
self.append("xml_nodes.nodename like '"); |
... | ... | |
1154 | 1146 |
self.append(returnPath); |
1155 | 1147 |
self.append("' AND "); |
1156 | 1148 |
}else { |
1157 |
MetaCatUtil.debugMessage("QuerySpecification.printAttributeQuery: "
|
|
1149 |
MetaCatUtil.debugMessage("QuerySpecification.printAttributeQuery: " |
|
1158 | 1150 |
+ "returnPath is null: " + returnPath, 30); |
1159 | 1151 |
} |
1160 | 1152 |
self.append("xml_nodes.nodename like '"); |
src/edu/ucsb/nceas/metacat/DBQuery.java | ||
---|---|---|
951 | 951 |
String extendedQuery = |
952 | 952 |
qspec.printExtendedSQL(doclist.toString(), controlPairs, useXMLIndex); |
953 | 953 |
MetaCatUtil.debugMessage("Extended query: " + extendedQuery, 30); |
954 |
pstmt = dbconn.prepareStatement(extendedQuery); |
|
955 |
//increase dbconnection usage count |
|
956 |
dbconn.increaseUsageCount(1); |
|
957 |
pstmt.execute(); |
|
958 |
rs = pstmt.getResultSet(); |
|
959 |
double extendedQueryEnd = System.currentTimeMillis() / 1000; |
|
960 |
MetaCatUtil.debugMessage("Time for execute extended query: " |
|
961 |
+ (extendedQueryEnd - extendedQueryStart), 30); |
|
962 |
tableHasRows = rs.next(); |
|
963 |
while (tableHasRows) |
|
964 |
{ |
|
965 |
ReturnFieldValue returnValue = new ReturnFieldValue(); |
|
966 |
docid = rs.getString(1).trim(); |
|
967 |
fieldname = rs.getString(2); |
|
968 |
fielddata = rs.getString(3); |
|
969 |
fielddata = MetaCatUtil.normalize(fielddata); |
|
970 |
String parentId = rs.getString(4); |
|
971 |
StringBuffer value = new StringBuffer(); |
|
972 | 954 |
|
973 |
// if xml_index is used, there would be just one record per nodeid |
|
974 |
// as xml_index just keeps one entry for each path |
|
975 |
if (useXMLIndex || !containsKey(parentidList, parentId)) |
|
976 |
{ |
|
977 |
// don't need to merger nodedata |
|
978 |
value.append("<param name=\""); |
|
979 |
value.append(fieldname); |
|
980 |
value.append("\">"); |
|
981 |
value.append(fielddata); |
|
982 |
value.append("</param>"); |
|
983 |
//set returnvalue |
|
984 |
returnValue.setDocid(docid); |
|
985 |
returnValue.setFieldValue(fielddata); |
|
986 |
returnValue.setXMLFieldValue(value.toString()); |
|
987 |
// Store it in hastable |
|
988 |
putInArray(parentidList, parentId, returnValue); |
|
989 |
} |
|
990 |
else |
|
991 |
{ |
|
992 |
// need to merge nodedata if they have same parent id and |
|
993 |
// node type is text |
|
994 |
fielddata = (String) ((ReturnFieldValue) getArrayValue( |
|
995 |
parentidList, parentId)).getFieldValue() |
|
996 |
+ fielddata; |
|
997 |
value.append("<param name=\""); |
|
998 |
value.append(fieldname); |
|
999 |
value.append("\">"); |
|
1000 |
value.append(fielddata); |
|
1001 |
value.append("</param>"); |
|
1002 |
returnValue.setDocid(docid); |
|
1003 |
returnValue.setFieldValue(fielddata); |
|
1004 |
returnValue.setXMLFieldValue(value.toString()); |
|
1005 |
// remove the old return value from paretnidList |
|
1006 |
parentidList.remove(parentId); |
|
1007 |
// store the new return value in parentidlit |
|
1008 |
putInArray(parentidList, parentId, returnValue); |
|
1009 |
} |
|
1010 |
tableHasRows = rs.next(); |
|
1011 |
}//while |
|
1012 |
rs.close(); |
|
1013 |
pstmt.close(); |
|
955 |
if(extendedQuery != null){ |
|
956 |
pstmt = dbconn.prepareStatement(extendedQuery); |
|
957 |
//increase dbconnection usage count |
|
958 |
dbconn.increaseUsageCount(1); |
|
959 |
pstmt.execute(); |
|
960 |
rs = pstmt.getResultSet(); |
|
961 |
double extendedQueryEnd = System.currentTimeMillis() / 1000; |
|
962 |
MetaCatUtil.debugMessage( |
|
963 |
"Time for execute extended query: " |
|
964 |
+ (extendedQueryEnd - extendedQueryStart), 30); |
|
965 |
tableHasRows = rs.next(); |
|
966 |
while (tableHasRows) { |
|
967 |
ReturnFieldValue returnValue = new ReturnFieldValue(); |
|
968 |
docid = rs.getString(1).trim(); |
|
969 |
fieldname = rs.getString(2); |
|
970 |
fielddata = rs.getString(3); |
|
971 |
fielddata = MetaCatUtil.normalize(fielddata); |
|
972 |
String parentId = rs.getString(4); |
|
973 |
StringBuffer value = new StringBuffer(); |
|
1014 | 974 |
|
1015 |
// put the merger node data info into doclistReult |
|
1016 |
Enumeration xmlFieldValue = (getElements(parentidList)).elements(); |
|
1017 |
while (xmlFieldValue.hasMoreElements()) |
|
1018 |
{ |
|
1019 |
ReturnFieldValue object = |
|
1020 |
(ReturnFieldValue) xmlFieldValue.nextElement(); |
|
1021 |
docid = object.getDocid(); |
|
1022 |
if (docListResult.containsKey(docid)) |
|
1023 |
{ |
|
1024 |
String removedelement = (String) docListResult.remove(docid); |
|
1025 |
docListResult. |
|
1026 |
put(docid, removedelement+ object.getXMLFieldValue()); |
|
1027 |
} |
|
1028 |
else |
|
1029 |
{ |
|
1030 |
docListResult.put(docid, object.getXMLFieldValue()); |
|
1031 |
} |
|
1032 |
}//while |
|
1033 |
double docListResultEnd = System.currentTimeMillis() / 1000; |
|
1034 |
MetaCatUtil.debugMessage("Time for prepare doclistresult after" |
|
1035 |
+ " execute extended query: " |
|
1036 |
+ (docListResultEnd - extendedQueryEnd), |
|
1037 |
30); |
|
975 |
// if xml_index is used, there would be just one record per nodeid |
|
976 |
// as xml_index just keeps one entry for each path |
|
977 |
if (useXMLIndex || !containsKey(parentidList, parentId)) { |
|
978 |
// don't need to merger nodedata |
|
979 |
value.append("<param name=\""); |
|
980 |
value.append(fieldname); |
|
981 |
value.append("\">"); |
|
982 |
value.append(fielddata); |
|
983 |
value.append("</param>"); |
|
984 |
//set returnvalue |
|
985 |
returnValue.setDocid(docid); |
|
986 |
returnValue.setFieldValue(fielddata); |
|
987 |
returnValue.setXMLFieldValue(value.toString()); |
|
988 |
// Store it in hastable |
|
989 |
putInArray(parentidList, parentId, returnValue); |
|
990 |
} |
|
991 |
else { |
|
992 |
// need to merge nodedata if they have same parent id and |
|
993 |
// node type is text |
|
994 |
fielddata = (String) ( (ReturnFieldValue) |
|
995 |
getArrayValue( |
|
996 |
parentidList, parentId)).getFieldValue() |
|
997 |
+ fielddata; |
|
998 |
value.append("<param name=\""); |
|
999 |
value.append(fieldname); |
|
1000 |
value.append("\">"); |
|
1001 |
value.append(fielddata); |
|
1002 |
value.append("</param>"); |
|
1003 |
returnValue.setDocid(docid); |
|
1004 |
returnValue.setFieldValue(fielddata); |
|
1005 |
returnValue.setXMLFieldValue(value.toString()); |
|
1006 |
// remove the old return value from paretnidList |
|
1007 |
parentidList.remove(parentId); |
|
1008 |
// store the new return value in parentidlit |
|
1009 |
putInArray(parentidList, parentId, returnValue); |
|
1010 |
} |
|
1011 |
tableHasRows = rs.next(); |
|
1012 |
} //while |
|
1013 |
rs.close(); |
|
1014 |
pstmt.close(); |
|
1038 | 1015 |
|
1039 |
// get attribures return |
|
1040 |
docListResult = getAttributeValueForReturn(qspec, |
|
1041 |
docListResult, doclist.toString(), useXMLIndex); |
|
1016 |
// put the merger node data info into doclistReult |
|
1017 |
Enumeration xmlFieldValue = (getElements(parentidList)). |
|
1018 |
elements(); |
|
1019 |
while (xmlFieldValue.hasMoreElements()) { |
|
1020 |
ReturnFieldValue object = |
|
1021 |
(ReturnFieldValue) xmlFieldValue.nextElement(); |
|
1022 |
docid = object.getDocid(); |
|
1023 |
if (docListResult.containsKey(docid)) { |
|
1024 |
String removedelement = (String) docListResult. |
|
1025 |
remove(docid); |
|
1026 |
docListResult. |
|
1027 |
put(docid, |
|
1028 |
removedelement + object.getXMLFieldValue()); |
|
1029 |
} |
|
1030 |
else { |
|
1031 |
docListResult.put(docid, object.getXMLFieldValue()); |
|
1032 |
} |
|
1033 |
} //while |
|
1034 |
double docListResultEnd = System.currentTimeMillis() / 1000; |
|
1035 |
MetaCatUtil.debugMessage( |
|
1036 |
"Time for prepare doclistresult after" |
|
1037 |
+ " execute extended query: " |
|
1038 |
+ (docListResultEnd - extendedQueryEnd), |
|
1039 |
30); |
|
1040 |
} |
|
1041 |
|
|
1042 |
// get attribures return |
|
1043 |
docListResult = getAttributeValueForReturn(qspec, |
|
1044 |
docListResult, doclist.toString(), useXMLIndex); |
|
1042 | 1045 |
}//if doclist lenght is great than zero |
1043 | 1046 |
|
1044 | 1047 |
}//if has extended query |
Also available in: Unified diff
1. removed the call to QuerySpecification.printAttributeSQL() from QuerySpecification.printExtendedSQL()
2. in QuerySpecification.printExtendedSQL() if ( returnFieldList.size() == 0 ) then it returns null
3. DBQuery.addReturnfield() doesnt execute the element query if printExtendedSQL returns null