Project

General

Profile

« Previous | Next » 

Revision b46b4c40

Added by Andreas Müller almost 8 years ago

Clean up AnnotationDao and AnnotationService

View differences:

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
	}

Also available in: Unified diff