114 |
114 |
|
115 |
115 |
public static final char PREDICATE_END = ']';
|
116 |
116 |
|
117 |
|
private boolean hasAttributeReturnField = false;
|
|
117 |
//private boolean hasAttributeReturnField = false;
|
118 |
118 |
|
119 |
|
private Hashtable attributeReturnList = new Hashtable();
|
|
119 |
//private Hashtable attributeReturnList = new Hashtable();
|
120 |
120 |
|
121 |
|
private int countAttributeReturnField = 0;
|
|
121 |
//private int countAttributeReturnField = 0;
|
122 |
122 |
|
123 |
123 |
private StringBuffer textBuffer = new StringBuffer();
|
124 |
124 |
|
... | ... | |
393 |
393 |
}
|
394 |
394 |
}
|
395 |
395 |
|
|
396 |
|
396 |
397 |
/**
|
397 |
|
* A method to get if the query has an attribute return field
|
398 |
|
*/
|
399 |
|
public boolean containsAttributeReturnField()
|
400 |
|
{
|
401 |
|
return hasAttributeReturnField;
|
402 |
|
}
|
403 |
|
|
404 |
|
/**
|
405 |
398 |
* Accessor method to return the identifier of this Query
|
406 |
399 |
*/
|
407 |
400 |
public String getIdentifier()
|
... | ... | |
710 |
703 |
}
|
711 |
704 |
}
|
712 |
705 |
*/
|
713 |
|
public void handleReturnField(String inputString)
|
|
706 |
private void handleReturnField(String inputString)
|
714 |
707 |
{
|
715 |
708 |
int attributePos = inputString.indexOf(ATTRIBUTESYMBOL);
|
716 |
709 |
int predicateStart = -1;
|
... | ... | |
755 |
748 |
|
756 |
749 |
containsExtendedSQL = true;
|
757 |
750 |
|
758 |
|
// make sure if return fields has an attribute or not
|
759 |
|
if (attributePos == -1)
|
760 |
|
{
|
|
751 |
|
761 |
752 |
// no attribute value will be returned
|
762 |
753 |
logMetacat.info("QuerySpecification.handleReturnField(): " );
|
763 |
754 |
logMetacat.info(" there are no attributes in the XPATH statement" );
|
764 |
755 |
returnFieldList.add(inputString);
|
765 |
|
return;
|
766 |
|
}
|
|
756 |
|
767 |
757 |
|
768 |
|
// case where the return field is solely an attribute
|
769 |
|
logMetacat.info("QuerySpecification.handleReturnField(): " );
|
770 |
|
logMetacat.info(" Found an attribute in the XPATH statement." );
|
771 |
|
String returnPath = inputString.substring(0,
|
772 |
|
attributePos == 0 ? attributePos : attributePos - 1);
|
773 |
|
String attributeName = inputString.substring(attributePos + 1).trim();
|
774 |
|
Vector pathInfo = new Vector();
|
775 |
|
// the vector has the information about return path and
|
776 |
|
// attributename
|
777 |
|
pathInfo.addElement(returnPath);
|
778 |
|
pathInfo.addElement(attributeName);
|
779 |
|
// put the vector into a hash table. The reseaon why don't put
|
780 |
|
// return path or attributename as a key is because they are not
|
781 |
|
// unique
|
782 |
|
attributeReturnList.put(new Integer(countAttributeReturnField),
|
783 |
|
pathInfo);
|
784 |
|
countAttributeReturnField++;
|
785 |
|
hasAttributeReturnField = true;
|
|
758 |
|
786 |
759 |
}
|
787 |
760 |
|
788 |
761 |
/**
|
... | ... | |
1080 |
1053 |
tempVector.add(it.next());
|
1081 |
1054 |
}
|
1082 |
1055 |
|
1083 |
|
Enumeration attEnum = attributeReturnList.elements();
|
|
1056 |
/*Enumeration attEnum = attributeReturnList.elements();
|
1084 |
1057 |
while(attEnum.hasMoreElements()){
|
1085 |
1058 |
Iterator tempIt = ((Vector)attEnum.nextElement()).iterator();
|
1086 |
1059 |
String rfield = "";
|
... | ... | |
1097 |
1070 |
}
|
1098 |
1071 |
}
|
1099 |
1072 |
tempVector.add(rfield);
|
1100 |
|
}
|
|
1073 |
}*/
|
1101 |
1074 |
|
1102 |
1075 |
// Sort the temporary vector
|
1103 |
1076 |
java.util.Collections.sort(tempVector);
|
... | ... | |
1146 |
1119 |
}
|
1147 |
1120 |
}*/
|
1148 |
1121 |
|
1149 |
|
/**
|
1150 |
|
* This method prints sql that finds the values of attributes in the xml
|
1151 |
|
* documents based upon the whether the returnfield tag in the pathquery
|
1152 |
|
* document has an attribute symbol (@). This allows for customization of
|
1153 |
|
* the returned fields.
|
1154 |
|
*
|
1155 |
|
* @param doclist the list of document ids to search
|
1156 |
|
* @param useXMLIndex a boolean flag indicating whether to search using
|
1157 |
|
* xml_index
|
1158 |
|
*/
|
1159 |
|
public String printAttributeQuery(String doclist, boolean useXMLIndex)
|
1160 |
|
{
|
1161 |
|
if (useXMLIndex && !containsPredicates) {
|
1162 |
|
return printAttributeQuery(doclist);
|
1163 |
|
} else {
|
1164 |
|
StringBuffer self = new StringBuffer();
|
1165 |
|
boolean firstfield = true;
|
1166 |
|
//put the returnfields attributes into the query
|
1167 |
|
//the for loop allows for multiple fields and attributes
|
1168 |
|
Enumeration returnAttributes = attributeReturnList.elements();
|
1169 |
|
while (returnAttributes.hasMoreElements()) {
|
1170 |
|
Vector currentVector = (Vector) returnAttributes.nextElement();
|
1171 |
|
String returnPath = (String) currentVector.elementAt(0);
|
1172 |
|
String attributeName = (String) currentVector.elementAt(1);
|
1173 |
|
if (firstfield) {
|
1174 |
|
firstfield = false;
|
1175 |
|
} else {
|
1176 |
|
self.append(" UNION ");
|
1177 |
|
}
|
1178 |
|
self.append("select xml_nodes.docid, '");
|
1179 |
|
self.append(returnPath.replaceAll("'", "''"));
|
1180 |
|
self.append("' as path, xml_nodes.nodedata, xml_nodes.nodename ");
|
1181 |
|
self.append("from xml_nodes, xml_documents ");
|
1182 |
|
self.append("where parentnodeid IN ");
|
1183 |
|
self.append(QueryTerm.useNestedStatements(returnPath));
|
1184 |
|
self.append(" AND xml_nodes.nodename like '");
|
1185 |
|
self.append(attributeName);
|
1186 |
|
self.append("' AND xml_nodes.docid in (");
|
1187 |
|
self.append(doclist);
|
1188 |
|
self.append(") AND xml_nodes.nodetype = 'ATTRIBUTE'");
|
1189 |
|
self.append(" AND xml_nodes.rootnodeid = xml_documents.rootnodeid");
|
1190 |
|
}
|
|
1122 |
|
1191 |
1123 |
|
1192 |
|
logMetacat.info("Attribute query: " + self.toString());
|
1193 |
1124 |
|
1194 |
|
return self.toString();
|
1195 |
|
}
|
1196 |
|
}
|
1197 |
1125 |
|
1198 |
|
/**
|
1199 |
|
* This method prints sql that finds the values of attributes in the xml
|
1200 |
|
* documents based upon the whether the returnfield tag in the pathquery
|
1201 |
|
* document has an attribute symbol (@). This allows for customization of
|
1202 |
|
* the returned fields.
|
1203 |
|
*
|
1204 |
|
* @param doclist the list of document ids to search
|
1205 |
|
*/
|
1206 |
|
public String printAttributeQuery(String doclist)
|
1207 |
|
{
|
1208 |
|
StringBuffer self = new StringBuffer();
|
1209 |
|
self.append("select xml_nodes.docid, xml_index.path, ");
|
1210 |
|
self.append("xml_nodes.nodedata, xml_nodes.nodename ");
|
1211 |
|
self.append("from xml_index, xml_nodes where xml_index.nodeid=");
|
1212 |
|
self.append("xml_nodes.parentnodeid and (");
|
1213 |
|
boolean firstfield = true;
|
1214 |
|
//put the returnfields attributes into the query
|
1215 |
|
//the for loop allows for multiple fields and attributes
|
1216 |
|
Enumeration returnAttributes = attributeReturnList.elements();
|
1217 |
|
while (returnAttributes.hasMoreElements()) {
|
1218 |
|
Vector currentVector = (Vector) returnAttributes.nextElement();
|
1219 |
|
String returnPath = (String) currentVector.elementAt(0);
|
1220 |
|
String attributeName = (String) currentVector.elementAt(1);
|
1221 |
|
if (firstfield) {
|
1222 |
|
firstfield = false;
|
1223 |
|
self.append("( ");
|
1224 |
|
if(returnPath != null){
|
1225 |
|
self.append("xml_index.path like '");
|
1226 |
|
self.append(returnPath);
|
1227 |
|
self.append("' AND ");
|
1228 |
|
}else {
|
1229 |
|
logMetacat.info("QuerySpecification.printAttributeQuery: "
|
1230 |
|
+ "returnPath is: " + returnPath);
|
1231 |
|
}
|
1232 |
|
self.append("xml_nodes.nodename like '");
|
1233 |
|
self.append(attributeName);
|
1234 |
|
self.append("') ");
|
1235 |
|
} else {
|
1236 |
|
self.append(" or (");
|
1237 |
|
if(returnPath != null){
|
1238 |
|
self.append("xml_index.path like '");
|
1239 |
|
self.append(returnPath);
|
1240 |
|
self.append("' AND ");
|
1241 |
|
}else {
|
1242 |
|
logMetacat.info("QuerySpecification.printAttributeQuery: "
|
1243 |
|
+ "returnPath is null: " + returnPath);
|
1244 |
|
}
|
1245 |
|
self.append("xml_nodes.nodename like '");
|
1246 |
|
self.append(attributeName);
|
1247 |
|
self.append("') ");
|
1248 |
|
}
|
1249 |
|
}
|
1250 |
|
self.append(") AND xml_nodes.docid in (");
|
1251 |
|
self.append(doclist);
|
1252 |
|
self.append(") AND xml_nodes.nodetype = 'ATTRIBUTE'");
|
1253 |
|
logMetacat.warn("Attribute query: " + self.toString());
|
1254 |
|
|
1255 |
|
return self.toString();
|
1256 |
|
}
|
1257 |
|
|
1258 |
1126 |
public static String printRelationSQL(String docid)
|
1259 |
1127 |
{
|
1260 |
1128 |
StringBuffer self = new StringBuffer();
|
Merge the getting return fields for both elements and attributes.