Project

General

Profile

Download (1.77 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/ 
9

    
10
package eu.etaxonomy.cdm.persistence.dao.hibernate.common;
11

    
12
import java.util.List;
13

    
14
import org.hibernate.Criteria;
15
import org.hibernate.criterion.Projections;
16
import org.hibernate.criterion.Restrictions;
17
import org.springframework.stereotype.Repository;
18

    
19
import eu.etaxonomy.cdm.model.common.Marker;
20
import eu.etaxonomy.cdm.model.common.MarkerType;
21
import eu.etaxonomy.cdm.persistence.dao.common.IMarkerDao;
22
import eu.etaxonomy.cdm.persistence.query.OrderHint;
23

    
24
@Repository
25
public class MarkerDaoImpl extends VersionableDaoBase<Marker> implements IMarkerDao {
26

    
27
	public MarkerDaoImpl() {
28
		super(Marker.class);
29
	}
30

    
31
	public int count(MarkerType markerType) {
32
		Criteria criteria = getSession().createCriteria(Marker.class);
33
		criteria.add(Restrictions.eq("markerType", markerType));
34
		criteria.setProjection(Projections.rowCount());
35
		return (Integer) criteria.uniqueResult();
36
	}
37

    
38
	public List<Marker> list(MarkerType markerType, Integer pageSize,	Integer pageNumber, List<OrderHint> orderHints,	List<String> propertyPaths) {
39
		Criteria criteria = getSession().createCriteria(Marker.class);
40
		criteria.add(Restrictions.eq("markerType", markerType));
41
		
42
		if(pageSize != null) {
43
			criteria.setMaxResults(pageSize);
44
		    if(pageNumber != null) {
45
		    	criteria.setFirstResult(pageNumber * pageSize);
46
		    }
47
		}
48
		
49
		addOrder(criteria, orderHints);
50
		List<Marker> results = (List<Marker>)criteria.list();		
51
		defaultBeanInitializer.initializeAll(results, propertyPaths);
52
		return results;
53
	}
54

    
55
}
(13-13/20)