Revision a51ab35e
Added by Katja Luther over 6 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImpl.java | ||
---|---|---|
26 | 26 |
import org.hibernate.FetchMode; |
27 | 27 |
import org.hibernate.Hibernate; |
28 | 28 |
import org.hibernate.Query; |
29 |
import org.hibernate.Session; |
|
29 | 30 |
import org.hibernate.criterion.Criterion; |
30 | 31 |
import org.hibernate.criterion.Order; |
31 | 32 |
import org.hibernate.criterion.Projections; |
... | ... | |
60 | 61 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
61 | 62 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
62 | 63 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; |
64 |
import eu.etaxonomy.cdm.model.taxon.UuidAndTitleCacheTaxonComparator; |
|
63 | 65 |
import eu.etaxonomy.cdm.model.view.AuditEvent; |
64 | 66 |
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.IdentifiableDaoBase; |
65 | 67 |
import eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao; |
... | ... | |
1854 | 1856 |
return results; |
1855 | 1857 |
} |
1856 | 1858 |
|
1859 |
@Override |
|
1860 |
public List<UuidAndTitleCache<TaxonBase>> getUuidAndTitleCache(Integer limit, String pattern){ |
|
1861 |
Session session = getSession(); |
|
1862 |
Query query = null; |
|
1863 |
if (pattern != null){ |
|
1864 |
query = session.createQuery("select taxonBase.uuid, taxonBase.id, taxonBase.titleCache, taxonBase.name.rank from TaxonBase as taxonBase where taxonBase.titleCache like :pattern"); |
|
1865 |
pattern = pattern.replace("*", "%"); |
|
1866 |
pattern = pattern.replace("?", "_"); |
|
1867 |
pattern = pattern + "%"; |
|
1868 |
query.setParameter("pattern", pattern); |
|
1869 |
} else { |
|
1870 |
query = session.createQuery("select uuid, id, titleCache, taxonBase.name.rank from TaxonBase " ); |
|
1871 |
} |
|
1872 |
if (limit != null){ |
|
1873 |
query.setMaxResults(limit); |
|
1874 |
} |
|
1875 |
|
|
1876 |
return getUuidAndTitleCache(query); |
|
1877 |
} |
|
1878 |
|
|
1879 |
@Override |
|
1880 |
protected List<UuidAndTitleCache<TaxonBase>> getUuidAndTitleCache(Query query){ |
|
1881 |
List<UuidAndTitleCache<TaxonBase>> list = new ArrayList<UuidAndTitleCache<TaxonBase>>(); |
|
1882 |
|
|
1883 |
List<Object[]> result = query.list(); |
|
1884 |
if (result != null && !result.isEmpty()){ |
|
1885 |
if (result.iterator().next().length == 4){ |
|
1886 |
Collections.sort(result, new UuidAndTitleCacheTaxonComparator()); |
|
1887 |
} |
|
1888 |
} |
|
1889 |
|
|
1890 |
for(Object[] object : result){ |
|
1891 |
list.add(new UuidAndTitleCache<TaxonBase>((UUID) object[0],(Integer) object[1], (String) object[2])); |
|
1892 |
} |
|
1893 |
return list; |
|
1894 |
} |
|
1895 |
|
|
1857 | 1896 |
|
1858 | 1897 |
} |
Also available in: Unified diff
ref #7078: add uuidAndTitleCacheComparator to sort by rank and name