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.HashMap; |
29 |
|
import java.util.Iterator; |
30 |
|
import java.util.List; |
31 |
|
import java.util.Map; |
32 |
|
import net.smartlab.web.DataAccessObject.SearchInfo.Filter; |
33 |
|
import net.smartlab.web.config.FactoryConfigurationStrategy; |
34 |
|
import net.smartlab.web.config.JNDIConfigurationStrategy; |
35 |
|
import org.apache.commons.logging.Log; |
36 |
|
import org.apache.commons.logging.LogFactory; |
37 |
|
import org.hibernate.Criteria; |
38 |
|
import org.hibernate.HibernateException; |
39 |
|
import org.hibernate.Query; |
40 |
|
import org.hibernate.Session; |
41 |
|
import org.hibernate.SessionFactory; |
42 |
|
import org.hibernate.Transaction; |
43 |
|
import org.hibernate.criterion.Expression; |
44 |
|
import org.hibernate.criterion.Order; |
45 |
|
import org.hibernate.criterion.Projections; |
46 |
|
import org.hibernate.impl.CriteriaImpl; |
47 |
|
import org.hibernate.transform.ResultTransformer; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
@author |
54 |
|
|
55 |
|
|
56 |
|
|
|
|
| 0% |
Uncovered Elements: 225 (225) |
Complexity: 75 |
Complexity Density: 0,54 |
|
57 |
|
public abstract class BusinessObjectFactory implements DataAccessObject { |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
protected final Log logger = LogFactory.getLog(this.getClass()); |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
private static final ThreadLocal session = new ThreadLocal(); |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
private static final ThreadLocal transaction = new ThreadLocal(); |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
protected SessionFactory factory; |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
private static FactoryConfigurationStrategy strategy = new JNDIConfigurationStrategy(); |
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0,6 |
|
84 |
0
|
static {... |
85 |
0
|
try { |
86 |
0
|
String strategy = System.getProperty("smartweb.factory.strategy"); |
87 |
0
|
if (strategy != null) { |
88 |
0
|
BusinessObjectFactory.strategy = (FactoryConfigurationStrategy)Class.forName(strategy).newInstance(); |
89 |
|
} else { |
90 |
0
|
LogFactory.getLog(BusinessObjectFactory.class).warn( |
91 |
|
"No configuration found: falling back to default configuration"); |
92 |
|
} |
93 |
|
} catch (Exception e) { |
94 |
|
LogFactory.getLog(BusinessObjectFactory.class).fatal("Error configuring SmartWeb", e); |
95 |
|
} |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
@param |
103 |
|
|
104 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
0
|
public static void setConfigurationStrategy(FactoryConfigurationStrategy strategy) {... |
106 |
0
|
BusinessObjectFactory.strategy = strategy; |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
@throws |
113 |
|
|
114 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0,5 |
|
115 |
0
|
public static void close() throws DAOException {... |
116 |
0
|
Map sessionMap = (Map) BusinessObjectFactory.session.get(); |
117 |
0
|
if (sessionMap != null) { |
118 |
0
|
Iterator iter = sessionMap.keySet().iterator(); |
119 |
0
|
while (iter.hasNext()) { |
120 |
0
|
Session session = (Session) sessionMap.get(iter.next()); |
121 |
0
|
if (session != null) { |
122 |
0
|
try { |
123 |
0
|
session.flush(); |
124 |
0
|
session.close(); |
125 |
|
} catch (HibernateException he) { |
126 |
|
throw new DAOException("errors.session.close", he); |
127 |
|
} finally { |
128 |
0
|
BusinessObjectFactory.session.set(null); |
129 |
|
} |
130 |
|
} |
131 |
|
} |
132 |
|
} |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
144 |
0
|
protected BusinessObjectFactory() {... |
145 |
0
|
this.factory = strategy.getSessionFactory(this); |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
@return |
154 |
|
|
155 |
|
@throws |
156 |
|
|
157 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 5 |
Complexity Density: 0,33 |
|
158 |
0
|
protected Session current() throws DAOException {... |
159 |
0
|
if (logger.isDebugEnabled()) { |
160 |
0
|
logger.debug("current() - start"); |
161 |
|
} |
162 |
|
|
163 |
0
|
Session session = null; |
164 |
0
|
Map sessionMap = (Map) BusinessObjectFactory.session.get(); |
165 |
0
|
if (sessionMap == null) { |
166 |
0
|
sessionMap = new HashMap(); |
167 |
|
} |
168 |
0
|
String archive = Domain.getLastArchiveName(this.getClass()); |
169 |
0
|
String configFile = Domain.getResource(this.getClass(), new String[] {"/META-INF/" + archive + ".hcf", |
170 |
|
"/META-INF/smartweb.jar.hcf"}).getFile(); |
171 |
0
|
session = (Session) sessionMap.get(configFile); |
172 |
0
|
if (session == null) { |
173 |
0
|
try { |
174 |
0
|
session = factory.openSession(); |
175 |
0
|
sessionMap.put(configFile, session); |
176 |
0
|
BusinessObjectFactory.session.set(sessionMap); |
177 |
|
} catch (Exception e) { |
178 |
|
throw new DAOException("errors.session.config", e); |
179 |
|
} |
180 |
|
} |
181 |
|
|
182 |
0
|
return session; |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
|
@see |
187 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 5 |
Complexity Density: 0,56 |
|
188 |
0
|
public Object findByKey(Serializable key) throws DAOException {... |
189 |
0
|
if (logger.isDebugEnabled()) { |
190 |
0
|
logger.debug("findByKey(key = " + key + ") - start"); |
191 |
|
} |
192 |
0
|
Serializable convertedKey = this.convertKey(key); |
193 |
0
|
if (convertedKey == null) { |
194 |
0
|
try { |
195 |
0
|
return this.getMappedClass().newInstance(); |
196 |
|
} catch (Exception e) { |
197 |
|
logger.error("findByKey(key = " + key + ") - instantiation failed", e); |
198 |
|
throw new DAOException("errors.session.select", e); |
199 |
|
} |
200 |
|
} else { |
201 |
0
|
Session session = this.current(); |
202 |
0
|
try { |
203 |
0
|
return session.get(this.getMappedClass(), convertedKey); |
204 |
|
} catch (HibernateException he) { |
205 |
|
logger.warn("findByKey(key = " + key + ") - deserialization failed", he); |
206 |
|
throw new UndefinedKeyException(key, this.getMappedClass(), he); |
207 |
|
} |
208 |
|
} |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
@see |
213 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0,75 |
|
214 |
0
|
public void remove(Object object) throws DAOException {... |
215 |
0
|
if (logger.isDebugEnabled()) { |
216 |
0
|
logger.debug("remove(object = " + object + ") - start"); |
217 |
|
} |
218 |
0
|
try { |
219 |
0
|
this.current().delete(object); |
220 |
|
} catch (HibernateException he) { |
221 |
|
logger.warn("remove(object = " + object + ") - failed", he); |
222 |
|
throw new DAOException("errors.session.remove", he); |
223 |
|
} |
224 |
|
} |
225 |
|
|
226 |
|
|
227 |
|
@see |
228 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0,75 |
|
229 |
0
|
public void update(Object object) throws DAOException {... |
230 |
0
|
if (logger.isDebugEnabled()) { |
231 |
0
|
logger.debug("update(object = " + object + ") - start"); |
232 |
|
} |
233 |
0
|
try { |
234 |
0
|
this.current().saveOrUpdate(object); |
235 |
|
} catch (HibernateException he) { |
236 |
|
logger.warn("update(object = " + object + ") - failed", he); |
237 |
|
this.current().clear(); |
238 |
|
throw new DAOException("errors.session.update", he); |
239 |
|
} |
240 |
|
} |
241 |
|
|
242 |
|
|
243 |
|
@see |
244 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0,6 |
|
245 |
0
|
public Collection list(SearchInfo info) throws DAOException {... |
246 |
0
|
if (logger.isDebugEnabled()) { |
247 |
0
|
logger.debug("list(info = " + info + ") - start"); |
248 |
|
} |
249 |
0
|
Criteria criteria = this.createCriteria(info); |
250 |
0
|
try { |
251 |
0
|
return criteria.list(); |
252 |
|
} catch (HibernateException he) { |
253 |
|
logger.warn("list(info = " + info + ") - failed", he); |
254 |
|
throw new DAOException("errors.session.search", he); |
255 |
|
} |
256 |
|
} |
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
@param |
262 |
|
@return |
263 |
|
@throws |
264 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0,6 |
|
265 |
0
|
public Collection page(SearchInfo info) throws DAOException {... |
266 |
0
|
if (logger.isDebugEnabled()) { |
267 |
0
|
logger.debug("page(info = " + info + ") - start"); |
268 |
|
} |
269 |
0
|
Criteria criteria = this.createCriteria(info); |
270 |
0
|
try { |
271 |
0
|
return new Paginator(criteria); |
272 |
|
} catch (HibernateException he) { |
273 |
|
logger.warn("page(info = " + info + ") - error", he); |
274 |
|
throw new DAOException("errors.session.paging", he); |
275 |
|
} |
276 |
|
} |
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
@return |
282 |
|
|
283 |
|
public abstract Class getMappedClass(); |
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
@param |
289 |
|
@return |
290 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 6 |
Complexity Density: 0,6 |
|
291 |
0
|
public Serializable convertKey(Serializable key) {... |
292 |
0
|
if (key != null) { |
293 |
0
|
if (key instanceof String) { |
294 |
0
|
if (key.equals("0")) { |
295 |
0
|
return null; |
296 |
|
} else { |
297 |
0
|
return new Long((String)key); |
298 |
|
} |
299 |
0
|
} else if (key instanceof Number) { |
300 |
0
|
if (((Number)key).longValue() == 0) { |
301 |
0
|
return null; |
302 |
|
} else { |
303 |
0
|
return new Long(((Number)key).toString()); |
304 |
|
} |
305 |
|
} |
306 |
|
} |
307 |
0
|
return key; |
308 |
|
} |
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
@param |
314 |
|
@return |
315 |
|
@throws |
316 |
|
|
|
|
| 0% |
Uncovered Elements: 79 (79) |
Complexity: 25 |
Complexity Density: 0,49 |
|
317 |
0
|
public Criteria createCriteria(SearchInfo info) throws DAOException {... |
318 |
0
|
if (logger.isDebugEnabled()) { |
319 |
0
|
logger.debug("createCriteria(info = " + info + ") - start"); |
320 |
|
} |
321 |
0
|
Session session = this.current(); |
322 |
0
|
Criteria criteria = session.createCriteria(this.getMappedClass()); |
323 |
0
|
if (info.isUnion()) { |
324 |
|
|
325 |
|
} |
326 |
0
|
Iterator filters = info.getFilters().iterator(); |
327 |
0
|
while (filters.hasNext()) { |
328 |
0
|
if (logger.isTraceEnabled()) { |
329 |
0
|
logger.trace("createCriteria(info = " + info + ") - parsing filter `" + filters + "`"); |
330 |
|
} |
331 |
0
|
Filter filter = (Filter)filters.next(); |
332 |
0
|
switch (filter.getCondition()) { |
333 |
0
|
case SearchInfo.EQUALS: |
334 |
0
|
for (int i = 0; i < filter.getValues().length; i++) { |
335 |
0
|
criteria.add(Expression.eq(filter.getColumn(), filter.getValue(i))); |
336 |
|
} |
337 |
0
|
break; |
338 |
0
|
case SearchInfo.GREATER: |
339 |
0
|
for (int i = 0; i < filter.getValues().length; i++) { |
340 |
0
|
criteria.add(Expression.gt(filter.getColumn(), filter.getValue(i))); |
341 |
|
} |
342 |
0
|
break; |
343 |
0
|
case SearchInfo.GREATER_EQUALS: |
344 |
0
|
for (int i = 0; i < filter.getValues().length; i++) { |
345 |
0
|
criteria.add(Expression.ge(filter.getColumn(), filter.getValue(i))); |
346 |
|
} |
347 |
0
|
break; |
348 |
0
|
case SearchInfo.LESSER: |
349 |
0
|
for (int i = 0; i < filter.getValues().length; i++) { |
350 |
0
|
criteria.add(Expression.le(filter.getColumn(), filter.getValue(i))); |
351 |
|
} |
352 |
0
|
break; |
353 |
0
|
case SearchInfo.LESSER_EQUALS: |
354 |
0
|
for (int i = 0; i < filter.getValues().length; i++) { |
355 |
0
|
criteria.add(Expression.ge(filter.getColumn(), filter.getValue(i))); |
356 |
|
} |
357 |
0
|
break; |
358 |
0
|
case SearchInfo.NOT_EQUALS: |
359 |
0
|
for (int i = 0; i < filter.getValues().length; i++) { |
360 |
0
|
criteria.add(Expression.not(Expression.eq(filter.getColumn(), filter.getValue(i)))); |
361 |
|
} |
362 |
0
|
break; |
363 |
0
|
case SearchInfo.BETWEEN: |
364 |
0
|
criteria.add(Expression.between(filter.getColumn(), filter.getValue(0), filter.getValue(1))); |
365 |
0
|
break; |
366 |
0
|
case SearchInfo.LIKE: |
367 |
0
|
for (int i = 0; i < filter.getValues().length; i++) { |
368 |
0
|
criteria.add(Expression.like(filter.getColumn(), filter.getValue(i))); |
369 |
|
} |
370 |
0
|
break; |
371 |
0
|
case SearchInfo.ILIKE: |
372 |
0
|
for (int i = 0; i < filter.getValues().length; i++) { |
373 |
0
|
criteria.add(Expression.ilike(filter.getColumn(), filter.getValue(i))); |
374 |
|
} |
375 |
0
|
break; |
376 |
|
} |
377 |
|
} |
378 |
0
|
if (info.getOrder() != null && info.getOrder().length() > 0) { |
379 |
0
|
if (info.isDescendant()) { |
380 |
0
|
criteria.addOrder(Order.desc(info.getOrder())); |
381 |
|
} else { |
382 |
0
|
criteria.addOrder(Order.asc(info.getOrder())); |
383 |
|
} |
384 |
|
} |
385 |
0
|
return criteria; |
386 |
|
} |
387 |
|
|
388 |
|
|
389 |
|
|
390 |
|
|
391 |
|
@throws |
392 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0,67 |
|
393 |
0
|
public void begin() throws DAOException {... |
394 |
0
|
if (logger.isDebugEnabled()) { |
395 |
0
|
logger.debug("begin() - start"); |
396 |
|
} |
397 |
0
|
if (BusinessObjectFactory.transaction.get() == null) { |
398 |
0
|
try { |
399 |
0
|
BusinessObjectFactory.transaction.set(this.current().beginTransaction()); |
400 |
|
} catch (HibernateException he) { |
401 |
|
logger.error("begin() - error", he); |
402 |
|
throw new DAOException("errors.session.begin", he); |
403 |
|
} |
404 |
|
} else { |
405 |
0
|
logger.warn("begin() - transaction already started"); |
406 |
|
} |
407 |
|
} |
408 |
|
|
409 |
|
|
410 |
|
|
411 |
|
|
412 |
|
@throws |
413 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 4 |
Complexity Density: 0,67 |
|
414 |
0
|
public void commit() throws DAOException {... |
415 |
0
|
if (logger.isDebugEnabled()) { |
416 |
0
|
logger.debug("commit() - start"); |
417 |
|
} |
418 |
0
|
Transaction transaction = (Transaction)BusinessObjectFactory.transaction.get(); |
419 |
0
|
try { |
420 |
0
|
transaction.commit(); |
421 |
|
} catch (HibernateException he) { |
422 |
|
logger.error("commit() - error", he); |
423 |
|
throw new DAOException("errors.session.commit", he); |
424 |
|
} catch (NullPointerException npe) { |
425 |
|
logger.warn("commit() - transaction never started"); |
426 |
|
throw new DAOException("errors.session.commit"); |
427 |
|
} finally { |
428 |
0
|
BusinessObjectFactory.transaction.set(null); |
429 |
|
} |
430 |
|
} |
431 |
|
|
432 |
|
|
433 |
|
|
434 |
|
|
435 |
|
@throws |
436 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 4 |
Complexity Density: 0,67 |
|
437 |
0
|
public void rollback() throws DAOException {... |
438 |
0
|
if (logger.isDebugEnabled()) { |
439 |
0
|
logger.debug("rollback() - start"); |
440 |
|
} |
441 |
0
|
Transaction transaction = (Transaction)BusinessObjectFactory.transaction.get(); |
442 |
0
|
try { |
443 |
0
|
transaction.rollback(); |
444 |
|
} catch (HibernateException he) { |
445 |
|
logger.error("rollback() - error", he); |
446 |
|
throw new DAOException("errors.session.rollback", he); |
447 |
|
} catch (NullPointerException npe) { |
448 |
|
logger.warn("rollback() - transaction never started", npe); |
449 |
|
} finally { |
450 |
0
|
BusinessObjectFactory.transaction.set(null); |
451 |
|
} |
452 |
|
} |
453 |
|
|
454 |
|
|
455 |
|
|
456 |
|
|
457 |
|
|
|
|
| 0% |
Uncovered Elements: 115 (115) |
Complexity: 36 |
Complexity Density: 0,54 |
|
458 |
|
public class Paginator extends net.smartlab.web.page.Paginator implements Collection { |
459 |
|
|
460 |
|
|
461 |
|
|
462 |
|
|
463 |
|
private final Log logger = LogFactory.getLog(Paginator.class); |
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
|
468 |
|
|
469 |
|
private Object statement; |
470 |
|
|
471 |
|
|
472 |
|
|
473 |
|
|
474 |
|
|
475 |
|
|
476 |
|
@param |
477 |
|
|
478 |
|
@throws |
479 |
|
|
480 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
481 |
0
|
public Paginator(Criteria criteria) throws HibernateException {... |
482 |
0
|
this(criteria, Paginator.UNLIMITED_ITEMS, Paginator.UNLIMITED_PAGES); |
483 |
|
} |
484 |
|
|
485 |
|
|
486 |
|
|
487 |
|
|
488 |
|
|
489 |
|
|
490 |
|
@param |
491 |
|
|
492 |
|
@param |
493 |
|
@param |
494 |
|
|
495 |
|
@throws |
496 |
|
|
497 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 4 |
Complexity Density: 0,21 |
|
498 |
0
|
public Paginator(Criteria criteria, int size, int pages) throws HibernateException {... |
499 |
0
|
super(size, pages); |
500 |
0
|
this.statement = criteria; |
501 |
0
|
ResultTransformer rt = ((CriteriaImpl)criteria).getResultTransformer(); |
502 |
0
|
List temp = new ArrayList(); |
503 |
0
|
Iterator orderings = ((CriteriaImpl)criteria).iterateOrderings(); |
504 |
0
|
while (orderings.hasNext()) { |
505 |
0
|
Order ordering = ((CriteriaImpl.OrderEntry)orderings.next()).getOrder(); |
506 |
0
|
orderings.remove(); |
507 |
0
|
temp.add(ordering); |
508 |
|
} |
509 |
0
|
criteria.setProjection(Projections.rowCount()); |
510 |
0
|
this.setCount(((Integer)criteria.uniqueResult()).intValue()); |
511 |
0
|
criteria.setProjection(null); |
512 |
0
|
if (rt == null) { |
513 |
0
|
rt = Criteria.ROOT_ENTITY; |
514 |
|
} |
515 |
0
|
criteria.setResultTransformer(rt); |
516 |
0
|
orderings = temp.iterator(); |
517 |
0
|
while (orderings.hasNext()) { |
518 |
0
|
criteria.addOrder((Order)orderings.next()); |
519 |
|
} |
520 |
0
|
this.setSize(size); |
521 |
|
} |
522 |
|
|
523 |
|
|
524 |
|
|
525 |
|
|
526 |
|
|
527 |
|
@param |
528 |
|
@throws |
529 |
|
|
530 |
|
@throws |
531 |
|
|
532 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
533 |
0
|
public Paginator(Query query) throws DAOException, HibernateException {... |
534 |
0
|
this(query, Paginator.UNLIMITED_ITEMS, Paginator.UNLIMITED_PAGES); |
535 |
|
} |
536 |
|
|
537 |
|
|
538 |
|
|
539 |
|
|
540 |
|
|
541 |
|
|
542 |
|
|
543 |
|
@param |
544 |
|
@param |
545 |
|
@param |
546 |
|
|
547 |
|
@throws |
548 |
|
|
549 |
|
@throws |
550 |
|
|
551 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
552 |
0
|
public Paginator(Query query, int size, int pages) throws DAOException, HibernateException {... |
553 |
0
|
super(size, pages); |
554 |
0
|
this.statement = query; |
555 |
0
|
int queryCount = query.count(); |
556 |
0
|
this.setCount(queryCount); |
557 |
0
|
this.setSize(size); |
558 |
|
} |
559 |
|
|
560 |
|
|
561 |
|
@see |
562 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0,5 |
|
563 |
0
|
public void setPage(int page) {... |
564 |
0
|
if (logger.isDebugEnabled()) { |
565 |
0
|
logger.debug("setPage(page = " + page + ") - start"); |
566 |
|
} |
567 |
0
|
if (statement instanceof Criteria) { |
568 |
0
|
((Criteria)this.statement).setFirstResult((page - 1) * super.getPageSize()); |
569 |
|
} else { |
570 |
0
|
((Query)this.statement).setFirstResult((page - 1) * super.getPageSize()); |
571 |
|
} |
572 |
0
|
super.setPage(page); |
573 |
|
} |
574 |
|
|
575 |
|
|
576 |
|
|
577 |
|
|
578 |
|
@param |
579 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0,5 |
|
580 |
0
|
public void setSize(int size) {... |
581 |
0
|
if (logger.isDebugEnabled()) { |
582 |
0
|
logger.debug("setSize(size = " + size + ") - start"); |
583 |
|
} |
584 |
0
|
if (size != UNLIMITED_ITEMS) { |
585 |
0
|
super.setPageSize(size); |
586 |
0
|
if (statement instanceof Criteria) { |
587 |
0
|
((Criteria)this.statement).setMaxResults(size); |
588 |
|
} else { |
589 |
0
|
((Query)this.statement).setMaxResults(size); |
590 |
|
} |
591 |
|
} else { |
592 |
0
|
super.setPageSize(this.getCount()); |
593 |
|
} |
594 |
|
} |
595 |
|
|
596 |
|
|
597 |
|
@see |
598 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 6 |
Complexity Density: 0,67 |
|
599 |
0
|
protected void setArray() {... |
600 |
0
|
if (logger.isDebugEnabled()) { |
601 |
0
|
logger.debug("setArray() - start"); |
602 |
|
} |
603 |
0
|
try { |
604 |
0
|
Iterator elements = null; |
605 |
0
|
if (statement instanceof Criteria) { |
606 |
0
|
elements = ((Criteria)this.statement).list().iterator(); |
607 |
|
} else { |
608 |
0
|
elements = ((Query)this.statement).list().iterator(); |
609 |
|
} |
610 |
0
|
for (int i = 0; i < array.length && elements.hasNext(); i++) { |
611 |
0
|
array[i] = elements.next(); |
612 |
|
} |
613 |
|
} catch (HibernateException he) { |
614 |
|
logger.error("setArray() - error", he); |
615 |
|
} |
616 |
|
} |
617 |
|
|
618 |
|
|
619 |
|
@see |
620 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
621 |
0
|
public boolean add(Object obj) {... |
622 |
0
|
throw new UnsupportedOperationException(); |
623 |
|
} |
624 |
|
|
625 |
|
|
626 |
|
@see |
627 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
628 |
0
|
public boolean addAll(Collection collection) {... |
629 |
0
|
throw new UnsupportedOperationException(); |
630 |
|
} |
631 |
|
|
632 |
|
|
633 |
|
@see |
634 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
635 |
0
|
public void clear() {... |
636 |
0
|
throw new UnsupportedOperationException(); |
637 |
|
} |
638 |
|
|
639 |
|
|
640 |
|
@see |
641 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0,67 |
|
642 |
0
|
public boolean contains(Object item) {... |
643 |
0
|
if (logger.isDebugEnabled()) { |
644 |
0
|
logger.debug("contains(item = " + item + ") - start"); |
645 |
|
} |
646 |
0
|
for (int i = 0; i < array.length; i++) { |
647 |
0
|
if (array[i].equals(item)) { |
648 |
0
|
return true; |
649 |
|
} |
650 |
|
} |
651 |
0
|
return false; |
652 |
|
} |
653 |
|
|
654 |
|
|
655 |
|
@see |
656 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
657 |
0
|
public boolean containsAll(Collection item) {... |
658 |
0
|
throw new UnsupportedOperationException(); |
659 |
|
} |
660 |
|
|
661 |
|
|
662 |
|
@see |
663 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
664 |
0
|
public boolean isEmpty() {... |
665 |
0
|
return super.getCount() == 0; |
666 |
|
} |
667 |
|
|
668 |
|
|
669 |
|
@see |
670 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
671 |
0
|
public Iterator iterator() {... |
672 |
0
|
return this; |
673 |
|
} |
674 |
|
|
675 |
|
|
676 |
|
@see |
677 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
678 |
0
|
public boolean remove(Object obj) {... |
679 |
0
|
throw new UnsupportedOperationException(); |
680 |
|
} |
681 |
|
|
682 |
|
|
683 |
|
@see |
684 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
685 |
0
|
public boolean removeAll(Collection collection) {... |
686 |
0
|
throw new UnsupportedOperationException(); |
687 |
|
} |
688 |
|
|
689 |
|
|
690 |
|
@see |
691 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
692 |
0
|
public boolean retainAll(Collection collection) {... |
693 |
0
|
throw new UnsupportedOperationException(); |
694 |
|
} |
695 |
|
|
696 |
|
|
697 |
|
@see |
698 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
699 |
0
|
public int size() {... |
700 |
0
|
return super.getCount(); |
701 |
|
} |
702 |
|
|
703 |
|
|
704 |
|
@see |
705 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
706 |
0
|
public Object[] toArray() {... |
707 |
0
|
return array; |
708 |
|
} |
709 |
|
|
710 |
|
|
711 |
|
@see |
712 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
713 |
0
|
public Object[] toArray(Object[] array) {... |
714 |
0
|
return this.array; |
715 |
|
} |
716 |
|
} |
717 |
|
} |