1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.api.criteria; |
17 | |
|
18 | |
import java.util.Collection; |
19 | |
|
20 | |
import javax.xml.bind.annotation.XmlAccessType; |
21 | |
import javax.xml.bind.annotation.XmlAccessorType; |
22 | |
import javax.xml.bind.annotation.XmlAnyElement; |
23 | |
import javax.xml.bind.annotation.XmlElement; |
24 | |
import javax.xml.bind.annotation.XmlRootElement; |
25 | |
import javax.xml.bind.annotation.XmlType; |
26 | |
|
27 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
28 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
29 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
30 | |
import org.kuali.rice.core.api.CoreConstants; |
31 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
32 | |
import org.w3c.dom.Element; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
@XmlRootElement(name = QueryByCriteria.Constants.ROOT_ELEMENT_NAME) |
60 | |
@XmlAccessorType(XmlAccessType.NONE) |
61 | |
@XmlType(name = QueryByCriteria.Constants.TYPE_NAME, propOrder = { |
62 | |
QueryByCriteria.Elements.CRITERIA, |
63 | |
QueryByCriteria.Elements.START_AT_INDEX, |
64 | |
QueryByCriteria.Elements.MAX_RESULTS, |
65 | |
QueryByCriteria.Elements.COUNT_FLAG, |
66 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS }) |
67 | 0 | public final class QueryByCriteria<T> implements ModelObjectComplete { |
68 | |
|
69 | |
private static final long serialVersionUID = 2210627777648920180L; |
70 | |
|
71 | |
@XmlElement(name = Elements.CRITERIA, required = true) |
72 | |
private final Criteria criteria; |
73 | |
|
74 | |
@XmlElement(name = Elements.START_AT_INDEX, required = false) |
75 | |
private final Integer startAtIndex; |
76 | |
|
77 | |
@XmlElement(name = Elements.MAX_RESULTS, required = false) |
78 | |
private final Integer maxResults; |
79 | |
|
80 | |
@XmlElement(name = Elements.COUNT_FLAG, required = true) |
81 | |
private final CountFlag countFlag; |
82 | |
|
83 | 0 | @SuppressWarnings("unused") |
84 | |
@XmlAnyElement |
85 | |
private final Collection<Element> _futureElements = null; |
86 | |
|
87 | 0 | private QueryByCriteria() { |
88 | 0 | this.criteria = null; |
89 | 0 | this.startAtIndex = null; |
90 | 0 | this.maxResults = null; |
91 | 0 | this.countFlag = null; |
92 | 0 | } |
93 | |
|
94 | 0 | private QueryByCriteria(Builder<T> builder) { |
95 | 0 | this.criteria = builder.getCriteriaBuilder().build(); |
96 | 0 | this.startAtIndex = builder.getStartAtIndex(); |
97 | 0 | this.maxResults = builder.getMaxResults(); |
98 | 0 | this.countFlag = builder.getCountFlag(); |
99 | 0 | } |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public Criteria getCriteria() { |
107 | 0 | return this.criteria; |
108 | |
} |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
public Integer getStartAtIndex() { |
123 | 0 | return this.startAtIndex; |
124 | |
} |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
public Integer getMaxResults() { |
134 | 0 | return this.maxResults; |
135 | |
} |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
public CountFlag getCountFlag() { |
147 | 0 | return this.countFlag; |
148 | |
} |
149 | |
|
150 | |
@Override |
151 | |
public int hashCode() { |
152 | 0 | return HashCodeBuilder.reflectionHashCode(this, |
153 | |
Constants.HASH_CODE_EQUALS_EXCLUDE); |
154 | |
} |
155 | |
|
156 | |
@Override |
157 | |
public boolean equals(Object obj) { |
158 | 0 | return EqualsBuilder.reflectionEquals(obj, this, |
159 | |
Constants.HASH_CODE_EQUALS_EXCLUDE); |
160 | |
} |
161 | |
|
162 | |
@Override |
163 | |
public String toString() { |
164 | 0 | return ToStringBuilder.reflectionToString(this); |
165 | |
} |
166 | |
|
167 | |
public static final class Builder<T> { |
168 | |
|
169 | |
private final CriteriaBuilder<T> criteriaBuilder; |
170 | |
private Integer startAtIndex; |
171 | |
private Integer maxResults; |
172 | |
private boolean includeCount; |
173 | |
private CountFlag countFlag; |
174 | |
|
175 | 0 | private Builder(Class<T> queryClass) { |
176 | 0 | this.criteriaBuilder = CriteriaBuilder.newCriteriaBuilder(queryClass); |
177 | 0 | this.countFlag = CountFlag.NONE; |
178 | 0 | } |
179 | |
|
180 | |
public static <T> Builder<T> create(Class<T> queryClass) { |
181 | 0 | return new Builder<T>(queryClass); |
182 | |
} |
183 | |
|
184 | |
public QueryByCriteria<T> build() { |
185 | 0 | return new QueryByCriteria<T>(this); |
186 | |
} |
187 | |
|
188 | |
public Integer getStartAtIndex() { |
189 | 0 | return this.startAtIndex; |
190 | |
} |
191 | |
|
192 | |
public void setStartAtIndex(Integer startAtIndex) { |
193 | 0 | this.startAtIndex = startAtIndex; |
194 | 0 | } |
195 | |
|
196 | |
public Integer getMaxResults() { |
197 | 0 | return this.maxResults; |
198 | |
} |
199 | |
|
200 | |
public void setMaxResults(Integer maxResults) { |
201 | 0 | this.maxResults = maxResults; |
202 | 0 | } |
203 | |
|
204 | |
public boolean isIncludeCount() { |
205 | 0 | return this.includeCount; |
206 | |
} |
207 | |
|
208 | |
public void setIncludeCount(boolean includeCount) { |
209 | 0 | this.includeCount = includeCount; |
210 | 0 | } |
211 | |
|
212 | |
public CountFlag getCountFlag() { |
213 | 0 | return this.countFlag; |
214 | |
} |
215 | |
|
216 | |
public void setCountFlag(CountFlag countFlag) { |
217 | 0 | this.countFlag = countFlag; |
218 | 0 | } |
219 | |
|
220 | |
public CriteriaBuilder<T> getCriteriaBuilder() { |
221 | 0 | return this.criteriaBuilder; |
222 | |
} |
223 | |
|
224 | |
} |
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | 0 | static class Constants { |
230 | |
final static String ROOT_ELEMENT_NAME = "queryByCriteria"; |
231 | |
final static String TYPE_NAME = "QueryByCriteriaType"; |
232 | 0 | final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS }; |
233 | |
} |
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | 0 | static class Elements { |
240 | |
final static String CRITERIA = "criteria"; |
241 | |
final static String START_AT_INDEX = "startAtIndex"; |
242 | |
final static String MAX_RESULTS = "maxResults"; |
243 | |
final static String COUNT_FLAG = "countFlag"; |
244 | |
} |
245 | |
|
246 | |
} |