Project

General

Profile

Download (2.43 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.Query;
16
import org.hibernate.criterion.Projections;
17
import org.hibernate.criterion.Restrictions;
18
import org.springframework.stereotype.Repository;
19

    
20
import eu.etaxonomy.cdm.model.agent.Person;
21
import eu.etaxonomy.cdm.model.common.Annotation;
22
import eu.etaxonomy.cdm.model.common.MarkerType;
23
import eu.etaxonomy.cdm.persistence.dao.common.IAnnotationDao;
24
import eu.etaxonomy.cdm.persistence.query.OrderHint;
25

    
26
@Repository
27
public class AnnotationDaoImpl extends LanguageStringBaseDaoImpl<Annotation> implements IAnnotationDao {
28

    
29
	public AnnotationDaoImpl() {
30
		super(Annotation.class);
31
	}
32

    
33
	public int count(Person commentator, MarkerType status) {
34
		checkNotInPriorView("AnnotationDaoImpl.count(Person commentator, MarkerType status)");
35
		Criteria criteria = getSession().createCriteria(Annotation.class);
36
		
37
		 if(commentator != null) {
38
	        criteria.add(Restrictions.eq("commentator",commentator));
39
	     }
40
			
41
		if(status != null) {
42
			criteria.createCriteria("markers").add(Restrictions.eq("markerType", status));
43
		} 
44
		
45
		criteria.setProjection(Projections.countDistinct("id"));
46
		
47
		return (Integer)criteria.uniqueResult();
48
	}
49

    
50
	public List<Annotation> list(Person commentator, MarkerType status,	Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
51
		checkNotInPriorView("AnnotationDaoImpl.list(Person commentator, MarkerType status,	Integer pageSize, Integer pageNumber)");
52
        Criteria criteria = getSession().createCriteria(Annotation.class);
53
        
54
        if(commentator != null) {
55
            criteria.add(Restrictions.eq("commentator",commentator));
56
        }
57
		
58
		if(status != null) {
59
			criteria.createCriteria("markers").add(Restrictions.eq("markerType", status));
60
		} 
61
		
62
		if(pageSize != null) {
63
			criteria.setMaxResults(pageSize);
64
		    if(pageNumber != null) {
65
		    	criteria.setFirstResult(pageNumber * pageSize);
66
		    }
67
		}
68
		
69
		addOrder(criteria, orderHints);
70
		List<Annotation> results = (List<Annotation>)criteria.list();		
71
		defaultBeanInitializer.initializeAll(results, propertyPaths);
72
		return results;
73
	}
74
}
(2-2/20)