2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.persistence
.dao
.hibernate
.common
;
12 import java
.util
.List
;
14 import org
.hibernate
.Criteria
;
15 import org
.hibernate
.criterion
.Projections
;
16 import org
.hibernate
.criterion
.Restrictions
;
17 import org
.springframework
.stereotype
.Repository
;
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
.common
.User
;
23 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IAnnotationDao
;
24 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
27 public class AnnotationDaoImpl
extends LanguageStringBaseDaoImpl
<Annotation
> implements IAnnotationDao
{
29 public AnnotationDaoImpl() {
30 super(Annotation
.class);
33 public int count(Person commentator
, MarkerType status
) {
34 checkNotInPriorView("AnnotationDaoImpl.count(Person commentator, MarkerType status)");
35 Criteria criteria
= getSession().createCriteria(Annotation
.class);
37 if(commentator
!= null) {
38 criteria
.add(Restrictions
.eq("commentator",commentator
));
42 criteria
.createCriteria("markers").add(Restrictions
.eq("markerType", status
));
45 criteria
.setProjection(Projections
.countDistinct("id"));
47 return ((Number
)criteria
.uniqueResult()).intValue();
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);
54 if(commentator
!= null) {
55 criteria
.add(Restrictions
.eq("commentator",commentator
));
59 criteria
.createCriteria("markers").add(Restrictions
.eq("markerType", status
));
62 if(pageSize
!= null) {
63 criteria
.setMaxResults(pageSize
);
64 if(pageNumber
!= null) {
65 criteria
.setFirstResult(pageNumber
* pageSize
);
69 addOrder(criteria
, orderHints
);
70 List
<Annotation
> results
= (List
<Annotation
>)criteria
.list();
71 defaultBeanInitializer
.initializeAll(results
, propertyPaths
);
75 public int count(User creator
, MarkerType status
) {
76 checkNotInPriorView("AnnotationDaoImpl.count(User creator, MarkerType statu)");
77 Criteria criteria
= getSession().createCriteria(Annotation
.class);
80 criteria
.add(Restrictions
.eq("createdBy",creator
));
84 criteria
.createCriteria("markers").add(Restrictions
.eq("markerType", status
));
87 criteria
.setProjection(Projections
.countDistinct("id"));
89 return ((Number
)criteria
.uniqueResult()).intValue();
92 public List
<Annotation
> list(User creator
, MarkerType status
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
93 checkNotInPriorView("AnnotationDaoImpl.list(User creator, MarkerType status, Integer pageSize, Integer pageNumber)");
94 Criteria criteria
= getSession().createCriteria(Annotation
.class);
97 criteria
.add(Restrictions
.eq("createdBy",creator
));
101 criteria
.createCriteria("markers").add(Restrictions
.eq("markerType", status
));
104 if(pageSize
!= null) {
105 criteria
.setMaxResults(pageSize
);
106 if(pageNumber
!= null) {
107 criteria
.setFirstResult(pageNumber
* pageSize
);
111 addOrder(criteria
, orderHints
);
112 List
<Annotation
> results
= (List
<Annotation
>)criteria
.list();
113 defaultBeanInitializer
.initializeAll(results
, propertyPaths
);