233 |
233 |
private Query createQueryForUuidAndTitleCache(Integer limit, UUID classificationUuid, String pattern, boolean includeDoubtful){
|
234 |
234 |
String doubtfulPattern = "";
|
235 |
235 |
String queryString = "SELECT new " + SortableTaxonNodeQueryResult.class.getName() + "("
|
236 |
|
+ " node.uuid, node.id, t.titleCache, rank"
|
|
236 |
+ " node.uuid, node.id, t.titleCache, rank, parent.uuid"
|
237 |
237 |
+ ") "
|
238 |
238 |
+ " FROM TaxonNode AS node "
|
239 |
239 |
+ " JOIN node.taxon as t " // FIXME why not inner join here?
|
240 |
240 |
+ " INNER JOIN t.name AS name "
|
|
241 |
+ " LEFT OUTER JOIN node.parent as parent"
|
241 |
242 |
+ " LEFT OUTER JOIN name.rank AS rank "
|
242 |
243 |
+ " WHERE ";
|
243 |
244 |
|
... | ... | |
247 |
248 |
if (pattern == null){
|
248 |
249 |
pattern = "*";
|
249 |
250 |
}
|
250 |
|
if (pattern != null){
|
251 |
|
if (pattern.equals("?")){
|
252 |
|
limit = null;
|
253 |
|
} else{
|
254 |
|
if (!pattern.endsWith("*")){
|
255 |
|
pattern += "%";
|
256 |
|
}
|
257 |
|
pattern = pattern.replace("*", "%");
|
258 |
|
pattern = pattern.replace("?", "%");
|
259 |
|
if (classificationUuid != null){
|
260 |
|
queryString = queryString + " AND ";
|
261 |
|
}
|
262 |
|
queryString = queryString + " (t.titleCache LIKE (:pattern) " ;
|
263 |
|
doubtfulPattern = "?" + pattern;
|
264 |
|
if (includeDoubtful){
|
265 |
|
queryString = queryString + " OR t.titleCache LIKE (:doubtfulPattern))";
|
266 |
|
}else{
|
267 |
|
queryString = queryString + ")";
|
268 |
|
}
|
269 |
|
}
|
270 |
251 |
|
|
252 |
if (pattern.equals("?")){
|
|
253 |
limit = null;
|
|
254 |
} else{
|
|
255 |
if (!pattern.endsWith("*")){
|
|
256 |
pattern += "%";
|
|
257 |
}
|
|
258 |
pattern = pattern.replace("*", "%");
|
|
259 |
pattern = pattern.replace("?", "%");
|
|
260 |
if (classificationUuid != null){
|
|
261 |
queryString = queryString + " AND ";
|
|
262 |
}
|
|
263 |
queryString = queryString + " (t.titleCache LIKE (:pattern) " ;
|
|
264 |
doubtfulPattern = "?" + pattern;
|
|
265 |
if (includeDoubtful){
|
|
266 |
queryString = queryString + " OR t.titleCache LIKE (:doubtfulPattern))";
|
|
267 |
}else{
|
|
268 |
queryString = queryString + ")";
|
|
269 |
}
|
271 |
270 |
}
|
272 |
271 |
|
|
272 |
|
|
273 |
|
273 |
274 |
Query query = getSession().createQuery(queryString);
|
274 |
275 |
if (pattern != null){
|
275 |
276 |
query.setParameter("pattern", pattern);
|
... | ... | |
1102 |
1103 |
|
1103 |
1104 |
if (searchForClassifications){
|
1104 |
1105 |
String queryString = "SELECT new " + SortableTaxonNodeQueryResult.class.getName() + "("
|
1105 |
|
+ " node.uuid, node.id, node.classification.titleCache"
|
|
1106 |
+ " node.uuid, node.id, node.classification.titleCache, parent.uuid"
|
1106 |
1107 |
+ ") "
|
1107 |
1108 |
+ " FROM TaxonNode AS node "
|
|
1109 |
+ " LEFT OUTER JOIN node.parent as parent"
|
1108 |
1110 |
+ " WHERE node.classification.id = " + classification.getId() +
|
1109 |
1111 |
" AND node.taxon IS NULL";
|
1110 |
1112 |
if (pattern != null){
|
ref #9843: adapt other uses of SortableTaxonNodeQueryResult