Revision f7a01923
Added by Andreas Müller almost 8 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/DefinedTermDaoImpl.java | ||
---|---|---|
13 | 13 |
import java.util.ArrayList; |
14 | 14 |
import java.util.Collection; |
15 | 15 |
import java.util.Enumeration; |
16 |
import java.util.Iterator; |
|
16 | 17 |
import java.util.List; |
17 | 18 |
import java.util.Locale; |
18 | 19 |
import java.util.Set; |
... | ... | |
649 | 650 |
@Override |
650 | 651 |
public <T extends DefinedTermBase> List<T> listByTermType(TermType termType, Integer limit, Integer start, |
651 | 652 |
List<OrderHint> orderHints, List<String> propertyPaths) { |
652 |
Query query = getSession().createQuery("select term from DefinedTermBase term where term.termType = :termType");
|
|
653 |
Query query = getSession().createQuery("SELECT term FROM DefinedTermBase term WHERE term.termType = :termType");
|
|
653 | 654 |
query.setParameter("termType", termType); |
654 | 655 |
|
655 |
List<T> result = query.list(); |
|
656 |
@SuppressWarnings("unchecked") |
|
657 |
List<T> result = query.list(); |
|
658 |
|
|
656 | 659 |
|
657 | 660 |
defaultBeanInitializer.initializeAll(result, propertyPaths); |
658 | 661 |
|
... | ... | |
666 | 669 |
Query query = getSession().createQuery("from " + clazz.getSimpleName()); |
667 | 670 |
//query.setParameter("DTYPE", ); |
668 | 671 |
|
669 |
List<TERM> result = query.list(); |
|
672 |
@SuppressWarnings("unchecked") |
|
673 |
List<TERM> result = query.list(); |
|
670 | 674 |
|
671 | 675 |
defaultBeanInitializer.initializeAll(result, propertyPaths); |
672 | 676 |
|
673 | 677 |
return result; |
674 | 678 |
} |
679 |
|
|
680 |
@Override |
|
681 |
public <S extends DefinedTermBase> List<S> list(Class<S> type, Integer limit, Integer start, |
|
682 |
List<OrderHint> orderHints, List<String> propertyPath) { |
|
683 |
|
|
684 |
return deduplicateResult(super.list(type, limit, start, orderHints, propertyPath)); |
|
685 |
} |
|
686 |
|
|
687 |
/** |
|
688 |
* Workaround for http://dev.e-taxonomy.eu/trac/ticket/5871 and #5945 |
|
689 |
* Terms with multiple representations return identical duplicates |
|
690 |
* due to eager representation loading. We expect these duplicates to appear |
|
691 |
* in line wo we only compare one term with its predecessor. If it already |
|
692 |
* exists we remove it from the result. |
|
693 |
* @param orginals |
|
694 |
* @return |
|
695 |
*/ |
|
696 |
private <S extends DefinedTermBase<?>> List<S> deduplicateResult(List<S> orginals) { |
|
697 |
List<S> result = new ArrayList<>(); |
|
698 |
Iterator<S> it = orginals.iterator(); |
|
699 |
S last = null; |
|
700 |
while (it.hasNext()){ |
|
701 |
S a = it.next(); |
|
702 |
if (a != last){ |
|
703 |
if (!result.contains(a)){ |
|
704 |
result.add(a); |
|
705 |
} |
|
706 |
} |
|
707 |
last = a; |
|
708 |
} |
|
709 |
return result; |
|
710 |
} |
|
711 |
|
|
675 | 712 |
} |
Also available in: Unified diff
#5945 Deduplicate results from termloading by class