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.agent.Person;
|
20
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
21
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
22
|
import eu.etaxonomy.cdm.model.permission.User;
|
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
|
@Override
|
34
|
public long count(Person commentator, MarkerType status) {
|
35
|
checkNotInPriorView("AnnotationDaoImpl.count(Person commentator, MarkerType status)");
|
36
|
Criteria criteria = getSession().createCriteria(Annotation.class);
|
37
|
|
38
|
if(commentator != null) {
|
39
|
criteria.add(Restrictions.eq("commentator",commentator));
|
40
|
}
|
41
|
|
42
|
if(status != null) {
|
43
|
criteria.createCriteria("markers").add(Restrictions.eq("markerType", status));
|
44
|
}
|
45
|
|
46
|
criteria.setProjection(Projections.countDistinct("id"));
|
47
|
|
48
|
return (Long)criteria.uniqueResult();
|
49
|
}
|
50
|
|
51
|
@Override
|
52
|
public List<Annotation> list(Person commentator, MarkerType status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
53
|
checkNotInPriorView("AnnotationDaoImpl.list(Person commentator, MarkerType status, Integer pageSize, Integer pageNumber)");
|
54
|
Criteria criteria = getSession().createCriteria(Annotation.class);
|
55
|
|
56
|
if(commentator != null) {
|
57
|
criteria.add(Restrictions.eq("commentator",commentator));
|
58
|
}
|
59
|
|
60
|
if(status != null) {
|
61
|
criteria.createCriteria("markers").add(Restrictions.eq("markerType", status));
|
62
|
}
|
63
|
|
64
|
if(pageSize != null) {
|
65
|
criteria.setMaxResults(pageSize);
|
66
|
if(pageNumber != null) {
|
67
|
criteria.setFirstResult(pageNumber * pageSize);
|
68
|
}
|
69
|
}
|
70
|
|
71
|
addOrder(criteria, orderHints);
|
72
|
List<Annotation> results = criteria.list();
|
73
|
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
74
|
return results;
|
75
|
}
|
76
|
|
77
|
@Override
|
78
|
public long count(User creator, MarkerType status) {
|
79
|
checkNotInPriorView("AnnotationDaoImpl.count(User creator, MarkerType statu)");
|
80
|
Criteria criteria = getSession().createCriteria(Annotation.class);
|
81
|
|
82
|
if(creator != null) {
|
83
|
criteria.add(Restrictions.eq("createdBy",creator));
|
84
|
}
|
85
|
|
86
|
if(status != null) {
|
87
|
criteria.createCriteria("markers").add(Restrictions.eq("markerType", status));
|
88
|
}
|
89
|
|
90
|
criteria.setProjection(Projections.countDistinct("id"));
|
91
|
|
92
|
return (Long)criteria.uniqueResult();
|
93
|
}
|
94
|
|
95
|
@Override
|
96
|
public List<Annotation> list(User creator, MarkerType status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
97
|
checkNotInPriorView("AnnotationDaoImpl.list(User creator, MarkerType status, Integer pageSize, Integer pageNumber)");
|
98
|
Criteria criteria = getSession().createCriteria(Annotation.class);
|
99
|
|
100
|
if(creator != null) {
|
101
|
criteria.add(Restrictions.eq("createdBy",creator));
|
102
|
}
|
103
|
|
104
|
if(status != null) {
|
105
|
criteria.createCriteria("markers").add(Restrictions.eq("markerType", status));
|
106
|
}
|
107
|
|
108
|
if(pageSize != null) {
|
109
|
criteria.setMaxResults(pageSize);
|
110
|
if(pageNumber != null) {
|
111
|
criteria.setFirstResult(pageNumber * pageSize);
|
112
|
}
|
113
|
}
|
114
|
|
115
|
addOrder(criteria, orderHints);
|
116
|
List<Annotation> results = criteria.list();
|
117
|
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
118
|
return results;
|
119
|
}
|
120
|
}
|