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.BatchSessionUtil;
039 import com.liferay.portal.service.persistence.ResourcePersistence;
040 import com.liferay.portal.service.persistence.UserPersistence;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.polls.NoSuchVoteException;
044 import com.liferay.portlet.polls.model.PollsVote;
045 import com.liferay.portlet.polls.model.impl.PollsVoteImpl;
046 import com.liferay.portlet.polls.model.impl.PollsVoteModelImpl;
047
048 import java.io.Serializable;
049
050 import java.util.ArrayList;
051 import java.util.Collections;
052 import java.util.List;
053
054
066 public class PollsVotePersistenceImpl extends BasePersistenceImpl<PollsVote>
067 implements PollsVotePersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = PollsVoteImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_QUESTIONID =
079 new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
080 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
081 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByQuestionId",
082 new String[] {
083 Long.class.getName(),
084
085 "java.lang.Integer", "java.lang.Integer",
086 "com.liferay.portal.kernel.util.OrderByComparator"
087 });
088 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID =
089 new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
090 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
091 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByQuestionId",
092 new String[] { Long.class.getName() },
093 PollsVoteModelImpl.QUESTIONID_COLUMN_BITMASK);
094 public static final FinderPath FINDER_PATH_COUNT_BY_QUESTIONID = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
095 PollsVoteModelImpl.FINDER_CACHE_ENABLED, Long.class,
096 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByQuestionId",
097 new String[] { Long.class.getName() });
098 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CHOICEID = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
099 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
100 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByChoiceId",
101 new String[] {
102 Long.class.getName(),
103
104 "java.lang.Integer", "java.lang.Integer",
105 "com.liferay.portal.kernel.util.OrderByComparator"
106 });
107 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CHOICEID =
108 new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
109 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
110 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByChoiceId",
111 new String[] { Long.class.getName() },
112 PollsVoteModelImpl.CHOICEID_COLUMN_BITMASK);
113 public static final FinderPath FINDER_PATH_COUNT_BY_CHOICEID = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
114 PollsVoteModelImpl.FINDER_CACHE_ENABLED, Long.class,
115 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByChoiceId",
116 new String[] { Long.class.getName() });
117 public static final FinderPath FINDER_PATH_FETCH_BY_Q_U = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
118 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
119 FINDER_CLASS_NAME_ENTITY, "fetchByQ_U",
120 new String[] { Long.class.getName(), Long.class.getName() },
121 PollsVoteModelImpl.QUESTIONID_COLUMN_BITMASK |
122 PollsVoteModelImpl.USERID_COLUMN_BITMASK);
123 public static final FinderPath FINDER_PATH_COUNT_BY_Q_U = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
124 PollsVoteModelImpl.FINDER_CACHE_ENABLED, Long.class,
125 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByQ_U",
126 new String[] { Long.class.getName(), Long.class.getName() });
127 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
128 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
129 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
130 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
131 PollsVoteModelImpl.FINDER_CACHE_ENABLED, PollsVoteImpl.class,
132 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
133 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
134 PollsVoteModelImpl.FINDER_CACHE_ENABLED, Long.class,
135 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
136
137
142 public void cacheResult(PollsVote pollsVote) {
143 EntityCacheUtil.putResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
144 PollsVoteImpl.class, pollsVote.getPrimaryKey(), pollsVote);
145
146 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
147 new Object[] {
148 Long.valueOf(pollsVote.getQuestionId()),
149 Long.valueOf(pollsVote.getUserId())
150 }, pollsVote);
151
152 pollsVote.resetOriginalValues();
153 }
154
155
160 public void cacheResult(List<PollsVote> pollsVotes) {
161 for (PollsVote pollsVote : pollsVotes) {
162 if (EntityCacheUtil.getResult(
163 PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
164 PollsVoteImpl.class, pollsVote.getPrimaryKey()) == null) {
165 cacheResult(pollsVote);
166 }
167 else {
168 pollsVote.resetOriginalValues();
169 }
170 }
171 }
172
173
180 @Override
181 public void clearCache() {
182 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
183 CacheRegistryUtil.clear(PollsVoteImpl.class.getName());
184 }
185
186 EntityCacheUtil.clearCache(PollsVoteImpl.class.getName());
187
188 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
189 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
190 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
191 }
192
193
200 @Override
201 public void clearCache(PollsVote pollsVote) {
202 EntityCacheUtil.removeResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
203 PollsVoteImpl.class, pollsVote.getPrimaryKey());
204
205 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
206 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
207
208 clearUniqueFindersCache(pollsVote);
209 }
210
211 @Override
212 public void clearCache(List<PollsVote> pollsVotes) {
213 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
214 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
215
216 for (PollsVote pollsVote : pollsVotes) {
217 EntityCacheUtil.removeResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
218 PollsVoteImpl.class, pollsVote.getPrimaryKey());
219
220 clearUniqueFindersCache(pollsVote);
221 }
222 }
223
224 protected void clearUniqueFindersCache(PollsVote pollsVote) {
225 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_U,
226 new Object[] {
227 Long.valueOf(pollsVote.getQuestionId()),
228 Long.valueOf(pollsVote.getUserId())
229 });
230 }
231
232
238 public PollsVote create(long voteId) {
239 PollsVote pollsVote = new PollsVoteImpl();
240
241 pollsVote.setNew(true);
242 pollsVote.setPrimaryKey(voteId);
243
244 return pollsVote;
245 }
246
247
255 public PollsVote remove(long voteId)
256 throws NoSuchVoteException, SystemException {
257 return remove(Long.valueOf(voteId));
258 }
259
260
268 @Override
269 public PollsVote remove(Serializable primaryKey)
270 throws NoSuchVoteException, SystemException {
271 Session session = null;
272
273 try {
274 session = openSession();
275
276 PollsVote pollsVote = (PollsVote)session.get(PollsVoteImpl.class,
277 primaryKey);
278
279 if (pollsVote == null) {
280 if (_log.isWarnEnabled()) {
281 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
282 }
283
284 throw new NoSuchVoteException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
285 primaryKey);
286 }
287
288 return remove(pollsVote);
289 }
290 catch (NoSuchVoteException nsee) {
291 throw nsee;
292 }
293 catch (Exception e) {
294 throw processException(e);
295 }
296 finally {
297 closeSession(session);
298 }
299 }
300
301 @Override
302 protected PollsVote removeImpl(PollsVote pollsVote)
303 throws SystemException {
304 pollsVote = toUnwrappedModel(pollsVote);
305
306 Session session = null;
307
308 try {
309 session = openSession();
310
311 BatchSessionUtil.delete(session, pollsVote);
312 }
313 catch (Exception e) {
314 throw processException(e);
315 }
316 finally {
317 closeSession(session);
318 }
319
320 clearCache(pollsVote);
321
322 return pollsVote;
323 }
324
325 @Override
326 public PollsVote updateImpl(
327 com.liferay.portlet.polls.model.PollsVote pollsVote, boolean merge)
328 throws SystemException {
329 pollsVote = toUnwrappedModel(pollsVote);
330
331 boolean isNew = pollsVote.isNew();
332
333 PollsVoteModelImpl pollsVoteModelImpl = (PollsVoteModelImpl)pollsVote;
334
335 Session session = null;
336
337 try {
338 session = openSession();
339
340 BatchSessionUtil.update(session, pollsVote, merge);
341
342 pollsVote.setNew(false);
343 }
344 catch (Exception e) {
345 throw processException(e);
346 }
347 finally {
348 closeSession(session);
349 }
350
351 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
352
353 if (isNew || !PollsVoteModelImpl.COLUMN_BITMASK_ENABLED) {
354 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
355 }
356
357 else {
358 if ((pollsVoteModelImpl.getColumnBitmask() &
359 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID.getColumnBitmask()) != 0) {
360 Object[] args = new Object[] {
361 Long.valueOf(pollsVoteModelImpl.getOriginalQuestionId())
362 };
363
364 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
365 args);
366 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
367 args);
368
369 args = new Object[] {
370 Long.valueOf(pollsVoteModelImpl.getQuestionId())
371 };
372
373 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
374 args);
375 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
376 args);
377 }
378
379 if ((pollsVoteModelImpl.getColumnBitmask() &
380 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CHOICEID.getColumnBitmask()) != 0) {
381 Object[] args = new Object[] {
382 Long.valueOf(pollsVoteModelImpl.getOriginalChoiceId())
383 };
384
385 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CHOICEID, args);
386 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CHOICEID,
387 args);
388
389 args = new Object[] {
390 Long.valueOf(pollsVoteModelImpl.getChoiceId())
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 }
398
399 EntityCacheUtil.putResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
400 PollsVoteImpl.class, pollsVote.getPrimaryKey(), pollsVote);
401
402 if (isNew) {
403 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
404 new Object[] {
405 Long.valueOf(pollsVote.getQuestionId()),
406 Long.valueOf(pollsVote.getUserId())
407 }, pollsVote);
408 }
409 else {
410 if ((pollsVoteModelImpl.getColumnBitmask() &
411 FINDER_PATH_FETCH_BY_Q_U.getColumnBitmask()) != 0) {
412 Object[] args = new Object[] {
413 Long.valueOf(pollsVoteModelImpl.getOriginalQuestionId()),
414 Long.valueOf(pollsVoteModelImpl.getOriginalUserId())
415 };
416
417 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_Q_U, args);
418
419 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_U, args);
420
421 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
422 new Object[] {
423 Long.valueOf(pollsVote.getQuestionId()),
424 Long.valueOf(pollsVote.getUserId())
425 }, pollsVote);
426 }
427 }
428
429 return pollsVote;
430 }
431
432 protected PollsVote toUnwrappedModel(PollsVote pollsVote) {
433 if (pollsVote instanceof PollsVoteImpl) {
434 return pollsVote;
435 }
436
437 PollsVoteImpl pollsVoteImpl = new PollsVoteImpl();
438
439 pollsVoteImpl.setNew(pollsVote.isNew());
440 pollsVoteImpl.setPrimaryKey(pollsVote.getPrimaryKey());
441
442 pollsVoteImpl.setVoteId(pollsVote.getVoteId());
443 pollsVoteImpl.setCompanyId(pollsVote.getCompanyId());
444 pollsVoteImpl.setUserId(pollsVote.getUserId());
445 pollsVoteImpl.setUserName(pollsVote.getUserName());
446 pollsVoteImpl.setCreateDate(pollsVote.getCreateDate());
447 pollsVoteImpl.setModifiedDate(pollsVote.getModifiedDate());
448 pollsVoteImpl.setQuestionId(pollsVote.getQuestionId());
449 pollsVoteImpl.setChoiceId(pollsVote.getChoiceId());
450 pollsVoteImpl.setVoteDate(pollsVote.getVoteDate());
451
452 return pollsVoteImpl;
453 }
454
455
463 @Override
464 public PollsVote findByPrimaryKey(Serializable primaryKey)
465 throws NoSuchModelException, SystemException {
466 return findByPrimaryKey(((Long)primaryKey).longValue());
467 }
468
469
477 public PollsVote findByPrimaryKey(long voteId)
478 throws NoSuchVoteException, SystemException {
479 PollsVote pollsVote = fetchByPrimaryKey(voteId);
480
481 if (pollsVote == null) {
482 if (_log.isWarnEnabled()) {
483 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + voteId);
484 }
485
486 throw new NoSuchVoteException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
487 voteId);
488 }
489
490 return pollsVote;
491 }
492
493
500 @Override
501 public PollsVote fetchByPrimaryKey(Serializable primaryKey)
502 throws SystemException {
503 return fetchByPrimaryKey(((Long)primaryKey).longValue());
504 }
505
506
513 public PollsVote fetchByPrimaryKey(long voteId) throws SystemException {
514 PollsVote pollsVote = (PollsVote)EntityCacheUtil.getResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
515 PollsVoteImpl.class, voteId);
516
517 if (pollsVote == _nullPollsVote) {
518 return null;
519 }
520
521 if (pollsVote == null) {
522 Session session = null;
523
524 boolean hasException = false;
525
526 try {
527 session = openSession();
528
529 pollsVote = (PollsVote)session.get(PollsVoteImpl.class,
530 Long.valueOf(voteId));
531 }
532 catch (Exception e) {
533 hasException = true;
534
535 throw processException(e);
536 }
537 finally {
538 if (pollsVote != null) {
539 cacheResult(pollsVote);
540 }
541 else if (!hasException) {
542 EntityCacheUtil.putResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
543 PollsVoteImpl.class, voteId, _nullPollsVote);
544 }
545
546 closeSession(session);
547 }
548 }
549
550 return pollsVote;
551 }
552
553
560 public List<PollsVote> findByQuestionId(long questionId)
561 throws SystemException {
562 return findByQuestionId(questionId, QueryUtil.ALL_POS,
563 QueryUtil.ALL_POS, null);
564 }
565
566
579 public List<PollsVote> findByQuestionId(long questionId, int start, int end)
580 throws SystemException {
581 return findByQuestionId(questionId, start, end, null);
582 }
583
584
598 public List<PollsVote> findByQuestionId(long questionId, int start,
599 int end, OrderByComparator orderByComparator) throws SystemException {
600 FinderPath finderPath = null;
601 Object[] finderArgs = null;
602
603 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
604 (orderByComparator == null)) {
605 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID;
606 finderArgs = new Object[] { questionId };
607 }
608 else {
609 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_QUESTIONID;
610 finderArgs = new Object[] { questionId, start, end, orderByComparator };
611 }
612
613 List<PollsVote> list = (List<PollsVote>)FinderCacheUtil.getResult(finderPath,
614 finderArgs, this);
615
616 if ((list != null) && !list.isEmpty()) {
617 for (PollsVote pollsVote : list) {
618 if ((questionId != pollsVote.getQuestionId())) {
619 list = null;
620
621 break;
622 }
623 }
624 }
625
626 if (list == null) {
627 StringBundler query = null;
628
629 if (orderByComparator != null) {
630 query = new StringBundler(3 +
631 (orderByComparator.getOrderByFields().length * 3));
632 }
633 else {
634 query = new StringBundler(2);
635 }
636
637 query.append(_SQL_SELECT_POLLSVOTE_WHERE);
638
639 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
640
641 if (orderByComparator != null) {
642 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
643 orderByComparator);
644 }
645
646 String sql = query.toString();
647
648 Session session = null;
649
650 try {
651 session = openSession();
652
653 Query q = session.createQuery(sql);
654
655 QueryPos qPos = QueryPos.getInstance(q);
656
657 qPos.add(questionId);
658
659 list = (List<PollsVote>)QueryUtil.list(q, getDialect(), start,
660 end);
661 }
662 catch (Exception e) {
663 throw processException(e);
664 }
665 finally {
666 if (list == null) {
667 FinderCacheUtil.removeResult(finderPath, finderArgs);
668 }
669 else {
670 cacheResult(list);
671
672 FinderCacheUtil.putResult(finderPath, finderArgs, list);
673 }
674
675 closeSession(session);
676 }
677 }
678
679 return list;
680 }
681
682
691 public PollsVote findByQuestionId_First(long questionId,
692 OrderByComparator orderByComparator)
693 throws NoSuchVoteException, SystemException {
694 PollsVote pollsVote = fetchByQuestionId_First(questionId,
695 orderByComparator);
696
697 if (pollsVote != null) {
698 return pollsVote;
699 }
700
701 StringBundler msg = new StringBundler(4);
702
703 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
704
705 msg.append("questionId=");
706 msg.append(questionId);
707
708 msg.append(StringPool.CLOSE_CURLY_BRACE);
709
710 throw new NoSuchVoteException(msg.toString());
711 }
712
713
721 public PollsVote fetchByQuestionId_First(long questionId,
722 OrderByComparator orderByComparator) throws SystemException {
723 List<PollsVote> list = findByQuestionId(questionId, 0, 1,
724 orderByComparator);
725
726 if (!list.isEmpty()) {
727 return list.get(0);
728 }
729
730 return null;
731 }
732
733
742 public PollsVote findByQuestionId_Last(long questionId,
743 OrderByComparator orderByComparator)
744 throws NoSuchVoteException, SystemException {
745 PollsVote pollsVote = fetchByQuestionId_Last(questionId,
746 orderByComparator);
747
748 if (pollsVote != null) {
749 return pollsVote;
750 }
751
752 StringBundler msg = new StringBundler(4);
753
754 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
755
756 msg.append("questionId=");
757 msg.append(questionId);
758
759 msg.append(StringPool.CLOSE_CURLY_BRACE);
760
761 throw new NoSuchVoteException(msg.toString());
762 }
763
764
772 public PollsVote fetchByQuestionId_Last(long questionId,
773 OrderByComparator orderByComparator) throws SystemException {
774 int count = countByQuestionId(questionId);
775
776 List<PollsVote> list = findByQuestionId(questionId, count - 1, count,
777 orderByComparator);
778
779 if (!list.isEmpty()) {
780 return list.get(0);
781 }
782
783 return null;
784 }
785
786
796 public PollsVote[] findByQuestionId_PrevAndNext(long voteId,
797 long questionId, OrderByComparator orderByComparator)
798 throws NoSuchVoteException, SystemException {
799 PollsVote pollsVote = findByPrimaryKey(voteId);
800
801 Session session = null;
802
803 try {
804 session = openSession();
805
806 PollsVote[] array = new PollsVoteImpl[3];
807
808 array[0] = getByQuestionId_PrevAndNext(session, pollsVote,
809 questionId, orderByComparator, true);
810
811 array[1] = pollsVote;
812
813 array[2] = getByQuestionId_PrevAndNext(session, pollsVote,
814 questionId, orderByComparator, false);
815
816 return array;
817 }
818 catch (Exception e) {
819 throw processException(e);
820 }
821 finally {
822 closeSession(session);
823 }
824 }
825
826 protected PollsVote getByQuestionId_PrevAndNext(Session session,
827 PollsVote pollsVote, long questionId,
828 OrderByComparator orderByComparator, boolean previous) {
829 StringBundler query = null;
830
831 if (orderByComparator != null) {
832 query = new StringBundler(6 +
833 (orderByComparator.getOrderByFields().length * 6));
834 }
835 else {
836 query = new StringBundler(3);
837 }
838
839 query.append(_SQL_SELECT_POLLSVOTE_WHERE);
840
841 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
842
843 if (orderByComparator != null) {
844 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
845
846 if (orderByConditionFields.length > 0) {
847 query.append(WHERE_AND);
848 }
849
850 for (int i = 0; i < orderByConditionFields.length; i++) {
851 query.append(_ORDER_BY_ENTITY_ALIAS);
852 query.append(orderByConditionFields[i]);
853
854 if ((i + 1) < orderByConditionFields.length) {
855 if (orderByComparator.isAscending() ^ previous) {
856 query.append(WHERE_GREATER_THAN_HAS_NEXT);
857 }
858 else {
859 query.append(WHERE_LESSER_THAN_HAS_NEXT);
860 }
861 }
862 else {
863 if (orderByComparator.isAscending() ^ previous) {
864 query.append(WHERE_GREATER_THAN);
865 }
866 else {
867 query.append(WHERE_LESSER_THAN);
868 }
869 }
870 }
871
872 query.append(ORDER_BY_CLAUSE);
873
874 String[] orderByFields = orderByComparator.getOrderByFields();
875
876 for (int i = 0; i < orderByFields.length; i++) {
877 query.append(_ORDER_BY_ENTITY_ALIAS);
878 query.append(orderByFields[i]);
879
880 if ((i + 1) < orderByFields.length) {
881 if (orderByComparator.isAscending() ^ previous) {
882 query.append(ORDER_BY_ASC_HAS_NEXT);
883 }
884 else {
885 query.append(ORDER_BY_DESC_HAS_NEXT);
886 }
887 }
888 else {
889 if (orderByComparator.isAscending() ^ previous) {
890 query.append(ORDER_BY_ASC);
891 }
892 else {
893 query.append(ORDER_BY_DESC);
894 }
895 }
896 }
897 }
898
899 String sql = query.toString();
900
901 Query q = session.createQuery(sql);
902
903 q.setFirstResult(0);
904 q.setMaxResults(2);
905
906 QueryPos qPos = QueryPos.getInstance(q);
907
908 qPos.add(questionId);
909
910 if (orderByComparator != null) {
911 Object[] values = orderByComparator.getOrderByConditionValues(pollsVote);
912
913 for (Object value : values) {
914 qPos.add(value);
915 }
916 }
917
918 List<PollsVote> list = q.list();
919
920 if (list.size() == 2) {
921 return list.get(1);
922 }
923 else {
924 return null;
925 }
926 }
927
928
935 public List<PollsVote> findByChoiceId(long choiceId)
936 throws SystemException {
937 return findByChoiceId(choiceId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
938 null);
939 }
940
941
954 public List<PollsVote> findByChoiceId(long choiceId, int start, int end)
955 throws SystemException {
956 return findByChoiceId(choiceId, start, end, null);
957 }
958
959
973 public List<PollsVote> findByChoiceId(long choiceId, int start, int end,
974 OrderByComparator orderByComparator) throws SystemException {
975 FinderPath finderPath = null;
976 Object[] finderArgs = null;
977
978 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
979 (orderByComparator == null)) {
980 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CHOICEID;
981 finderArgs = new Object[] { choiceId };
982 }
983 else {
984 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CHOICEID;
985 finderArgs = new Object[] { choiceId, start, end, orderByComparator };
986 }
987
988 List<PollsVote> list = (List<PollsVote>)FinderCacheUtil.getResult(finderPath,
989 finderArgs, this);
990
991 if ((list != null) && !list.isEmpty()) {
992 for (PollsVote pollsVote : list) {
993 if ((choiceId != pollsVote.getChoiceId())) {
994 list = null;
995
996 break;
997 }
998 }
999 }
1000
1001 if (list == null) {
1002 StringBundler query = null;
1003
1004 if (orderByComparator != null) {
1005 query = new StringBundler(3 +
1006 (orderByComparator.getOrderByFields().length * 3));
1007 }
1008 else {
1009 query = new StringBundler(2);
1010 }
1011
1012 query.append(_SQL_SELECT_POLLSVOTE_WHERE);
1013
1014 query.append(_FINDER_COLUMN_CHOICEID_CHOICEID_2);
1015
1016 if (orderByComparator != null) {
1017 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1018 orderByComparator);
1019 }
1020
1021 String sql = query.toString();
1022
1023 Session session = null;
1024
1025 try {
1026 session = openSession();
1027
1028 Query q = session.createQuery(sql);
1029
1030 QueryPos qPos = QueryPos.getInstance(q);
1031
1032 qPos.add(choiceId);
1033
1034 list = (List<PollsVote>)QueryUtil.list(q, getDialect(), start,
1035 end);
1036 }
1037 catch (Exception e) {
1038 throw processException(e);
1039 }
1040 finally {
1041 if (list == null) {
1042 FinderCacheUtil.removeResult(finderPath, finderArgs);
1043 }
1044 else {
1045 cacheResult(list);
1046
1047 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1048 }
1049
1050 closeSession(session);
1051 }
1052 }
1053
1054 return list;
1055 }
1056
1057
1066 public PollsVote findByChoiceId_First(long choiceId,
1067 OrderByComparator orderByComparator)
1068 throws NoSuchVoteException, SystemException {
1069 PollsVote pollsVote = fetchByChoiceId_First(choiceId, orderByComparator);
1070
1071 if (pollsVote != null) {
1072 return pollsVote;
1073 }
1074
1075 StringBundler msg = new StringBundler(4);
1076
1077 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1078
1079 msg.append("choiceId=");
1080 msg.append(choiceId);
1081
1082 msg.append(StringPool.CLOSE_CURLY_BRACE);
1083
1084 throw new NoSuchVoteException(msg.toString());
1085 }
1086
1087
1095 public PollsVote fetchByChoiceId_First(long choiceId,
1096 OrderByComparator orderByComparator) throws SystemException {
1097 List<PollsVote> list = findByChoiceId(choiceId, 0, 1, orderByComparator);
1098
1099 if (!list.isEmpty()) {
1100 return list.get(0);
1101 }
1102
1103 return null;
1104 }
1105
1106
1115 public PollsVote findByChoiceId_Last(long choiceId,
1116 OrderByComparator orderByComparator)
1117 throws NoSuchVoteException, SystemException {
1118 PollsVote pollsVote = fetchByChoiceId_Last(choiceId, orderByComparator);
1119
1120 if (pollsVote != null) {
1121 return pollsVote;
1122 }
1123
1124 StringBundler msg = new StringBundler(4);
1125
1126 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1127
1128 msg.append("choiceId=");
1129 msg.append(choiceId);
1130
1131 msg.append(StringPool.CLOSE_CURLY_BRACE);
1132
1133 throw new NoSuchVoteException(msg.toString());
1134 }
1135
1136
1144 public PollsVote fetchByChoiceId_Last(long choiceId,
1145 OrderByComparator orderByComparator) throws SystemException {
1146 int count = countByChoiceId(choiceId);
1147
1148 List<PollsVote> list = findByChoiceId(choiceId, count - 1, count,
1149 orderByComparator);
1150
1151 if (!list.isEmpty()) {
1152 return list.get(0);
1153 }
1154
1155 return null;
1156 }
1157
1158
1168 public PollsVote[] findByChoiceId_PrevAndNext(long voteId, long choiceId,
1169 OrderByComparator orderByComparator)
1170 throws NoSuchVoteException, SystemException {
1171 PollsVote pollsVote = findByPrimaryKey(voteId);
1172
1173 Session session = null;
1174
1175 try {
1176 session = openSession();
1177
1178 PollsVote[] array = new PollsVoteImpl[3];
1179
1180 array[0] = getByChoiceId_PrevAndNext(session, pollsVote, choiceId,
1181 orderByComparator, true);
1182
1183 array[1] = pollsVote;
1184
1185 array[2] = getByChoiceId_PrevAndNext(session, pollsVote, choiceId,
1186 orderByComparator, false);
1187
1188 return array;
1189 }
1190 catch (Exception e) {
1191 throw processException(e);
1192 }
1193 finally {
1194 closeSession(session);
1195 }
1196 }
1197
1198 protected PollsVote getByChoiceId_PrevAndNext(Session session,
1199 PollsVote pollsVote, long choiceId,
1200 OrderByComparator orderByComparator, boolean previous) {
1201 StringBundler query = null;
1202
1203 if (orderByComparator != null) {
1204 query = new StringBundler(6 +
1205 (orderByComparator.getOrderByFields().length * 6));
1206 }
1207 else {
1208 query = new StringBundler(3);
1209 }
1210
1211 query.append(_SQL_SELECT_POLLSVOTE_WHERE);
1212
1213 query.append(_FINDER_COLUMN_CHOICEID_CHOICEID_2);
1214
1215 if (orderByComparator != null) {
1216 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1217
1218 if (orderByConditionFields.length > 0) {
1219 query.append(WHERE_AND);
1220 }
1221
1222 for (int i = 0; i < orderByConditionFields.length; i++) {
1223 query.append(_ORDER_BY_ENTITY_ALIAS);
1224 query.append(orderByConditionFields[i]);
1225
1226 if ((i + 1) < orderByConditionFields.length) {
1227 if (orderByComparator.isAscending() ^ previous) {
1228 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1229 }
1230 else {
1231 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1232 }
1233 }
1234 else {
1235 if (orderByComparator.isAscending() ^ previous) {
1236 query.append(WHERE_GREATER_THAN);
1237 }
1238 else {
1239 query.append(WHERE_LESSER_THAN);
1240 }
1241 }
1242 }
1243
1244 query.append(ORDER_BY_CLAUSE);
1245
1246 String[] orderByFields = orderByComparator.getOrderByFields();
1247
1248 for (int i = 0; i < orderByFields.length; i++) {
1249 query.append(_ORDER_BY_ENTITY_ALIAS);
1250 query.append(orderByFields[i]);
1251
1252 if ((i + 1) < orderByFields.length) {
1253 if (orderByComparator.isAscending() ^ previous) {
1254 query.append(ORDER_BY_ASC_HAS_NEXT);
1255 }
1256 else {
1257 query.append(ORDER_BY_DESC_HAS_NEXT);
1258 }
1259 }
1260 else {
1261 if (orderByComparator.isAscending() ^ previous) {
1262 query.append(ORDER_BY_ASC);
1263 }
1264 else {
1265 query.append(ORDER_BY_DESC);
1266 }
1267 }
1268 }
1269 }
1270
1271 String sql = query.toString();
1272
1273 Query q = session.createQuery(sql);
1274
1275 q.setFirstResult(0);
1276 q.setMaxResults(2);
1277
1278 QueryPos qPos = QueryPos.getInstance(q);
1279
1280 qPos.add(choiceId);
1281
1282 if (orderByComparator != null) {
1283 Object[] values = orderByComparator.getOrderByConditionValues(pollsVote);
1284
1285 for (Object value : values) {
1286 qPos.add(value);
1287 }
1288 }
1289
1290 List<PollsVote> list = q.list();
1291
1292 if (list.size() == 2) {
1293 return list.get(1);
1294 }
1295 else {
1296 return null;
1297 }
1298 }
1299
1300
1309 public PollsVote findByQ_U(long questionId, long userId)
1310 throws NoSuchVoteException, SystemException {
1311 PollsVote pollsVote = fetchByQ_U(questionId, userId);
1312
1313 if (pollsVote == null) {
1314 StringBundler msg = new StringBundler(6);
1315
1316 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1317
1318 msg.append("questionId=");
1319 msg.append(questionId);
1320
1321 msg.append(", userId=");
1322 msg.append(userId);
1323
1324 msg.append(StringPool.CLOSE_CURLY_BRACE);
1325
1326 if (_log.isWarnEnabled()) {
1327 _log.warn(msg.toString());
1328 }
1329
1330 throw new NoSuchVoteException(msg.toString());
1331 }
1332
1333 return pollsVote;
1334 }
1335
1336
1344 public PollsVote fetchByQ_U(long questionId, long userId)
1345 throws SystemException {
1346 return fetchByQ_U(questionId, userId, true);
1347 }
1348
1349
1358 public PollsVote fetchByQ_U(long questionId, long userId,
1359 boolean retrieveFromCache) throws SystemException {
1360 Object[] finderArgs = new Object[] { questionId, userId };
1361
1362 Object result = null;
1363
1364 if (retrieveFromCache) {
1365 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_Q_U,
1366 finderArgs, this);
1367 }
1368
1369 if (result instanceof PollsVote) {
1370 PollsVote pollsVote = (PollsVote)result;
1371
1372 if ((questionId != pollsVote.getQuestionId()) ||
1373 (userId != pollsVote.getUserId())) {
1374 result = null;
1375 }
1376 }
1377
1378 if (result == null) {
1379 StringBundler query = new StringBundler(3);
1380
1381 query.append(_SQL_SELECT_POLLSVOTE_WHERE);
1382
1383 query.append(_FINDER_COLUMN_Q_U_QUESTIONID_2);
1384
1385 query.append(_FINDER_COLUMN_Q_U_USERID_2);
1386
1387 String sql = query.toString();
1388
1389 Session session = null;
1390
1391 try {
1392 session = openSession();
1393
1394 Query q = session.createQuery(sql);
1395
1396 QueryPos qPos = QueryPos.getInstance(q);
1397
1398 qPos.add(questionId);
1399
1400 qPos.add(userId);
1401
1402 List<PollsVote> list = q.list();
1403
1404 result = list;
1405
1406 PollsVote pollsVote = null;
1407
1408 if (list.isEmpty()) {
1409 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
1410 finderArgs, list);
1411 }
1412 else {
1413 pollsVote = list.get(0);
1414
1415 cacheResult(pollsVote);
1416
1417 if ((pollsVote.getQuestionId() != questionId) ||
1418 (pollsVote.getUserId() != userId)) {
1419 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
1420 finderArgs, pollsVote);
1421 }
1422 }
1423
1424 return pollsVote;
1425 }
1426 catch (Exception e) {
1427 throw processException(e);
1428 }
1429 finally {
1430 if (result == null) {
1431 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_U,
1432 finderArgs);
1433 }
1434
1435 closeSession(session);
1436 }
1437 }
1438 else {
1439 if (result instanceof List<?>) {
1440 return null;
1441 }
1442 else {
1443 return (PollsVote)result;
1444 }
1445 }
1446 }
1447
1448
1454 public List<PollsVote> findAll() throws SystemException {
1455 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1456 }
1457
1458
1470 public List<PollsVote> findAll(int start, int end)
1471 throws SystemException {
1472 return findAll(start, end, null);
1473 }
1474
1475
1488 public List<PollsVote> findAll(int start, int end,
1489 OrderByComparator orderByComparator) throws SystemException {
1490 FinderPath finderPath = null;
1491 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1492
1493 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1494 (orderByComparator == null)) {
1495 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1496 finderArgs = FINDER_ARGS_EMPTY;
1497 }
1498 else {
1499 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1500 finderArgs = new Object[] { start, end, orderByComparator };
1501 }
1502
1503 List<PollsVote> list = (List<PollsVote>)FinderCacheUtil.getResult(finderPath,
1504 finderArgs, this);
1505
1506 if (list == null) {
1507 StringBundler query = null;
1508 String sql = null;
1509
1510 if (orderByComparator != null) {
1511 query = new StringBundler(2 +
1512 (orderByComparator.getOrderByFields().length * 3));
1513
1514 query.append(_SQL_SELECT_POLLSVOTE);
1515
1516 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1517 orderByComparator);
1518
1519 sql = query.toString();
1520 }
1521 else {
1522 sql = _SQL_SELECT_POLLSVOTE;
1523 }
1524
1525 Session session = null;
1526
1527 try {
1528 session = openSession();
1529
1530 Query q = session.createQuery(sql);
1531
1532 if (orderByComparator == null) {
1533 list = (List<PollsVote>)QueryUtil.list(q, getDialect(),
1534 start, end, false);
1535
1536 Collections.sort(list);
1537 }
1538 else {
1539 list = (List<PollsVote>)QueryUtil.list(q, getDialect(),
1540 start, end);
1541 }
1542 }
1543 catch (Exception e) {
1544 throw processException(e);
1545 }
1546 finally {
1547 if (list == null) {
1548 FinderCacheUtil.removeResult(finderPath, finderArgs);
1549 }
1550 else {
1551 cacheResult(list);
1552
1553 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1554 }
1555
1556 closeSession(session);
1557 }
1558 }
1559
1560 return list;
1561 }
1562
1563
1569 public void removeByQuestionId(long questionId) throws SystemException {
1570 for (PollsVote pollsVote : findByQuestionId(questionId)) {
1571 remove(pollsVote);
1572 }
1573 }
1574
1575
1581 public void removeByChoiceId(long choiceId) throws SystemException {
1582 for (PollsVote pollsVote : findByChoiceId(choiceId)) {
1583 remove(pollsVote);
1584 }
1585 }
1586
1587
1595 public PollsVote removeByQ_U(long questionId, long userId)
1596 throws NoSuchVoteException, SystemException {
1597 PollsVote pollsVote = findByQ_U(questionId, userId);
1598
1599 return remove(pollsVote);
1600 }
1601
1602
1607 public void removeAll() throws SystemException {
1608 for (PollsVote pollsVote : findAll()) {
1609 remove(pollsVote);
1610 }
1611 }
1612
1613
1620 public int countByQuestionId(long questionId) throws SystemException {
1621 Object[] finderArgs = new Object[] { questionId };
1622
1623 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1624 finderArgs, this);
1625
1626 if (count == null) {
1627 StringBundler query = new StringBundler(2);
1628
1629 query.append(_SQL_COUNT_POLLSVOTE_WHERE);
1630
1631 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1632
1633 String sql = query.toString();
1634
1635 Session session = null;
1636
1637 try {
1638 session = openSession();
1639
1640 Query q = session.createQuery(sql);
1641
1642 QueryPos qPos = QueryPos.getInstance(q);
1643
1644 qPos.add(questionId);
1645
1646 count = (Long)q.uniqueResult();
1647 }
1648 catch (Exception e) {
1649 throw processException(e);
1650 }
1651 finally {
1652 if (count == null) {
1653 count = Long.valueOf(0);
1654 }
1655
1656 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1657 finderArgs, count);
1658
1659 closeSession(session);
1660 }
1661 }
1662
1663 return count.intValue();
1664 }
1665
1666
1673 public int countByChoiceId(long choiceId) throws SystemException {
1674 Object[] finderArgs = new Object[] { choiceId };
1675
1676 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CHOICEID,
1677 finderArgs, this);
1678
1679 if (count == null) {
1680 StringBundler query = new StringBundler(2);
1681
1682 query.append(_SQL_COUNT_POLLSVOTE_WHERE);
1683
1684 query.append(_FINDER_COLUMN_CHOICEID_CHOICEID_2);
1685
1686 String sql = query.toString();
1687
1688 Session session = null;
1689
1690 try {
1691 session = openSession();
1692
1693 Query q = session.createQuery(sql);
1694
1695 QueryPos qPos = QueryPos.getInstance(q);
1696
1697 qPos.add(choiceId);
1698
1699 count = (Long)q.uniqueResult();
1700 }
1701 catch (Exception e) {
1702 throw processException(e);
1703 }
1704 finally {
1705 if (count == null) {
1706 count = Long.valueOf(0);
1707 }
1708
1709 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CHOICEID,
1710 finderArgs, count);
1711
1712 closeSession(session);
1713 }
1714 }
1715
1716 return count.intValue();
1717 }
1718
1719
1727 public int countByQ_U(long questionId, long userId)
1728 throws SystemException {
1729 Object[] finderArgs = new Object[] { questionId, userId };
1730
1731 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_Q_U,
1732 finderArgs, this);
1733
1734 if (count == null) {
1735 StringBundler query = new StringBundler(3);
1736
1737 query.append(_SQL_COUNT_POLLSVOTE_WHERE);
1738
1739 query.append(_FINDER_COLUMN_Q_U_QUESTIONID_2);
1740
1741 query.append(_FINDER_COLUMN_Q_U_USERID_2);
1742
1743 String sql = query.toString();
1744
1745 Session session = null;
1746
1747 try {
1748 session = openSession();
1749
1750 Query q = session.createQuery(sql);
1751
1752 QueryPos qPos = QueryPos.getInstance(q);
1753
1754 qPos.add(questionId);
1755
1756 qPos.add(userId);
1757
1758 count = (Long)q.uniqueResult();
1759 }
1760 catch (Exception e) {
1761 throw processException(e);
1762 }
1763 finally {
1764 if (count == null) {
1765 count = Long.valueOf(0);
1766 }
1767
1768 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_Q_U, finderArgs,
1769 count);
1770
1771 closeSession(session);
1772 }
1773 }
1774
1775 return count.intValue();
1776 }
1777
1778
1784 public int countAll() throws SystemException {
1785 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1786 FINDER_ARGS_EMPTY, this);
1787
1788 if (count == null) {
1789 Session session = null;
1790
1791 try {
1792 session = openSession();
1793
1794 Query q = session.createQuery(_SQL_COUNT_POLLSVOTE);
1795
1796 count = (Long)q.uniqueResult();
1797 }
1798 catch (Exception e) {
1799 throw processException(e);
1800 }
1801 finally {
1802 if (count == null) {
1803 count = Long.valueOf(0);
1804 }
1805
1806 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1807 FINDER_ARGS_EMPTY, count);
1808
1809 closeSession(session);
1810 }
1811 }
1812
1813 return count.intValue();
1814 }
1815
1816
1819 public void afterPropertiesSet() {
1820 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1821 com.liferay.portal.util.PropsUtil.get(
1822 "value.object.listener.com.liferay.portlet.polls.model.PollsVote")));
1823
1824 if (listenerClassNames.length > 0) {
1825 try {
1826 List<ModelListener<PollsVote>> listenersList = new ArrayList<ModelListener<PollsVote>>();
1827
1828 for (String listenerClassName : listenerClassNames) {
1829 listenersList.add((ModelListener<PollsVote>)InstanceFactory.newInstance(
1830 listenerClassName));
1831 }
1832
1833 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1834 }
1835 catch (Exception e) {
1836 _log.error(e);
1837 }
1838 }
1839 }
1840
1841 public void destroy() {
1842 EntityCacheUtil.removeCache(PollsVoteImpl.class.getName());
1843 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1844 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1845 }
1846
1847 @BeanReference(type = PollsChoicePersistence.class)
1848 protected PollsChoicePersistence pollsChoicePersistence;
1849 @BeanReference(type = PollsQuestionPersistence.class)
1850 protected PollsQuestionPersistence pollsQuestionPersistence;
1851 @BeanReference(type = PollsVotePersistence.class)
1852 protected PollsVotePersistence pollsVotePersistence;
1853 @BeanReference(type = ResourcePersistence.class)
1854 protected ResourcePersistence resourcePersistence;
1855 @BeanReference(type = UserPersistence.class)
1856 protected UserPersistence userPersistence;
1857 private static final String _SQL_SELECT_POLLSVOTE = "SELECT pollsVote FROM PollsVote pollsVote";
1858 private static final String _SQL_SELECT_POLLSVOTE_WHERE = "SELECT pollsVote FROM PollsVote pollsVote WHERE ";
1859 private static final String _SQL_COUNT_POLLSVOTE = "SELECT COUNT(pollsVote) FROM PollsVote pollsVote";
1860 private static final String _SQL_COUNT_POLLSVOTE_WHERE = "SELECT COUNT(pollsVote) FROM PollsVote pollsVote WHERE ";
1861 private static final String _FINDER_COLUMN_QUESTIONID_QUESTIONID_2 = "pollsVote.questionId = ?";
1862 private static final String _FINDER_COLUMN_CHOICEID_CHOICEID_2 = "pollsVote.choiceId = ?";
1863 private static final String _FINDER_COLUMN_Q_U_QUESTIONID_2 = "pollsVote.questionId = ? AND ";
1864 private static final String _FINDER_COLUMN_Q_U_USERID_2 = "pollsVote.userId = ?";
1865 private static final String _ORDER_BY_ENTITY_ALIAS = "pollsVote.";
1866 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsVote exists with the primary key ";
1867 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsVote exists with the key {";
1868 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1869 private static Log _log = LogFactoryUtil.getLog(PollsVotePersistenceImpl.class);
1870 private static PollsVote _nullPollsVote = new PollsVoteImpl() {
1871 @Override
1872 public Object clone() {
1873 return this;
1874 }
1875
1876 @Override
1877 public CacheModel<PollsVote> toCacheModel() {
1878 return _nullPollsVoteCacheModel;
1879 }
1880 };
1881
1882 private static CacheModel<PollsVote> _nullPollsVoteCacheModel = new CacheModel<PollsVote>() {
1883 public PollsVote toEntityModel() {
1884 return _nullPollsVote;
1885 }
1886 };
1887 }