Revision 5419a179
Added by Andreas Müller about 9 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/TermVocabularyDaoImpl.java | ||
---|---|---|
232 | 232 |
} |
233 | 233 |
|
234 | 234 |
@Override |
235 |
public void missingTermUuids(Map<UUID, Set<UUID>> uuidsRequested, |
|
236 |
Map<UUID, Set<UUID>> uuidMissingTermsRepsonse, Map<UUID, TermVocabulary<?>> vocabularyResponse){ |
|
235 |
public void missingTermUuids( |
|
236 |
Map<UUID, Set<UUID>> uuidsRequested, |
|
237 |
Map<UUID, Set<UUID>> uuidMissingTermsRepsonse, |
|
238 |
Map<UUID, TermVocabulary<?>> vocabularyResponse){ |
|
237 | 239 |
|
238 | 240 |
Set<UUID> missingTermCandidateUuids = new HashSet<UUID>(); |
239 | 241 |
|
... | ... | |
241 | 243 |
missingTermCandidateUuids.addAll(uuidsPerVocSet); |
242 | 244 |
} |
243 | 245 |
|
244 |
//search persisted subset of required (usuallay all
|
|
246 |
//search persisted subset of required (usually all)
|
|
245 | 247 |
String hql = " SELECT terms.uuid " + |
246 | 248 |
" FROM TermVocabulary voc join voc.terms terms " + |
247 | 249 |
" WHERE terms.uuid IN (:uuids) " + |
248 | 250 |
" ORDER BY voc.uuid "; |
249 | 251 |
Query query = getSession().createQuery(hql); |
250 |
query.setParameterList("uuids",missingTermCandidateUuids); |
|
252 |
query.setParameterList("uuids", missingTermCandidateUuids);
|
|
251 | 253 |
List<?> persistedUuids = query.list(); |
252 | 254 |
|
253 | 255 |
|
254 | 256 |
//fully load and initialize vocabularies if required |
255 | 257 |
if (vocabularyResponse != null){ |
256 |
String hql2 = " SELECT voc " + |
|
257 |
" FROM TermVocabulary voc left join fetch voc.terms terms left join fetch terms.representations representations " + |
|
258 |
" left join fetch voc.representations vocReps " + |
|
259 |
" WHERE terms.uuid IN (:termUuids) OR ( voc.uuid IN (:vocUuids) AND voc.terms is empty ) " + |
|
258 |
String hql2 = " SELECT DISTINCT voc " + |
|
259 |
" FROM TermVocabulary voc " + |
|
260 |
" LEFT JOIN FETCH voc.terms terms " + |
|
261 |
" LEFT JOIN FETCH terms.representations representations " + |
|
262 |
" LEFT JOIN FETCH voc.representations vocReps " + |
|
263 |
" WHERE terms.uuid IN (:termUuids) OR ( voc.uuid IN (:vocUuids) ) " + //was: AND voc.terms is empty, but did not load originally empty vocabularies with user defined terms added |
|
260 | 264 |
// " WHERE voc.uuid IN (:vocUuids) AND voc.terms is empty " + |
261 | 265 |
" ORDER BY voc.uuid "; |
262 | 266 |
query = getSession().createQuery(hql2); |
... | ... | |
273 | 277 |
missingTermCandidateUuids.clear(); |
274 | 278 |
}else{ |
275 | 279 |
missingTermCandidateUuids.removeAll(persistedUuids); |
276 |
}
|
|
277 |
|
|
278 |
//add missing terms to response
|
|
279 |
for (UUID vocUUID : uuidsRequested.keySet()){
|
|
280 |
for (UUID termUuid : uuidsRequested.get(vocUUID)){
|
|
281 |
if (missingTermCandidateUuids.contains(termUuid)){
|
|
282 |
Set<UUID> r = uuidMissingTermsRepsonse.get(vocUUID);
|
|
283 |
if (r == null){
|
|
284 |
r = new HashSet<UUID>();
|
|
285 |
uuidMissingTermsRepsonse.put(vocUUID, r);
|
|
280 |
//add missing terms to response
|
|
281 |
for (UUID vocUUID : uuidsRequested.keySet()){ |
|
282 |
for (UUID termUuid : uuidsRequested.get(vocUUID)){
|
|
283 |
if (missingTermCandidateUuids.contains(termUuid)){
|
|
284 |
Set<UUID> r = uuidMissingTermsRepsonse.get(vocUUID);
|
|
285 |
if (r == null){
|
|
286 |
r = new HashSet<UUID>();
|
|
287 |
uuidMissingTermsRepsonse.put(vocUUID, r);
|
|
288 |
}
|
|
289 |
r.add(termUuid);
|
|
286 | 290 |
} |
287 |
r.add(termUuid); |
|
288 | 291 |
} |
289 | 292 |
} |
290 | 293 |
} |
291 | 294 |
|
292 |
|
|
293 | 295 |
return; |
294 | 296 |
} |
295 | 297 |
|
Also available in: Unified diff
fix term loading bug for originally empty vocabularies #4248