1
|
package eu.etaxonomy.cdm.persistence.dao.hibernate.description;
|
2
|
|
3
|
import java.util.List;
|
4
|
import java.util.UUID;
|
5
|
|
6
|
import org.hibernate.Query;
|
7
|
import org.springframework.beans.factory.annotation.Autowired;
|
8
|
import org.springframework.beans.factory.annotation.Qualifier;
|
9
|
import org.springframework.stereotype.Repository;
|
10
|
|
11
|
import eu.etaxonomy.cdm.model.description.IIdentificationKey;
|
12
|
import eu.etaxonomy.cdm.persistence.dao.description.IIdentificationKeyDao;
|
13
|
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.DaoBase;
|
14
|
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
|
15
|
|
16
|
@Repository
|
17
|
public class IdentificationKeyDaoImpl extends DaoBase implements IIdentificationKeyDao {
|
18
|
|
19
|
@Autowired
|
20
|
@Qualifier("defaultBeanInitializer")
|
21
|
protected IBeanInitializer defaultBeanInitializer;
|
22
|
|
23
|
@Override
|
24
|
public int count() {
|
25
|
Query query = getSession().createQuery("select count(key) from eu.etaxonomy.cdm.model.description.IIdentificationKey key");
|
26
|
|
27
|
List<Long> result = query.list();
|
28
|
Integer total = 0;
|
29
|
for(Long l : result) {
|
30
|
total += l.intValue();
|
31
|
}
|
32
|
return total;
|
33
|
}
|
34
|
|
35
|
@Override
|
36
|
public List<IIdentificationKey> list(Integer limit,Integer start, List<String> propertyPaths) {
|
37
|
Query query = getSession().createQuery("select key from eu.etaxonomy.cdm.model.description.IIdentificationKey key order by created desc");
|
38
|
|
39
|
if(limit != null) {
|
40
|
if(start != null) {
|
41
|
query.setFirstResult(start);
|
42
|
} else {
|
43
|
query.setFirstResult(0);
|
44
|
}
|
45
|
query.setMaxResults(limit);
|
46
|
}
|
47
|
|
48
|
List<IIdentificationKey> results = query.list();
|
49
|
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
50
|
return results;
|
51
|
}
|
52
|
|
53
|
/* (non-Javadoc)
|
54
|
* @see eu.etaxonomy.cdm.persistence.dao.description.IIdentificationKeyDao#findKeysConvering(eu.etaxonomy.cdm.model.taxon.TaxonBase, java.lang.Class, java.lang.Integer, java.lang.Integer, java.util.List)
|
55
|
*/
|
56
|
@Override
|
57
|
public <T extends IIdentificationKey> List<T> findByTaxonomicScope(
|
58
|
UUID taxonUuid, Class<T> type, Integer pageSize,
|
59
|
Integer pageNumber, List<String> propertyPaths) {
|
60
|
|
61
|
Query query = getSession().createQuery("select key from " + type.getCanonicalName() +" key join key.taxonomicScope ts where ts.uuid = (:taxon_uuid)");
|
62
|
query.setParameter("taxon_uuid", taxonUuid);
|
63
|
List<T> results = query.list();
|
64
|
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
65
|
return results;
|
66
|
}
|
67
|
|
68
|
/* (non-Javadoc)
|
69
|
* @see eu.etaxonomy.cdm.persistence.dao.description.IIdentificationKeyDao#findKeysConvering(eu.etaxonomy.cdm.model.taxon.TaxonBase, java.lang.Class, java.lang.Integer, java.lang.Integer, java.util.List)
|
70
|
*/
|
71
|
@Override
|
72
|
public <T extends IIdentificationKey> Long countByTaxonomicScope(UUID taxonUuid, Class<T> type) {
|
73
|
|
74
|
Query query = getSession().createQuery("select count(key) from " + type.getCanonicalName() +" key join key.taxonomicScope ts where ts.uuid = (:taxon_uuid)");
|
75
|
query.setParameter("taxon_uuid", taxonUuid);
|
76
|
List<Long> list = query.list();
|
77
|
Long count = 0l;
|
78
|
for(Long perTypeCount : list){
|
79
|
count += perTypeCount;
|
80
|
}
|
81
|
return count;
|
82
|
}
|
83
|
|
84
|
}
|