Revision 3771
Added by Jing Tao almost 17 years ago
src/edu/ucsb/nceas/metacat/QuerySpecification.java | ||
---|---|---|
896 | 896 |
self.append("xml_nodes.nodedata, "); |
897 | 897 |
self.append("xml_nodes.parentnodeid, "); |
898 | 898 |
self.append("xml_nodes.nodetype "); |
899 |
self.append("from xml_nodes, xml_documents "); |
|
900 |
self.append("where parentnodeid IN "); |
|
899 |
//self.append("from xml_nodes, xml_documents "); |
|
900 |
self.append("from xml_nodes "); |
|
901 |
self.append("where "); |
|
901 | 902 |
self.append(QueryTerm.useNestedStatements(path)); |
902 | 903 |
|
903 | 904 |
self.append(" AND xml_nodes.docid in ("); |
904 | 905 |
self.append(doclist); |
905 |
self.append(") AND xml_nodes.nodetype = 'TEXT'"); |
|
906 |
self.append(" AND xml_nodes.rootnodeid = xml_documents.rootnodeid"); |
|
906 |
if (returnFieldIsAttribute(path)) |
|
907 |
{ |
|
908 |
self.append(")"); |
|
909 |
} |
|
910 |
else |
|
911 |
{ |
|
912 |
self.append(") AND xml_nodes.nodetype = 'TEXT'"); |
|
913 |
} |
|
914 |
//self.append(" AND xml_nodes.rootnodeid = xml_documents.rootnodeid"); |
|
907 | 915 |
|
908 | 916 |
//addAccessRestrictionSQL(unaccessableNodePair, self); |
909 | 917 |
} |
... | ... | |
911 | 919 |
return self.toString(); |
912 | 920 |
} |
913 | 921 |
} |
922 |
|
|
923 |
/* |
|
924 |
* Determines the returnfield is an attribute of not. |
|
925 |
* For given returnfield, this programm will cut the part of path after last slash. |
|
926 |
* If no slash in the path, the original string will be considered as last part. |
|
927 |
* If first character of last part is @ it will retrun true. |
|
928 |
*/ |
|
929 |
private boolean returnFieldIsAttribute(String path) |
|
930 |
{ |
|
931 |
boolean isAttribute = false; |
|
932 |
if (path != null) |
|
933 |
{ |
|
934 |
int slashIndex = path.lastIndexOf("/"); |
|
935 |
if (slashIndex !=-1) |
|
936 |
{ |
|
937 |
// if there is slash in the path, path should be replace by the last part |
|
938 |
path = path.substring(slashIndex+1); |
|
939 |
} |
|
940 |
logMetacat.debug("In QuerySpecification.returnFieldIsAttribute method, final path is "+path); |
|
941 |
// if first of character of path is @, the path is attribute |
|
942 |
if (path.charAt(0) == '@') |
|
943 |
{ |
|
944 |
logMetacat.debug("it is attribute"); |
|
945 |
isAttribute = true; |
|
946 |
} |
|
947 |
} |
|
948 |
return isAttribute; |
|
949 |
} |
|
914 | 950 |
|
915 | 951 |
/** |
916 | 952 |
* This method prints sql based upon the <returnfield> tag in the |
src/edu/ucsb/nceas/metacat/QueryTerm.java | ||
---|---|---|
303 | 303 |
} |
304 | 304 |
else { |
305 | 305 |
// without using XML Index; using nested statements instead |
306 |
self.append("AND parentnodeid IN "); |
|
306 |
//self.append("AND parentnodeid IN "); |
|
307 |
self.append("AND "); |
|
307 | 308 |
self.append(useNestedStatements(pathexpr)); |
308 | 309 |
} |
309 | 310 |
} |
... | ... | |
335 | 336 |
{ |
336 | 337 |
log.info("useNestedStatements()"); |
337 | 338 |
log.info("pathexpr: " + pathexpr); |
339 |
String elementPrefix = " parentnodeid IN "; |
|
340 |
String attributePrefix = " nodeid IN "; |
|
341 |
boolean lastOneIsAttribute = false; |
|
338 | 342 |
StringBuffer nestedStmts = new StringBuffer(); |
339 | 343 |
String path = pathexpr.trim(); |
344 |
String sql = ""; |
|
340 | 345 |
|
341 | 346 |
if (path.indexOf('/') == 0) |
342 | 347 |
{ |
... | ... | |
366 | 371 |
{ |
367 | 372 |
// no and it's the last node |
368 | 373 |
node = path; |
374 |
if (node != null && node.indexOf(QuerySpecification.ATTRIBUTESYMBOL) != -1) |
|
375 |
{ |
|
376 |
lastOneIsAttribute = true; |
|
377 |
node = removeAttributeSymbol(node); |
|
378 |
} |
|
369 | 379 |
path = ""; |
370 | 380 |
} |
371 | 381 |
else |
... | ... | |
426 | 436 |
nestedStmts.append(") "); |
427 | 437 |
} |
428 | 438 |
while (!path.equals("")); |
429 |
|
|
430 |
return nestedStmts.toString(); |
|
439 |
if (lastOneIsAttribute) |
|
440 |
{ |
|
441 |
sql = attributePrefix+nestedStmts.toString(); |
|
442 |
} |
|
443 |
else |
|
444 |
{ |
|
445 |
sql = elementPrefix+nestedStmts.toString(); |
|
446 |
} |
|
447 |
return sql; |
|
431 | 448 |
} |
449 |
|
|
450 |
|
|
451 |
/* |
|
452 |
* Removes @ symbol from path. For example, if path is @entity, entity will be returned. |
|
453 |
* If path is entity, entity will be returned. |
|
454 |
*/ |
|
455 |
private static String removeAttributeSymbol(String path) |
|
456 |
{ |
|
457 |
String newPath =""; |
|
458 |
log.debug("Original string before removing @ is " + path); |
|
459 |
if (path != null) |
|
460 |
{ |
|
461 |
|
|
462 |
int attribute = path.indexOf(QuerySpecification.ATTRIBUTESYMBOL); |
|
463 |
if (attribute != -1) |
|
464 |
{ |
|
465 |
// has attribute symbol. Reomve it and return the remained part. |
|
466 |
try |
|
467 |
{ |
|
468 |
newPath = path.substring(attribute + 1).trim(); |
|
469 |
} |
|
470 |
catch (Exception e) |
|
471 |
{ |
|
472 |
newPath = path; |
|
473 |
} |
|
474 |
} |
|
475 |
else |
|
476 |
{ |
|
477 |
// doesn't have attribute symbol. Return original string |
|
478 |
newPath = path; |
|
479 |
} |
|
480 |
} |
|
481 |
else |
|
482 |
{ |
|
483 |
// if is null, return null; |
|
484 |
newPath = path; |
|
485 |
} |
|
486 |
log.debug("String after removing @ is " + newPath); |
|
487 |
return newPath; |
|
488 |
|
|
489 |
} |
|
432 | 490 |
|
433 | 491 |
/** |
434 | 492 |
* |
Also available in: Unified diff
Fixed bug that lsid couldn't be shown up in result page of kepler skin. The bug is that in extended query, lsid attribute was treated as a element, but it is attribute.
I also optimized the query by deleting xml_documents table from query. The table is not needed.