001
014
015 package com.liferay.portlet.polls.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.UserPersistence;
039 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040
041 import com.liferay.portlet.polls.NoSuchVoteException;
042 import com.liferay.portlet.polls.model.PollsVote;
043 import com.liferay.portlet.polls.model.impl.PollsVoteImpl;
044 import com.liferay.portlet.polls.model.impl.PollsVoteModelImpl;
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 PollsVotePersistenceImpl extends BasePersistenceImpl<PollsVote>
065 implements PollsVotePersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = PollsVoteImpl.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_BY_QUESTIONID =
077 new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
078 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
079 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByQuestionId",
080 new String[] {
081 Long.class.getName(),
082
083 "java.lang.Integer", "java.lang.Integer",
084 "com.liferay.portal.kernel.util.OrderByComparator"
085 });
086 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID =
087 new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
088 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
089 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByQuestionId",
090 new String[] { Long.class.getName() },
091 PollsVoteModelImpl.QUESTIONID_COLUMN_BITMASK);
092 public static final FinderPath FINDER_PATH_COUNT_BY_QUESTIONID = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
093 PollsVoteModelImpl.FINDER_CACHE_ENABLED, Long.class,
094 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByQuestionId",
095 new String[] { Long.class.getName() });
096 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CHOICEID = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
097 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
098 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByChoiceId",
099 new String[] {
100 Long.class.getName(),
101
102 "java.lang.Integer", "java.lang.Integer",
103 "com.liferay.portal.kernel.util.OrderByComparator"
104 });
105 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CHOICEID =
106 new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
107 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
108 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByChoiceId",
109 new String[] { Long.class.getName() },
110 PollsVoteModelImpl.CHOICEID_COLUMN_BITMASK);
111 public static final FinderPath FINDER_PATH_COUNT_BY_CHOICEID = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
112 PollsVoteModelImpl.FINDER_CACHE_ENABLED, Long.class,
113 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByChoiceId",
114 new String[] { Long.class.getName() });
115 public static final FinderPath FINDER_PATH_FETCH_BY_Q_U = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
116 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
117 FINDER_CLASS_NAME_ENTITY, "fetchByQ_U",
118 new String[] { Long.class.getName(), Long.class.getName() },
119 PollsVoteModelImpl.QUESTIONID_COLUMN_BITMASK |
120 PollsVoteModelImpl.USERID_COLUMN_BITMASK);
121 public static final FinderPath FINDER_PATH_COUNT_BY_Q_U = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
122 PollsVoteModelImpl.FINDER_CACHE_ENABLED, Long.class,
123 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByQ_U",
124 new String[] { Long.class.getName(), Long.class.getName() });
125 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
126 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
127 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
128 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
129 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
130 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
131 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
132 PollsVoteModelImpl.FINDER_CACHE_ENABLED, Long.class,
133 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
134
135
140 public void cacheResult(PollsVote pollsVote) {
141 EntityCacheUtil.putResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
142 PollsVoteImpl.class, pollsVote.getPrimaryKey(), pollsVote);
143
144 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
145 new Object[] {
146 Long.valueOf(pollsVote.getQuestionId()),
147 Long.valueOf(pollsVote.getUserId())
148 }, pollsVote);
149
150 pollsVote.resetOriginalValues();
151 }
152
153
158 public void cacheResult(List<PollsVote> pollsVotes) {
159 for (PollsVote pollsVote : pollsVotes) {
160 if (EntityCacheUtil.getResult(
161 PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
162 PollsVoteImpl.class, pollsVote.getPrimaryKey()) == null) {
163 cacheResult(pollsVote);
164 }
165 else {
166 pollsVote.resetOriginalValues();
167 }
168 }
169 }
170
171
178 @Override
179 public void clearCache() {
180 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
181 CacheRegistryUtil.clear(PollsVoteImpl.class.getName());
182 }
183
184 EntityCacheUtil.clearCache(PollsVoteImpl.class.getName());
185
186 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
187 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
188 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
189 }
190
191
198 @Override
199 public void clearCache(PollsVote pollsVote) {
200 EntityCacheUtil.removeResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
201 PollsVoteImpl.class, pollsVote.getPrimaryKey());
202
203 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
204 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
205
206 clearUniqueFindersCache(pollsVote);
207 }
208
209 @Override
210 public void clearCache(List<PollsVote> pollsVotes) {
211 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
212 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
213
214 for (PollsVote pollsVote : pollsVotes) {
215 EntityCacheUtil.removeResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
216 PollsVoteImpl.class, pollsVote.getPrimaryKey());
217
218 clearUniqueFindersCache(pollsVote);
219 }
220 }
221
222 protected void clearUniqueFindersCache(PollsVote pollsVote) {
223 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_U,
224 new Object[] {
225 Long.valueOf(pollsVote.getQuestionId()),
226 Long.valueOf(pollsVote.getUserId())
227 });
228 }
229
230
236 public PollsVote create(long voteId) {
237 PollsVote pollsVote = new PollsVoteImpl();
238
239 pollsVote.setNew(true);
240 pollsVote.setPrimaryKey(voteId);
241
242 return pollsVote;
243 }
244
245
253 public PollsVote remove(long voteId)
254 throws NoSuchVoteException, SystemException {
255 return remove(Long.valueOf(voteId));
256 }
257
258
266 @Override
267 public PollsVote remove(Serializable primaryKey)
268 throws NoSuchVoteException, SystemException {
269 Session session = null;
270
271 try {
272 session = openSession();
273
274 PollsVote pollsVote = (PollsVote)session.get(PollsVoteImpl.class,
275 primaryKey);
276
277 if (pollsVote == null) {
278 if (_log.isWarnEnabled()) {
279 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
280 }
281
282 throw new NoSuchVoteException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
283 primaryKey);
284 }
285
286 return remove(pollsVote);
287 }
288 catch (NoSuchVoteException nsee) {
289 throw nsee;
290 }
291 catch (Exception e) {
292 throw processException(e);
293 }
294 finally {
295 closeSession(session);
296 }
297 }
298
299 @Override
300 protected PollsVote removeImpl(PollsVote pollsVote)
301 throws SystemException {
302 pollsVote = toUnwrappedModel(pollsVote);
303
304 Session session = null;
305
306 try {
307 session = openSession();
308
309 if (pollsVote.isCachedModel()) {
310 pollsVote = (PollsVote)session.get(PollsVoteImpl.class,
311 pollsVote.getPrimaryKeyObj());
312 }
313
314 session.delete(pollsVote);
315 }
316 catch (Exception e) {
317 throw processException(e);
318 }
319 finally {
320 closeSession(session);
321 }
322
323 clearCache(pollsVote);
324
325 return pollsVote;
326 }
327
328 @Override
329 public PollsVote updateImpl(
330 com.liferay.portlet.polls.model.PollsVote pollsVote)
331 throws SystemException {
332 pollsVote = toUnwrappedModel(pollsVote);
333
334 boolean isNew = pollsVote.isNew();
335
336 PollsVoteModelImpl pollsVoteModelImpl = (PollsVoteModelImpl)pollsVote;
337
338 Session session = null;
339
340 try {
341 session = openSession();
342
343 if (pollsVote.isNew()) {
344 session.save(pollsVote);
345
346 pollsVote.setNew(false);
347 }
348 else {
349 session.merge(pollsVote);
350 }
351 }
352 catch (Exception e) {
353 throw processException(e);
354 }
355 finally {
356 closeSession(session);
357 }
358
359 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
360
361 if (isNew || !PollsVoteModelImpl.COLUMN_BITMASK_ENABLED) {
362 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
363 }
364
365 else {
366 if ((pollsVoteModelImpl.getColumnBitmask() &
367 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID.getColumnBitmask()) != 0) {
368 Object[] args = new Object[] {
369 Long.valueOf(pollsVoteModelImpl.getOriginalQuestionId())
370 };
371
372 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
373 args);
374 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
375 args);
376
377 args = new Object[] {
378 Long.valueOf(pollsVoteModelImpl.getQuestionId())
379 };
380
381 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
382 args);
383 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
384 args);
385 }
386
387 if ((pollsVoteModelImpl.getColumnBitmask() &
388 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CHOICEID.getColumnBitmask()) != 0) {
389 Object[] args = new Object[] {
390 Long.valueOf(pollsVoteModelImpl.getOriginalChoiceId())
391 };
392
393 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CHOICEID, args);
394 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CHOICEID,
395 args);
396
397 args = new Object[] {
398 Long.valueOf(pollsVoteModelImpl.getChoiceId())
399 };
400
401 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CHOICEID, args);
402 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CHOICEID,
403 args);
404 }
405 }
406
407 EntityCacheUtil.putResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
408 PollsVoteImpl.class, pollsVote.getPrimaryKey(), pollsVote);
409
410 if (isNew) {
411 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
412 new Object[] {
413 Long.valueOf(pollsVote.getQuestionId()),
414 Long.valueOf(pollsVote.getUserId())
415 }, pollsVote);
416 }
417 else {
418 if ((pollsVoteModelImpl.getColumnBitmask() &
419 FINDER_PATH_FETCH_BY_Q_U.getColumnBitmask()) != 0) {
420 Object[] args = new Object[] {
421 Long.valueOf(pollsVoteModelImpl.getOriginalQuestionId()),
422 Long.valueOf(pollsVoteModelImpl.getOriginalUserId())
423 };
424
425 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_Q_U, args);
426
427 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_U, args);
428
429 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
430 new Object[] {
431 Long.valueOf(pollsVote.getQuestionId()),
432 Long.valueOf(pollsVote.getUserId())
433 }, pollsVote);
434 }
435 }
436
437 return pollsVote;
438 }
439
440 protected PollsVote toUnwrappedModel(PollsVote pollsVote) {
441 if (pollsVote instanceof PollsVoteImpl) {
442 return pollsVote;
443 }
444
445 PollsVoteImpl pollsVoteImpl = new PollsVoteImpl();
446
447 pollsVoteImpl.setNew(pollsVote.isNew());
448 pollsVoteImpl.setPrimaryKey(pollsVote.getPrimaryKey());
449
450 pollsVoteImpl.setVoteId(pollsVote.getVoteId());
451 pollsVoteImpl.setCompanyId(pollsVote.getCompanyId());
452 pollsVoteImpl.setUserId(pollsVote.getUserId());
453 pollsVoteImpl.setUserName(pollsVote.getUserName());
454 pollsVoteImpl.setCreateDate(pollsVote.getCreateDate());
455 pollsVoteImpl.setModifiedDate(pollsVote.getModifiedDate());
456 pollsVoteImpl.setQuestionId(pollsVote.getQuestionId());
457 pollsVoteImpl.setChoiceId(pollsVote.getChoiceId());
458 pollsVoteImpl.setVoteDate(pollsVote.getVoteDate());
459
460 return pollsVoteImpl;
461 }
462
463
471 @Override
472 public PollsVote findByPrimaryKey(Serializable primaryKey)
473 throws NoSuchModelException, SystemException {
474 return findByPrimaryKey(((Long)primaryKey).longValue());
475 }
476
477
485 public PollsVote findByPrimaryKey(long voteId)
486 throws NoSuchVoteException, SystemException {
487 PollsVote pollsVote = fetchByPrimaryKey(voteId);
488
489 if (pollsVote == null) {
490 if (_log.isWarnEnabled()) {
491 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + voteId);
492 }
493
494 throw new NoSuchVoteException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
495 voteId);
496 }
497
498 return pollsVote;
499 }
500
501
508 @Override
509 public PollsVote fetchByPrimaryKey(Serializable primaryKey)
510 throws SystemException {
511 return fetchByPrimaryKey(((Long)primaryKey).longValue());
512 }
513
514
521 public PollsVote fetchByPrimaryKey(long voteId) throws SystemException {
522 PollsVote pollsVote = (PollsVote)EntityCacheUtil.getResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
523 PollsVoteImpl.class, voteId);
524
525 if (pollsVote == _nullPollsVote) {
526 return null;
527 }
528
529 if (pollsVote == null) {
530 Session session = null;
531
532 boolean hasException = false;
533
534 try {
535 session = openSession();
536
537 pollsVote = (PollsVote)session.get(PollsVoteImpl.class,
538 Long.valueOf(voteId));
539 }
540 catch (Exception e) {
541 hasException = true;
542
543 throw processException(e);
544 }
545 finally {
546 if (pollsVote != null) {
547 cacheResult(pollsVote);
548 }
549 else if (!hasException) {
550 EntityCacheUtil.putResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
551 PollsVoteImpl.class, voteId, _nullPollsVote);
552 }
553
554 closeSession(session);
555 }
556 }
557
558 return pollsVote;
559 }
560
561
568 public List<PollsVote> findByQuestionId(long questionId)
569 throws SystemException {
570 return findByQuestionId(questionId, QueryUtil.ALL_POS,
571 QueryUtil.ALL_POS, null);
572 }
573
574
587 public List<PollsVote> findByQuestionId(long questionId, int start, int end)
588 throws SystemException {
589 return findByQuestionId(questionId, start, end, null);
590 }
591
592
606 public List<PollsVote> findByQuestionId(long questionId, int start,
607 int end, OrderByComparator orderByComparator) throws SystemException {
608 FinderPath finderPath = null;
609 Object[] finderArgs = null;
610
611 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
612 (orderByComparator == null)) {
613 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID;
614 finderArgs = new Object[] { questionId };
615 }
616 else {
617 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_QUESTIONID;
618 finderArgs = new Object[] { questionId, start, end, orderByComparator };
619 }
620
621 List<PollsVote> list = (List<PollsVote>)FinderCacheUtil.getResult(finderPath,
622 finderArgs, this);
623
624 if ((list != null) && !list.isEmpty()) {
625 for (PollsVote pollsVote : list) {
626 if ((questionId != pollsVote.getQuestionId())) {
627 list = null;
628
629 break;
630 }
631 }
632 }
633
634 if (list == null) {
635 StringBundler query = null;
636
637 if (orderByComparator != null) {
638 query = new StringBundler(3 +
639 (orderByComparator.getOrderByFields().length * 3));
640 }
641 else {
642 query = new StringBundler(2);
643 }
644
645 query.append(_SQL_SELECT_POLLSVOTE_WHERE);
646
647 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
648
649 if (orderByComparator != null) {
650 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
651 orderByComparator);
652 }
653
654 String sql = query.toString();
655
656 Session session = null;
657
658 try {
659 session = openSession();
660
661 Query q = session.createQuery(sql);
662
663 QueryPos qPos = QueryPos.getInstance(q);
664
665 qPos.add(questionId);
666
667 list = (List<PollsVote>)QueryUtil.list(q, getDialect(), start,
668 end);
669 }
670 catch (Exception e) {
671 throw processException(e);
672 }
673 finally {
674 if (list == null) {
675 FinderCacheUtil.removeResult(finderPath, finderArgs);
676 }
677 else {
678 cacheResult(list);
679
680 FinderCacheUtil.putResult(finderPath, finderArgs, list);
681 }
682
683 closeSession(session);
684 }
685 }
686
687 return list;
688 }
689
690
699 public PollsVote findByQuestionId_First(long questionId,
700 OrderByComparator orderByComparator)
701 throws NoSuchVoteException, SystemException {
702 PollsVote pollsVote = fetchByQuestionId_First(questionId,
703 orderByComparator);
704
705 if (pollsVote != null) {
706 return pollsVote;
707 }
708
709 StringBundler msg = new StringBundler(4);
710
711 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
712
713 msg.append("questionId=");
714 msg.append(questionId);
715
716 msg.append(StringPool.CLOSE_CURLY_BRACE);
717
718 throw new NoSuchVoteException(msg.toString());
719 }
720
721
729 public PollsVote fetchByQuestionId_First(long questionId,
730 OrderByComparator orderByComparator) throws SystemException {
731 List<PollsVote> list = findByQuestionId(questionId, 0, 1,
732 orderByComparator);
733
734 if (!list.isEmpty()) {
735 return list.get(0);
736 }
737
738 return null;
739 }
740
741
750 public PollsVote findByQuestionId_Last(long questionId,
751 OrderByComparator orderByComparator)
752 throws NoSuchVoteException, SystemException {
753 PollsVote pollsVote = fetchByQuestionId_Last(questionId,
754 orderByComparator);
755
756 if (pollsVote != null) {
757 return pollsVote;
758 }
759
760 StringBundler msg = new StringBundler(4);
761
762 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
763
764 msg.append("questionId=");
765 msg.append(questionId);
766
767 msg.append(StringPool.CLOSE_CURLY_BRACE);
768
769 throw new NoSuchVoteException(msg.toString());
770 }
771
772
780 public PollsVote fetchByQuestionId_Last(long questionId,
781 OrderByComparator orderByComparator) throws SystemException {
782 int count = countByQuestionId(questionId);
783
784 List<PollsVote> list = findByQuestionId(questionId, count - 1, count,
785 orderByComparator);
786
787 if (!list.isEmpty()) {
788 return list.get(0);
789 }
790
791 return null;
792 }
793
794
804 public PollsVote[] findByQuestionId_PrevAndNext(long voteId,
805 long questionId, OrderByComparator orderByComparator)
806 throws NoSuchVoteException, SystemException {
807 PollsVote pollsVote = findByPrimaryKey(voteId);
808
809 Session session = null;
810
811 try {
812 session = openSession();
813
814 PollsVote[] array = new PollsVoteImpl[3];
815
816 array[0] = getByQuestionId_PrevAndNext(session, pollsVote,
817 questionId, orderByComparator, true);
818
819 array[1] = pollsVote;
820
821 array[2] = getByQuestionId_PrevAndNext(session, pollsVote,
822 questionId, orderByComparator, false);
823
824 return array;
825 }
826 catch (Exception e) {
827 throw processException(e);
828 }
829 finally {
830 closeSession(session);
831 }
832 }
833
834 protected PollsVote getByQuestionId_PrevAndNext(Session session,
835 PollsVote pollsVote, long questionId,
836 OrderByComparator orderByComparator, boolean previous) {
837 StringBundler query = null;
838
839 if (orderByComparator != null) {
840 query = new StringBundler(6 +
841 (orderByComparator.getOrderByFields().length * 6));
842 }
843 else {
844 query = new StringBundler(3);
845 }
846
847 query.append(_SQL_SELECT_POLLSVOTE_WHERE);
848
849 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
850
851 if (orderByComparator != null) {
852 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
853
854 if (orderByConditionFields.length > 0) {
855 query.append(WHERE_AND);
856 }
857
858 for (int i = 0; i < orderByConditionFields.length; i++) {
859 query.append(_ORDER_BY_ENTITY_ALIAS);
860 query.append(orderByConditionFields[i]);
861
862 if ((i + 1) < orderByConditionFields.length) {
863 if (orderByComparator.isAscending() ^ previous) {
864 query.append(WHERE_GREATER_THAN_HAS_NEXT);
865 }
866 else {
867 query.append(WHERE_LESSER_THAN_HAS_NEXT);
868 }
869 }
870 else {
871 if (orderByComparator.isAscending() ^ previous) {
872 query.append(WHERE_GREATER_THAN);
873 }
874 else {
875 query.append(WHERE_LESSER_THAN);
876 }
877 }
878 }
879
880 query.append(ORDER_BY_CLAUSE);
881
882 String[] orderByFields = orderByComparator.getOrderByFields();
883
884 for (int i = 0; i < orderByFields.length; i++) {
885 query.append(_ORDER_BY_ENTITY_ALIAS);
886 query.append(orderByFields[i]);
887
888 if ((i + 1) < orderByFields.length) {
889 if (orderByComparator.isAscending() ^ previous) {
890 query.append(ORDER_BY_ASC_HAS_NEXT);
891 }
892 else {
893 query.append(ORDER_BY_DESC_HAS_NEXT);
894 }
895 }
896 else {
897 if (orderByComparator.isAscending() ^ previous) {
898 query.append(ORDER_BY_ASC);
899 }
900 else {
901 query.append(ORDER_BY_DESC);
902 }
903 }
904 }
905 }
906
907 String sql = query.toString();
908
909 Query q = session.createQuery(sql);
910
911 q.setFirstResult(0);
912 q.setMaxResults(2);
913
914 QueryPos qPos = QueryPos.getInstance(q);
915
916 qPos.add(questionId);
917
918 if (orderByComparator != null) {
919 Object[] values = orderByComparator.getOrderByConditionValues(pollsVote);
920
921 for (Object value : values) {
922 qPos.add(value);
923 }
924 }
925
926 List<PollsVote> list = q.list();
927
928 if (list.size() == 2) {
929 return list.get(1);
930 }
931 else {
932 return null;
933 }
934 }
935
936
943 public List<PollsVote> findByChoiceId(long choiceId)
944 throws SystemException {
945 return findByChoiceId(choiceId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
946 null);
947 }
948
949
962 public List<PollsVote> findByChoiceId(long choiceId, int start, int end)
963 throws SystemException {
964 return findByChoiceId(choiceId, start, end, null);
965 }
966
967
981 public List<PollsVote> findByChoiceId(long choiceId, int start, int end,
982 OrderByComparator orderByComparator) throws SystemException {
983 FinderPath finderPath = null;
984 Object[] finderArgs = null;
985
986 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
987 (orderByComparator == null)) {
988 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CHOICEID;
989 finderArgs = new Object[] { choiceId };
990 }
991 else {
992 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CHOICEID;
993 finderArgs = new Object[] { choiceId, start, end, orderByComparator };
994 }
995
996 List<PollsVote> list = (List<PollsVote>)FinderCacheUtil.getResult(finderPath,
997 finderArgs, this);
998
999 if ((list != null) && !list.isEmpty()) {
1000 for (PollsVote pollsVote : list) {
1001 if ((choiceId != pollsVote.getChoiceId())) {
1002 list = null;
1003
1004 break;
1005 }
1006 }
1007 }
1008
1009 if (list == null) {
1010 StringBundler query = null;
1011
1012 if (orderByComparator != null) {
1013 query = new StringBundler(3 +
1014 (orderByComparator.getOrderByFields().length * 3));
1015 }
1016 else {
1017 query = new StringBundler(2);
1018 }
1019
1020 query.append(_SQL_SELECT_POLLSVOTE_WHERE);
1021
1022 query.append(_FINDER_COLUMN_CHOICEID_CHOICEID_2);
1023
1024 if (orderByComparator != null) {
1025 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1026 orderByComparator);
1027 }
1028
1029 String sql = query.toString();
1030
1031 Session session = null;
1032
1033 try {
1034 session = openSession();
1035
1036 Query q = session.createQuery(sql);
1037
1038 QueryPos qPos = QueryPos.getInstance(q);
1039
1040 qPos.add(choiceId);
1041
1042 list = (List<PollsVote>)QueryUtil.list(q, getDialect(), start,
1043 end);
1044 }
1045 catch (Exception e) {
1046 throw processException(e);
1047 }
1048 finally {
1049 if (list == null) {
1050 FinderCacheUtil.removeResult(finderPath, finderArgs);
1051 }
1052 else {
1053 cacheResult(list);
1054
1055 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1056 }
1057
1058 closeSession(session);
1059 }
1060 }
1061
1062 return list;
1063 }
1064
1065
1074 public PollsVote findByChoiceId_First(long choiceId,
1075 OrderByComparator orderByComparator)
1076 throws NoSuchVoteException, SystemException {
1077 PollsVote pollsVote = fetchByChoiceId_First(choiceId, orderByComparator);
1078
1079 if (pollsVote != null) {
1080 return pollsVote;
1081 }
1082
1083 StringBundler msg = new StringBundler(4);
1084
1085 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1086
1087 msg.append("choiceId=");
1088 msg.append(choiceId);
1089
1090 msg.append(StringPool.CLOSE_CURLY_BRACE);
1091
1092 throw new NoSuchVoteException(msg.toString());
1093 }
1094
1095
1103 public PollsVote fetchByChoiceId_First(long choiceId,
1104 OrderByComparator orderByComparator) throws SystemException {
1105 List<PollsVote> list = findByChoiceId(choiceId, 0, 1, orderByComparator);
1106
1107 if (!list.isEmpty()) {
1108 return list.get(0);
1109 }
1110
1111 return null;
1112 }
1113
1114
1123 public PollsVote findByChoiceId_Last(long choiceId,
1124 OrderByComparator orderByComparator)
1125 throws NoSuchVoteException, SystemException {
1126 PollsVote pollsVote = fetchByChoiceId_Last(choiceId, orderByComparator);
1127
1128 if (pollsVote != null) {
1129 return pollsVote;
1130 }
1131
1132 StringBundler msg = new StringBundler(4);
1133
1134 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1135
1136 msg.append("choiceId=");
1137 msg.append(choiceId);
1138
1139 msg.append(StringPool.CLOSE_CURLY_BRACE);
1140
1141 throw new NoSuchVoteException(msg.toString());
1142 }
1143
1144
1152 public PollsVote fetchByChoiceId_Last(long choiceId,
1153 OrderByComparator orderByComparator) throws SystemException {
1154 int count = countByChoiceId(choiceId);
1155
1156 List<PollsVote> list = findByChoiceId(choiceId, count - 1, count,
1157 orderByComparator);
1158
1159 if (!list.isEmpty()) {
1160 return list.get(0);
1161 }
1162
1163 return null;
1164 }
1165
1166
1176 public PollsVote[] findByChoiceId_PrevAndNext(long voteId, long choiceId,
1177 OrderByComparator orderByComparator)
1178 throws NoSuchVoteException, SystemException {
1179 PollsVote pollsVote = findByPrimaryKey(voteId);
1180
1181 Session session = null;
1182
1183 try {
1184 session = openSession();
1185
1186 PollsVote[] array = new PollsVoteImpl[3];
1187
1188 array[0] = getByChoiceId_PrevAndNext(session, pollsVote, choiceId,
1189 orderByComparator, true);
1190
1191 array[1] = pollsVote;
1192
1193 array[2] = getByChoiceId_PrevAndNext(session, pollsVote, choiceId,
1194 orderByComparator, false);
1195
1196 return array;
1197 }
1198 catch (Exception e) {
1199 throw processException(e);
1200 }
1201 finally {
1202 closeSession(session);
1203 }
1204 }
1205
1206 protected PollsVote getByChoiceId_PrevAndNext(Session session,
1207 PollsVote pollsVote, long choiceId,
1208 OrderByComparator orderByComparator, boolean previous) {
1209 StringBundler query = null;
1210
1211 if (orderByComparator != null) {
1212 query = new StringBundler(6 +
1213 (orderByComparator.getOrderByFields().length * 6));
1214 }
1215 else {
1216 query = new StringBundler(3);
1217 }
1218
1219 query.append(_SQL_SELECT_POLLSVOTE_WHERE);
1220
1221 query.append(_FINDER_COLUMN_CHOICEID_CHOICEID_2);
1222
1223 if (orderByComparator != null) {
1224 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1225
1226 if (orderByConditionFields.length > 0) {
1227 query.append(WHERE_AND);
1228 }
1229
1230 for (int i = 0; i < orderByConditionFields.length; i++) {
1231 query.append(_ORDER_BY_ENTITY_ALIAS);
1232 query.append(orderByConditionFields[i]);
1233
1234 if ((i + 1) < orderByConditionFields.length) {
1235 if (orderByComparator.isAscending() ^ previous) {
1236 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1237 }
1238 else {
1239 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1240 }
1241 }
1242 else {
1243 if (orderByComparator.isAscending() ^ previous) {
1244 query.append(WHERE_GREATER_THAN);
1245 }
1246 else {
1247 query.append(WHERE_LESSER_THAN);
1248 }
1249 }
1250 }
1251
1252 query.append(ORDER_BY_CLAUSE);
1253
1254 String[] orderByFields = orderByComparator.getOrderByFields();
1255
1256 for (int i = 0; i < orderByFields.length; i++) {
1257 query.append(_ORDER_BY_ENTITY_ALIAS);
1258 query.append(orderByFields[i]);
1259
1260 if ((i + 1) < orderByFields.length) {
1261 if (orderByComparator.isAscending() ^ previous) {
1262 query.append(ORDER_BY_ASC_HAS_NEXT);
1263 }
1264 else {
1265 query.append(ORDER_BY_DESC_HAS_NEXT);
1266 }
1267 }
1268 else {
1269 if (orderByComparator.isAscending() ^ previous) {
1270 query.append(ORDER_BY_ASC);
1271 }
1272 else {
1273 query.append(ORDER_BY_DESC);
1274 }
1275 }
1276 }
1277 }
1278
1279 String sql = query.toString();
1280
1281 Query q = session.createQuery(sql);
1282
1283 q.setFirstResult(0);
1284 q.setMaxResults(2);
1285
1286 QueryPos qPos = QueryPos.getInstance(q);
1287
1288 qPos.add(choiceId);
1289
1290 if (orderByComparator != null) {
1291 Object[] values = orderByComparator.getOrderByConditionValues(pollsVote);
1292
1293 for (Object value : values) {
1294 qPos.add(value);
1295 }
1296 }
1297
1298 List<PollsVote> list = q.list();
1299
1300 if (list.size() == 2) {
1301 return list.get(1);
1302 }
1303 else {
1304 return null;
1305 }
1306 }
1307
1308
1317 public PollsVote findByQ_U(long questionId, long userId)
1318 throws NoSuchVoteException, SystemException {
1319 PollsVote pollsVote = fetchByQ_U(questionId, userId);
1320
1321 if (pollsVote == null) {
1322 StringBundler msg = new StringBundler(6);
1323
1324 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1325
1326 msg.append("questionId=");
1327 msg.append(questionId);
1328
1329 msg.append(", userId=");
1330 msg.append(userId);
1331
1332 msg.append(StringPool.CLOSE_CURLY_BRACE);
1333
1334 if (_log.isWarnEnabled()) {
1335 _log.warn(msg.toString());
1336 }
1337
1338 throw new NoSuchVoteException(msg.toString());
1339 }
1340
1341 return pollsVote;
1342 }
1343
1344
1352 public PollsVote fetchByQ_U(long questionId, long userId)
1353 throws SystemException {
1354 return fetchByQ_U(questionId, userId, true);
1355 }
1356
1357
1366 public PollsVote fetchByQ_U(long questionId, long userId,
1367 boolean retrieveFromCache) throws SystemException {
1368 Object[] finderArgs = new Object[] { questionId, userId };
1369
1370 Object result = null;
1371
1372 if (retrieveFromCache) {
1373 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_Q_U,
1374 finderArgs, this);
1375 }
1376
1377 if (result instanceof PollsVote) {
1378 PollsVote pollsVote = (PollsVote)result;
1379
1380 if ((questionId != pollsVote.getQuestionId()) ||
1381 (userId != pollsVote.getUserId())) {
1382 result = null;
1383 }
1384 }
1385
1386 if (result == null) {
1387 StringBundler query = new StringBundler(3);
1388
1389 query.append(_SQL_SELECT_POLLSVOTE_WHERE);
1390
1391 query.append(_FINDER_COLUMN_Q_U_QUESTIONID_2);
1392
1393 query.append(_FINDER_COLUMN_Q_U_USERID_2);
1394
1395 String sql = query.toString();
1396
1397 Session session = null;
1398
1399 try {
1400 session = openSession();
1401
1402 Query q = session.createQuery(sql);
1403
1404 QueryPos qPos = QueryPos.getInstance(q);
1405
1406 qPos.add(questionId);
1407
1408 qPos.add(userId);
1409
1410 List<PollsVote> list = q.list();
1411
1412 result = list;
1413
1414 PollsVote pollsVote = null;
1415
1416 if (list.isEmpty()) {
1417 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
1418 finderArgs, list);
1419 }
1420 else {
1421 pollsVote = list.get(0);
1422
1423 cacheResult(pollsVote);
1424
1425 if ((pollsVote.getQuestionId() != questionId) ||
1426 (pollsVote.getUserId() != userId)) {
1427 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
1428 finderArgs, pollsVote);
1429 }
1430 }
1431
1432 return pollsVote;
1433 }
1434 catch (Exception e) {
1435 throw processException(e);
1436 }
1437 finally {
1438 if (result == null) {
1439 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_U,
1440 finderArgs);
1441 }
1442
1443 closeSession(session);
1444 }
1445 }
1446 else {
1447 if (result instanceof List<?>) {
1448 return null;
1449 }
1450 else {
1451 return (PollsVote)result;
1452 }
1453 }
1454 }
1455
1456
1462 public List<PollsVote> findAll() throws SystemException {
1463 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1464 }
1465
1466
1478 public List<PollsVote> findAll(int start, int end)
1479 throws SystemException {
1480 return findAll(start, end, null);
1481 }
1482
1483
1496 public List<PollsVote> findAll(int start, int end,
1497 OrderByComparator orderByComparator) throws SystemException {
1498 FinderPath finderPath = null;
1499 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1500
1501 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1502 (orderByComparator == null)) {
1503 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1504 finderArgs = FINDER_ARGS_EMPTY;
1505 }
1506 else {
1507 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1508 finderArgs = new Object[] { start, end, orderByComparator };
1509 }
1510
1511 List<PollsVote> list = (List<PollsVote>)FinderCacheUtil.getResult(finderPath,
1512 finderArgs, this);
1513
1514 if (list == null) {
1515 StringBundler query = null;
1516 String sql = null;
1517
1518 if (orderByComparator != null) {
1519 query = new StringBundler(2 +
1520 (orderByComparator.getOrderByFields().length * 3));
1521
1522 query.append(_SQL_SELECT_POLLSVOTE);
1523
1524 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1525 orderByComparator);
1526
1527 sql = query.toString();
1528 }
1529 else {
1530 sql = _SQL_SELECT_POLLSVOTE;
1531 }
1532
1533 Session session = null;
1534
1535 try {
1536 session = openSession();
1537
1538 Query q = session.createQuery(sql);
1539
1540 if (orderByComparator == null) {
1541 list = (List<PollsVote>)QueryUtil.list(q, getDialect(),
1542 start, end, false);
1543
1544 Collections.sort(list);
1545 }
1546 else {
1547 list = (List<PollsVote>)QueryUtil.list(q, getDialect(),
1548 start, end);
1549 }
1550 }
1551 catch (Exception e) {
1552 throw processException(e);
1553 }
1554 finally {
1555 if (list == null) {
1556 FinderCacheUtil.removeResult(finderPath, finderArgs);
1557 }
1558 else {
1559 cacheResult(list);
1560
1561 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1562 }
1563
1564 closeSession(session);
1565 }
1566 }
1567
1568 return list;
1569 }
1570
1571
1577 public void removeByQuestionId(long questionId) throws SystemException {
1578 for (PollsVote pollsVote : findByQuestionId(questionId)) {
1579 remove(pollsVote);
1580 }
1581 }
1582
1583
1589 public void removeByChoiceId(long choiceId) throws SystemException {
1590 for (PollsVote pollsVote : findByChoiceId(choiceId)) {
1591 remove(pollsVote);
1592 }
1593 }
1594
1595
1603 public PollsVote removeByQ_U(long questionId, long userId)
1604 throws NoSuchVoteException, SystemException {
1605 PollsVote pollsVote = findByQ_U(questionId, userId);
1606
1607 return remove(pollsVote);
1608 }
1609
1610
1615 public void removeAll() throws SystemException {
1616 for (PollsVote pollsVote : findAll()) {
1617 remove(pollsVote);
1618 }
1619 }
1620
1621
1628 public int countByQuestionId(long questionId) throws SystemException {
1629 Object[] finderArgs = new Object[] { questionId };
1630
1631 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1632 finderArgs, this);
1633
1634 if (count == null) {
1635 StringBundler query = new StringBundler(2);
1636
1637 query.append(_SQL_COUNT_POLLSVOTE_WHERE);
1638
1639 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1640
1641 String sql = query.toString();
1642
1643 Session session = null;
1644
1645 try {
1646 session = openSession();
1647
1648 Query q = session.createQuery(sql);
1649
1650 QueryPos qPos = QueryPos.getInstance(q);
1651
1652 qPos.add(questionId);
1653
1654 count = (Long)q.uniqueResult();
1655 }
1656 catch (Exception e) {
1657 throw processException(e);
1658 }
1659 finally {
1660 if (count == null) {
1661 count = Long.valueOf(0);
1662 }
1663
1664 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1665 finderArgs, count);
1666
1667 closeSession(session);
1668 }
1669 }
1670
1671 return count.intValue();
1672 }
1673
1674
1681 public int countByChoiceId(long choiceId) throws SystemException {
1682 Object[] finderArgs = new Object[] { choiceId };
1683
1684 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CHOICEID,
1685 finderArgs, this);
1686
1687 if (count == null) {
1688 StringBundler query = new StringBundler(2);
1689
1690 query.append(_SQL_COUNT_POLLSVOTE_WHERE);
1691
1692 query.append(_FINDER_COLUMN_CHOICEID_CHOICEID_2);
1693
1694 String sql = query.toString();
1695
1696 Session session = null;
1697
1698 try {
1699 session = openSession();
1700
1701 Query q = session.createQuery(sql);
1702
1703 QueryPos qPos = QueryPos.getInstance(q);
1704
1705 qPos.add(choiceId);
1706
1707 count = (Long)q.uniqueResult();
1708 }
1709 catch (Exception e) {
1710 throw processException(e);
1711 }
1712 finally {
1713 if (count == null) {
1714 count = Long.valueOf(0);
1715 }
1716
1717 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CHOICEID,
1718 finderArgs, count);
1719
1720 closeSession(session);
1721 }
1722 }
1723
1724 return count.intValue();
1725 }
1726
1727
1735 public int countByQ_U(long questionId, long userId)
1736 throws SystemException {
1737 Object[] finderArgs = new Object[] { questionId, userId };
1738
1739 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_Q_U,
1740 finderArgs, this);
1741
1742 if (count == null) {
1743 StringBundler query = new StringBundler(3);
1744
1745 query.append(_SQL_COUNT_POLLSVOTE_WHERE);
1746
1747 query.append(_FINDER_COLUMN_Q_U_QUESTIONID_2);
1748
1749 query.append(_FINDER_COLUMN_Q_U_USERID_2);
1750
1751 String sql = query.toString();
1752
1753 Session session = null;
1754
1755 try {
1756 session = openSession();
1757
1758 Query q = session.createQuery(sql);
1759
1760 QueryPos qPos = QueryPos.getInstance(q);
1761
1762 qPos.add(questionId);
1763
1764 qPos.add(userId);
1765
1766 count = (Long)q.uniqueResult();
1767 }
1768 catch (Exception e) {
1769 throw processException(e);
1770 }
1771 finally {
1772 if (count == null) {
1773 count = Long.valueOf(0);
1774 }
1775
1776 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_Q_U, finderArgs,
1777 count);
1778
1779 closeSession(session);
1780 }
1781 }
1782
1783 return count.intValue();
1784 }
1785
1786
1792 public int countAll() throws SystemException {
1793 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1794 FINDER_ARGS_EMPTY, this);
1795
1796 if (count == null) {
1797 Session session = null;
1798
1799 try {
1800 session = openSession();
1801
1802 Query q = session.createQuery(_SQL_COUNT_POLLSVOTE);
1803
1804 count = (Long)q.uniqueResult();
1805 }
1806 catch (Exception e) {
1807 throw processException(e);
1808 }
1809 finally {
1810 if (count == null) {
1811 count = Long.valueOf(0);
1812 }
1813
1814 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1815 FINDER_ARGS_EMPTY, count);
1816
1817 closeSession(session);
1818 }
1819 }
1820
1821 return count.intValue();
1822 }
1823
1824
1827 public void afterPropertiesSet() {
1828 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1829 com.liferay.portal.util.PropsUtil.get(
1830 "value.object.listener.com.liferay.portlet.polls.model.PollsVote")));
1831
1832 if (listenerClassNames.length > 0) {
1833 try {
1834 List<ModelListener<PollsVote>> listenersList = new ArrayList<ModelListener<PollsVote>>();
1835
1836 for (String listenerClassName : listenerClassNames) {
1837 listenersList.add((ModelListener<PollsVote>)InstanceFactory.newInstance(
1838 listenerClassName));
1839 }
1840
1841 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1842 }
1843 catch (Exception e) {
1844 _log.error(e);
1845 }
1846 }
1847 }
1848
1849 public void destroy() {
1850 EntityCacheUtil.removeCache(PollsVoteImpl.class.getName());
1851 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1852 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1853 }
1854
1855 @BeanReference(type = PollsChoicePersistence.class)
1856 protected PollsChoicePersistence pollsChoicePersistence;
1857 @BeanReference(type = PollsQuestionPersistence.class)
1858 protected PollsQuestionPersistence pollsQuestionPersistence;
1859 @BeanReference(type = PollsVotePersistence.class)
1860 protected PollsVotePersistence pollsVotePersistence;
1861 @BeanReference(type = UserPersistence.class)
1862 protected UserPersistence userPersistence;
1863 private static final String _SQL_SELECT_POLLSVOTE = "SELECT pollsVote FROM PollsVote pollsVote";
1864 private static final String _SQL_SELECT_POLLSVOTE_WHERE = "SELECT pollsVote FROM PollsVote pollsVote WHERE ";
1865 private static final String _SQL_COUNT_POLLSVOTE = "SELECT COUNT(pollsVote) FROM PollsVote pollsVote";
1866 private static final String _SQL_COUNT_POLLSVOTE_WHERE = "SELECT COUNT(pollsVote) FROM PollsVote pollsVote WHERE ";
1867 private static final String _FINDER_COLUMN_QUESTIONID_QUESTIONID_2 = "pollsVote.questionId = ?";
1868 private static final String _FINDER_COLUMN_CHOICEID_CHOICEID_2 = "pollsVote.choiceId = ?";
1869 private static final String _FINDER_COLUMN_Q_U_QUESTIONID_2 = "pollsVote.questionId = ? AND ";
1870 private static final String _FINDER_COLUMN_Q_U_USERID_2 = "pollsVote.userId = ?";
1871 private static final String _ORDER_BY_ENTITY_ALIAS = "pollsVote.";
1872 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsVote exists with the primary key ";
1873 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsVote exists with the key {";
1874 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1875 private static Log _log = LogFactoryUtil.getLog(PollsVotePersistenceImpl.class);
1876 private static PollsVote _nullPollsVote = new PollsVoteImpl() {
1877 @Override
1878 public Object clone() {
1879 return this;
1880 }
1881
1882 @Override
1883 public CacheModel<PollsVote> toCacheModel() {
1884 return _nullPollsVoteCacheModel;
1885 }
1886 };
1887
1888 private static CacheModel<PollsVote> _nullPollsVoteCacheModel = new CacheModel<PollsVote>() {
1889 public PollsVote toEntityModel() {
1890 return _nullPollsVote;
1891 }
1892 };
1893 }