Revision 8e9115f6
Added by Katja Luther almost 6 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImpl.java | ||
---|---|---|
1203 | 1203 |
return hql; |
1204 | 1204 |
} |
1205 | 1205 |
|
1206 |
@Override |
|
1207 |
public List<UuidAndTitleCache<TaxonNode>> getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(Classification classification, Integer limit, String pattern) { |
|
1208 |
int classificationId = classification.getId(); |
|
1209 |
// StringBuffer excludeUuids = new StringBuffer(); |
|
1210 |
|
|
1211 |
String queryString = "SELECT nodes.uuid, nodes.id, taxon.titleCache, taxon.name.rank FROM TaxonNode AS nodes JOIN nodes.taxon as taxon WHERE nodes.classification.id = " + classificationId ; |
|
1212 |
if (pattern != null){ |
|
1213 |
if (pattern.equals("?")){ |
|
1214 |
limit = null; |
|
1215 |
} else{ |
|
1216 |
if (!pattern.endsWith("*")){ |
|
1217 |
pattern += "%"; |
|
1218 |
} |
|
1219 |
pattern = pattern.replace("*", "%"); |
|
1220 |
pattern = pattern.replace("?", "%"); |
|
1221 |
queryString = queryString + " AND taxon.titleCache like (:pattern)" ; |
|
1222 |
} |
|
1223 |
} |
|
1224 |
|
|
1225 |
|
|
1226 |
|
|
1227 |
Query query = getSession().createQuery(queryString); |
|
1228 |
|
|
1229 |
|
|
1230 |
if (limit != null){ |
|
1231 |
query.setMaxResults(limit); |
|
1232 |
} |
|
1233 |
|
|
1234 |
if (pattern != null && !pattern.equals("?")){ |
|
1235 |
query.setParameter("pattern", pattern); |
|
1236 |
} |
|
1237 |
@SuppressWarnings("unchecked") |
|
1238 |
List<Object[]> result = query.list(); |
|
1239 |
|
|
1240 |
if(result.size() == 0){ |
|
1241 |
return null; |
|
1242 |
}else{ |
|
1243 |
List<UuidAndTitleCache<TaxonNode>> list = new ArrayList<UuidAndTitleCache<TaxonNode>>(result.size()); |
|
1244 |
if (result != null && !result.isEmpty()){ |
|
1245 |
if (result.iterator().next().length == 4){ |
|
1246 |
Collections.sort(result, new UuidAndTitleCacheTaxonComparator()); |
|
1247 |
} |
|
1248 |
} |
|
1249 |
for (Object object : result){ |
|
1250 |
|
|
1251 |
Object[] objectArray = (Object[]) object; |
|
1252 |
|
|
1253 |
UUID uuid = (UUID)objectArray[0]; |
|
1254 |
Integer id = (Integer) objectArray[1]; |
|
1255 |
String titleCache = (String) objectArray[2]; |
|
1256 |
|
|
1257 |
list.add(new UuidAndTitleCache<TaxonNode>(TaxonNode.class, uuid, id, titleCache)); |
|
1258 |
} |
|
1259 |
|
|
1260 |
return list; |
|
1261 |
} |
|
1262 |
} |
|
1206 |
|
|
1263 | 1207 |
|
1264 | 1208 |
|
1265 | 1209 |
@Override |
Also available in: Unified diff
add the possibility to search for classifications in getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification