001
014
015 package com.liferay.portlet.polls.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
039
040 import com.liferay.portlet.polls.NoSuchVoteException;
041 import com.liferay.portlet.polls.model.PollsVote;
042 import com.liferay.portlet.polls.model.impl.PollsVoteImpl;
043 import com.liferay.portlet.polls.model.impl.PollsVoteModelImpl;
044
045 import java.io.Serializable;
046
047 import java.util.ArrayList;
048 import java.util.Collections;
049 import java.util.List;
050
051
063 public class PollsVotePersistenceImpl extends BasePersistenceImpl<PollsVote>
064 implements PollsVotePersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = PollsVoteImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
076 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
077 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
078 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
079 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
080 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
082 PollsVoteModelImpl.FINDER_CACHE_ENABLED, Long.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
084 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_QUESTIONID =
085 new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
086 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
087 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByQuestionId",
088 new String[] {
089 Long.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_QUESTIONID =
095 new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
096 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByQuestionId",
098 new String[] { Long.class.getName() },
099 PollsVoteModelImpl.QUESTIONID_COLUMN_BITMASK);
100 public static final FinderPath FINDER_PATH_COUNT_BY_QUESTIONID = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
101 PollsVoteModelImpl.FINDER_CACHE_ENABLED, Long.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByQuestionId",
103 new String[] { Long.class.getName() });
104
105
112 public List<PollsVote> findByQuestionId(long questionId)
113 throws SystemException {
114 return findByQuestionId(questionId, QueryUtil.ALL_POS,
115 QueryUtil.ALL_POS, null);
116 }
117
118
131 public List<PollsVote> findByQuestionId(long questionId, int start, int end)
132 throws SystemException {
133 return findByQuestionId(questionId, start, end, null);
134 }
135
136
150 public List<PollsVote> findByQuestionId(long questionId, int start,
151 int end, OrderByComparator orderByComparator) throws SystemException {
152 boolean pagination = true;
153 FinderPath finderPath = null;
154 Object[] finderArgs = null;
155
156 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
157 (orderByComparator == null)) {
158 pagination = false;
159 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID;
160 finderArgs = new Object[] { questionId };
161 }
162 else {
163 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_QUESTIONID;
164 finderArgs = new Object[] { questionId, start, end, orderByComparator };
165 }
166
167 List<PollsVote> list = (List<PollsVote>)FinderCacheUtil.getResult(finderPath,
168 finderArgs, this);
169
170 if ((list != null) && !list.isEmpty()) {
171 for (PollsVote pollsVote : list) {
172 if ((questionId != pollsVote.getQuestionId())) {
173 list = null;
174
175 break;
176 }
177 }
178 }
179
180 if (list == null) {
181 StringBundler query = null;
182
183 if (orderByComparator != null) {
184 query = new StringBundler(3 +
185 (orderByComparator.getOrderByFields().length * 3));
186 }
187 else {
188 query = new StringBundler(3);
189 }
190
191 query.append(_SQL_SELECT_POLLSVOTE_WHERE);
192
193 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
194
195 if (orderByComparator != null) {
196 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
197 orderByComparator);
198 }
199 else
200 if (pagination) {
201 query.append(PollsVoteModelImpl.ORDER_BY_JPQL);
202 }
203
204 String sql = query.toString();
205
206 Session session = null;
207
208 try {
209 session = openSession();
210
211 Query q = session.createQuery(sql);
212
213 QueryPos qPos = QueryPos.getInstance(q);
214
215 qPos.add(questionId);
216
217 if (!pagination) {
218 list = (List<PollsVote>)QueryUtil.list(q, getDialect(),
219 start, end, false);
220
221 Collections.sort(list);
222
223 list = new UnmodifiableList<PollsVote>(list);
224 }
225 else {
226 list = (List<PollsVote>)QueryUtil.list(q, getDialect(),
227 start, end);
228 }
229
230 cacheResult(list);
231
232 FinderCacheUtil.putResult(finderPath, finderArgs, list);
233 }
234 catch (Exception e) {
235 FinderCacheUtil.removeResult(finderPath, finderArgs);
236
237 throw processException(e);
238 }
239 finally {
240 closeSession(session);
241 }
242 }
243
244 return list;
245 }
246
247
256 public PollsVote findByQuestionId_First(long questionId,
257 OrderByComparator orderByComparator)
258 throws NoSuchVoteException, SystemException {
259 PollsVote pollsVote = fetchByQuestionId_First(questionId,
260 orderByComparator);
261
262 if (pollsVote != null) {
263 return pollsVote;
264 }
265
266 StringBundler msg = new StringBundler(4);
267
268 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
269
270 msg.append("questionId=");
271 msg.append(questionId);
272
273 msg.append(StringPool.CLOSE_CURLY_BRACE);
274
275 throw new NoSuchVoteException(msg.toString());
276 }
277
278
286 public PollsVote fetchByQuestionId_First(long questionId,
287 OrderByComparator orderByComparator) throws SystemException {
288 List<PollsVote> list = findByQuestionId(questionId, 0, 1,
289 orderByComparator);
290
291 if (!list.isEmpty()) {
292 return list.get(0);
293 }
294
295 return null;
296 }
297
298
307 public PollsVote findByQuestionId_Last(long questionId,
308 OrderByComparator orderByComparator)
309 throws NoSuchVoteException, SystemException {
310 PollsVote pollsVote = fetchByQuestionId_Last(questionId,
311 orderByComparator);
312
313 if (pollsVote != null) {
314 return pollsVote;
315 }
316
317 StringBundler msg = new StringBundler(4);
318
319 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
320
321 msg.append("questionId=");
322 msg.append(questionId);
323
324 msg.append(StringPool.CLOSE_CURLY_BRACE);
325
326 throw new NoSuchVoteException(msg.toString());
327 }
328
329
337 public PollsVote fetchByQuestionId_Last(long questionId,
338 OrderByComparator orderByComparator) throws SystemException {
339 int count = countByQuestionId(questionId);
340
341 List<PollsVote> list = findByQuestionId(questionId, count - 1, count,
342 orderByComparator);
343
344 if (!list.isEmpty()) {
345 return list.get(0);
346 }
347
348 return null;
349 }
350
351
361 public PollsVote[] findByQuestionId_PrevAndNext(long voteId,
362 long questionId, OrderByComparator orderByComparator)
363 throws NoSuchVoteException, SystemException {
364 PollsVote pollsVote = findByPrimaryKey(voteId);
365
366 Session session = null;
367
368 try {
369 session = openSession();
370
371 PollsVote[] array = new PollsVoteImpl[3];
372
373 array[0] = getByQuestionId_PrevAndNext(session, pollsVote,
374 questionId, orderByComparator, true);
375
376 array[1] = pollsVote;
377
378 array[2] = getByQuestionId_PrevAndNext(session, pollsVote,
379 questionId, orderByComparator, false);
380
381 return array;
382 }
383 catch (Exception e) {
384 throw processException(e);
385 }
386 finally {
387 closeSession(session);
388 }
389 }
390
391 protected PollsVote getByQuestionId_PrevAndNext(Session session,
392 PollsVote pollsVote, long questionId,
393 OrderByComparator orderByComparator, boolean previous) {
394 StringBundler query = null;
395
396 if (orderByComparator != null) {
397 query = new StringBundler(6 +
398 (orderByComparator.getOrderByFields().length * 6));
399 }
400 else {
401 query = new StringBundler(3);
402 }
403
404 query.append(_SQL_SELECT_POLLSVOTE_WHERE);
405
406 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
407
408 if (orderByComparator != null) {
409 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
410
411 if (orderByConditionFields.length > 0) {
412 query.append(WHERE_AND);
413 }
414
415 for (int i = 0; i < orderByConditionFields.length; i++) {
416 query.append(_ORDER_BY_ENTITY_ALIAS);
417 query.append(orderByConditionFields[i]);
418
419 if ((i + 1) < orderByConditionFields.length) {
420 if (orderByComparator.isAscending() ^ previous) {
421 query.append(WHERE_GREATER_THAN_HAS_NEXT);
422 }
423 else {
424 query.append(WHERE_LESSER_THAN_HAS_NEXT);
425 }
426 }
427 else {
428 if (orderByComparator.isAscending() ^ previous) {
429 query.append(WHERE_GREATER_THAN);
430 }
431 else {
432 query.append(WHERE_LESSER_THAN);
433 }
434 }
435 }
436
437 query.append(ORDER_BY_CLAUSE);
438
439 String[] orderByFields = orderByComparator.getOrderByFields();
440
441 for (int i = 0; i < orderByFields.length; i++) {
442 query.append(_ORDER_BY_ENTITY_ALIAS);
443 query.append(orderByFields[i]);
444
445 if ((i + 1) < orderByFields.length) {
446 if (orderByComparator.isAscending() ^ previous) {
447 query.append(ORDER_BY_ASC_HAS_NEXT);
448 }
449 else {
450 query.append(ORDER_BY_DESC_HAS_NEXT);
451 }
452 }
453 else {
454 if (orderByComparator.isAscending() ^ previous) {
455 query.append(ORDER_BY_ASC);
456 }
457 else {
458 query.append(ORDER_BY_DESC);
459 }
460 }
461 }
462 }
463 else {
464 query.append(PollsVoteModelImpl.ORDER_BY_JPQL);
465 }
466
467 String sql = query.toString();
468
469 Query q = session.createQuery(sql);
470
471 q.setFirstResult(0);
472 q.setMaxResults(2);
473
474 QueryPos qPos = QueryPos.getInstance(q);
475
476 qPos.add(questionId);
477
478 if (orderByComparator != null) {
479 Object[] values = orderByComparator.getOrderByConditionValues(pollsVote);
480
481 for (Object value : values) {
482 qPos.add(value);
483 }
484 }
485
486 List<PollsVote> list = q.list();
487
488 if (list.size() == 2) {
489 return list.get(1);
490 }
491 else {
492 return null;
493 }
494 }
495
496
502 public void removeByQuestionId(long questionId) throws SystemException {
503 for (PollsVote pollsVote : findByQuestionId(questionId,
504 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
505 remove(pollsVote);
506 }
507 }
508
509
516 public int countByQuestionId(long questionId) throws SystemException {
517 FinderPath finderPath = FINDER_PATH_COUNT_BY_QUESTIONID;
518
519 Object[] finderArgs = new Object[] { questionId };
520
521 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
522 this);
523
524 if (count == null) {
525 StringBundler query = new StringBundler(2);
526
527 query.append(_SQL_COUNT_POLLSVOTE_WHERE);
528
529 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
530
531 String sql = query.toString();
532
533 Session session = null;
534
535 try {
536 session = openSession();
537
538 Query q = session.createQuery(sql);
539
540 QueryPos qPos = QueryPos.getInstance(q);
541
542 qPos.add(questionId);
543
544 count = (Long)q.uniqueResult();
545
546 FinderCacheUtil.putResult(finderPath, finderArgs, count);
547 }
548 catch (Exception e) {
549 FinderCacheUtil.removeResult(finderPath, finderArgs);
550
551 throw processException(e);
552 }
553 finally {
554 closeSession(session);
555 }
556 }
557
558 return count.intValue();
559 }
560
561 private static final String _FINDER_COLUMN_QUESTIONID_QUESTIONID_2 = "pollsVote.questionId = ?";
562 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CHOICEID = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
563 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
564 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByChoiceId",
565 new String[] {
566 Long.class.getName(),
567
568 Integer.class.getName(), Integer.class.getName(),
569 OrderByComparator.class.getName()
570 });
571 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CHOICEID =
572 new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
573 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
574 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByChoiceId",
575 new String[] { Long.class.getName() },
576 PollsVoteModelImpl.CHOICEID_COLUMN_BITMASK);
577 public static final FinderPath FINDER_PATH_COUNT_BY_CHOICEID = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
578 PollsVoteModelImpl.FINDER_CACHE_ENABLED, Long.class,
579 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByChoiceId",
580 new String[] { Long.class.getName() });
581
582
589 public List<PollsVote> findByChoiceId(long choiceId)
590 throws SystemException {
591 return findByChoiceId(choiceId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
592 null);
593 }
594
595
608 public List<PollsVote> findByChoiceId(long choiceId, int start, int end)
609 throws SystemException {
610 return findByChoiceId(choiceId, start, end, null);
611 }
612
613
627 public List<PollsVote> findByChoiceId(long choiceId, int start, int end,
628 OrderByComparator orderByComparator) throws SystemException {
629 boolean pagination = true;
630 FinderPath finderPath = null;
631 Object[] finderArgs = null;
632
633 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
634 (orderByComparator == null)) {
635 pagination = false;
636 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CHOICEID;
637 finderArgs = new Object[] { choiceId };
638 }
639 else {
640 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CHOICEID;
641 finderArgs = new Object[] { choiceId, start, end, orderByComparator };
642 }
643
644 List<PollsVote> list = (List<PollsVote>)FinderCacheUtil.getResult(finderPath,
645 finderArgs, this);
646
647 if ((list != null) && !list.isEmpty()) {
648 for (PollsVote pollsVote : list) {
649 if ((choiceId != pollsVote.getChoiceId())) {
650 list = null;
651
652 break;
653 }
654 }
655 }
656
657 if (list == null) {
658 StringBundler query = null;
659
660 if (orderByComparator != null) {
661 query = new StringBundler(3 +
662 (orderByComparator.getOrderByFields().length * 3));
663 }
664 else {
665 query = new StringBundler(3);
666 }
667
668 query.append(_SQL_SELECT_POLLSVOTE_WHERE);
669
670 query.append(_FINDER_COLUMN_CHOICEID_CHOICEID_2);
671
672 if (orderByComparator != null) {
673 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
674 orderByComparator);
675 }
676 else
677 if (pagination) {
678 query.append(PollsVoteModelImpl.ORDER_BY_JPQL);
679 }
680
681 String sql = query.toString();
682
683 Session session = null;
684
685 try {
686 session = openSession();
687
688 Query q = session.createQuery(sql);
689
690 QueryPos qPos = QueryPos.getInstance(q);
691
692 qPos.add(choiceId);
693
694 if (!pagination) {
695 list = (List<PollsVote>)QueryUtil.list(q, getDialect(),
696 start, end, false);
697
698 Collections.sort(list);
699
700 list = new UnmodifiableList<PollsVote>(list);
701 }
702 else {
703 list = (List<PollsVote>)QueryUtil.list(q, getDialect(),
704 start, end);
705 }
706
707 cacheResult(list);
708
709 FinderCacheUtil.putResult(finderPath, finderArgs, list);
710 }
711 catch (Exception e) {
712 FinderCacheUtil.removeResult(finderPath, finderArgs);
713
714 throw processException(e);
715 }
716 finally {
717 closeSession(session);
718 }
719 }
720
721 return list;
722 }
723
724
733 public PollsVote findByChoiceId_First(long choiceId,
734 OrderByComparator orderByComparator)
735 throws NoSuchVoteException, SystemException {
736 PollsVote pollsVote = fetchByChoiceId_First(choiceId, orderByComparator);
737
738 if (pollsVote != null) {
739 return pollsVote;
740 }
741
742 StringBundler msg = new StringBundler(4);
743
744 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
745
746 msg.append("choiceId=");
747 msg.append(choiceId);
748
749 msg.append(StringPool.CLOSE_CURLY_BRACE);
750
751 throw new NoSuchVoteException(msg.toString());
752 }
753
754
762 public PollsVote fetchByChoiceId_First(long choiceId,
763 OrderByComparator orderByComparator) throws SystemException {
764 List<PollsVote> list = findByChoiceId(choiceId, 0, 1, orderByComparator);
765
766 if (!list.isEmpty()) {
767 return list.get(0);
768 }
769
770 return null;
771 }
772
773
782 public PollsVote findByChoiceId_Last(long choiceId,
783 OrderByComparator orderByComparator)
784 throws NoSuchVoteException, SystemException {
785 PollsVote pollsVote = fetchByChoiceId_Last(choiceId, orderByComparator);
786
787 if (pollsVote != null) {
788 return pollsVote;
789 }
790
791 StringBundler msg = new StringBundler(4);
792
793 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
794
795 msg.append("choiceId=");
796 msg.append(choiceId);
797
798 msg.append(StringPool.CLOSE_CURLY_BRACE);
799
800 throw new NoSuchVoteException(msg.toString());
801 }
802
803
811 public PollsVote fetchByChoiceId_Last(long choiceId,
812 OrderByComparator orderByComparator) throws SystemException {
813 int count = countByChoiceId(choiceId);
814
815 List<PollsVote> list = findByChoiceId(choiceId, count - 1, count,
816 orderByComparator);
817
818 if (!list.isEmpty()) {
819 return list.get(0);
820 }
821
822 return null;
823 }
824
825
835 public PollsVote[] findByChoiceId_PrevAndNext(long voteId, long choiceId,
836 OrderByComparator orderByComparator)
837 throws NoSuchVoteException, SystemException {
838 PollsVote pollsVote = findByPrimaryKey(voteId);
839
840 Session session = null;
841
842 try {
843 session = openSession();
844
845 PollsVote[] array = new PollsVoteImpl[3];
846
847 array[0] = getByChoiceId_PrevAndNext(session, pollsVote, choiceId,
848 orderByComparator, true);
849
850 array[1] = pollsVote;
851
852 array[2] = getByChoiceId_PrevAndNext(session, pollsVote, choiceId,
853 orderByComparator, false);
854
855 return array;
856 }
857 catch (Exception e) {
858 throw processException(e);
859 }
860 finally {
861 closeSession(session);
862 }
863 }
864
865 protected PollsVote getByChoiceId_PrevAndNext(Session session,
866 PollsVote pollsVote, long choiceId,
867 OrderByComparator orderByComparator, boolean previous) {
868 StringBundler query = null;
869
870 if (orderByComparator != null) {
871 query = new StringBundler(6 +
872 (orderByComparator.getOrderByFields().length * 6));
873 }
874 else {
875 query = new StringBundler(3);
876 }
877
878 query.append(_SQL_SELECT_POLLSVOTE_WHERE);
879
880 query.append(_FINDER_COLUMN_CHOICEID_CHOICEID_2);
881
882 if (orderByComparator != null) {
883 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
884
885 if (orderByConditionFields.length > 0) {
886 query.append(WHERE_AND);
887 }
888
889 for (int i = 0; i < orderByConditionFields.length; i++) {
890 query.append(_ORDER_BY_ENTITY_ALIAS);
891 query.append(orderByConditionFields[i]);
892
893 if ((i + 1) < orderByConditionFields.length) {
894 if (orderByComparator.isAscending() ^ previous) {
895 query.append(WHERE_GREATER_THAN_HAS_NEXT);
896 }
897 else {
898 query.append(WHERE_LESSER_THAN_HAS_NEXT);
899 }
900 }
901 else {
902 if (orderByComparator.isAscending() ^ previous) {
903 query.append(WHERE_GREATER_THAN);
904 }
905 else {
906 query.append(WHERE_LESSER_THAN);
907 }
908 }
909 }
910
911 query.append(ORDER_BY_CLAUSE);
912
913 String[] orderByFields = orderByComparator.getOrderByFields();
914
915 for (int i = 0; i < orderByFields.length; i++) {
916 query.append(_ORDER_BY_ENTITY_ALIAS);
917 query.append(orderByFields[i]);
918
919 if ((i + 1) < orderByFields.length) {
920 if (orderByComparator.isAscending() ^ previous) {
921 query.append(ORDER_BY_ASC_HAS_NEXT);
922 }
923 else {
924 query.append(ORDER_BY_DESC_HAS_NEXT);
925 }
926 }
927 else {
928 if (orderByComparator.isAscending() ^ previous) {
929 query.append(ORDER_BY_ASC);
930 }
931 else {
932 query.append(ORDER_BY_DESC);
933 }
934 }
935 }
936 }
937 else {
938 query.append(PollsVoteModelImpl.ORDER_BY_JPQL);
939 }
940
941 String sql = query.toString();
942
943 Query q = session.createQuery(sql);
944
945 q.setFirstResult(0);
946 q.setMaxResults(2);
947
948 QueryPos qPos = QueryPos.getInstance(q);
949
950 qPos.add(choiceId);
951
952 if (orderByComparator != null) {
953 Object[] values = orderByComparator.getOrderByConditionValues(pollsVote);
954
955 for (Object value : values) {
956 qPos.add(value);
957 }
958 }
959
960 List<PollsVote> list = q.list();
961
962 if (list.size() == 2) {
963 return list.get(1);
964 }
965 else {
966 return null;
967 }
968 }
969
970
976 public void removeByChoiceId(long choiceId) throws SystemException {
977 for (PollsVote pollsVote : findByChoiceId(choiceId, QueryUtil.ALL_POS,
978 QueryUtil.ALL_POS, null)) {
979 remove(pollsVote);
980 }
981 }
982
983
990 public int countByChoiceId(long choiceId) throws SystemException {
991 FinderPath finderPath = FINDER_PATH_COUNT_BY_CHOICEID;
992
993 Object[] finderArgs = new Object[] { choiceId };
994
995 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
996 this);
997
998 if (count == null) {
999 StringBundler query = new StringBundler(2);
1000
1001 query.append(_SQL_COUNT_POLLSVOTE_WHERE);
1002
1003 query.append(_FINDER_COLUMN_CHOICEID_CHOICEID_2);
1004
1005 String sql = query.toString();
1006
1007 Session session = null;
1008
1009 try {
1010 session = openSession();
1011
1012 Query q = session.createQuery(sql);
1013
1014 QueryPos qPos = QueryPos.getInstance(q);
1015
1016 qPos.add(choiceId);
1017
1018 count = (Long)q.uniqueResult();
1019
1020 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1021 }
1022 catch (Exception e) {
1023 FinderCacheUtil.removeResult(finderPath, finderArgs);
1024
1025 throw processException(e);
1026 }
1027 finally {
1028 closeSession(session);
1029 }
1030 }
1031
1032 return count.intValue();
1033 }
1034
1035 private static final String _FINDER_COLUMN_CHOICEID_CHOICEID_2 = "pollsVote.choiceId = ?";
1036 public static final FinderPath FINDER_PATH_FETCH_BY_Q_U = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
1037 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
1038 FINDER_CLASS_NAME_ENTITY, "fetchByQ_U",
1039 new String[] { Long.class.getName(), Long.class.getName() },
1040 PollsVoteModelImpl.QUESTIONID_COLUMN_BITMASK |
1041 PollsVoteModelImpl.USERID_COLUMN_BITMASK);
1042 public static final FinderPath FINDER_PATH_COUNT_BY_Q_U = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
1043 PollsVoteModelImpl.FINDER_CACHE_ENABLED, Long.class,
1044 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByQ_U",
1045 new String[] { Long.class.getName(), Long.class.getName() });
1046
1047
1056 public PollsVote findByQ_U(long questionId, long userId)
1057 throws NoSuchVoteException, SystemException {
1058 PollsVote pollsVote = fetchByQ_U(questionId, userId);
1059
1060 if (pollsVote == null) {
1061 StringBundler msg = new StringBundler(6);
1062
1063 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1064
1065 msg.append("questionId=");
1066 msg.append(questionId);
1067
1068 msg.append(", userId=");
1069 msg.append(userId);
1070
1071 msg.append(StringPool.CLOSE_CURLY_BRACE);
1072
1073 if (_log.isWarnEnabled()) {
1074 _log.warn(msg.toString());
1075 }
1076
1077 throw new NoSuchVoteException(msg.toString());
1078 }
1079
1080 return pollsVote;
1081 }
1082
1083
1091 public PollsVote fetchByQ_U(long questionId, long userId)
1092 throws SystemException {
1093 return fetchByQ_U(questionId, userId, true);
1094 }
1095
1096
1105 public PollsVote fetchByQ_U(long questionId, long userId,
1106 boolean retrieveFromCache) throws SystemException {
1107 Object[] finderArgs = new Object[] { questionId, userId };
1108
1109 Object result = null;
1110
1111 if (retrieveFromCache) {
1112 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_Q_U,
1113 finderArgs, this);
1114 }
1115
1116 if (result instanceof PollsVote) {
1117 PollsVote pollsVote = (PollsVote)result;
1118
1119 if ((questionId != pollsVote.getQuestionId()) ||
1120 (userId != pollsVote.getUserId())) {
1121 result = null;
1122 }
1123 }
1124
1125 if (result == null) {
1126 StringBundler query = new StringBundler(4);
1127
1128 query.append(_SQL_SELECT_POLLSVOTE_WHERE);
1129
1130 query.append(_FINDER_COLUMN_Q_U_QUESTIONID_2);
1131
1132 query.append(_FINDER_COLUMN_Q_U_USERID_2);
1133
1134 String sql = query.toString();
1135
1136 Session session = null;
1137
1138 try {
1139 session = openSession();
1140
1141 Query q = session.createQuery(sql);
1142
1143 QueryPos qPos = QueryPos.getInstance(q);
1144
1145 qPos.add(questionId);
1146
1147 qPos.add(userId);
1148
1149 List<PollsVote> list = q.list();
1150
1151 if (list.isEmpty()) {
1152 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
1153 finderArgs, list);
1154 }
1155 else {
1156 PollsVote pollsVote = list.get(0);
1157
1158 result = pollsVote;
1159
1160 cacheResult(pollsVote);
1161
1162 if ((pollsVote.getQuestionId() != questionId) ||
1163 (pollsVote.getUserId() != userId)) {
1164 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
1165 finderArgs, pollsVote);
1166 }
1167 }
1168 }
1169 catch (Exception e) {
1170 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_U,
1171 finderArgs);
1172
1173 throw processException(e);
1174 }
1175 finally {
1176 closeSession(session);
1177 }
1178 }
1179
1180 if (result instanceof List<?>) {
1181 return null;
1182 }
1183 else {
1184 return (PollsVote)result;
1185 }
1186 }
1187
1188
1196 public PollsVote removeByQ_U(long questionId, long userId)
1197 throws NoSuchVoteException, SystemException {
1198 PollsVote pollsVote = findByQ_U(questionId, userId);
1199
1200 return remove(pollsVote);
1201 }
1202
1203
1211 public int countByQ_U(long questionId, long userId)
1212 throws SystemException {
1213 FinderPath finderPath = FINDER_PATH_COUNT_BY_Q_U;
1214
1215 Object[] finderArgs = new Object[] { questionId, userId };
1216
1217 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1218 this);
1219
1220 if (count == null) {
1221 StringBundler query = new StringBundler(3);
1222
1223 query.append(_SQL_COUNT_POLLSVOTE_WHERE);
1224
1225 query.append(_FINDER_COLUMN_Q_U_QUESTIONID_2);
1226
1227 query.append(_FINDER_COLUMN_Q_U_USERID_2);
1228
1229 String sql = query.toString();
1230
1231 Session session = null;
1232
1233 try {
1234 session = openSession();
1235
1236 Query q = session.createQuery(sql);
1237
1238 QueryPos qPos = QueryPos.getInstance(q);
1239
1240 qPos.add(questionId);
1241
1242 qPos.add(userId);
1243
1244 count = (Long)q.uniqueResult();
1245
1246 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1247 }
1248 catch (Exception e) {
1249 FinderCacheUtil.removeResult(finderPath, finderArgs);
1250
1251 throw processException(e);
1252 }
1253 finally {
1254 closeSession(session);
1255 }
1256 }
1257
1258 return count.intValue();
1259 }
1260
1261 private static final String _FINDER_COLUMN_Q_U_QUESTIONID_2 = "pollsVote.questionId = ? AND ";
1262 private static final String _FINDER_COLUMN_Q_U_USERID_2 = "pollsVote.userId = ?";
1263
1264
1269 public void cacheResult(PollsVote pollsVote) {
1270 EntityCacheUtil.putResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
1271 PollsVoteImpl.class, pollsVote.getPrimaryKey(), pollsVote);
1272
1273 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
1274 new Object[] {
1275 Long.valueOf(pollsVote.getQuestionId()),
1276 Long.valueOf(pollsVote.getUserId())
1277 }, pollsVote);
1278
1279 pollsVote.resetOriginalValues();
1280 }
1281
1282
1287 public void cacheResult(List<PollsVote> pollsVotes) {
1288 for (PollsVote pollsVote : pollsVotes) {
1289 if (EntityCacheUtil.getResult(
1290 PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
1291 PollsVoteImpl.class, pollsVote.getPrimaryKey()) == null) {
1292 cacheResult(pollsVote);
1293 }
1294 else {
1295 pollsVote.resetOriginalValues();
1296 }
1297 }
1298 }
1299
1300
1307 @Override
1308 public void clearCache() {
1309 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1310 CacheRegistryUtil.clear(PollsVoteImpl.class.getName());
1311 }
1312
1313 EntityCacheUtil.clearCache(PollsVoteImpl.class.getName());
1314
1315 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1316 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1317 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1318 }
1319
1320
1327 @Override
1328 public void clearCache(PollsVote pollsVote) {
1329 EntityCacheUtil.removeResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
1330 PollsVoteImpl.class, pollsVote.getPrimaryKey());
1331
1332 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1333 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1334
1335 clearUniqueFindersCache(pollsVote);
1336 }
1337
1338 @Override
1339 public void clearCache(List<PollsVote> pollsVotes) {
1340 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1341 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1342
1343 for (PollsVote pollsVote : pollsVotes) {
1344 EntityCacheUtil.removeResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
1345 PollsVoteImpl.class, pollsVote.getPrimaryKey());
1346
1347 clearUniqueFindersCache(pollsVote);
1348 }
1349 }
1350
1351 protected void cacheUniqueFindersCache(PollsVote pollsVote) {
1352 if (pollsVote.isNew()) {
1353 Object[] args = new Object[] {
1354 Long.valueOf(pollsVote.getQuestionId()),
1355 Long.valueOf(pollsVote.getUserId())
1356 };
1357
1358 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_Q_U, args,
1359 Long.valueOf(1));
1360 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U, args, pollsVote);
1361 }
1362 else {
1363 PollsVoteModelImpl pollsVoteModelImpl = (PollsVoteModelImpl)pollsVote;
1364
1365 if ((pollsVoteModelImpl.getColumnBitmask() &
1366 FINDER_PATH_FETCH_BY_Q_U.getColumnBitmask()) != 0) {
1367 Object[] args = new Object[] {
1368 Long.valueOf(pollsVote.getQuestionId()),
1369 Long.valueOf(pollsVote.getUserId())
1370 };
1371
1372 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_Q_U, args,
1373 Long.valueOf(1));
1374 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U, args,
1375 pollsVote);
1376 }
1377 }
1378 }
1379
1380 protected void clearUniqueFindersCache(PollsVote pollsVote) {
1381 PollsVoteModelImpl pollsVoteModelImpl = (PollsVoteModelImpl)pollsVote;
1382
1383 Object[] args = new Object[] {
1384 Long.valueOf(pollsVote.getQuestionId()),
1385 Long.valueOf(pollsVote.getUserId())
1386 };
1387
1388 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_Q_U, args);
1389 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_U, args);
1390
1391 if ((pollsVoteModelImpl.getColumnBitmask() &
1392 FINDER_PATH_FETCH_BY_Q_U.getColumnBitmask()) != 0) {
1393 args = new Object[] {
1394 Long.valueOf(pollsVoteModelImpl.getOriginalQuestionId()),
1395 Long.valueOf(pollsVoteModelImpl.getOriginalUserId())
1396 };
1397
1398 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_Q_U, args);
1399 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_U, args);
1400 }
1401 }
1402
1403
1409 public PollsVote create(long voteId) {
1410 PollsVote pollsVote = new PollsVoteImpl();
1411
1412 pollsVote.setNew(true);
1413 pollsVote.setPrimaryKey(voteId);
1414
1415 return pollsVote;
1416 }
1417
1418
1426 public PollsVote remove(long voteId)
1427 throws NoSuchVoteException, SystemException {
1428 return remove(Long.valueOf(voteId));
1429 }
1430
1431
1439 @Override
1440 public PollsVote remove(Serializable primaryKey)
1441 throws NoSuchVoteException, SystemException {
1442 Session session = null;
1443
1444 try {
1445 session = openSession();
1446
1447 PollsVote pollsVote = (PollsVote)session.get(PollsVoteImpl.class,
1448 primaryKey);
1449
1450 if (pollsVote == null) {
1451 if (_log.isWarnEnabled()) {
1452 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1453 }
1454
1455 throw new NoSuchVoteException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1456 primaryKey);
1457 }
1458
1459 return remove(pollsVote);
1460 }
1461 catch (NoSuchVoteException nsee) {
1462 throw nsee;
1463 }
1464 catch (Exception e) {
1465 throw processException(e);
1466 }
1467 finally {
1468 closeSession(session);
1469 }
1470 }
1471
1472 @Override
1473 protected PollsVote removeImpl(PollsVote pollsVote)
1474 throws SystemException {
1475 pollsVote = toUnwrappedModel(pollsVote);
1476
1477 Session session = null;
1478
1479 try {
1480 session = openSession();
1481
1482 if (!session.contains(pollsVote)) {
1483 pollsVote = (PollsVote)session.get(PollsVoteImpl.class,
1484 pollsVote.getPrimaryKeyObj());
1485 }
1486
1487 if (pollsVote != null) {
1488 session.delete(pollsVote);
1489 }
1490 }
1491 catch (Exception e) {
1492 throw processException(e);
1493 }
1494 finally {
1495 closeSession(session);
1496 }
1497
1498 if (pollsVote != null) {
1499 clearCache(pollsVote);
1500 }
1501
1502 return pollsVote;
1503 }
1504
1505 @Override
1506 public PollsVote updateImpl(
1507 com.liferay.portlet.polls.model.PollsVote pollsVote)
1508 throws SystemException {
1509 pollsVote = toUnwrappedModel(pollsVote);
1510
1511 boolean isNew = pollsVote.isNew();
1512
1513 PollsVoteModelImpl pollsVoteModelImpl = (PollsVoteModelImpl)pollsVote;
1514
1515 Session session = null;
1516
1517 try {
1518 session = openSession();
1519
1520 if (pollsVote.isNew()) {
1521 session.save(pollsVote);
1522
1523 pollsVote.setNew(false);
1524 }
1525 else {
1526 session.merge(pollsVote);
1527 }
1528 }
1529 catch (Exception e) {
1530 throw processException(e);
1531 }
1532 finally {
1533 closeSession(session);
1534 }
1535
1536 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1537
1538 if (isNew || !PollsVoteModelImpl.COLUMN_BITMASK_ENABLED) {
1539 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1540 }
1541
1542 else {
1543 if ((pollsVoteModelImpl.getColumnBitmask() &
1544 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID.getColumnBitmask()) != 0) {
1545 Object[] args = new Object[] {
1546 Long.valueOf(pollsVoteModelImpl.getOriginalQuestionId())
1547 };
1548
1549 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1550 args);
1551 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
1552 args);
1553
1554 args = new Object[] {
1555 Long.valueOf(pollsVoteModelImpl.getQuestionId())
1556 };
1557
1558 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1559 args);
1560 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
1561 args);
1562 }
1563
1564 if ((pollsVoteModelImpl.getColumnBitmask() &
1565 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CHOICEID.getColumnBitmask()) != 0) {
1566 Object[] args = new Object[] {
1567 Long.valueOf(pollsVoteModelImpl.getOriginalChoiceId())
1568 };
1569
1570 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CHOICEID, args);
1571 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CHOICEID,
1572 args);
1573
1574 args = new Object[] {
1575 Long.valueOf(pollsVoteModelImpl.getChoiceId())
1576 };
1577
1578 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CHOICEID, args);
1579 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CHOICEID,
1580 args);
1581 }
1582 }
1583
1584 EntityCacheUtil.putResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
1585 PollsVoteImpl.class, pollsVote.getPrimaryKey(), pollsVote);
1586
1587 clearUniqueFindersCache(pollsVote);
1588 cacheUniqueFindersCache(pollsVote);
1589
1590 return pollsVote;
1591 }
1592
1593 protected PollsVote toUnwrappedModel(PollsVote pollsVote) {
1594 if (pollsVote instanceof PollsVoteImpl) {
1595 return pollsVote;
1596 }
1597
1598 PollsVoteImpl pollsVoteImpl = new PollsVoteImpl();
1599
1600 pollsVoteImpl.setNew(pollsVote.isNew());
1601 pollsVoteImpl.setPrimaryKey(pollsVote.getPrimaryKey());
1602
1603 pollsVoteImpl.setVoteId(pollsVote.getVoteId());
1604 pollsVoteImpl.setCompanyId(pollsVote.getCompanyId());
1605 pollsVoteImpl.setUserId(pollsVote.getUserId());
1606 pollsVoteImpl.setUserName(pollsVote.getUserName());
1607 pollsVoteImpl.setCreateDate(pollsVote.getCreateDate());
1608 pollsVoteImpl.setModifiedDate(pollsVote.getModifiedDate());
1609 pollsVoteImpl.setQuestionId(pollsVote.getQuestionId());
1610 pollsVoteImpl.setChoiceId(pollsVote.getChoiceId());
1611 pollsVoteImpl.setVoteDate(pollsVote.getVoteDate());
1612
1613 return pollsVoteImpl;
1614 }
1615
1616
1624 @Override
1625 public PollsVote findByPrimaryKey(Serializable primaryKey)
1626 throws NoSuchModelException, SystemException {
1627 return findByPrimaryKey(((Long)primaryKey).longValue());
1628 }
1629
1630
1638 public PollsVote findByPrimaryKey(long voteId)
1639 throws NoSuchVoteException, SystemException {
1640 PollsVote pollsVote = fetchByPrimaryKey(voteId);
1641
1642 if (pollsVote == null) {
1643 if (_log.isWarnEnabled()) {
1644 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + voteId);
1645 }
1646
1647 throw new NoSuchVoteException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1648 voteId);
1649 }
1650
1651 return pollsVote;
1652 }
1653
1654
1661 @Override
1662 public PollsVote fetchByPrimaryKey(Serializable primaryKey)
1663 throws SystemException {
1664 return fetchByPrimaryKey(((Long)primaryKey).longValue());
1665 }
1666
1667
1674 public PollsVote fetchByPrimaryKey(long voteId) throws SystemException {
1675 PollsVote pollsVote = (PollsVote)EntityCacheUtil.getResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
1676 PollsVoteImpl.class, voteId);
1677
1678 if (pollsVote == _nullPollsVote) {
1679 return null;
1680 }
1681
1682 if (pollsVote == null) {
1683 Session session = null;
1684
1685 try {
1686 session = openSession();
1687
1688 pollsVote = (PollsVote)session.get(PollsVoteImpl.class,
1689 Long.valueOf(voteId));
1690
1691 if (pollsVote != null) {
1692 cacheResult(pollsVote);
1693 }
1694 else {
1695 EntityCacheUtil.putResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
1696 PollsVoteImpl.class, voteId, _nullPollsVote);
1697 }
1698 }
1699 catch (Exception e) {
1700 EntityCacheUtil.removeResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
1701 PollsVoteImpl.class, voteId);
1702
1703 throw processException(e);
1704 }
1705 finally {
1706 closeSession(session);
1707 }
1708 }
1709
1710 return pollsVote;
1711 }
1712
1713
1719 public List<PollsVote> findAll() throws SystemException {
1720 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1721 }
1722
1723
1735 public List<PollsVote> findAll(int start, int end)
1736 throws SystemException {
1737 return findAll(start, end, null);
1738 }
1739
1740
1753 public List<PollsVote> findAll(int start, int end,
1754 OrderByComparator orderByComparator) throws SystemException {
1755 boolean pagination = true;
1756 FinderPath finderPath = null;
1757 Object[] finderArgs = null;
1758
1759 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1760 (orderByComparator == null)) {
1761 pagination = false;
1762 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1763 finderArgs = FINDER_ARGS_EMPTY;
1764 }
1765 else {
1766 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1767 finderArgs = new Object[] { start, end, orderByComparator };
1768 }
1769
1770 List<PollsVote> list = (List<PollsVote>)FinderCacheUtil.getResult(finderPath,
1771 finderArgs, this);
1772
1773 if (list == null) {
1774 StringBundler query = null;
1775 String sql = null;
1776
1777 if (orderByComparator != null) {
1778 query = new StringBundler(2 +
1779 (orderByComparator.getOrderByFields().length * 3));
1780
1781 query.append(_SQL_SELECT_POLLSVOTE);
1782
1783 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1784 orderByComparator);
1785
1786 sql = query.toString();
1787 }
1788 else {
1789 sql = _SQL_SELECT_POLLSVOTE;
1790
1791 if (pagination) {
1792 sql = sql.concat(PollsVoteModelImpl.ORDER_BY_JPQL);
1793 }
1794 }
1795
1796 Session session = null;
1797
1798 try {
1799 session = openSession();
1800
1801 Query q = session.createQuery(sql);
1802
1803 if (!pagination) {
1804 list = (List<PollsVote>)QueryUtil.list(q, getDialect(),
1805 start, end, false);
1806
1807 Collections.sort(list);
1808
1809 list = new UnmodifiableList<PollsVote>(list);
1810 }
1811 else {
1812 list = (List<PollsVote>)QueryUtil.list(q, getDialect(),
1813 start, end);
1814 }
1815
1816 cacheResult(list);
1817
1818 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1819 }
1820 catch (Exception e) {
1821 FinderCacheUtil.removeResult(finderPath, finderArgs);
1822
1823 throw processException(e);
1824 }
1825 finally {
1826 closeSession(session);
1827 }
1828 }
1829
1830 return list;
1831 }
1832
1833
1838 public void removeAll() throws SystemException {
1839 for (PollsVote pollsVote : findAll()) {
1840 remove(pollsVote);
1841 }
1842 }
1843
1844
1850 public int countAll() throws SystemException {
1851 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1852 FINDER_ARGS_EMPTY, this);
1853
1854 if (count == null) {
1855 Session session = null;
1856
1857 try {
1858 session = openSession();
1859
1860 Query q = session.createQuery(_SQL_COUNT_POLLSVOTE);
1861
1862 count = (Long)q.uniqueResult();
1863
1864 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1865 FINDER_ARGS_EMPTY, count);
1866 }
1867 catch (Exception e) {
1868 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1869 FINDER_ARGS_EMPTY);
1870
1871 throw processException(e);
1872 }
1873 finally {
1874 closeSession(session);
1875 }
1876 }
1877
1878 return count.intValue();
1879 }
1880
1881
1884 public void afterPropertiesSet() {
1885 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1886 com.liferay.portal.util.PropsUtil.get(
1887 "value.object.listener.com.liferay.portlet.polls.model.PollsVote")));
1888
1889 if (listenerClassNames.length > 0) {
1890 try {
1891 List<ModelListener<PollsVote>> listenersList = new ArrayList<ModelListener<PollsVote>>();
1892
1893 for (String listenerClassName : listenerClassNames) {
1894 listenersList.add((ModelListener<PollsVote>)InstanceFactory.newInstance(
1895 listenerClassName));
1896 }
1897
1898 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1899 }
1900 catch (Exception e) {
1901 _log.error(e);
1902 }
1903 }
1904 }
1905
1906 public void destroy() {
1907 EntityCacheUtil.removeCache(PollsVoteImpl.class.getName());
1908 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1909 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1910 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1911 }
1912
1913 private static final String _SQL_SELECT_POLLSVOTE = "SELECT pollsVote FROM PollsVote pollsVote";
1914 private static final String _SQL_SELECT_POLLSVOTE_WHERE = "SELECT pollsVote FROM PollsVote pollsVote WHERE ";
1915 private static final String _SQL_COUNT_POLLSVOTE = "SELECT COUNT(pollsVote) FROM PollsVote pollsVote";
1916 private static final String _SQL_COUNT_POLLSVOTE_WHERE = "SELECT COUNT(pollsVote) FROM PollsVote pollsVote WHERE ";
1917 private static final String _ORDER_BY_ENTITY_ALIAS = "pollsVote.";
1918 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsVote exists with the primary key ";
1919 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsVote exists with the key {";
1920 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1921 private static Log _log = LogFactoryUtil.getLog(PollsVotePersistenceImpl.class);
1922 private static PollsVote _nullPollsVote = new PollsVoteImpl() {
1923 @Override
1924 public Object clone() {
1925 return this;
1926 }
1927
1928 @Override
1929 public CacheModel<PollsVote> toCacheModel() {
1930 return _nullPollsVoteCacheModel;
1931 }
1932 };
1933
1934 private static CacheModel<PollsVote> _nullPollsVoteCacheModel = new CacheModel<PollsVote>() {
1935 public PollsVote toEntityModel() {
1936 return _nullPollsVote;
1937 }
1938 };
1939 }