1
14
15 package com.liferay.portlet.polls.service.persistence;
16
17 import com.liferay.portal.NoSuchModelException;
18 import com.liferay.portal.SystemException;
19 import com.liferay.portal.kernel.annotation.BeanReference;
20 import com.liferay.portal.kernel.cache.CacheRegistry;
21 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
22 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
23 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
24 import com.liferay.portal.kernel.dao.orm.FinderPath;
25 import com.liferay.portal.kernel.dao.orm.Query;
26 import com.liferay.portal.kernel.dao.orm.QueryPos;
27 import com.liferay.portal.kernel.dao.orm.QueryUtil;
28 import com.liferay.portal.kernel.dao.orm.Session;
29 import com.liferay.portal.kernel.log.Log;
30 import com.liferay.portal.kernel.log.LogFactoryUtil;
31 import com.liferay.portal.kernel.util.GetterUtil;
32 import com.liferay.portal.kernel.util.OrderByComparator;
33 import com.liferay.portal.kernel.util.StringBundler;
34 import com.liferay.portal.kernel.util.StringPool;
35 import com.liferay.portal.kernel.util.StringUtil;
36 import com.liferay.portal.kernel.util.Validator;
37 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
38 import com.liferay.portal.model.ModelListener;
39 import com.liferay.portal.service.persistence.BatchSessionUtil;
40 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41
42 import com.liferay.portlet.polls.NoSuchChoiceException;
43 import com.liferay.portlet.polls.model.PollsChoice;
44 import com.liferay.portlet.polls.model.impl.PollsChoiceImpl;
45 import com.liferay.portlet.polls.model.impl.PollsChoiceModelImpl;
46
47 import java.io.Serializable;
48
49 import java.util.ArrayList;
50 import java.util.Collections;
51 import java.util.List;
52
53
66 public class PollsChoicePersistenceImpl extends BasePersistenceImpl<PollsChoice>
67 implements PollsChoicePersistence {
68 public static final String FINDER_CLASS_NAME_ENTITY = PollsChoiceImpl.class.getName();
69 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
70 ".List";
71 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
72 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
73 "findByUuid", new String[] { String.class.getName() });
74 public static final FinderPath FINDER_PATH_FIND_BY_OBC_UUID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
75 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
76 "findByUuid",
77 new String[] {
78 String.class.getName(),
79
80 "java.lang.Integer", "java.lang.Integer",
81 "com.liferay.portal.kernel.util.OrderByComparator"
82 });
83 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
84 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
85 "countByUuid", new String[] { String.class.getName() });
86 public static final FinderPath FINDER_PATH_FIND_BY_QUESTIONID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
87 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
88 "findByQuestionId", new String[] { Long.class.getName() });
89 public static final FinderPath FINDER_PATH_FIND_BY_OBC_QUESTIONID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
90 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
91 "findByQuestionId",
92 new String[] {
93 Long.class.getName(),
94
95 "java.lang.Integer", "java.lang.Integer",
96 "com.liferay.portal.kernel.util.OrderByComparator"
97 });
98 public static final FinderPath FINDER_PATH_COUNT_BY_QUESTIONID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
99 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
100 "countByQuestionId", new String[] { Long.class.getName() });
101 public static final FinderPath FINDER_PATH_FETCH_BY_Q_N = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
102 PollsChoiceModelImpl.FINDER_CACHE_ENABLED,
103 FINDER_CLASS_NAME_ENTITY, "fetchByQ_N",
104 new String[] { Long.class.getName(), String.class.getName() });
105 public static final FinderPath FINDER_PATH_COUNT_BY_Q_N = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
106 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
107 "countByQ_N",
108 new String[] { Long.class.getName(), String.class.getName() });
109 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
110 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
111 "findAll", new String[0]);
112 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
113 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
114 "countAll", new String[0]);
115
116 public void cacheResult(PollsChoice pollsChoice) {
117 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
118 PollsChoiceImpl.class, pollsChoice.getPrimaryKey(), pollsChoice);
119
120 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
121 new Object[] {
122 new Long(pollsChoice.getQuestionId()),
123
124 pollsChoice.getName()
125 }, pollsChoice);
126 }
127
128 public void cacheResult(List<PollsChoice> pollsChoices) {
129 for (PollsChoice pollsChoice : pollsChoices) {
130 if (EntityCacheUtil.getResult(
131 PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
132 PollsChoiceImpl.class, pollsChoice.getPrimaryKey(), this) == null) {
133 cacheResult(pollsChoice);
134 }
135 }
136 }
137
138 public void clearCache() {
139 CacheRegistry.clear(PollsChoiceImpl.class.getName());
140 EntityCacheUtil.clearCache(PollsChoiceImpl.class.getName());
141 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
142 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
143 }
144
145 public PollsChoice create(long choiceId) {
146 PollsChoice pollsChoice = new PollsChoiceImpl();
147
148 pollsChoice.setNew(true);
149 pollsChoice.setPrimaryKey(choiceId);
150
151 String uuid = PortalUUIDUtil.generate();
152
153 pollsChoice.setUuid(uuid);
154
155 return pollsChoice;
156 }
157
158 public PollsChoice remove(Serializable primaryKey)
159 throws NoSuchModelException, SystemException {
160 return remove(((Long)primaryKey).longValue());
161 }
162
163 public PollsChoice remove(long choiceId)
164 throws NoSuchChoiceException, SystemException {
165 Session session = null;
166
167 try {
168 session = openSession();
169
170 PollsChoice pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
171 new Long(choiceId));
172
173 if (pollsChoice == null) {
174 if (_log.isWarnEnabled()) {
175 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + choiceId);
176 }
177
178 throw new NoSuchChoiceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
179 choiceId);
180 }
181
182 return remove(pollsChoice);
183 }
184 catch (NoSuchChoiceException nsee) {
185 throw nsee;
186 }
187 catch (Exception e) {
188 throw processException(e);
189 }
190 finally {
191 closeSession(session);
192 }
193 }
194
195 public PollsChoice remove(PollsChoice pollsChoice)
196 throws SystemException {
197 for (ModelListener<PollsChoice> listener : listeners) {
198 listener.onBeforeRemove(pollsChoice);
199 }
200
201 pollsChoice = removeImpl(pollsChoice);
202
203 for (ModelListener<PollsChoice> listener : listeners) {
204 listener.onAfterRemove(pollsChoice);
205 }
206
207 return pollsChoice;
208 }
209
210 protected PollsChoice removeImpl(PollsChoice pollsChoice)
211 throws SystemException {
212 pollsChoice = toUnwrappedModel(pollsChoice);
213
214 Session session = null;
215
216 try {
217 session = openSession();
218
219 if (pollsChoice.isCachedModel() || BatchSessionUtil.isEnabled()) {
220 Object staleObject = session.get(PollsChoiceImpl.class,
221 pollsChoice.getPrimaryKeyObj());
222
223 if (staleObject != null) {
224 session.evict(staleObject);
225 }
226 }
227
228 session.delete(pollsChoice);
229
230 session.flush();
231 }
232 catch (Exception e) {
233 throw processException(e);
234 }
235 finally {
236 closeSession(session);
237 }
238
239 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
240
241 PollsChoiceModelImpl pollsChoiceModelImpl = (PollsChoiceModelImpl)pollsChoice;
242
243 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N,
244 new Object[] {
245 new Long(pollsChoiceModelImpl.getOriginalQuestionId()),
246
247 pollsChoiceModelImpl.getOriginalName()
248 });
249
250 EntityCacheUtil.removeResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
251 PollsChoiceImpl.class, pollsChoice.getPrimaryKey());
252
253 return pollsChoice;
254 }
255
256
259 public PollsChoice update(PollsChoice pollsChoice)
260 throws SystemException {
261 if (_log.isWarnEnabled()) {
262 _log.warn(
263 "Using the deprecated update(PollsChoice pollsChoice) method. Use update(PollsChoice pollsChoice, boolean merge) instead.");
264 }
265
266 return update(pollsChoice, false);
267 }
268
269 public PollsChoice updateImpl(
270 com.liferay.portlet.polls.model.PollsChoice pollsChoice, boolean merge)
271 throws SystemException {
272 pollsChoice = toUnwrappedModel(pollsChoice);
273
274 boolean isNew = pollsChoice.isNew();
275
276 PollsChoiceModelImpl pollsChoiceModelImpl = (PollsChoiceModelImpl)pollsChoice;
277
278 if (Validator.isNull(pollsChoice.getUuid())) {
279 String uuid = PortalUUIDUtil.generate();
280
281 pollsChoice.setUuid(uuid);
282 }
283
284 Session session = null;
285
286 try {
287 session = openSession();
288
289 BatchSessionUtil.update(session, pollsChoice, merge);
290
291 pollsChoice.setNew(false);
292 }
293 catch (Exception e) {
294 throw processException(e);
295 }
296 finally {
297 closeSession(session);
298 }
299
300 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
301
302 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
303 PollsChoiceImpl.class, pollsChoice.getPrimaryKey(), pollsChoice);
304
305 if (!isNew &&
306 ((pollsChoice.getQuestionId() != pollsChoiceModelImpl.getOriginalQuestionId()) ||
307 !Validator.equals(pollsChoice.getName(),
308 pollsChoiceModelImpl.getOriginalName()))) {
309 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N,
310 new Object[] {
311 new Long(pollsChoiceModelImpl.getOriginalQuestionId()),
312
313 pollsChoiceModelImpl.getOriginalName()
314 });
315 }
316
317 if (isNew ||
318 ((pollsChoice.getQuestionId() != pollsChoiceModelImpl.getOriginalQuestionId()) ||
319 !Validator.equals(pollsChoice.getName(),
320 pollsChoiceModelImpl.getOriginalName()))) {
321 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
322 new Object[] {
323 new Long(pollsChoice.getQuestionId()),
324
325 pollsChoice.getName()
326 }, pollsChoice);
327 }
328
329 return pollsChoice;
330 }
331
332 protected PollsChoice toUnwrappedModel(PollsChoice pollsChoice) {
333 if (pollsChoice instanceof PollsChoiceImpl) {
334 return pollsChoice;
335 }
336
337 PollsChoiceImpl pollsChoiceImpl = new PollsChoiceImpl();
338
339 pollsChoiceImpl.setNew(pollsChoice.isNew());
340 pollsChoiceImpl.setPrimaryKey(pollsChoice.getPrimaryKey());
341
342 pollsChoiceImpl.setUuid(pollsChoice.getUuid());
343 pollsChoiceImpl.setChoiceId(pollsChoice.getChoiceId());
344 pollsChoiceImpl.setQuestionId(pollsChoice.getQuestionId());
345 pollsChoiceImpl.setName(pollsChoice.getName());
346 pollsChoiceImpl.setDescription(pollsChoice.getDescription());
347
348 return pollsChoiceImpl;
349 }
350
351 public PollsChoice findByPrimaryKey(Serializable primaryKey)
352 throws NoSuchModelException, SystemException {
353 return findByPrimaryKey(((Long)primaryKey).longValue());
354 }
355
356 public PollsChoice findByPrimaryKey(long choiceId)
357 throws NoSuchChoiceException, SystemException {
358 PollsChoice pollsChoice = fetchByPrimaryKey(choiceId);
359
360 if (pollsChoice == null) {
361 if (_log.isWarnEnabled()) {
362 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + choiceId);
363 }
364
365 throw new NoSuchChoiceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
366 choiceId);
367 }
368
369 return pollsChoice;
370 }
371
372 public PollsChoice fetchByPrimaryKey(Serializable primaryKey)
373 throws SystemException {
374 return fetchByPrimaryKey(((Long)primaryKey).longValue());
375 }
376
377 public PollsChoice fetchByPrimaryKey(long choiceId)
378 throws SystemException {
379 PollsChoice pollsChoice = (PollsChoice)EntityCacheUtil.getResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
380 PollsChoiceImpl.class, choiceId, this);
381
382 if (pollsChoice == null) {
383 Session session = null;
384
385 try {
386 session = openSession();
387
388 pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
389 new Long(choiceId));
390 }
391 catch (Exception e) {
392 throw processException(e);
393 }
394 finally {
395 if (pollsChoice != null) {
396 cacheResult(pollsChoice);
397 }
398
399 closeSession(session);
400 }
401 }
402
403 return pollsChoice;
404 }
405
406 public List<PollsChoice> findByUuid(String uuid) throws SystemException {
407 Object[] finderArgs = new Object[] { uuid };
408
409 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
410 finderArgs, this);
411
412 if (list == null) {
413 Session session = null;
414
415 try {
416 session = openSession();
417
418 StringBundler query = new StringBundler(3);
419
420 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
421
422 if (uuid == null) {
423 query.append(_FINDER_COLUMN_UUID_UUID_1);
424 }
425 else {
426 if (uuid.equals(StringPool.BLANK)) {
427 query.append(_FINDER_COLUMN_UUID_UUID_3);
428 }
429 else {
430 query.append(_FINDER_COLUMN_UUID_UUID_2);
431 }
432 }
433
434 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
435
436 String sql = query.toString();
437
438 Query q = session.createQuery(sql);
439
440 QueryPos qPos = QueryPos.getInstance(q);
441
442 if (uuid != null) {
443 qPos.add(uuid);
444 }
445
446 list = q.list();
447 }
448 catch (Exception e) {
449 throw processException(e);
450 }
451 finally {
452 if (list == null) {
453 list = new ArrayList<PollsChoice>();
454 }
455
456 cacheResult(list);
457
458 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
459 list);
460
461 closeSession(session);
462 }
463 }
464
465 return list;
466 }
467
468 public List<PollsChoice> findByUuid(String uuid, int start, int end)
469 throws SystemException {
470 return findByUuid(uuid, start, end, null);
471 }
472
473 public List<PollsChoice> findByUuid(String uuid, int start, int end,
474 OrderByComparator obc) throws SystemException {
475 Object[] finderArgs = new Object[] {
476 uuid,
477
478 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
479 };
480
481 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_UUID,
482 finderArgs, this);
483
484 if (list == null) {
485 Session session = null;
486
487 try {
488 session = openSession();
489
490 StringBundler query = null;
491
492 if (obc != null) {
493 query = new StringBundler(3 +
494 (obc.getOrderByFields().length * 3));
495 }
496 else {
497 query = new StringBundler(3);
498 }
499
500 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
501
502 if (uuid == null) {
503 query.append(_FINDER_COLUMN_UUID_UUID_1);
504 }
505 else {
506 if (uuid.equals(StringPool.BLANK)) {
507 query.append(_FINDER_COLUMN_UUID_UUID_3);
508 }
509 else {
510 query.append(_FINDER_COLUMN_UUID_UUID_2);
511 }
512 }
513
514 if (obc != null) {
515 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
516 }
517
518 else {
519 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
520 }
521
522 String sql = query.toString();
523
524 Query q = session.createQuery(sql);
525
526 QueryPos qPos = QueryPos.getInstance(q);
527
528 if (uuid != null) {
529 qPos.add(uuid);
530 }
531
532 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
533 start, end);
534 }
535 catch (Exception e) {
536 throw processException(e);
537 }
538 finally {
539 if (list == null) {
540 list = new ArrayList<PollsChoice>();
541 }
542
543 cacheResult(list);
544
545 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
546 finderArgs, list);
547
548 closeSession(session);
549 }
550 }
551
552 return list;
553 }
554
555 public PollsChoice findByUuid_First(String uuid, OrderByComparator obc)
556 throws NoSuchChoiceException, SystemException {
557 List<PollsChoice> list = findByUuid(uuid, 0, 1, obc);
558
559 if (list.isEmpty()) {
560 StringBundler msg = new StringBundler(4);
561
562 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
563
564 msg.append("uuid=");
565 msg.append(uuid);
566
567 msg.append(StringPool.CLOSE_CURLY_BRACE);
568
569 throw new NoSuchChoiceException(msg.toString());
570 }
571 else {
572 return list.get(0);
573 }
574 }
575
576 public PollsChoice findByUuid_Last(String uuid, OrderByComparator obc)
577 throws NoSuchChoiceException, SystemException {
578 int count = countByUuid(uuid);
579
580 List<PollsChoice> list = findByUuid(uuid, count - 1, count, obc);
581
582 if (list.isEmpty()) {
583 StringBundler msg = new StringBundler(4);
584
585 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
586
587 msg.append("uuid=");
588 msg.append(uuid);
589
590 msg.append(StringPool.CLOSE_CURLY_BRACE);
591
592 throw new NoSuchChoiceException(msg.toString());
593 }
594 else {
595 return list.get(0);
596 }
597 }
598
599 public PollsChoice[] findByUuid_PrevAndNext(long choiceId, String uuid,
600 OrderByComparator obc) throws NoSuchChoiceException, SystemException {
601 PollsChoice pollsChoice = findByPrimaryKey(choiceId);
602
603 int count = countByUuid(uuid);
604
605 Session session = null;
606
607 try {
608 session = openSession();
609
610 StringBundler query = null;
611
612 if (obc != null) {
613 query = new StringBundler(3 +
614 (obc.getOrderByFields().length * 3));
615 }
616 else {
617 query = new StringBundler(3);
618 }
619
620 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
621
622 if (uuid == null) {
623 query.append(_FINDER_COLUMN_UUID_UUID_1);
624 }
625 else {
626 if (uuid.equals(StringPool.BLANK)) {
627 query.append(_FINDER_COLUMN_UUID_UUID_3);
628 }
629 else {
630 query.append(_FINDER_COLUMN_UUID_UUID_2);
631 }
632 }
633
634 if (obc != null) {
635 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
636 }
637
638 else {
639 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
640 }
641
642 String sql = query.toString();
643
644 Query q = session.createQuery(sql);
645
646 QueryPos qPos = QueryPos.getInstance(q);
647
648 if (uuid != null) {
649 qPos.add(uuid);
650 }
651
652 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
653 pollsChoice);
654
655 PollsChoice[] array = new PollsChoiceImpl[3];
656
657 array[0] = (PollsChoice)objArray[0];
658 array[1] = (PollsChoice)objArray[1];
659 array[2] = (PollsChoice)objArray[2];
660
661 return array;
662 }
663 catch (Exception e) {
664 throw processException(e);
665 }
666 finally {
667 closeSession(session);
668 }
669 }
670
671 public List<PollsChoice> findByQuestionId(long questionId)
672 throws SystemException {
673 Object[] finderArgs = new Object[] { new Long(questionId) };
674
675 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_QUESTIONID,
676 finderArgs, this);
677
678 if (list == null) {
679 Session session = null;
680
681 try {
682 session = openSession();
683
684 StringBundler query = new StringBundler(3);
685
686 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
687
688 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
689
690 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
691
692 String sql = query.toString();
693
694 Query q = session.createQuery(sql);
695
696 QueryPos qPos = QueryPos.getInstance(q);
697
698 qPos.add(questionId);
699
700 list = q.list();
701 }
702 catch (Exception e) {
703 throw processException(e);
704 }
705 finally {
706 if (list == null) {
707 list = new ArrayList<PollsChoice>();
708 }
709
710 cacheResult(list);
711
712 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_QUESTIONID,
713 finderArgs, list);
714
715 closeSession(session);
716 }
717 }
718
719 return list;
720 }
721
722 public List<PollsChoice> findByQuestionId(long questionId, int start,
723 int end) throws SystemException {
724 return findByQuestionId(questionId, start, end, null);
725 }
726
727 public List<PollsChoice> findByQuestionId(long questionId, int start,
728 int end, OrderByComparator obc) throws SystemException {
729 Object[] finderArgs = new Object[] {
730 new Long(questionId),
731
732 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
733 };
734
735 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_QUESTIONID,
736 finderArgs, this);
737
738 if (list == null) {
739 Session session = null;
740
741 try {
742 session = openSession();
743
744 StringBundler query = null;
745
746 if (obc != null) {
747 query = new StringBundler(3 +
748 (obc.getOrderByFields().length * 3));
749 }
750 else {
751 query = new StringBundler(3);
752 }
753
754 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
755
756 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
757
758 if (obc != null) {
759 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
760 }
761
762 else {
763 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
764 }
765
766 String sql = query.toString();
767
768 Query q = session.createQuery(sql);
769
770 QueryPos qPos = QueryPos.getInstance(q);
771
772 qPos.add(questionId);
773
774 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
775 start, end);
776 }
777 catch (Exception e) {
778 throw processException(e);
779 }
780 finally {
781 if (list == null) {
782 list = new ArrayList<PollsChoice>();
783 }
784
785 cacheResult(list);
786
787 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_QUESTIONID,
788 finderArgs, list);
789
790 closeSession(session);
791 }
792 }
793
794 return list;
795 }
796
797 public PollsChoice findByQuestionId_First(long questionId,
798 OrderByComparator obc) throws NoSuchChoiceException, SystemException {
799 List<PollsChoice> list = findByQuestionId(questionId, 0, 1, obc);
800
801 if (list.isEmpty()) {
802 StringBundler msg = new StringBundler(4);
803
804 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
805
806 msg.append("questionId=");
807 msg.append(questionId);
808
809 msg.append(StringPool.CLOSE_CURLY_BRACE);
810
811 throw new NoSuchChoiceException(msg.toString());
812 }
813 else {
814 return list.get(0);
815 }
816 }
817
818 public PollsChoice findByQuestionId_Last(long questionId,
819 OrderByComparator obc) throws NoSuchChoiceException, SystemException {
820 int count = countByQuestionId(questionId);
821
822 List<PollsChoice> list = findByQuestionId(questionId, count - 1, count,
823 obc);
824
825 if (list.isEmpty()) {
826 StringBundler msg = new StringBundler(4);
827
828 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
829
830 msg.append("questionId=");
831 msg.append(questionId);
832
833 msg.append(StringPool.CLOSE_CURLY_BRACE);
834
835 throw new NoSuchChoiceException(msg.toString());
836 }
837 else {
838 return list.get(0);
839 }
840 }
841
842 public PollsChoice[] findByQuestionId_PrevAndNext(long choiceId,
843 long questionId, OrderByComparator obc)
844 throws NoSuchChoiceException, SystemException {
845 PollsChoice pollsChoice = findByPrimaryKey(choiceId);
846
847 int count = countByQuestionId(questionId);
848
849 Session session = null;
850
851 try {
852 session = openSession();
853
854 StringBundler query = null;
855
856 if (obc != null) {
857 query = new StringBundler(3 +
858 (obc.getOrderByFields().length * 3));
859 }
860 else {
861 query = new StringBundler(3);
862 }
863
864 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
865
866 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
867
868 if (obc != null) {
869 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
870 }
871
872 else {
873 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
874 }
875
876 String sql = query.toString();
877
878 Query q = session.createQuery(sql);
879
880 QueryPos qPos = QueryPos.getInstance(q);
881
882 qPos.add(questionId);
883
884 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
885 pollsChoice);
886
887 PollsChoice[] array = new PollsChoiceImpl[3];
888
889 array[0] = (PollsChoice)objArray[0];
890 array[1] = (PollsChoice)objArray[1];
891 array[2] = (PollsChoice)objArray[2];
892
893 return array;
894 }
895 catch (Exception e) {
896 throw processException(e);
897 }
898 finally {
899 closeSession(session);
900 }
901 }
902
903 public PollsChoice findByQ_N(long questionId, String name)
904 throws NoSuchChoiceException, SystemException {
905 PollsChoice pollsChoice = fetchByQ_N(questionId, name);
906
907 if (pollsChoice == null) {
908 StringBundler msg = new StringBundler(6);
909
910 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
911
912 msg.append("questionId=");
913 msg.append(questionId);
914
915 msg.append(", name=");
916 msg.append(name);
917
918 msg.append(StringPool.CLOSE_CURLY_BRACE);
919
920 if (_log.isWarnEnabled()) {
921 _log.warn(msg.toString());
922 }
923
924 throw new NoSuchChoiceException(msg.toString());
925 }
926
927 return pollsChoice;
928 }
929
930 public PollsChoice fetchByQ_N(long questionId, String name)
931 throws SystemException {
932 return fetchByQ_N(questionId, name, true);
933 }
934
935 public PollsChoice fetchByQ_N(long questionId, String name,
936 boolean retrieveFromCache) throws SystemException {
937 Object[] finderArgs = new Object[] { new Long(questionId), name };
938
939 Object result = null;
940
941 if (retrieveFromCache) {
942 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_Q_N,
943 finderArgs, this);
944 }
945
946 if (result == null) {
947 Session session = null;
948
949 try {
950 session = openSession();
951
952 StringBundler query = new StringBundler(4);
953
954 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
955
956 query.append(_FINDER_COLUMN_Q_N_QUESTIONID_2);
957
958 if (name == null) {
959 query.append(_FINDER_COLUMN_Q_N_NAME_1);
960 }
961 else {
962 if (name.equals(StringPool.BLANK)) {
963 query.append(_FINDER_COLUMN_Q_N_NAME_3);
964 }
965 else {
966 query.append(_FINDER_COLUMN_Q_N_NAME_2);
967 }
968 }
969
970 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
971
972 String sql = query.toString();
973
974 Query q = session.createQuery(sql);
975
976 QueryPos qPos = QueryPos.getInstance(q);
977
978 qPos.add(questionId);
979
980 if (name != null) {
981 qPos.add(name);
982 }
983
984 List<PollsChoice> list = q.list();
985
986 result = list;
987
988 PollsChoice pollsChoice = null;
989
990 if (list.isEmpty()) {
991 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
992 finderArgs, list);
993 }
994 else {
995 pollsChoice = list.get(0);
996
997 cacheResult(pollsChoice);
998
999 if ((pollsChoice.getQuestionId() != questionId) ||
1000 (pollsChoice.getName() == null) ||
1001 !pollsChoice.getName().equals(name)) {
1002 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
1003 finderArgs, pollsChoice);
1004 }
1005 }
1006
1007 return pollsChoice;
1008 }
1009 catch (Exception e) {
1010 throw processException(e);
1011 }
1012 finally {
1013 if (result == null) {
1014 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
1015 finderArgs, new ArrayList<PollsChoice>());
1016 }
1017
1018 closeSession(session);
1019 }
1020 }
1021 else {
1022 if (result instanceof List<?>) {
1023 return null;
1024 }
1025 else {
1026 return (PollsChoice)result;
1027 }
1028 }
1029 }
1030
1031 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1032 throws SystemException {
1033 Session session = null;
1034
1035 try {
1036 session = openSession();
1037
1038 dynamicQuery.compile(session);
1039
1040 return dynamicQuery.list();
1041 }
1042 catch (Exception e) {
1043 throw processException(e);
1044 }
1045 finally {
1046 closeSession(session);
1047 }
1048 }
1049
1050 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1051 int start, int end) throws SystemException {
1052 Session session = null;
1053
1054 try {
1055 session = openSession();
1056
1057 dynamicQuery.setLimit(start, end);
1058
1059 dynamicQuery.compile(session);
1060
1061 return dynamicQuery.list();
1062 }
1063 catch (Exception e) {
1064 throw processException(e);
1065 }
1066 finally {
1067 closeSession(session);
1068 }
1069 }
1070
1071 public List<PollsChoice> findAll() throws SystemException {
1072 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1073 }
1074
1075 public List<PollsChoice> findAll(int start, int end)
1076 throws SystemException {
1077 return findAll(start, end, null);
1078 }
1079
1080 public List<PollsChoice> findAll(int start, int end, OrderByComparator obc)
1081 throws SystemException {
1082 Object[] finderArgs = new Object[] {
1083 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1084 };
1085
1086 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1087 finderArgs, this);
1088
1089 if (list == null) {
1090 Session session = null;
1091
1092 try {
1093 session = openSession();
1094
1095 StringBundler query = null;
1096 String sql = null;
1097
1098 if (obc != null) {
1099 query = new StringBundler(2 +
1100 (obc.getOrderByFields().length * 3));
1101
1102 query.append(_SQL_SELECT_POLLSCHOICE);
1103
1104 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1105
1106 sql = query.toString();
1107 }
1108
1109 else {
1110 sql = _SQL_SELECT_POLLSCHOICE.concat(PollsChoiceModelImpl.ORDER_BY_JPQL);
1111 }
1112
1113 Query q = session.createQuery(sql);
1114
1115 if (obc == null) {
1116 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1117 start, end, false);
1118
1119 Collections.sort(list);
1120 }
1121 else {
1122 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1123 start, end);
1124 }
1125 }
1126 catch (Exception e) {
1127 throw processException(e);
1128 }
1129 finally {
1130 if (list == null) {
1131 list = new ArrayList<PollsChoice>();
1132 }
1133
1134 cacheResult(list);
1135
1136 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1137
1138 closeSession(session);
1139 }
1140 }
1141
1142 return list;
1143 }
1144
1145 public void removeByUuid(String uuid) throws SystemException {
1146 for (PollsChoice pollsChoice : findByUuid(uuid)) {
1147 remove(pollsChoice);
1148 }
1149 }
1150
1151 public void removeByQuestionId(long questionId) throws SystemException {
1152 for (PollsChoice pollsChoice : findByQuestionId(questionId)) {
1153 remove(pollsChoice);
1154 }
1155 }
1156
1157 public void removeByQ_N(long questionId, String name)
1158 throws NoSuchChoiceException, SystemException {
1159 PollsChoice pollsChoice = findByQ_N(questionId, name);
1160
1161 remove(pollsChoice);
1162 }
1163
1164 public void removeAll() throws SystemException {
1165 for (PollsChoice pollsChoice : findAll()) {
1166 remove(pollsChoice);
1167 }
1168 }
1169
1170 public int countByUuid(String uuid) throws SystemException {
1171 Object[] finderArgs = new Object[] { uuid };
1172
1173 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1174 finderArgs, this);
1175
1176 if (count == null) {
1177 Session session = null;
1178
1179 try {
1180 session = openSession();
1181
1182 StringBundler query = new StringBundler(2);
1183
1184 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
1185
1186 if (uuid == null) {
1187 query.append(_FINDER_COLUMN_UUID_UUID_1);
1188 }
1189 else {
1190 if (uuid.equals(StringPool.BLANK)) {
1191 query.append(_FINDER_COLUMN_UUID_UUID_3);
1192 }
1193 else {
1194 query.append(_FINDER_COLUMN_UUID_UUID_2);
1195 }
1196 }
1197
1198 String sql = query.toString();
1199
1200 Query q = session.createQuery(sql);
1201
1202 QueryPos qPos = QueryPos.getInstance(q);
1203
1204 if (uuid != null) {
1205 qPos.add(uuid);
1206 }
1207
1208 count = (Long)q.uniqueResult();
1209 }
1210 catch (Exception e) {
1211 throw processException(e);
1212 }
1213 finally {
1214 if (count == null) {
1215 count = Long.valueOf(0);
1216 }
1217
1218 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1219 finderArgs, count);
1220
1221 closeSession(session);
1222 }
1223 }
1224
1225 return count.intValue();
1226 }
1227
1228 public int countByQuestionId(long questionId) throws SystemException {
1229 Object[] finderArgs = new Object[] { new Long(questionId) };
1230
1231 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1232 finderArgs, this);
1233
1234 if (count == null) {
1235 Session session = null;
1236
1237 try {
1238 session = openSession();
1239
1240 StringBundler query = new StringBundler(2);
1241
1242 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
1243
1244 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1245
1246 String sql = query.toString();
1247
1248 Query q = session.createQuery(sql);
1249
1250 QueryPos qPos = QueryPos.getInstance(q);
1251
1252 qPos.add(questionId);
1253
1254 count = (Long)q.uniqueResult();
1255 }
1256 catch (Exception e) {
1257 throw processException(e);
1258 }
1259 finally {
1260 if (count == null) {
1261 count = Long.valueOf(0);
1262 }
1263
1264 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1265 finderArgs, count);
1266
1267 closeSession(session);
1268 }
1269 }
1270
1271 return count.intValue();
1272 }
1273
1274 public int countByQ_N(long questionId, String name)
1275 throws SystemException {
1276 Object[] finderArgs = new Object[] { new Long(questionId), name };
1277
1278 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_Q_N,
1279 finderArgs, this);
1280
1281 if (count == null) {
1282 Session session = null;
1283
1284 try {
1285 session = openSession();
1286
1287 StringBundler query = new StringBundler(3);
1288
1289 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
1290
1291 query.append(_FINDER_COLUMN_Q_N_QUESTIONID_2);
1292
1293 if (name == null) {
1294 query.append(_FINDER_COLUMN_Q_N_NAME_1);
1295 }
1296 else {
1297 if (name.equals(StringPool.BLANK)) {
1298 query.append(_FINDER_COLUMN_Q_N_NAME_3);
1299 }
1300 else {
1301 query.append(_FINDER_COLUMN_Q_N_NAME_2);
1302 }
1303 }
1304
1305 String sql = query.toString();
1306
1307 Query q = session.createQuery(sql);
1308
1309 QueryPos qPos = QueryPos.getInstance(q);
1310
1311 qPos.add(questionId);
1312
1313 if (name != null) {
1314 qPos.add(name);
1315 }
1316
1317 count = (Long)q.uniqueResult();
1318 }
1319 catch (Exception e) {
1320 throw processException(e);
1321 }
1322 finally {
1323 if (count == null) {
1324 count = Long.valueOf(0);
1325 }
1326
1327 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_Q_N, finderArgs,
1328 count);
1329
1330 closeSession(session);
1331 }
1332 }
1333
1334 return count.intValue();
1335 }
1336
1337 public int countAll() throws SystemException {
1338 Object[] finderArgs = new Object[0];
1339
1340 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1341 finderArgs, this);
1342
1343 if (count == null) {
1344 Session session = null;
1345
1346 try {
1347 session = openSession();
1348
1349 Query q = session.createQuery(_SQL_COUNT_POLLSCHOICE);
1350
1351 count = (Long)q.uniqueResult();
1352 }
1353 catch (Exception e) {
1354 throw processException(e);
1355 }
1356 finally {
1357 if (count == null) {
1358 count = Long.valueOf(0);
1359 }
1360
1361 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1362 count);
1363
1364 closeSession(session);
1365 }
1366 }
1367
1368 return count.intValue();
1369 }
1370
1371 public void afterPropertiesSet() {
1372 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1373 com.liferay.portal.util.PropsUtil.get(
1374 "value.object.listener.com.liferay.portlet.polls.model.PollsChoice")));
1375
1376 if (listenerClassNames.length > 0) {
1377 try {
1378 List<ModelListener<PollsChoice>> listenersList = new ArrayList<ModelListener<PollsChoice>>();
1379
1380 for (String listenerClassName : listenerClassNames) {
1381 listenersList.add((ModelListener<PollsChoice>)Class.forName(
1382 listenerClassName).newInstance());
1383 }
1384
1385 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1386 }
1387 catch (Exception e) {
1388 _log.error(e);
1389 }
1390 }
1391 }
1392
1393 @BeanReference(name = "com.liferay.portlet.polls.service.persistence.PollsChoicePersistence")
1394 protected com.liferay.portlet.polls.service.persistence.PollsChoicePersistence pollsChoicePersistence;
1395 @BeanReference(name = "com.liferay.portlet.polls.service.persistence.PollsQuestionPersistence")
1396 protected com.liferay.portlet.polls.service.persistence.PollsQuestionPersistence pollsQuestionPersistence;
1397 @BeanReference(name = "com.liferay.portlet.polls.service.persistence.PollsVotePersistence")
1398 protected com.liferay.portlet.polls.service.persistence.PollsVotePersistence pollsVotePersistence;
1399 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
1400 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1401 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
1402 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1403 private static final String _SQL_SELECT_POLLSCHOICE = "SELECT pollsChoice FROM PollsChoice pollsChoice";
1404 private static final String _SQL_SELECT_POLLSCHOICE_WHERE = "SELECT pollsChoice FROM PollsChoice pollsChoice WHERE ";
1405 private static final String _SQL_COUNT_POLLSCHOICE = "SELECT COUNT(pollsChoice) FROM PollsChoice pollsChoice";
1406 private static final String _SQL_COUNT_POLLSCHOICE_WHERE = "SELECT COUNT(pollsChoice) FROM PollsChoice pollsChoice WHERE ";
1407 private static final String _FINDER_COLUMN_UUID_UUID_1 = "pollsChoice.uuid IS NULL";
1408 private static final String _FINDER_COLUMN_UUID_UUID_2 = "pollsChoice.uuid = ?";
1409 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(pollsChoice.uuid IS NULL OR pollsChoice.uuid = ?)";
1410 private static final String _FINDER_COLUMN_QUESTIONID_QUESTIONID_2 = "pollsChoice.questionId = ?";
1411 private static final String _FINDER_COLUMN_Q_N_QUESTIONID_2 = "pollsChoice.questionId = ? AND ";
1412 private static final String _FINDER_COLUMN_Q_N_NAME_1 = "pollsChoice.name IS NULL";
1413 private static final String _FINDER_COLUMN_Q_N_NAME_2 = "pollsChoice.name = ?";
1414 private static final String _FINDER_COLUMN_Q_N_NAME_3 = "(pollsChoice.name IS NULL OR pollsChoice.name = ?)";
1415 private static final String _ORDER_BY_ENTITY_ALIAS = "pollsChoice.";
1416 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsChoice exists with the primary key ";
1417 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsChoice exists with the key {";
1418 private static Log _log = LogFactoryUtil.getLog(PollsChoicePersistenceImpl.class);
1419}