Project

General

Profile

Download (3.07 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.persistence.dao.hibernate.description;
2

    
3
import java.util.List;
4

    
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;
9

    
10
import eu.etaxonomy.cdm.model.description.IIdentificationKey;
11
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
12
import eu.etaxonomy.cdm.persistence.dao.BeanInitializer;
13
import eu.etaxonomy.cdm.persistence.dao.description.IIdentificationKeyDao;
14
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.DaoBase;
15

    
16
@Repository
17
public class IdentificationKeyDaoImpl extends DaoBase implements IIdentificationKeyDao {
18
	
19
	@Autowired
20
	@Qualifier("defaultBeanInitializer")
21
	protected BeanInitializer defaultBeanInitializer;
22

    
23
	public int count() {
24
		Query query = getSession().createQuery("select count(key) from eu.etaxonomy.cdm.model.description.IIdentificationKey key");
25
		
26
		List<Long> result = (List<Long>)query.list();
27
		Integer total = 0;
28
		for(Long l : result) {
29
			total += l.intValue();
30
		}
31
		return total;
32
	}
33

    
34
	public List<IIdentificationKey> list(Integer limit,Integer start, List<String> propertyPaths) {
35
		Query query = getSession().createQuery("select key from eu.etaxonomy.cdm.model.description.IIdentificationKey key order by created desc");
36
		
37
		if(limit != null) {
38
			if(start != null) {
39
				query.setFirstResult(start);
40
			} else {
41
				query.setFirstResult(0);
42
			}
43
			query.setMaxResults(limit);
44
		}
45
		
46
		List<IIdentificationKey> results = (List<IIdentificationKey>)query.list();
47
		defaultBeanInitializer.initializeAll(results, propertyPaths);
48
		return results; 
49
	}
50

    
51
	/* (non-Javadoc)
52
	 * @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)
53
	 */
54
	@Override
55
	public <T extends IIdentificationKey> List<T> findByTaxonomicScope(
56
			TaxonBase taxon, Class<T> type, Integer pageSize,
57
			Integer pageNumber, List<String> propertyPaths) {
58
		
59
		Query query = getSession().createQuery("select key from " + type.getCanonicalName() +" key join key.taxonomicScope ts where ts = (:taxon)");
60
		query.setParameter("taxon", taxon);
61
		List<T> results = query.list();
62
		defaultBeanInitializer.initializeAll(results, propertyPaths);
63
		return results;
64
	}
65
	
66
	/* (non-Javadoc)
67
	 * @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)
68
	 */
69
	@Override
70
	public <T extends IIdentificationKey> Long countByTaxonomicScope(TaxonBase taxon, Class<T> type) {
71
		
72
		Query query = getSession().createQuery("select count(key) from " + type.getCanonicalName() +" key join key.taxonomicScope ts where ts = (:taxon)");
73
		query.setParameter("taxon", taxon);
74
		List<Long> list = query.list();
75
		Long count = 0l; 
76
		for(Long perTypeCount : list){
77
			count += perTypeCount;
78
		}
79
		return count;
80
	}
81

    
82
}
(6-6/10)