1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
package net.smartlab.web; |
24 |
|
|
25 |
|
import java.io.Serializable; |
26 |
|
import java.util.ArrayList; |
27 |
|
import java.util.Collection; |
28 |
|
import java.util.List; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
@author |
35 |
|
|
36 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
37 |
|
public interface DataAccessObject { |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
@param |
44 |
|
|
45 |
|
@return |
46 |
|
|
47 |
|
@throws |
48 |
|
|
49 |
|
@throws |
50 |
|
|
51 |
|
|
52 |
|
public Object findByKey(Serializable key) throws DAOException; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
@param |
58 |
|
|
59 |
|
@throws |
60 |
|
|
61 |
|
|
62 |
|
public void remove(Object object) throws DAOException; |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
@param |
71 |
|
@throws |
72 |
|
|
73 |
|
|
74 |
|
public void update(Object object) throws DAOException; |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
@param |
81 |
|
@return |
82 |
|
@throws |
83 |
|
|
84 |
|
|
85 |
|
public Collection list(SearchInfo info) throws DAOException; |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
@author |
93 |
|
|
|
|
| 0% |
Uncovered Elements: 76 (76) |
Complexity: 28 |
Complexity Density: 0,61 |
|
94 |
|
public static class SearchInfo { |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
private Collection filters = new ArrayList(); |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
private String order = null; |
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
private boolean descendant = false; |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
private boolean union = false; |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
public final static int EQUALS = 0; |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
public final static int GREATER = 1; |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
public final static int GREATER_EQUALS = 2; |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
public final static int LESSER = 3; |
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
public final static int LESSER_EQUALS = 4; |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
public final static int NOT_EQUALS = 5; |
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
public final static int LIKE = 6; |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
public final static int ILIKE = 7; |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
public final static int BETWEEN = 8; |
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
@return |
172 |
|
|
173 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
174 |
0
|
public boolean isDescendant() {... |
175 |
0
|
return descendant; |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
|
@return |
180 |
|
|
181 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
182 |
0
|
public Collection getFilters() {... |
183 |
0
|
return filters; |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
@param |
188 |
|
|
189 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
190 |
0
|
public void setFilters(Collection filters) {... |
191 |
0
|
this.filters = filters; |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
|
@param |
196 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 1 |
|
197 |
0
|
public void setFilters(String[] filters) {... |
198 |
0
|
if (filters != null) { |
199 |
0
|
for (int i = 0; i < filters.length; i++) { |
200 |
0
|
this.addFilter(filters[i]); |
201 |
|
} |
202 |
|
} |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
@param |
209 |
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 11 |
Complexity Density: 0,41 |
|
210 |
0
|
public void addFilter(String filter) {... |
211 |
0
|
for (int i = 0; i < filter.length(); i++) { |
212 |
0
|
switch (filter.charAt(i)) { |
213 |
|
|
214 |
0
|
case '=': |
215 |
0
|
filters.add(new Filter(filter.substring(0, i), EQUALS, filter.substring(i + 1))); |
216 |
0
|
return; |
217 |
|
|
218 |
0
|
case '>': |
219 |
|
|
220 |
0
|
if (filter.charAt(i + 1) == '=') { |
221 |
0
|
filters |
222 |
|
.add(new Filter(filter.substring(0, i + 1), GREATER_EQUALS, filter.substring(i + 2))); |
223 |
|
} else { |
224 |
0
|
filters.add(new Filter(filter.substring(0, i), GREATER, filter.substring(i + 1))); |
225 |
|
} |
226 |
0
|
return; |
227 |
|
|
228 |
0
|
case '<': |
229 |
|
|
230 |
0
|
if (filter.charAt(i + 1) == '=') { |
231 |
0
|
filters.add(new Filter(filter.substring(0, i + 1), LESSER_EQUALS, filter.substring(i + 2))); |
232 |
|
} else { |
233 |
0
|
filters.add(new Filter(filter.substring(0, i), LESSER, filter.substring(i + 1))); |
234 |
|
} |
235 |
0
|
return; |
236 |
|
|
237 |
0
|
case '!': |
238 |
0
|
filters.add(new Filter(filter.substring(0, i), NOT_EQUALS, filter.substring(i + 1))); |
239 |
0
|
return; |
240 |
|
|
241 |
0
|
case '|': |
242 |
0
|
filters.add(new Filter(filter.substring(0, i), BETWEEN, filter.substring(i + 1))); |
243 |
0
|
return; |
244 |
|
|
245 |
0
|
case '%': |
246 |
0
|
if (filter.charAt(i + 1) == '%') { |
247 |
|
|
248 |
0
|
filters.add(new Filter(filter.substring(0, i), ILIKE, filter.substring(i + 1))); |
249 |
0
|
return; |
250 |
|
} else { |
251 |
|
|
252 |
0
|
filters.add(new Filter(filter.substring(0, i), ILIKE, filter.substring(i + 1))); |
253 |
0
|
return; |
254 |
|
} |
255 |
|
} |
256 |
|
} |
257 |
|
} |
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
@param |
263 |
|
@param |
264 |
|
@param |
265 |
|
|
266 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
267 |
0
|
public void addFilter(String column, int expression, String values) {... |
268 |
0
|
filters.add(new Filter(column, expression, values)); |
269 |
|
} |
270 |
|
|
271 |
|
|
272 |
|
@return |
273 |
|
|
274 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
275 |
0
|
public String getOrder() {... |
276 |
0
|
return order; |
277 |
|
} |
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
@param |
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0,67 |
|
290 |
0
|
public void setOrder(String order) {... |
291 |
0
|
if (order != null && order.length() > 0) { |
292 |
0
|
if (order.charAt(0) == '!') { |
293 |
0
|
this.descendant = true; |
294 |
0
|
this.order = order.substring(1); |
295 |
|
} else { |
296 |
0
|
this.order = order; |
297 |
|
} |
298 |
|
} else { |
299 |
0
|
order = null; |
300 |
|
} |
301 |
|
} |
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
@param |
307 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
308 |
0
|
public void setUnion(String style) {... |
309 |
0
|
if (style != null && style.length() > 0) { |
310 |
0
|
if (style.equalsIgnoreCase("OR")) { |
311 |
0
|
this.union = true; |
312 |
|
} else { |
313 |
0
|
this.union = false; |
314 |
|
} |
315 |
|
} |
316 |
|
} |
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
@return |
322 |
|
|
323 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
324 |
0
|
public boolean isUnion() {... |
325 |
0
|
return union; |
326 |
|
} |
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
@author |
334 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 6 |
Complexity Density: 0,55 |
|
335 |
|
protected class Filter { |
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
private String column; |
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
private int condition; |
350 |
|
|
351 |
|
|
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
private String[] values; |
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
@param |
364 |
|
@param |
365 |
|
@param |
366 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0,29 |
|
367 |
0
|
private Filter(String column, int condition, String values) {... |
368 |
0
|
this.column = column; |
369 |
0
|
this.condition = condition; |
370 |
0
|
List list = new ArrayList(); |
371 |
0
|
for (int start = 0, end = values.indexOf(','); end > -1; start = end + 1, end = values.indexOf(start, |
372 |
|
',')) { |
373 |
0
|
list.add(values.substring(start, end)); |
374 |
|
} |
375 |
0
|
list.add(values.substring(values.lastIndexOf(',') + 1)); |
376 |
0
|
this.values = (String[])list.toArray(new String[0]); |
377 |
|
} |
378 |
|
|
379 |
|
|
380 |
|
|
381 |
|
|
382 |
|
@return |
383 |
|
|
384 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
385 |
0
|
protected String getColumn() {... |
386 |
0
|
return column; |
387 |
|
} |
388 |
|
|
389 |
|
|
390 |
|
|
391 |
|
|
392 |
|
@return |
393 |
|
|
394 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
395 |
0
|
protected int getCondition() {... |
396 |
0
|
return condition; |
397 |
|
} |
398 |
|
|
399 |
|
|
400 |
|
|
401 |
|
|
402 |
|
@return |
403 |
|
|
404 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
405 |
0
|
protected String[] getValues() {... |
406 |
0
|
return values; |
407 |
|
} |
408 |
|
|
409 |
|
|
410 |
|
|
411 |
|
|
412 |
|
|
413 |
|
@param |
414 |
|
@return |
415 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
416 |
0
|
protected String getValue(int index) {... |
417 |
0
|
return values[index]; |
418 |
|
} |
419 |
|
} |
420 |
|
} |
421 |
|
} |