Revision b46b4c40
Added by Andreas Müller almost 8 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/AnnotationDaoImpl.java | ||
---|---|---|
5 | 5 |
* |
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 |
*/
|
|
8 |
*/ |
|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.cdm.persistence.dao.hibernate.common; |
11 | 11 |
|
... | ... | |
30 | 30 |
super(Annotation.class); |
31 | 31 |
} |
32 | 32 |
|
33 |
@Override |
|
33 | 34 |
public int count(Person commentator, MarkerType status) { |
34 | 35 |
checkNotInPriorView("AnnotationDaoImpl.count(Person commentator, MarkerType status)"); |
35 | 36 |
Criteria criteria = getSession().createCriteria(Annotation.class); |
36 |
|
|
37 |
|
|
37 | 38 |
if(commentator != null) { |
38 | 39 |
criteria.add(Restrictions.eq("commentator",commentator)); |
39 | 40 |
} |
40 |
|
|
41 |
|
|
41 | 42 |
if(status != null) { |
42 | 43 |
criteria.createCriteria("markers").add(Restrictions.eq("markerType", status)); |
43 |
}
|
|
44 |
|
|
44 |
} |
|
45 |
|
|
45 | 46 |
criteria.setProjection(Projections.countDistinct("id")); |
46 |
|
|
47 |
|
|
47 | 48 |
return ((Number)criteria.uniqueResult()).intValue(); |
48 | 49 |
} |
49 | 50 |
|
50 |
public List<Annotation> list(Person commentator, MarkerType status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) { |
|
51 |
@Override |
|
52 |
public List<Annotation> list(Person commentator, MarkerType status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) { |
|
51 | 53 |
checkNotInPriorView("AnnotationDaoImpl.list(Person commentator, MarkerType status, Integer pageSize, Integer pageNumber)"); |
52 | 54 |
Criteria criteria = getSession().createCriteria(Annotation.class); |
53 |
|
|
55 |
|
|
54 | 56 |
if(commentator != null) { |
55 | 57 |
criteria.add(Restrictions.eq("commentator",commentator)); |
56 | 58 |
} |
57 |
|
|
59 |
|
|
58 | 60 |
if(status != null) { |
59 | 61 |
criteria.createCriteria("markers").add(Restrictions.eq("markerType", status)); |
60 |
}
|
|
61 |
|
|
62 |
} |
|
63 |
|
|
62 | 64 |
if(pageSize != null) { |
63 | 65 |
criteria.setMaxResults(pageSize); |
64 | 66 |
if(pageNumber != null) { |
65 | 67 |
criteria.setFirstResult(pageNumber * pageSize); |
66 | 68 |
} |
67 | 69 |
} |
68 |
|
|
70 |
|
|
69 | 71 |
addOrder(criteria, orderHints); |
70 |
List<Annotation> results = (List<Annotation>)criteria.list();
|
|
72 |
List<Annotation> results = criteria.list();
|
|
71 | 73 |
defaultBeanInitializer.initializeAll(results, propertyPaths); |
72 | 74 |
return results; |
73 | 75 |
} |
74 | 76 |
|
75 |
public int count(User creator, MarkerType status) { |
|
77 |
@Override |
|
78 |
public int count(User creator, MarkerType status) { |
|
76 | 79 |
checkNotInPriorView("AnnotationDaoImpl.count(User creator, MarkerType statu)"); |
77 | 80 |
Criteria criteria = getSession().createCriteria(Annotation.class); |
78 |
|
|
81 |
|
|
79 | 82 |
if(creator != null) { |
80 | 83 |
criteria.add(Restrictions.eq("createdBy",creator)); |
81 | 84 |
} |
82 |
|
|
85 |
|
|
83 | 86 |
if(status != null) { |
84 | 87 |
criteria.createCriteria("markers").add(Restrictions.eq("markerType", status)); |
85 |
}
|
|
86 |
|
|
88 |
} |
|
89 |
|
|
87 | 90 |
criteria.setProjection(Projections.countDistinct("id")); |
88 |
|
|
91 |
|
|
89 | 92 |
return ((Number)criteria.uniqueResult()).intValue(); |
90 | 93 |
} |
91 | 94 |
|
92 |
public List<Annotation> list(User creator, MarkerType status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) { |
|
95 |
@Override |
|
96 |
public List<Annotation> list(User creator, MarkerType status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) { |
|
93 | 97 |
checkNotInPriorView("AnnotationDaoImpl.list(User creator, MarkerType status, Integer pageSize, Integer pageNumber)"); |
94 | 98 |
Criteria criteria = getSession().createCriteria(Annotation.class); |
95 |
|
|
99 |
|
|
96 | 100 |
if(creator != null) { |
97 | 101 |
criteria.add(Restrictions.eq("createdBy",creator)); |
98 | 102 |
} |
99 |
|
|
103 |
|
|
100 | 104 |
if(status != null) { |
101 | 105 |
criteria.createCriteria("markers").add(Restrictions.eq("markerType", status)); |
102 |
}
|
|
103 |
|
|
106 |
} |
|
107 |
|
|
104 | 108 |
if(pageSize != null) { |
105 | 109 |
criteria.setMaxResults(pageSize); |
106 | 110 |
if(pageNumber != null) { |
107 | 111 |
criteria.setFirstResult(pageNumber * pageSize); |
108 | 112 |
} |
109 | 113 |
} |
110 |
|
|
114 |
|
|
111 | 115 |
addOrder(criteria, orderHints); |
112 |
List<Annotation> results = (List<Annotation>)criteria.list();
|
|
116 |
List<Annotation> results = criteria.list();
|
|
113 | 117 |
defaultBeanInitializer.initializeAll(results, propertyPaths); |
114 | 118 |
return results; |
115 | 119 |
} |
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/AnnotationDaoTest.java | ||
---|---|---|
115 | 115 |
assertEquals("getAnnotations should return 2",2,annotations.size()); |
116 | 116 |
} |
117 | 117 |
|
118 |
/* (non-Javadoc) |
|
119 |
* @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData() |
|
120 |
*/ |
|
121 | 118 |
@Override |
122 | 119 |
public void createTestDataSet() throws FileNotFoundException { |
123 | 120 |
// TODO Auto-generated method stub |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/AnnotationService.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.cdm.api.service; |
|
12 |
|
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
import org.springframework.beans.factory.annotation.Autowired; |
|
17 |
import org.springframework.stereotype.Service; |
|
18 |
import org.springframework.transaction.annotation.Transactional; |
|
19 |
|
|
20 |
import eu.etaxonomy.cdm.api.service.pager.Pager; |
|
21 |
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl; |
|
22 |
import eu.etaxonomy.cdm.model.agent.Person; |
|
23 |
import eu.etaxonomy.cdm.model.common.Annotation; |
|
24 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
|
25 |
import eu.etaxonomy.cdm.model.common.User; |
|
26 |
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.AnnotationDaoImpl; |
|
27 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
|
28 |
|
|
29 |
@Service |
|
30 |
@Transactional(readOnly = true) |
|
31 |
public class AnnotationService extends AnnotatableServiceBase<Annotation, AnnotationDaoImpl> implements |
|
32 |
IAnnotationService { |
|
33 |
|
|
34 |
@Autowired |
|
35 |
protected void setDao(AnnotationDaoImpl dao) { |
|
36 |
this.dao = dao; |
|
37 |
} |
|
38 |
|
|
39 |
public int count(Person commentator, MarkerType status) { |
|
40 |
return dao.count(commentator, status); |
|
41 |
} |
|
42 |
|
|
43 |
public Pager<Annotation> list(Person commentator, MarkerType status,Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) { |
|
44 |
Integer numberOfResults = dao.count(commentator, status); |
|
45 |
|
|
46 |
List<Annotation> results = new ArrayList<Annotation>(); |
|
47 |
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize) |
|
48 |
results = dao.list(commentator, status, pageSize, pageNumber, orderHints, propertyPaths); |
|
49 |
} |
|
50 |
|
|
51 |
return new DefaultPagerImpl<Annotation>(pageNumber, numberOfResults, pageSize, results); |
|
52 |
} |
|
53 |
|
|
54 |
public int count(User creator, MarkerType status) { |
|
55 |
return dao.count(creator, status); |
|
56 |
} |
|
57 |
|
|
58 |
public Pager<Annotation> list(User creator, MarkerType status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, |
|
59 |
List<String> propertyPaths) { |
|
60 |
Integer numberOfResults = dao.count(creator, status); |
|
61 |
|
|
62 |
List<Annotation> results = new ArrayList<Annotation>(); |
|
63 |
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize) |
|
64 |
results = dao.list(creator, status, pageSize, pageNumber, orderHints, propertyPaths); |
|
65 |
} |
|
66 |
|
|
67 |
return new DefaultPagerImpl<Annotation>(pageNumber, numberOfResults, pageSize, results); |
|
68 |
} |
|
69 |
} |
|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.cdm.api.service; |
|
12 |
|
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
import org.springframework.beans.factory.annotation.Autowired; |
|
17 |
import org.springframework.stereotype.Service; |
|
18 |
import org.springframework.transaction.annotation.Transactional; |
|
19 |
|
|
20 |
import eu.etaxonomy.cdm.api.service.pager.Pager; |
|
21 |
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl; |
|
22 |
import eu.etaxonomy.cdm.model.agent.Person; |
|
23 |
import eu.etaxonomy.cdm.model.common.Annotation; |
|
24 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
|
25 |
import eu.etaxonomy.cdm.model.common.User; |
|
26 |
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.AnnotationDaoImpl; |
|
27 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
|
28 |
|
|
29 |
@Service |
|
30 |
@Transactional(readOnly = true) |
|
31 |
public class AnnotationService extends AnnotatableServiceBase<Annotation, AnnotationDaoImpl> implements |
|
32 |
IAnnotationService { |
|
33 |
|
|
34 |
@Override |
|
35 |
@Autowired |
|
36 |
protected void setDao(AnnotationDaoImpl dao) { |
|
37 |
this.dao = dao; |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public int count(Person commentator, MarkerType status) { |
|
42 |
return dao.count(commentator, status); |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public Pager<Annotation> list(Person commentator, MarkerType status,Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) { |
|
47 |
Integer numberOfResults = dao.count(commentator, status); |
|
48 |
|
|
49 |
List<Annotation> results = new ArrayList<Annotation>(); |
|
50 |
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize) |
|
51 |
results = dao.list(commentator, status, pageSize, pageNumber, orderHints, propertyPaths); |
|
52 |
} |
|
53 |
|
|
54 |
return new DefaultPagerImpl<Annotation>(pageNumber, numberOfResults, pageSize, results); |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public int count(User creator, MarkerType status) { |
|
59 |
return dao.count(creator, status); |
|
60 |
} |
|
61 |
|
|
62 |
@Override |
|
63 |
public Pager<Annotation> list(User creator, MarkerType status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, |
|
64 |
List<String> propertyPaths) { |
|
65 |
Integer numberOfResults = dao.count(creator, status); |
|
66 |
|
|
67 |
List<Annotation> results = new ArrayList<Annotation>(); |
|
68 |
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize) |
|
69 |
results = dao.list(creator, status, pageSize, pageNumber, orderHints, propertyPaths); |
|
70 |
} |
|
71 |
|
|
72 |
return new DefaultPagerImpl<Annotation>(pageNumber, numberOfResults, pageSize, results); |
|
73 |
} |
|
74 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/pager/impl/DefaultPagerImpl.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2009 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.cdm.api.service.pager.impl; |
|
12 |
|
|
13 |
import java.util.List; |
|
14 |
|
|
15 |
public class DefaultPagerImpl<T> extends AbstractPagerImpl<T> { |
|
16 |
|
|
17 |
private static final long serialVersionUID = 1L; |
|
18 |
|
|
19 |
/** |
|
20 |
* Constructor |
|
21 |
* |
|
22 |
* @param currentIndex the page of this result set (0-based), can be null |
|
23 |
* @param count the total number of results available for this query |
|
24 |
* @param pageSize The size of pages (can be null or 0 if all results should be returned if available) |
|
25 |
* @param records A list of objects in this page (can be empty if there were no results) |
|
26 |
* |
|
27 |
* @deprecated This constructor only supports total result counts to {@link Integer#MAX_VALUE} u |
|
28 |
* use {@link DefaultPagerImpl(Integer currentIndex, Long count, Integer pageSize, List<T> records, String suggestion)} |
|
29 |
* instead |
|
30 |
*/ |
|
31 |
@Deprecated |
|
32 |
public DefaultPagerImpl(Integer currentIndex, Integer count, Integer pageSize, List<T> records) { |
|
33 |
super(currentIndex, count, pageSize, records); |
|
34 |
} |
|
35 |
|
|
36 |
/** |
|
37 |
* Constructor |
|
38 |
* |
|
39 |
* @param currentIndex the page of this result set (0-based), can be null |
|
40 |
* @param count the total number of results available for this query |
|
41 |
* @param pageSize The size of pages (can be null or 0 if all results should be returned if available) |
|
42 |
* @param records A list of objects in this page (can be empty if there were no results) |
|
43 |
*/ |
|
44 |
public DefaultPagerImpl(Integer currentIndex, Long count, Integer pageSize, List<T> records) { |
|
45 |
super(currentIndex, count, pageSize, records); |
|
46 |
} |
|
47 |
|
|
48 |
/** |
|
49 |
* Constructor |
|
50 |
* |
|
51 |
* @param currentIndex the page of this result set (0-based), can be null |
|
52 |
* @param count the total number of results available for this query |
|
53 |
* @param pageSize The size of pages (can be null if all results should be returned if available) |
|
54 |
* @param records A list of objects in this page (can be empty if there were no results) |
|
55 |
* @param suggestion a suggested query that would improve the search (only applicable for free-text / lucene queries) |
|
56 |
* |
|
57 |
* @deprecated This constructor only supports total result counts to {@link Integer#MAX_VALUE} u |
|
58 |
* use {@link DefaultPagerImpl(Integer currentIndex, Integer count, Integer pageSize, List<T> records, String suggestion)} |
|
59 |
* instead |
|
60 |
*/ |
|
61 |
@Deprecated |
|
62 |
public DefaultPagerImpl(Integer currentIndex, Integer count, Integer pageSize, List<T> records, String suggestion) { |
|
63 |
super(currentIndex, count, pageSize, records,suggestion); |
|
64 |
} |
|
65 |
|
|
66 |
/* (non-Javadoc) |
|
67 |
* @see eu.etaxonomy.cdm.api.service.pager.impl.AbstractPagerImpl#createLabel(java.lang.String, java.lang.String) |
|
68 |
*/ |
|
69 |
@Override |
|
70 |
protected String createLabel(String s1, String s2) { |
|
71 |
return s1 + DefaultPagerImpl.LABEL_DIVIDER + s2; |
|
72 |
} |
|
73 |
} |
|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2009 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.cdm.api.service.pager.impl; |
|
12 |
|
|
13 |
import java.util.List; |
|
14 |
|
|
15 |
public class DefaultPagerImpl<T> extends AbstractPagerImpl<T> { |
|
16 |
|
|
17 |
private static final long serialVersionUID = 1L; |
|
18 |
|
|
19 |
/** |
|
20 |
* Constructor |
|
21 |
* |
|
22 |
* @param currentIndex the page of this result set (0-based), can be null |
|
23 |
* @param count the total number of results available for this query |
|
24 |
* @param pageSize The size of pages (can be null or 0 if all results should be returned if available) |
|
25 |
* @param records A list of objects in this page (can be empty if there were no results) |
|
26 |
* |
|
27 |
* @deprecated This constructor only supports total result counts to {@link Integer#MAX_VALUE} u |
|
28 |
* use {@link DefaultPagerImpl(Integer currentIndex, Long count, Integer pageSize, List<T> records, String suggestion)} |
|
29 |
* instead |
|
30 |
*/ |
|
31 |
@Deprecated |
|
32 |
public DefaultPagerImpl(Integer currentIndex, Integer count, Integer pageSize, List<T> records) { |
|
33 |
super(currentIndex, count, pageSize, records); |
|
34 |
} |
|
35 |
|
|
36 |
/** |
|
37 |
* Constructor |
|
38 |
* |
|
39 |
* @param currentIndex the page of this result set (0-based), can be null |
|
40 |
* @param count the total number of results available for this query |
|
41 |
* @param pageSize The size of pages (can be null or 0 if all results should be returned if available) |
|
42 |
* @param records A list of objects in this page (can be empty if there were no results) |
|
43 |
*/ |
|
44 |
public DefaultPagerImpl(Integer currentIndex, Long count, Integer pageSize, List<T> records) { |
|
45 |
super(currentIndex, count, pageSize, records); |
|
46 |
} |
|
47 |
|
|
48 |
/** |
|
49 |
* Constructor |
|
50 |
* |
|
51 |
* @param currentIndex the page of this result set (0-based), can be null |
|
52 |
* @param count the total number of results available for this query |
|
53 |
* @param pageSize The size of pages (can be null if all results should be returned if available) |
|
54 |
* @param records A list of objects in this page (can be empty if there were no results) |
|
55 |
* @param suggestion a suggested query that would improve the search (only applicable for free-text / lucene queries) |
|
56 |
* |
|
57 |
* @deprecated This constructor only supports total result counts to {@link Integer#MAX_VALUE} u |
|
58 |
* use {@link DefaultPagerImpl(Integer currentIndex, Integer count, Integer pageSize, List<T> records, String suggestion)} |
|
59 |
* instead |
|
60 |
*/ |
|
61 |
@Deprecated |
|
62 |
public DefaultPagerImpl(Integer currentIndex, Integer count, Integer pageSize, List<T> records, String suggestion) { |
|
63 |
super(currentIndex, count, pageSize, records,suggestion); |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
protected String createLabel(String s1, String s2) { |
|
68 |
return s1 + DefaultPagerImpl.LABEL_DIVIDER + s2; |
|
69 |
} |
|
70 |
} |
Also available in: Unified diff
Clean up AnnotationDao and AnnotationService