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