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 org.kuali.rice.core.api.CoreConstants; |
19 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
20 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
21 | |
import org.w3c.dom.Element; |
22 | |
|
23 | |
import javax.xml.bind.annotation.XmlAccessType; |
24 | |
import javax.xml.bind.annotation.XmlAccessorType; |
25 | |
import javax.xml.bind.annotation.XmlAnyElement; |
26 | |
import javax.xml.bind.annotation.XmlElement; |
27 | |
import javax.xml.bind.annotation.XmlElements; |
28 | |
import javax.xml.bind.annotation.XmlRootElement; |
29 | |
import javax.xml.bind.annotation.XmlType; |
30 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
31 | |
import java.io.Serializable; |
32 | |
import java.util.Arrays; |
33 | |
import java.util.Collection; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
@XmlRootElement(name = QueryByCriteria.Constants.ROOT_ELEMENT_NAME) |
58 | |
@XmlAccessorType(XmlAccessType.NONE) |
59 | |
@XmlType(name = QueryByCriteria.Constants.TYPE_NAME, propOrder = { |
60 | |
QueryByCriteria.Elements.PREDICATE, |
61 | |
QueryByCriteria.Elements.START_AT_INDEX, |
62 | |
QueryByCriteria.Elements.MAX_RESULTS, |
63 | |
QueryByCriteria.Elements.COUNT_FLAG, |
64 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS }) |
65 | 0 | public final class QueryByCriteria extends AbstractDataTransferObject { |
66 | |
|
67 | |
private static final long serialVersionUID = 2210627777648920180L; |
68 | |
|
69 | |
@XmlElements(value = { |
70 | |
@XmlElement(name = AndPredicate.Constants.ROOT_ELEMENT_NAME, type = AndPredicate.class, required = false), |
71 | |
@XmlElement(name = EqualPredicate.Constants.ROOT_ELEMENT_NAME, type = EqualPredicate.class, required = false), |
72 | |
@XmlElement(name = GreaterThanPredicate.Constants.ROOT_ELEMENT_NAME, type = GreaterThanPredicate.class, required = false), |
73 | |
@XmlElement(name = GreaterThanOrEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = GreaterThanOrEqualPredicate.class, required = false), |
74 | |
@XmlElement(name = InPredicate.Constants.ROOT_ELEMENT_NAME, type = InPredicate.class, required = false), |
75 | |
@XmlElement(name = LessThanPredicate.Constants.ROOT_ELEMENT_NAME, type = LessThanPredicate.class, required = false), |
76 | |
@XmlElement(name = LessThanOrEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = LessThanOrEqualPredicate.class, required = false), |
77 | |
@XmlElement(name = LikePredicate.Constants.ROOT_ELEMENT_NAME, type = LikePredicate.class, required = false), |
78 | |
@XmlElement(name = NotEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = NotEqualPredicate.class, required = false), |
79 | |
@XmlElement(name = NotInPredicate.Constants.ROOT_ELEMENT_NAME, type = NotInPredicate.class, required = false), |
80 | |
@XmlElement(name = NotLikePredicate.Constants.ROOT_ELEMENT_NAME, type = NotLikePredicate.class, required = false), |
81 | |
@XmlElement(name = NotNullPredicate.Constants.ROOT_ELEMENT_NAME, type = NotNullPredicate.class, required = false), |
82 | |
@XmlElement(name = NullPredicate.Constants.ROOT_ELEMENT_NAME, type = NullPredicate.class, required = false), |
83 | |
@XmlElement(name = OrPredicate.Constants.ROOT_ELEMENT_NAME, type = OrPredicate.class, required = false) |
84 | |
}) |
85 | |
private final Predicate predicate; |
86 | |
|
87 | |
@XmlElement(name = Elements.START_AT_INDEX, required = false) |
88 | |
private final Integer startAtIndex; |
89 | |
|
90 | |
@XmlElement(name = Elements.MAX_RESULTS, required = false) |
91 | |
private final Integer maxResults; |
92 | |
|
93 | |
@XmlJavaTypeAdapter(CountFlag.Adapter.class) |
94 | |
@XmlElement(name = Elements.COUNT_FLAG, required = true) |
95 | |
private final String countFlag; |
96 | |
|
97 | 0 | @SuppressWarnings("unused") |
98 | |
@XmlAnyElement |
99 | |
private final Collection<Element> _futureElements = null; |
100 | |
|
101 | 0 | private QueryByCriteria() { |
102 | 0 | this.predicate = null; |
103 | 0 | this.startAtIndex = null; |
104 | 0 | this.maxResults = null; |
105 | 0 | this.countFlag = null; |
106 | 0 | } |
107 | |
|
108 | 0 | private QueryByCriteria(Builder builder) { |
109 | 0 | final Predicate[] preds = builder.predicates; |
110 | 0 | if (preds != null && preds.length > 1) { |
111 | |
|
112 | 0 | this.predicate = PredicateFactory.and(builder.predicates); |
113 | 0 | } else if (preds != null && preds.length == 1) { |
114 | 0 | this.predicate = builder.predicates[0]; |
115 | |
} else { |
116 | 0 | this.predicate = null; |
117 | |
} |
118 | |
|
119 | 0 | this.startAtIndex = builder.getStartAtIndex(); |
120 | 0 | this.maxResults = builder.getMaxResults(); |
121 | 0 | this.countFlag = builder.getCountFlag() == null ? null : builder.getCountFlag().getFlag(); |
122 | 0 | } |
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
public Predicate getPredicate() { |
130 | 0 | return this.predicate; |
131 | |
} |
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
public Integer getStartAtIndex() { |
149 | 0 | return this.startAtIndex; |
150 | |
} |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
public Integer getMaxResults() { |
164 | 0 | return this.maxResults; |
165 | |
} |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
public CountFlag getCountFlag() { |
177 | 0 | return this.countFlag == null ? null : CountFlag.valueOf(this.countFlag); |
178 | |
} |
179 | |
|
180 | 0 | public static final class Builder implements ModelBuilder, Serializable { |
181 | |
|
182 | |
private Predicate[] predicates; |
183 | |
private Integer startAtIndex; |
184 | |
private Integer maxResults; |
185 | |
private CountFlag countFlag; |
186 | |
|
187 | 0 | private Builder() { |
188 | 0 | this.countFlag = CountFlag.NONE; |
189 | 0 | } |
190 | |
|
191 | |
public static Builder create() { |
192 | 0 | return new Builder(); |
193 | |
} |
194 | |
|
195 | |
public Integer getStartAtIndex() { |
196 | 0 | return this.startAtIndex; |
197 | |
} |
198 | |
|
199 | |
public void setStartAtIndex(Integer startAtIndex) { |
200 | 0 | if (startAtIndex != null && startAtIndex < 0) { |
201 | 0 | throw new IllegalArgumentException("startAtIndex < 0"); |
202 | |
} |
203 | |
|
204 | 0 | this.startAtIndex = startAtIndex; |
205 | 0 | } |
206 | |
|
207 | |
public Integer getMaxResults() { |
208 | 0 | return this.maxResults; |
209 | |
} |
210 | |
|
211 | |
public void setMaxResults(Integer maxResults) { |
212 | 0 | if (maxResults != null && maxResults < 0) { |
213 | 0 | throw new IllegalArgumentException("maxResults < 0"); |
214 | |
} |
215 | |
|
216 | 0 | this.maxResults = maxResults; |
217 | 0 | } |
218 | |
|
219 | |
public CountFlag getCountFlag() { |
220 | 0 | return this.countFlag; |
221 | |
} |
222 | |
|
223 | |
public void setCountFlag(CountFlag countFlag) { |
224 | 0 | if (countFlag == null) { |
225 | 0 | throw new IllegalArgumentException("countFlag was null"); |
226 | |
} |
227 | |
|
228 | 0 | this.countFlag = countFlag; |
229 | 0 | } |
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
public Predicate[] getPredicates() { |
236 | 0 | if (this.predicates == null) { |
237 | 0 | return null; |
238 | |
} |
239 | |
|
240 | |
|
241 | 0 | return Arrays.copyOf(predicates, predicates.length); |
242 | |
} |
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
public void setPredicates(Predicate... predicates) { |
251 | |
|
252 | 0 | this.predicates = predicates != null ? Arrays.copyOf(predicates, predicates.length) : null; |
253 | 0 | } |
254 | |
|
255 | |
@Override |
256 | |
public QueryByCriteria build() { |
257 | 0 | return new QueryByCriteria(this); |
258 | |
} |
259 | |
} |
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | 0 | static class Constants { |
265 | |
final static String ROOT_ELEMENT_NAME = "queryByCriteria"; |
266 | |
final static String TYPE_NAME = "QueryByCriteriaType"; |
267 | |
} |
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | 0 | static class Elements { |
274 | |
final static String PREDICATE = "predicate"; |
275 | |
final static String START_AT_INDEX = "startAtIndex"; |
276 | |
final static String MAX_RESULTS = "maxResults"; |
277 | |
final static String COUNT_FLAG = "countFlag"; |
278 | |
} |
279 | |
|
280 | |
} |