1 package eu
.etaxonomy
.cdm
.persistence
.dao
.hibernate
.description
;
5 import org
.hibernate
.Query
;
6 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
7 import org
.springframework
.beans
.factory
.annotation
.Qualifier
;
8 import org
.springframework
.stereotype
.Repository
;
10 import eu
.etaxonomy
.cdm
.model
.description
.IIdentificationKey
;
11 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
12 import eu
.etaxonomy
.cdm
.persistence
.dao
.IBeanInitializer
;
13 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IIdentificationKeyDao
;
14 import eu
.etaxonomy
.cdm
.persistence
.dao
.hibernate
.common
.DaoBase
;
17 public class IdentificationKeyDaoImpl
extends DaoBase
implements IIdentificationKeyDao
{
20 @Qualifier("defaultBeanInitializer")
21 protected IBeanInitializer defaultBeanInitializer
;
25 Query query
= getSession().createQuery("select count(key) from eu.etaxonomy.cdm.model.description.IIdentificationKey key");
27 List
<Long
> result
= query
.list();
29 for(Long l
: result
) {
30 total
+= l
.intValue();
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");
41 query
.setFirstResult(start
);
43 query
.setFirstResult(0);
45 query
.setMaxResults(limit
);
48 List
<IIdentificationKey
> results
= query
.list();
49 defaultBeanInitializer
.initializeAll(results
, propertyPaths
);
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)
57 public <T
extends IIdentificationKey
> List
<T
> findByTaxonomicScope(
58 TaxonBase taxon
, Class
<T
> type
, Integer pageSize
,
59 Integer pageNumber
, List
<String
> propertyPaths
) {
61 Query query
= getSession().createQuery("select key from " + type
.getCanonicalName() +" key join key.taxonomicScope ts where ts = (:taxon)");
62 query
.setParameter("taxon", taxon
);
63 List
<T
> results
= query
.list();
64 defaultBeanInitializer
.initializeAll(results
, propertyPaths
);
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)
72 public <T
extends IIdentificationKey
> Long
countByTaxonomicScope(TaxonBase taxon
, Class
<T
> type
) {
74 Query query
= getSession().createQuery("select count(key) from " + type
.getCanonicalName() +" key join key.taxonomicScope ts where ts = (:taxon)");
75 query
.setParameter("taxon", taxon
);
76 List
<Long
> list
= query
.list();
78 for(Long perTypeCount
: list
){
79 count
+= perTypeCount
;