001
014
015 package com.liferay.portlet.polls.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.Session;
025 import com.liferay.portal.kernel.exception.SystemException;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.GetterUtil;
029 import com.liferay.portal.kernel.util.InstanceFactory;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.StringUtil;
034 import com.liferay.portal.kernel.util.UnmodifiableList;
035 import com.liferay.portal.kernel.util.Validator;
036 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040
041 import com.liferay.portlet.polls.NoSuchChoiceException;
042 import com.liferay.portlet.polls.model.PollsChoice;
043 import com.liferay.portlet.polls.model.impl.PollsChoiceImpl;
044 import com.liferay.portlet.polls.model.impl.PollsChoiceModelImpl;
045
046 import java.io.Serializable;
047
048 import java.util.ArrayList;
049 import java.util.Collections;
050 import java.util.List;
051
052
064 public class PollsChoicePersistenceImpl extends BasePersistenceImpl<PollsChoice>
065 implements PollsChoicePersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = PollsChoiceImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
077 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
080 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
083 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
086 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
087 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
088 new String[] {
089 String.class.getName(),
090
091 Integer.class.getName(), Integer.class.getName(),
092 OrderByComparator.class.getName()
093 });
094 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
095 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
096 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
097 new String[] { String.class.getName() },
098 PollsChoiceModelImpl.UUID_COLUMN_BITMASK |
099 PollsChoiceModelImpl.QUESTIONID_COLUMN_BITMASK |
100 PollsChoiceModelImpl.NAME_COLUMN_BITMASK);
101 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
102 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
103 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
104 new String[] { String.class.getName() });
105
106
113 public List<PollsChoice> findByUuid(String uuid) throws SystemException {
114 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
115 }
116
117
130 public List<PollsChoice> findByUuid(String uuid, int start, int end)
131 throws SystemException {
132 return findByUuid(uuid, start, end, null);
133 }
134
135
149 public List<PollsChoice> findByUuid(String uuid, int start, int end,
150 OrderByComparator orderByComparator) throws SystemException {
151 boolean pagination = true;
152 FinderPath finderPath = null;
153 Object[] finderArgs = null;
154
155 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
156 (orderByComparator == null)) {
157 pagination = false;
158 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
159 finderArgs = new Object[] { uuid };
160 }
161 else {
162 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
163 finderArgs = new Object[] { uuid, start, end, orderByComparator };
164 }
165
166 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
167 finderArgs, this);
168
169 if ((list != null) && !list.isEmpty()) {
170 for (PollsChoice pollsChoice : list) {
171 if (!Validator.equals(uuid, pollsChoice.getUuid())) {
172 list = null;
173
174 break;
175 }
176 }
177 }
178
179 if (list == null) {
180 StringBundler query = null;
181
182 if (orderByComparator != null) {
183 query = new StringBundler(3 +
184 (orderByComparator.getOrderByFields().length * 3));
185 }
186 else {
187 query = new StringBundler(3);
188 }
189
190 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
191
192 boolean bindUuid = false;
193
194 if (uuid == null) {
195 query.append(_FINDER_COLUMN_UUID_UUID_1);
196 }
197 else if (uuid.equals(StringPool.BLANK)) {
198 query.append(_FINDER_COLUMN_UUID_UUID_3);
199 }
200 else {
201 bindUuid = true;
202
203 query.append(_FINDER_COLUMN_UUID_UUID_2);
204 }
205
206 if (orderByComparator != null) {
207 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
208 orderByComparator);
209 }
210 else
211 if (pagination) {
212 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
213 }
214
215 String sql = query.toString();
216
217 Session session = null;
218
219 try {
220 session = openSession();
221
222 Query q = session.createQuery(sql);
223
224 QueryPos qPos = QueryPos.getInstance(q);
225
226 if (bindUuid) {
227 qPos.add(uuid);
228 }
229
230 if (!pagination) {
231 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
232 start, end, false);
233
234 Collections.sort(list);
235
236 list = new UnmodifiableList<PollsChoice>(list);
237 }
238 else {
239 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
240 start, end);
241 }
242
243 cacheResult(list);
244
245 FinderCacheUtil.putResult(finderPath, finderArgs, list);
246 }
247 catch (Exception e) {
248 FinderCacheUtil.removeResult(finderPath, finderArgs);
249
250 throw processException(e);
251 }
252 finally {
253 closeSession(session);
254 }
255 }
256
257 return list;
258 }
259
260
269 public PollsChoice findByUuid_First(String uuid,
270 OrderByComparator orderByComparator)
271 throws NoSuchChoiceException, SystemException {
272 PollsChoice pollsChoice = fetchByUuid_First(uuid, orderByComparator);
273
274 if (pollsChoice != null) {
275 return pollsChoice;
276 }
277
278 StringBundler msg = new StringBundler(4);
279
280 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
281
282 msg.append("uuid=");
283 msg.append(uuid);
284
285 msg.append(StringPool.CLOSE_CURLY_BRACE);
286
287 throw new NoSuchChoiceException(msg.toString());
288 }
289
290
298 public PollsChoice fetchByUuid_First(String uuid,
299 OrderByComparator orderByComparator) throws SystemException {
300 List<PollsChoice> list = findByUuid(uuid, 0, 1, orderByComparator);
301
302 if (!list.isEmpty()) {
303 return list.get(0);
304 }
305
306 return null;
307 }
308
309
318 public PollsChoice findByUuid_Last(String uuid,
319 OrderByComparator orderByComparator)
320 throws NoSuchChoiceException, SystemException {
321 PollsChoice pollsChoice = fetchByUuid_Last(uuid, orderByComparator);
322
323 if (pollsChoice != null) {
324 return pollsChoice;
325 }
326
327 StringBundler msg = new StringBundler(4);
328
329 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
330
331 msg.append("uuid=");
332 msg.append(uuid);
333
334 msg.append(StringPool.CLOSE_CURLY_BRACE);
335
336 throw new NoSuchChoiceException(msg.toString());
337 }
338
339
347 public PollsChoice fetchByUuid_Last(String uuid,
348 OrderByComparator orderByComparator) throws SystemException {
349 int count = countByUuid(uuid);
350
351 List<PollsChoice> list = findByUuid(uuid, count - 1, count,
352 orderByComparator);
353
354 if (!list.isEmpty()) {
355 return list.get(0);
356 }
357
358 return null;
359 }
360
361
371 public PollsChoice[] findByUuid_PrevAndNext(long choiceId, String uuid,
372 OrderByComparator orderByComparator)
373 throws NoSuchChoiceException, SystemException {
374 PollsChoice pollsChoice = findByPrimaryKey(choiceId);
375
376 Session session = null;
377
378 try {
379 session = openSession();
380
381 PollsChoice[] array = new PollsChoiceImpl[3];
382
383 array[0] = getByUuid_PrevAndNext(session, pollsChoice, uuid,
384 orderByComparator, true);
385
386 array[1] = pollsChoice;
387
388 array[2] = getByUuid_PrevAndNext(session, pollsChoice, uuid,
389 orderByComparator, false);
390
391 return array;
392 }
393 catch (Exception e) {
394 throw processException(e);
395 }
396 finally {
397 closeSession(session);
398 }
399 }
400
401 protected PollsChoice getByUuid_PrevAndNext(Session session,
402 PollsChoice pollsChoice, String uuid,
403 OrderByComparator orderByComparator, boolean previous) {
404 StringBundler query = null;
405
406 if (orderByComparator != null) {
407 query = new StringBundler(6 +
408 (orderByComparator.getOrderByFields().length * 6));
409 }
410 else {
411 query = new StringBundler(3);
412 }
413
414 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
415
416 boolean bindUuid = false;
417
418 if (uuid == null) {
419 query.append(_FINDER_COLUMN_UUID_UUID_1);
420 }
421 else if (uuid.equals(StringPool.BLANK)) {
422 query.append(_FINDER_COLUMN_UUID_UUID_3);
423 }
424 else {
425 bindUuid = true;
426
427 query.append(_FINDER_COLUMN_UUID_UUID_2);
428 }
429
430 if (orderByComparator != null) {
431 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
432
433 if (orderByConditionFields.length > 0) {
434 query.append(WHERE_AND);
435 }
436
437 for (int i = 0; i < orderByConditionFields.length; i++) {
438 query.append(_ORDER_BY_ENTITY_ALIAS);
439 query.append(orderByConditionFields[i]);
440
441 if ((i + 1) < orderByConditionFields.length) {
442 if (orderByComparator.isAscending() ^ previous) {
443 query.append(WHERE_GREATER_THAN_HAS_NEXT);
444 }
445 else {
446 query.append(WHERE_LESSER_THAN_HAS_NEXT);
447 }
448 }
449 else {
450 if (orderByComparator.isAscending() ^ previous) {
451 query.append(WHERE_GREATER_THAN);
452 }
453 else {
454 query.append(WHERE_LESSER_THAN);
455 }
456 }
457 }
458
459 query.append(ORDER_BY_CLAUSE);
460
461 String[] orderByFields = orderByComparator.getOrderByFields();
462
463 for (int i = 0; i < orderByFields.length; i++) {
464 query.append(_ORDER_BY_ENTITY_ALIAS);
465 query.append(orderByFields[i]);
466
467 if ((i + 1) < orderByFields.length) {
468 if (orderByComparator.isAscending() ^ previous) {
469 query.append(ORDER_BY_ASC_HAS_NEXT);
470 }
471 else {
472 query.append(ORDER_BY_DESC_HAS_NEXT);
473 }
474 }
475 else {
476 if (orderByComparator.isAscending() ^ previous) {
477 query.append(ORDER_BY_ASC);
478 }
479 else {
480 query.append(ORDER_BY_DESC);
481 }
482 }
483 }
484 }
485 else {
486 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
487 }
488
489 String sql = query.toString();
490
491 Query q = session.createQuery(sql);
492
493 q.setFirstResult(0);
494 q.setMaxResults(2);
495
496 QueryPos qPos = QueryPos.getInstance(q);
497
498 if (bindUuid) {
499 qPos.add(uuid);
500 }
501
502 if (orderByComparator != null) {
503 Object[] values = orderByComparator.getOrderByConditionValues(pollsChoice);
504
505 for (Object value : values) {
506 qPos.add(value);
507 }
508 }
509
510 List<PollsChoice> list = q.list();
511
512 if (list.size() == 2) {
513 return list.get(1);
514 }
515 else {
516 return null;
517 }
518 }
519
520
526 public void removeByUuid(String uuid) throws SystemException {
527 for (PollsChoice pollsChoice : findByUuid(uuid, QueryUtil.ALL_POS,
528 QueryUtil.ALL_POS, null)) {
529 remove(pollsChoice);
530 }
531 }
532
533
540 public int countByUuid(String uuid) throws SystemException {
541 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
542
543 Object[] finderArgs = new Object[] { uuid };
544
545 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
546 this);
547
548 if (count == null) {
549 StringBundler query = new StringBundler(2);
550
551 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
552
553 boolean bindUuid = false;
554
555 if (uuid == null) {
556 query.append(_FINDER_COLUMN_UUID_UUID_1);
557 }
558 else if (uuid.equals(StringPool.BLANK)) {
559 query.append(_FINDER_COLUMN_UUID_UUID_3);
560 }
561 else {
562 bindUuid = true;
563
564 query.append(_FINDER_COLUMN_UUID_UUID_2);
565 }
566
567 String sql = query.toString();
568
569 Session session = null;
570
571 try {
572 session = openSession();
573
574 Query q = session.createQuery(sql);
575
576 QueryPos qPos = QueryPos.getInstance(q);
577
578 if (bindUuid) {
579 qPos.add(uuid);
580 }
581
582 count = (Long)q.uniqueResult();
583
584 FinderCacheUtil.putResult(finderPath, finderArgs, count);
585 }
586 catch (Exception e) {
587 FinderCacheUtil.removeResult(finderPath, finderArgs);
588
589 throw processException(e);
590 }
591 finally {
592 closeSession(session);
593 }
594 }
595
596 return count.intValue();
597 }
598
599 private static final String _FINDER_COLUMN_UUID_UUID_1 = "pollsChoice.uuid IS NULL";
600 private static final String _FINDER_COLUMN_UUID_UUID_2 = "pollsChoice.uuid = ?";
601 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(pollsChoice.uuid IS NULL OR pollsChoice.uuid = '')";
602 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_QUESTIONID =
603 new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
604 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
605 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByQuestionId",
606 new String[] {
607 Long.class.getName(),
608
609 Integer.class.getName(), Integer.class.getName(),
610 OrderByComparator.class.getName()
611 });
612 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID =
613 new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
614 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
615 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByQuestionId",
616 new String[] { Long.class.getName() },
617 PollsChoiceModelImpl.QUESTIONID_COLUMN_BITMASK |
618 PollsChoiceModelImpl.NAME_COLUMN_BITMASK);
619 public static final FinderPath FINDER_PATH_COUNT_BY_QUESTIONID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
620 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
621 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByQuestionId",
622 new String[] { Long.class.getName() });
623
624
631 public List<PollsChoice> findByQuestionId(long questionId)
632 throws SystemException {
633 return findByQuestionId(questionId, QueryUtil.ALL_POS,
634 QueryUtil.ALL_POS, null);
635 }
636
637
650 public List<PollsChoice> findByQuestionId(long questionId, int start,
651 int end) throws SystemException {
652 return findByQuestionId(questionId, start, end, null);
653 }
654
655
669 public List<PollsChoice> findByQuestionId(long questionId, int start,
670 int end, OrderByComparator orderByComparator) throws SystemException {
671 boolean pagination = true;
672 FinderPath finderPath = null;
673 Object[] finderArgs = null;
674
675 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
676 (orderByComparator == null)) {
677 pagination = false;
678 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID;
679 finderArgs = new Object[] { questionId };
680 }
681 else {
682 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_QUESTIONID;
683 finderArgs = new Object[] { questionId, start, end, orderByComparator };
684 }
685
686 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
687 finderArgs, this);
688
689 if ((list != null) && !list.isEmpty()) {
690 for (PollsChoice pollsChoice : list) {
691 if ((questionId != pollsChoice.getQuestionId())) {
692 list = null;
693
694 break;
695 }
696 }
697 }
698
699 if (list == null) {
700 StringBundler query = null;
701
702 if (orderByComparator != null) {
703 query = new StringBundler(3 +
704 (orderByComparator.getOrderByFields().length * 3));
705 }
706 else {
707 query = new StringBundler(3);
708 }
709
710 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
711
712 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
713
714 if (orderByComparator != null) {
715 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
716 orderByComparator);
717 }
718 else
719 if (pagination) {
720 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
721 }
722
723 String sql = query.toString();
724
725 Session session = null;
726
727 try {
728 session = openSession();
729
730 Query q = session.createQuery(sql);
731
732 QueryPos qPos = QueryPos.getInstance(q);
733
734 qPos.add(questionId);
735
736 if (!pagination) {
737 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
738 start, end, false);
739
740 Collections.sort(list);
741
742 list = new UnmodifiableList<PollsChoice>(list);
743 }
744 else {
745 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
746 start, end);
747 }
748
749 cacheResult(list);
750
751 FinderCacheUtil.putResult(finderPath, finderArgs, list);
752 }
753 catch (Exception e) {
754 FinderCacheUtil.removeResult(finderPath, finderArgs);
755
756 throw processException(e);
757 }
758 finally {
759 closeSession(session);
760 }
761 }
762
763 return list;
764 }
765
766
775 public PollsChoice findByQuestionId_First(long questionId,
776 OrderByComparator orderByComparator)
777 throws NoSuchChoiceException, SystemException {
778 PollsChoice pollsChoice = fetchByQuestionId_First(questionId,
779 orderByComparator);
780
781 if (pollsChoice != null) {
782 return pollsChoice;
783 }
784
785 StringBundler msg = new StringBundler(4);
786
787 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
788
789 msg.append("questionId=");
790 msg.append(questionId);
791
792 msg.append(StringPool.CLOSE_CURLY_BRACE);
793
794 throw new NoSuchChoiceException(msg.toString());
795 }
796
797
805 public PollsChoice fetchByQuestionId_First(long questionId,
806 OrderByComparator orderByComparator) throws SystemException {
807 List<PollsChoice> list = findByQuestionId(questionId, 0, 1,
808 orderByComparator);
809
810 if (!list.isEmpty()) {
811 return list.get(0);
812 }
813
814 return null;
815 }
816
817
826 public PollsChoice findByQuestionId_Last(long questionId,
827 OrderByComparator orderByComparator)
828 throws NoSuchChoiceException, SystemException {
829 PollsChoice pollsChoice = fetchByQuestionId_Last(questionId,
830 orderByComparator);
831
832 if (pollsChoice != null) {
833 return pollsChoice;
834 }
835
836 StringBundler msg = new StringBundler(4);
837
838 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
839
840 msg.append("questionId=");
841 msg.append(questionId);
842
843 msg.append(StringPool.CLOSE_CURLY_BRACE);
844
845 throw new NoSuchChoiceException(msg.toString());
846 }
847
848
856 public PollsChoice fetchByQuestionId_Last(long questionId,
857 OrderByComparator orderByComparator) throws SystemException {
858 int count = countByQuestionId(questionId);
859
860 List<PollsChoice> list = findByQuestionId(questionId, count - 1, count,
861 orderByComparator);
862
863 if (!list.isEmpty()) {
864 return list.get(0);
865 }
866
867 return null;
868 }
869
870
880 public PollsChoice[] findByQuestionId_PrevAndNext(long choiceId,
881 long questionId, OrderByComparator orderByComparator)
882 throws NoSuchChoiceException, SystemException {
883 PollsChoice pollsChoice = findByPrimaryKey(choiceId);
884
885 Session session = null;
886
887 try {
888 session = openSession();
889
890 PollsChoice[] array = new PollsChoiceImpl[3];
891
892 array[0] = getByQuestionId_PrevAndNext(session, pollsChoice,
893 questionId, orderByComparator, true);
894
895 array[1] = pollsChoice;
896
897 array[2] = getByQuestionId_PrevAndNext(session, pollsChoice,
898 questionId, orderByComparator, false);
899
900 return array;
901 }
902 catch (Exception e) {
903 throw processException(e);
904 }
905 finally {
906 closeSession(session);
907 }
908 }
909
910 protected PollsChoice getByQuestionId_PrevAndNext(Session session,
911 PollsChoice pollsChoice, long questionId,
912 OrderByComparator orderByComparator, boolean previous) {
913 StringBundler query = null;
914
915 if (orderByComparator != null) {
916 query = new StringBundler(6 +
917 (orderByComparator.getOrderByFields().length * 6));
918 }
919 else {
920 query = new StringBundler(3);
921 }
922
923 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
924
925 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
926
927 if (orderByComparator != null) {
928 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
929
930 if (orderByConditionFields.length > 0) {
931 query.append(WHERE_AND);
932 }
933
934 for (int i = 0; i < orderByConditionFields.length; i++) {
935 query.append(_ORDER_BY_ENTITY_ALIAS);
936 query.append(orderByConditionFields[i]);
937
938 if ((i + 1) < orderByConditionFields.length) {
939 if (orderByComparator.isAscending() ^ previous) {
940 query.append(WHERE_GREATER_THAN_HAS_NEXT);
941 }
942 else {
943 query.append(WHERE_LESSER_THAN_HAS_NEXT);
944 }
945 }
946 else {
947 if (orderByComparator.isAscending() ^ previous) {
948 query.append(WHERE_GREATER_THAN);
949 }
950 else {
951 query.append(WHERE_LESSER_THAN);
952 }
953 }
954 }
955
956 query.append(ORDER_BY_CLAUSE);
957
958 String[] orderByFields = orderByComparator.getOrderByFields();
959
960 for (int i = 0; i < orderByFields.length; i++) {
961 query.append(_ORDER_BY_ENTITY_ALIAS);
962 query.append(orderByFields[i]);
963
964 if ((i + 1) < orderByFields.length) {
965 if (orderByComparator.isAscending() ^ previous) {
966 query.append(ORDER_BY_ASC_HAS_NEXT);
967 }
968 else {
969 query.append(ORDER_BY_DESC_HAS_NEXT);
970 }
971 }
972 else {
973 if (orderByComparator.isAscending() ^ previous) {
974 query.append(ORDER_BY_ASC);
975 }
976 else {
977 query.append(ORDER_BY_DESC);
978 }
979 }
980 }
981 }
982 else {
983 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
984 }
985
986 String sql = query.toString();
987
988 Query q = session.createQuery(sql);
989
990 q.setFirstResult(0);
991 q.setMaxResults(2);
992
993 QueryPos qPos = QueryPos.getInstance(q);
994
995 qPos.add(questionId);
996
997 if (orderByComparator != null) {
998 Object[] values = orderByComparator.getOrderByConditionValues(pollsChoice);
999
1000 for (Object value : values) {
1001 qPos.add(value);
1002 }
1003 }
1004
1005 List<PollsChoice> list = q.list();
1006
1007 if (list.size() == 2) {
1008 return list.get(1);
1009 }
1010 else {
1011 return null;
1012 }
1013 }
1014
1015
1021 public void removeByQuestionId(long questionId) throws SystemException {
1022 for (PollsChoice pollsChoice : findByQuestionId(questionId,
1023 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1024 remove(pollsChoice);
1025 }
1026 }
1027
1028
1035 public int countByQuestionId(long questionId) throws SystemException {
1036 FinderPath finderPath = FINDER_PATH_COUNT_BY_QUESTIONID;
1037
1038 Object[] finderArgs = new Object[] { questionId };
1039
1040 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1041 this);
1042
1043 if (count == null) {
1044 StringBundler query = new StringBundler(2);
1045
1046 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
1047
1048 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1049
1050 String sql = query.toString();
1051
1052 Session session = null;
1053
1054 try {
1055 session = openSession();
1056
1057 Query q = session.createQuery(sql);
1058
1059 QueryPos qPos = QueryPos.getInstance(q);
1060
1061 qPos.add(questionId);
1062
1063 count = (Long)q.uniqueResult();
1064
1065 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1066 }
1067 catch (Exception e) {
1068 FinderCacheUtil.removeResult(finderPath, finderArgs);
1069
1070 throw processException(e);
1071 }
1072 finally {
1073 closeSession(session);
1074 }
1075 }
1076
1077 return count.intValue();
1078 }
1079
1080 private static final String _FINDER_COLUMN_QUESTIONID_QUESTIONID_2 = "pollsChoice.questionId = ?";
1081 public static final FinderPath FINDER_PATH_FETCH_BY_Q_N = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
1082 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
1083 FINDER_CLASS_NAME_ENTITY, "fetchByQ_N",
1084 new String[] { Long.class.getName(), String.class.getName() },
1085 PollsChoiceModelImpl.QUESTIONID_COLUMN_BITMASK |
1086 PollsChoiceModelImpl.NAME_COLUMN_BITMASK);
1087 public static final FinderPath FINDER_PATH_COUNT_BY_Q_N = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
1088 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
1089 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByQ_N",
1090 new String[] { Long.class.getName(), String.class.getName() });
1091
1092
1101 public PollsChoice findByQ_N(long questionId, String name)
1102 throws NoSuchChoiceException, SystemException {
1103 PollsChoice pollsChoice = fetchByQ_N(questionId, name);
1104
1105 if (pollsChoice == null) {
1106 StringBundler msg = new StringBundler(6);
1107
1108 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1109
1110 msg.append("questionId=");
1111 msg.append(questionId);
1112
1113 msg.append(", name=");
1114 msg.append(name);
1115
1116 msg.append(StringPool.CLOSE_CURLY_BRACE);
1117
1118 if (_log.isWarnEnabled()) {
1119 _log.warn(msg.toString());
1120 }
1121
1122 throw new NoSuchChoiceException(msg.toString());
1123 }
1124
1125 return pollsChoice;
1126 }
1127
1128
1136 public PollsChoice fetchByQ_N(long questionId, String name)
1137 throws SystemException {
1138 return fetchByQ_N(questionId, name, true);
1139 }
1140
1141
1150 public PollsChoice fetchByQ_N(long questionId, String name,
1151 boolean retrieveFromCache) throws SystemException {
1152 Object[] finderArgs = new Object[] { questionId, name };
1153
1154 Object result = null;
1155
1156 if (retrieveFromCache) {
1157 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_Q_N,
1158 finderArgs, this);
1159 }
1160
1161 if (result instanceof PollsChoice) {
1162 PollsChoice pollsChoice = (PollsChoice)result;
1163
1164 if ((questionId != pollsChoice.getQuestionId()) ||
1165 !Validator.equals(name, pollsChoice.getName())) {
1166 result = null;
1167 }
1168 }
1169
1170 if (result == null) {
1171 StringBundler query = new StringBundler(4);
1172
1173 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
1174
1175 query.append(_FINDER_COLUMN_Q_N_QUESTIONID_2);
1176
1177 boolean bindName = false;
1178
1179 if (name == null) {
1180 query.append(_FINDER_COLUMN_Q_N_NAME_1);
1181 }
1182 else if (name.equals(StringPool.BLANK)) {
1183 query.append(_FINDER_COLUMN_Q_N_NAME_3);
1184 }
1185 else {
1186 bindName = true;
1187
1188 query.append(_FINDER_COLUMN_Q_N_NAME_2);
1189 }
1190
1191 String sql = query.toString();
1192
1193 Session session = null;
1194
1195 try {
1196 session = openSession();
1197
1198 Query q = session.createQuery(sql);
1199
1200 QueryPos qPos = QueryPos.getInstance(q);
1201
1202 qPos.add(questionId);
1203
1204 if (bindName) {
1205 qPos.add(name);
1206 }
1207
1208 List<PollsChoice> list = q.list();
1209
1210 if (list.isEmpty()) {
1211 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
1212 finderArgs, list);
1213 }
1214 else {
1215 PollsChoice pollsChoice = list.get(0);
1216
1217 result = pollsChoice;
1218
1219 cacheResult(pollsChoice);
1220
1221 if ((pollsChoice.getQuestionId() != questionId) ||
1222 (pollsChoice.getName() == null) ||
1223 !pollsChoice.getName().equals(name)) {
1224 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
1225 finderArgs, pollsChoice);
1226 }
1227 }
1228 }
1229 catch (Exception e) {
1230 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N,
1231 finderArgs);
1232
1233 throw processException(e);
1234 }
1235 finally {
1236 closeSession(session);
1237 }
1238 }
1239
1240 if (result instanceof List<?>) {
1241 return null;
1242 }
1243 else {
1244 return (PollsChoice)result;
1245 }
1246 }
1247
1248
1256 public PollsChoice removeByQ_N(long questionId, String name)
1257 throws NoSuchChoiceException, SystemException {
1258 PollsChoice pollsChoice = findByQ_N(questionId, name);
1259
1260 return remove(pollsChoice);
1261 }
1262
1263
1271 public int countByQ_N(long questionId, String name)
1272 throws SystemException {
1273 FinderPath finderPath = FINDER_PATH_COUNT_BY_Q_N;
1274
1275 Object[] finderArgs = new Object[] { questionId, name };
1276
1277 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1278 this);
1279
1280 if (count == null) {
1281 StringBundler query = new StringBundler(3);
1282
1283 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
1284
1285 query.append(_FINDER_COLUMN_Q_N_QUESTIONID_2);
1286
1287 boolean bindName = false;
1288
1289 if (name == null) {
1290 query.append(_FINDER_COLUMN_Q_N_NAME_1);
1291 }
1292 else if (name.equals(StringPool.BLANK)) {
1293 query.append(_FINDER_COLUMN_Q_N_NAME_3);
1294 }
1295 else {
1296 bindName = true;
1297
1298 query.append(_FINDER_COLUMN_Q_N_NAME_2);
1299 }
1300
1301 String sql = query.toString();
1302
1303 Session session = null;
1304
1305 try {
1306 session = openSession();
1307
1308 Query q = session.createQuery(sql);
1309
1310 QueryPos qPos = QueryPos.getInstance(q);
1311
1312 qPos.add(questionId);
1313
1314 if (bindName) {
1315 qPos.add(name);
1316 }
1317
1318 count = (Long)q.uniqueResult();
1319
1320 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1321 }
1322 catch (Exception e) {
1323 FinderCacheUtil.removeResult(finderPath, finderArgs);
1324
1325 throw processException(e);
1326 }
1327 finally {
1328 closeSession(session);
1329 }
1330 }
1331
1332 return count.intValue();
1333 }
1334
1335 private static final String _FINDER_COLUMN_Q_N_QUESTIONID_2 = "pollsChoice.questionId = ? AND ";
1336 private static final String _FINDER_COLUMN_Q_N_NAME_1 = "pollsChoice.name IS NULL";
1337 private static final String _FINDER_COLUMN_Q_N_NAME_2 = "pollsChoice.name = ?";
1338 private static final String _FINDER_COLUMN_Q_N_NAME_3 = "(pollsChoice.name IS NULL OR pollsChoice.name = '')";
1339
1340
1345 public void cacheResult(PollsChoice pollsChoice) {
1346 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
1347 PollsChoiceImpl.class, pollsChoice.getPrimaryKey(), pollsChoice);
1348
1349 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
1350 new Object[] { pollsChoice.getQuestionId(), pollsChoice.getName() },
1351 pollsChoice);
1352
1353 pollsChoice.resetOriginalValues();
1354 }
1355
1356
1361 public void cacheResult(List<PollsChoice> pollsChoices) {
1362 for (PollsChoice pollsChoice : pollsChoices) {
1363 if (EntityCacheUtil.getResult(
1364 PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
1365 PollsChoiceImpl.class, pollsChoice.getPrimaryKey()) == null) {
1366 cacheResult(pollsChoice);
1367 }
1368 else {
1369 pollsChoice.resetOriginalValues();
1370 }
1371 }
1372 }
1373
1374
1381 @Override
1382 public void clearCache() {
1383 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1384 CacheRegistryUtil.clear(PollsChoiceImpl.class.getName());
1385 }
1386
1387 EntityCacheUtil.clearCache(PollsChoiceImpl.class.getName());
1388
1389 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1390 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1391 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1392 }
1393
1394
1401 @Override
1402 public void clearCache(PollsChoice pollsChoice) {
1403 EntityCacheUtil.removeResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
1404 PollsChoiceImpl.class, pollsChoice.getPrimaryKey());
1405
1406 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1407 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1408
1409 clearUniqueFindersCache(pollsChoice);
1410 }
1411
1412 @Override
1413 public void clearCache(List<PollsChoice> pollsChoices) {
1414 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1415 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1416
1417 for (PollsChoice pollsChoice : pollsChoices) {
1418 EntityCacheUtil.removeResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
1419 PollsChoiceImpl.class, pollsChoice.getPrimaryKey());
1420
1421 clearUniqueFindersCache(pollsChoice);
1422 }
1423 }
1424
1425 protected void cacheUniqueFindersCache(PollsChoice pollsChoice) {
1426 if (pollsChoice.isNew()) {
1427 Object[] args = new Object[] {
1428 pollsChoice.getQuestionId(), pollsChoice.getName()
1429 };
1430
1431 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_Q_N, args,
1432 Long.valueOf(1));
1433 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N, args,
1434 pollsChoice);
1435 }
1436 else {
1437 PollsChoiceModelImpl pollsChoiceModelImpl = (PollsChoiceModelImpl)pollsChoice;
1438
1439 if ((pollsChoiceModelImpl.getColumnBitmask() &
1440 FINDER_PATH_FETCH_BY_Q_N.getColumnBitmask()) != 0) {
1441 Object[] args = new Object[] {
1442 pollsChoice.getQuestionId(), pollsChoice.getName()
1443 };
1444
1445 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_Q_N, args,
1446 Long.valueOf(1));
1447 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N, args,
1448 pollsChoice);
1449 }
1450 }
1451 }
1452
1453 protected void clearUniqueFindersCache(PollsChoice pollsChoice) {
1454 PollsChoiceModelImpl pollsChoiceModelImpl = (PollsChoiceModelImpl)pollsChoice;
1455
1456 Object[] args = new Object[] {
1457 pollsChoice.getQuestionId(), pollsChoice.getName()
1458 };
1459
1460 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_Q_N, args);
1461 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N, args);
1462
1463 if ((pollsChoiceModelImpl.getColumnBitmask() &
1464 FINDER_PATH_FETCH_BY_Q_N.getColumnBitmask()) != 0) {
1465 args = new Object[] {
1466 pollsChoiceModelImpl.getOriginalQuestionId(),
1467 pollsChoiceModelImpl.getOriginalName()
1468 };
1469
1470 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_Q_N, args);
1471 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N, args);
1472 }
1473 }
1474
1475
1481 public PollsChoice create(long choiceId) {
1482 PollsChoice pollsChoice = new PollsChoiceImpl();
1483
1484 pollsChoice.setNew(true);
1485 pollsChoice.setPrimaryKey(choiceId);
1486
1487 String uuid = PortalUUIDUtil.generate();
1488
1489 pollsChoice.setUuid(uuid);
1490
1491 return pollsChoice;
1492 }
1493
1494
1502 public PollsChoice remove(long choiceId)
1503 throws NoSuchChoiceException, SystemException {
1504 return remove((Serializable)choiceId);
1505 }
1506
1507
1515 @Override
1516 public PollsChoice remove(Serializable primaryKey)
1517 throws NoSuchChoiceException, SystemException {
1518 Session session = null;
1519
1520 try {
1521 session = openSession();
1522
1523 PollsChoice pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
1524 primaryKey);
1525
1526 if (pollsChoice == null) {
1527 if (_log.isWarnEnabled()) {
1528 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1529 }
1530
1531 throw new NoSuchChoiceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1532 primaryKey);
1533 }
1534
1535 return remove(pollsChoice);
1536 }
1537 catch (NoSuchChoiceException nsee) {
1538 throw nsee;
1539 }
1540 catch (Exception e) {
1541 throw processException(e);
1542 }
1543 finally {
1544 closeSession(session);
1545 }
1546 }
1547
1548 @Override
1549 protected PollsChoice removeImpl(PollsChoice pollsChoice)
1550 throws SystemException {
1551 pollsChoice = toUnwrappedModel(pollsChoice);
1552
1553 Session session = null;
1554
1555 try {
1556 session = openSession();
1557
1558 if (!session.contains(pollsChoice)) {
1559 pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
1560 pollsChoice.getPrimaryKeyObj());
1561 }
1562
1563 if (pollsChoice != null) {
1564 session.delete(pollsChoice);
1565 }
1566 }
1567 catch (Exception e) {
1568 throw processException(e);
1569 }
1570 finally {
1571 closeSession(session);
1572 }
1573
1574 if (pollsChoice != null) {
1575 clearCache(pollsChoice);
1576 }
1577
1578 return pollsChoice;
1579 }
1580
1581 @Override
1582 public PollsChoice updateImpl(
1583 com.liferay.portlet.polls.model.PollsChoice pollsChoice)
1584 throws SystemException {
1585 pollsChoice = toUnwrappedModel(pollsChoice);
1586
1587 boolean isNew = pollsChoice.isNew();
1588
1589 PollsChoiceModelImpl pollsChoiceModelImpl = (PollsChoiceModelImpl)pollsChoice;
1590
1591 if (Validator.isNull(pollsChoice.getUuid())) {
1592 String uuid = PortalUUIDUtil.generate();
1593
1594 pollsChoice.setUuid(uuid);
1595 }
1596
1597 Session session = null;
1598
1599 try {
1600 session = openSession();
1601
1602 if (pollsChoice.isNew()) {
1603 session.save(pollsChoice);
1604
1605 pollsChoice.setNew(false);
1606 }
1607 else {
1608 session.merge(pollsChoice);
1609 }
1610 }
1611 catch (Exception e) {
1612 throw processException(e);
1613 }
1614 finally {
1615 closeSession(session);
1616 }
1617
1618 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1619
1620 if (isNew || !PollsChoiceModelImpl.COLUMN_BITMASK_ENABLED) {
1621 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1622 }
1623
1624 else {
1625 if ((pollsChoiceModelImpl.getColumnBitmask() &
1626 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
1627 Object[] args = new Object[] {
1628 pollsChoiceModelImpl.getOriginalUuid()
1629 };
1630
1631 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
1632 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
1633 args);
1634
1635 args = new Object[] { pollsChoiceModelImpl.getUuid() };
1636
1637 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
1638 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
1639 args);
1640 }
1641
1642 if ((pollsChoiceModelImpl.getColumnBitmask() &
1643 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID.getColumnBitmask()) != 0) {
1644 Object[] args = new Object[] {
1645 pollsChoiceModelImpl.getOriginalQuestionId()
1646 };
1647
1648 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1649 args);
1650 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
1651 args);
1652
1653 args = new Object[] { pollsChoiceModelImpl.getQuestionId() };
1654
1655 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1656 args);
1657 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
1658 args);
1659 }
1660 }
1661
1662 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
1663 PollsChoiceImpl.class, pollsChoice.getPrimaryKey(), pollsChoice);
1664
1665 clearUniqueFindersCache(pollsChoice);
1666 cacheUniqueFindersCache(pollsChoice);
1667
1668 return pollsChoice;
1669 }
1670
1671 protected PollsChoice toUnwrappedModel(PollsChoice pollsChoice) {
1672 if (pollsChoice instanceof PollsChoiceImpl) {
1673 return pollsChoice;
1674 }
1675
1676 PollsChoiceImpl pollsChoiceImpl = new PollsChoiceImpl();
1677
1678 pollsChoiceImpl.setNew(pollsChoice.isNew());
1679 pollsChoiceImpl.setPrimaryKey(pollsChoice.getPrimaryKey());
1680
1681 pollsChoiceImpl.setUuid(pollsChoice.getUuid());
1682 pollsChoiceImpl.setChoiceId(pollsChoice.getChoiceId());
1683 pollsChoiceImpl.setQuestionId(pollsChoice.getQuestionId());
1684 pollsChoiceImpl.setName(pollsChoice.getName());
1685 pollsChoiceImpl.setDescription(pollsChoice.getDescription());
1686
1687 return pollsChoiceImpl;
1688 }
1689
1690
1698 @Override
1699 public PollsChoice findByPrimaryKey(Serializable primaryKey)
1700 throws NoSuchChoiceException, SystemException {
1701 PollsChoice pollsChoice = fetchByPrimaryKey(primaryKey);
1702
1703 if (pollsChoice == null) {
1704 if (_log.isWarnEnabled()) {
1705 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1706 }
1707
1708 throw new NoSuchChoiceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1709 primaryKey);
1710 }
1711
1712 return pollsChoice;
1713 }
1714
1715
1723 public PollsChoice findByPrimaryKey(long choiceId)
1724 throws NoSuchChoiceException, SystemException {
1725 return findByPrimaryKey((Serializable)choiceId);
1726 }
1727
1728
1735 @Override
1736 public PollsChoice fetchByPrimaryKey(Serializable primaryKey)
1737 throws SystemException {
1738 PollsChoice pollsChoice = (PollsChoice)EntityCacheUtil.getResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
1739 PollsChoiceImpl.class, primaryKey);
1740
1741 if (pollsChoice == _nullPollsChoice) {
1742 return null;
1743 }
1744
1745 if (pollsChoice == null) {
1746 Session session = null;
1747
1748 try {
1749 session = openSession();
1750
1751 pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
1752 primaryKey);
1753
1754 if (pollsChoice != null) {
1755 cacheResult(pollsChoice);
1756 }
1757 else {
1758 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
1759 PollsChoiceImpl.class, primaryKey, _nullPollsChoice);
1760 }
1761 }
1762 catch (Exception e) {
1763 EntityCacheUtil.removeResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
1764 PollsChoiceImpl.class, primaryKey);
1765
1766 throw processException(e);
1767 }
1768 finally {
1769 closeSession(session);
1770 }
1771 }
1772
1773 return pollsChoice;
1774 }
1775
1776
1783 public PollsChoice fetchByPrimaryKey(long choiceId)
1784 throws SystemException {
1785 return fetchByPrimaryKey((Serializable)choiceId);
1786 }
1787
1788
1794 public List<PollsChoice> findAll() throws SystemException {
1795 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1796 }
1797
1798
1810 public List<PollsChoice> findAll(int start, int end)
1811 throws SystemException {
1812 return findAll(start, end, null);
1813 }
1814
1815
1828 public List<PollsChoice> findAll(int start, int end,
1829 OrderByComparator orderByComparator) throws SystemException {
1830 boolean pagination = true;
1831 FinderPath finderPath = null;
1832 Object[] finderArgs = null;
1833
1834 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1835 (orderByComparator == null)) {
1836 pagination = false;
1837 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1838 finderArgs = FINDER_ARGS_EMPTY;
1839 }
1840 else {
1841 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1842 finderArgs = new Object[] { start, end, orderByComparator };
1843 }
1844
1845 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
1846 finderArgs, this);
1847
1848 if (list == null) {
1849 StringBundler query = null;
1850 String sql = null;
1851
1852 if (orderByComparator != null) {
1853 query = new StringBundler(2 +
1854 (orderByComparator.getOrderByFields().length * 3));
1855
1856 query.append(_SQL_SELECT_POLLSCHOICE);
1857
1858 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1859 orderByComparator);
1860
1861 sql = query.toString();
1862 }
1863 else {
1864 sql = _SQL_SELECT_POLLSCHOICE;
1865
1866 if (pagination) {
1867 sql = sql.concat(PollsChoiceModelImpl.ORDER_BY_JPQL);
1868 }
1869 }
1870
1871 Session session = null;
1872
1873 try {
1874 session = openSession();
1875
1876 Query q = session.createQuery(sql);
1877
1878 if (!pagination) {
1879 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1880 start, end, false);
1881
1882 Collections.sort(list);
1883
1884 list = new UnmodifiableList<PollsChoice>(list);
1885 }
1886 else {
1887 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1888 start, end);
1889 }
1890
1891 cacheResult(list);
1892
1893 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1894 }
1895 catch (Exception e) {
1896 FinderCacheUtil.removeResult(finderPath, finderArgs);
1897
1898 throw processException(e);
1899 }
1900 finally {
1901 closeSession(session);
1902 }
1903 }
1904
1905 return list;
1906 }
1907
1908
1913 public void removeAll() throws SystemException {
1914 for (PollsChoice pollsChoice : findAll()) {
1915 remove(pollsChoice);
1916 }
1917 }
1918
1919
1925 public int countAll() throws SystemException {
1926 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1927 FINDER_ARGS_EMPTY, this);
1928
1929 if (count == null) {
1930 Session session = null;
1931
1932 try {
1933 session = openSession();
1934
1935 Query q = session.createQuery(_SQL_COUNT_POLLSCHOICE);
1936
1937 count = (Long)q.uniqueResult();
1938
1939 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1940 FINDER_ARGS_EMPTY, count);
1941 }
1942 catch (Exception e) {
1943 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1944 FINDER_ARGS_EMPTY);
1945
1946 throw processException(e);
1947 }
1948 finally {
1949 closeSession(session);
1950 }
1951 }
1952
1953 return count.intValue();
1954 }
1955
1956
1959 public void afterPropertiesSet() {
1960 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1961 com.liferay.portal.util.PropsUtil.get(
1962 "value.object.listener.com.liferay.portlet.polls.model.PollsChoice")));
1963
1964 if (listenerClassNames.length > 0) {
1965 try {
1966 List<ModelListener<PollsChoice>> listenersList = new ArrayList<ModelListener<PollsChoice>>();
1967
1968 for (String listenerClassName : listenerClassNames) {
1969 listenersList.add((ModelListener<PollsChoice>)InstanceFactory.newInstance(
1970 listenerClassName));
1971 }
1972
1973 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1974 }
1975 catch (Exception e) {
1976 _log.error(e);
1977 }
1978 }
1979 }
1980
1981 public void destroy() {
1982 EntityCacheUtil.removeCache(PollsChoiceImpl.class.getName());
1983 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1984 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1985 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1986 }
1987
1988 private static final String _SQL_SELECT_POLLSCHOICE = "SELECT pollsChoice FROM PollsChoice pollsChoice";
1989 private static final String _SQL_SELECT_POLLSCHOICE_WHERE = "SELECT pollsChoice FROM PollsChoice pollsChoice WHERE ";
1990 private static final String _SQL_COUNT_POLLSCHOICE = "SELECT COUNT(pollsChoice) FROM PollsChoice pollsChoice";
1991 private static final String _SQL_COUNT_POLLSCHOICE_WHERE = "SELECT COUNT(pollsChoice) FROM PollsChoice pollsChoice WHERE ";
1992 private static final String _ORDER_BY_ENTITY_ALIAS = "pollsChoice.";
1993 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsChoice exists with the primary key ";
1994 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsChoice exists with the key {";
1995 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1996 private static Log _log = LogFactoryUtil.getLog(PollsChoicePersistenceImpl.class);
1997 private static PollsChoice _nullPollsChoice = new PollsChoiceImpl() {
1998 @Override
1999 public Object clone() {
2000 return this;
2001 }
2002
2003 @Override
2004 public CacheModel<PollsChoice> toCacheModel() {
2005 return _nullPollsChoiceCacheModel;
2006 }
2007 };
2008
2009 private static CacheModel<PollsChoice> _nullPollsChoiceCacheModel = new CacheModel<PollsChoice>() {
2010 public PollsChoice toEntityModel() {
2011 return _nullPollsChoice;
2012 }
2013 };
2014 }