Revision 1348
Added by Jing Tao almost 22 years ago
src/edu/ucsb/nceas/metacat/QuerySpecification.java | ||
---|---|---|
70 | 70 |
private Vector siteList; |
71 | 71 |
/** The root query group that contains the recursive query constraints */ |
72 | 72 |
private QueryGroup query = null; |
73 |
|
|
73 |
|
|
74 | 74 |
// Query data structures used temporarily during XML parsing |
75 | 75 |
private Stack elementStack; |
76 | 76 |
private Stack queryStack; |
... | ... | |
84 | 84 |
private static final String PUBLIC = "public"; |
85 | 85 |
private String [] group = null; |
86 | 86 |
|
87 |
|
|
87 |
public static final String ATTRIBUTESYMBOL = "@"; |
|
88 | 88 |
/** |
89 | 89 |
* construct an instance of the QuerySpecification class |
90 | 90 |
* |
... | ... | |
1029 | 1029 |
//self.append(nodedataterm + " LIKE " + "'" + searchvalue + "' "); |
1030 | 1030 |
self.append(searchexpr); |
1031 | 1031 |
|
1032 |
if (pathexpr != null) { |
|
1033 |
self.append("AND parentnodeid IN "); |
|
1032 |
if (pathexpr != null) |
|
1033 |
{ |
|
1034 |
|
|
1034 | 1035 |
// use XML Index |
1035 |
if ( useXMLIndex ) { |
|
1036 |
if ( useXMLIndex ) |
|
1037 |
{ |
|
1038 |
if (!hasAttributeInPath(pathexpr)) |
|
1039 |
{ |
|
1040 |
// without attributes in path |
|
1041 |
self.append("AND parentnodeid IN "); |
|
1042 |
} |
|
1043 |
else |
|
1044 |
{ |
|
1045 |
// has a attribute in path |
|
1046 |
String attributeName = getAttributeName(pathexpr); |
|
1047 |
self.append("AND nodetype LIKE 'ATTRIBUTE' AND nodename LIKE '"+ |
|
1048 |
attributeName + "' "); |
|
1049 |
self.append("AND parentnodeid IN "); |
|
1050 |
pathexpr = newPathExpressionWithOutAttribute(pathexpr); |
|
1051 |
|
|
1052 |
} |
|
1036 | 1053 |
self.append("(SELECT nodeid FROM xml_index WHERE path LIKE " + |
1037 | 1054 |
"'" + pathexpr + "') " ); |
1038 |
// without using XML Index; using nested statements instead |
|
1039 |
} else { |
|
1055 |
} |
|
1056 |
else |
|
1057 |
{ |
|
1058 |
// without using XML Index; using nested statements instead |
|
1059 |
self.append("AND parentnodeid IN "); |
|
1040 | 1060 |
self.append(useNestedStatements(pathexpr)); |
1041 | 1061 |
} |
1042 | 1062 |
} |
1043 | 1063 |
|
1044 | 1064 |
return self.toString(); |
1045 | 1065 |
} |
1046 |
|
|
1066 |
|
|
1067 |
/* A method to judge if a path have attribute */ |
|
1068 |
private boolean hasAttributeInPath(String path) |
|
1069 |
{ |
|
1070 |
if (path.indexOf(ATTRIBUTESYMBOL)!=-1) |
|
1071 |
{ |
|
1072 |
return true; |
|
1073 |
} |
|
1074 |
else |
|
1075 |
{ |
|
1076 |
return false; |
|
1077 |
} |
|
1078 |
} |
|
1079 |
|
|
1080 |
/* A method to get rid of attribute part in path expression*/ |
|
1081 |
private String newPathExpressionWithOutAttribute(String pathExpression) |
|
1082 |
{ |
|
1083 |
if (pathExpression == null) |
|
1084 |
{ |
|
1085 |
return null; |
|
1086 |
} |
|
1087 |
int index = pathExpression.lastIndexOf(ATTRIBUTESYMBOL); |
|
1088 |
String newExpression = null; |
|
1089 |
if (index != 1) |
|
1090 |
{ |
|
1091 |
newExpression=pathExpression.substring(0, index-1); |
|
1092 |
} |
|
1093 |
MetaCatUtil.debugMessage("The path expression without attributes: )" + |
|
1094 |
newExpression, 30); |
|
1095 |
return newExpression; |
|
1096 |
} |
|
1097 |
|
|
1098 |
/* A method to get attribute name from path */ |
|
1099 |
private String getAttributeName(String path) |
|
1100 |
{ |
|
1101 |
if (path == null) |
|
1102 |
{ |
|
1103 |
return null; |
|
1104 |
} |
|
1105 |
int index = path.lastIndexOf(ATTRIBUTESYMBOL); |
|
1106 |
int size = path.length(); |
|
1107 |
String attributeName = null; |
|
1108 |
if (index != 1) |
|
1109 |
{ |
|
1110 |
attributeName = path.substring(index+1, size); |
|
1111 |
} |
|
1112 |
MetaCatUtil.debugMessage("The attirbute name from path: )" + |
|
1113 |
attributeName, 30); |
|
1114 |
return attributeName; |
|
1115 |
} |
|
1116 |
|
|
1047 | 1117 |
/* |
1048 | 1118 |
* Constraint the query with @pathexp without using the XML Index, |
1049 | 1119 |
* but nested SQL statements instead. The query migth be slower. |
Also available in: Unified diff
Add new feature to support attribute in query.