1
22
23 package com.liferay.portlet.polls.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
27 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
28 import com.liferay.portal.kernel.dao.orm.Query;
29 import com.liferay.portal.kernel.dao.orm.QueryPos;
30 import com.liferay.portal.kernel.dao.orm.QueryUtil;
31 import com.liferay.portal.kernel.dao.orm.Session;
32 import com.liferay.portal.kernel.util.GetterUtil;
33 import com.liferay.portal.kernel.util.ListUtil;
34 import com.liferay.portal.kernel.util.OrderByComparator;
35 import com.liferay.portal.kernel.util.StringPool;
36 import com.liferay.portal.kernel.util.StringUtil;
37 import com.liferay.portal.model.ModelListener;
38 import com.liferay.portal.service.persistence.BatchSessionUtil;
39 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
40
41 import com.liferay.portlet.polls.NoSuchVoteException;
42 import com.liferay.portlet.polls.model.PollsVote;
43 import com.liferay.portlet.polls.model.impl.PollsVoteImpl;
44 import com.liferay.portlet.polls.model.impl.PollsVoteModelImpl;
45
46 import org.apache.commons.logging.Log;
47 import org.apache.commons.logging.LogFactory;
48
49 import java.util.ArrayList;
50 import java.util.Collections;
51 import java.util.Iterator;
52 import java.util.List;
53
54
60 public class PollsVotePersistenceImpl extends BasePersistenceImpl
61 implements PollsVotePersistence {
62 public PollsVote create(long voteId) {
63 PollsVote pollsVote = new PollsVoteImpl();
64
65 pollsVote.setNew(true);
66 pollsVote.setPrimaryKey(voteId);
67
68 return pollsVote;
69 }
70
71 public PollsVote remove(long voteId)
72 throws NoSuchVoteException, SystemException {
73 Session session = null;
74
75 try {
76 session = openSession();
77
78 PollsVote pollsVote = (PollsVote)session.get(PollsVoteImpl.class,
79 new Long(voteId));
80
81 if (pollsVote == null) {
82 if (_log.isWarnEnabled()) {
83 _log.warn("No PollsVote exists with the primary key " +
84 voteId);
85 }
86
87 throw new NoSuchVoteException(
88 "No PollsVote exists with the primary key " + voteId);
89 }
90
91 return remove(pollsVote);
92 }
93 catch (NoSuchVoteException nsee) {
94 throw nsee;
95 }
96 catch (Exception e) {
97 throw processException(e);
98 }
99 finally {
100 closeSession(session);
101 }
102 }
103
104 public PollsVote remove(PollsVote pollsVote) throws SystemException {
105 if (_listeners.length > 0) {
106 for (ModelListener listener : _listeners) {
107 listener.onBeforeRemove(pollsVote);
108 }
109 }
110
111 pollsVote = removeImpl(pollsVote);
112
113 if (_listeners.length > 0) {
114 for (ModelListener listener : _listeners) {
115 listener.onAfterRemove(pollsVote);
116 }
117 }
118
119 return pollsVote;
120 }
121
122 protected PollsVote removeImpl(PollsVote pollsVote)
123 throws SystemException {
124 Session session = null;
125
126 try {
127 session = openSession();
128
129 if (BatchSessionUtil.isEnabled()) {
130 Object staleObject = session.get(PollsVoteImpl.class,
131 pollsVote.getPrimaryKeyObj());
132
133 if (staleObject != null) {
134 session.evict(staleObject);
135 }
136 }
137
138 session.delete(pollsVote);
139
140 session.flush();
141
142 return pollsVote;
143 }
144 catch (Exception e) {
145 throw processException(e);
146 }
147 finally {
148 closeSession(session);
149
150 FinderCacheUtil.clearCache(PollsVote.class.getName());
151 }
152 }
153
154
157 public PollsVote update(PollsVote pollsVote) throws SystemException {
158 if (_log.isWarnEnabled()) {
159 _log.warn(
160 "Using the deprecated update(PollsVote pollsVote) method. Use update(PollsVote pollsVote, boolean merge) instead.");
161 }
162
163 return update(pollsVote, false);
164 }
165
166
179 public PollsVote update(PollsVote pollsVote, boolean merge)
180 throws SystemException {
181 boolean isNew = pollsVote.isNew();
182
183 if (_listeners.length > 0) {
184 for (ModelListener listener : _listeners) {
185 if (isNew) {
186 listener.onBeforeCreate(pollsVote);
187 }
188 else {
189 listener.onBeforeUpdate(pollsVote);
190 }
191 }
192 }
193
194 pollsVote = updateImpl(pollsVote, merge);
195
196 if (_listeners.length > 0) {
197 for (ModelListener listener : _listeners) {
198 if (isNew) {
199 listener.onAfterCreate(pollsVote);
200 }
201 else {
202 listener.onAfterUpdate(pollsVote);
203 }
204 }
205 }
206
207 return pollsVote;
208 }
209
210 public PollsVote updateImpl(
211 com.liferay.portlet.polls.model.PollsVote pollsVote, boolean merge)
212 throws SystemException {
213 Session session = null;
214
215 try {
216 session = openSession();
217
218 BatchSessionUtil.update(session, pollsVote, merge);
219
220 pollsVote.setNew(false);
221
222 return pollsVote;
223 }
224 catch (Exception e) {
225 throw processException(e);
226 }
227 finally {
228 closeSession(session);
229
230 FinderCacheUtil.clearCache(PollsVote.class.getName());
231 }
232 }
233
234 public PollsVote findByPrimaryKey(long voteId)
235 throws NoSuchVoteException, SystemException {
236 PollsVote pollsVote = fetchByPrimaryKey(voteId);
237
238 if (pollsVote == null) {
239 if (_log.isWarnEnabled()) {
240 _log.warn("No PollsVote exists with the primary key " + voteId);
241 }
242
243 throw new NoSuchVoteException(
244 "No PollsVote exists with the primary key " + voteId);
245 }
246
247 return pollsVote;
248 }
249
250 public PollsVote fetchByPrimaryKey(long voteId) throws SystemException {
251 Session session = null;
252
253 try {
254 session = openSession();
255
256 return (PollsVote)session.get(PollsVoteImpl.class, new Long(voteId));
257 }
258 catch (Exception e) {
259 throw processException(e);
260 }
261 finally {
262 closeSession(session);
263 }
264 }
265
266 public List<PollsVote> findByQuestionId(long questionId)
267 throws SystemException {
268 boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
269 String finderClassName = PollsVote.class.getName();
270 String finderMethodName = "findByQuestionId";
271 String[] finderParams = new String[] { Long.class.getName() };
272 Object[] finderArgs = new Object[] { new Long(questionId) };
273
274 Object result = null;
275
276 if (finderClassNameCacheEnabled) {
277 result = FinderCacheUtil.getResult(finderClassName,
278 finderMethodName, finderParams, finderArgs, this);
279 }
280
281 if (result == null) {
282 Session session = null;
283
284 try {
285 session = openSession();
286
287 StringBuilder query = new StringBuilder();
288
289 query.append(
290 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
291
292 query.append("questionId = ?");
293
294 query.append(" ");
295
296 Query q = session.createQuery(query.toString());
297
298 QueryPos qPos = QueryPos.getInstance(q);
299
300 qPos.add(questionId);
301
302 List<PollsVote> list = q.list();
303
304 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
305 finderClassName, finderMethodName, finderParams,
306 finderArgs, list);
307
308 return list;
309 }
310 catch (Exception e) {
311 throw processException(e);
312 }
313 finally {
314 closeSession(session);
315 }
316 }
317 else {
318 return (List<PollsVote>)result;
319 }
320 }
321
322 public List<PollsVote> findByQuestionId(long questionId, int start, int end)
323 throws SystemException {
324 return findByQuestionId(questionId, start, end, null);
325 }
326
327 public List<PollsVote> findByQuestionId(long questionId, int start,
328 int end, OrderByComparator obc) throws SystemException {
329 boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
330 String finderClassName = PollsVote.class.getName();
331 String finderMethodName = "findByQuestionId";
332 String[] finderParams = new String[] {
333 Long.class.getName(),
334
335 "java.lang.Integer", "java.lang.Integer",
336 "com.liferay.portal.kernel.util.OrderByComparator"
337 };
338 Object[] finderArgs = new Object[] {
339 new Long(questionId),
340
341 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
342 };
343
344 Object result = null;
345
346 if (finderClassNameCacheEnabled) {
347 result = FinderCacheUtil.getResult(finderClassName,
348 finderMethodName, finderParams, finderArgs, this);
349 }
350
351 if (result == null) {
352 Session session = null;
353
354 try {
355 session = openSession();
356
357 StringBuilder query = new StringBuilder();
358
359 query.append(
360 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
361
362 query.append("questionId = ?");
363
364 query.append(" ");
365
366 if (obc != null) {
367 query.append("ORDER BY ");
368 query.append(obc.getOrderBy());
369 }
370
371 Query q = session.createQuery(query.toString());
372
373 QueryPos qPos = QueryPos.getInstance(q);
374
375 qPos.add(questionId);
376
377 List<PollsVote> list = (List<PollsVote>)QueryUtil.list(q,
378 getDialect(), start, end);
379
380 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
381 finderClassName, finderMethodName, finderParams,
382 finderArgs, list);
383
384 return list;
385 }
386 catch (Exception e) {
387 throw processException(e);
388 }
389 finally {
390 closeSession(session);
391 }
392 }
393 else {
394 return (List<PollsVote>)result;
395 }
396 }
397
398 public PollsVote findByQuestionId_First(long questionId,
399 OrderByComparator obc) throws NoSuchVoteException, SystemException {
400 List<PollsVote> list = findByQuestionId(questionId, 0, 1, obc);
401
402 if (list.size() == 0) {
403 StringBuilder msg = new StringBuilder();
404
405 msg.append("No PollsVote exists with the key {");
406
407 msg.append("questionId=" + questionId);
408
409 msg.append(StringPool.CLOSE_CURLY_BRACE);
410
411 throw new NoSuchVoteException(msg.toString());
412 }
413 else {
414 return list.get(0);
415 }
416 }
417
418 public PollsVote findByQuestionId_Last(long questionId,
419 OrderByComparator obc) throws NoSuchVoteException, SystemException {
420 int count = countByQuestionId(questionId);
421
422 List<PollsVote> list = findByQuestionId(questionId, count - 1, count,
423 obc);
424
425 if (list.size() == 0) {
426 StringBuilder msg = new StringBuilder();
427
428 msg.append("No PollsVote exists with the key {");
429
430 msg.append("questionId=" + questionId);
431
432 msg.append(StringPool.CLOSE_CURLY_BRACE);
433
434 throw new NoSuchVoteException(msg.toString());
435 }
436 else {
437 return list.get(0);
438 }
439 }
440
441 public PollsVote[] findByQuestionId_PrevAndNext(long voteId,
442 long questionId, OrderByComparator obc)
443 throws NoSuchVoteException, SystemException {
444 PollsVote pollsVote = findByPrimaryKey(voteId);
445
446 int count = countByQuestionId(questionId);
447
448 Session session = null;
449
450 try {
451 session = openSession();
452
453 StringBuilder query = new StringBuilder();
454
455 query.append(
456 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
457
458 query.append("questionId = ?");
459
460 query.append(" ");
461
462 if (obc != null) {
463 query.append("ORDER BY ");
464 query.append(obc.getOrderBy());
465 }
466
467 Query q = session.createQuery(query.toString());
468
469 QueryPos qPos = QueryPos.getInstance(q);
470
471 qPos.add(questionId);
472
473 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
474 pollsVote);
475
476 PollsVote[] array = new PollsVoteImpl[3];
477
478 array[0] = (PollsVote)objArray[0];
479 array[1] = (PollsVote)objArray[1];
480 array[2] = (PollsVote)objArray[2];
481
482 return array;
483 }
484 catch (Exception e) {
485 throw processException(e);
486 }
487 finally {
488 closeSession(session);
489 }
490 }
491
492 public List<PollsVote> findByChoiceId(long choiceId)
493 throws SystemException {
494 boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
495 String finderClassName = PollsVote.class.getName();
496 String finderMethodName = "findByChoiceId";
497 String[] finderParams = new String[] { Long.class.getName() };
498 Object[] finderArgs = new Object[] { new Long(choiceId) };
499
500 Object result = null;
501
502 if (finderClassNameCacheEnabled) {
503 result = FinderCacheUtil.getResult(finderClassName,
504 finderMethodName, finderParams, finderArgs, this);
505 }
506
507 if (result == null) {
508 Session session = null;
509
510 try {
511 session = openSession();
512
513 StringBuilder query = new StringBuilder();
514
515 query.append(
516 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
517
518 query.append("choiceId = ?");
519
520 query.append(" ");
521
522 Query q = session.createQuery(query.toString());
523
524 QueryPos qPos = QueryPos.getInstance(q);
525
526 qPos.add(choiceId);
527
528 List<PollsVote> list = q.list();
529
530 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
531 finderClassName, finderMethodName, finderParams,
532 finderArgs, list);
533
534 return list;
535 }
536 catch (Exception e) {
537 throw processException(e);
538 }
539 finally {
540 closeSession(session);
541 }
542 }
543 else {
544 return (List<PollsVote>)result;
545 }
546 }
547
548 public List<PollsVote> findByChoiceId(long choiceId, int start, int end)
549 throws SystemException {
550 return findByChoiceId(choiceId, start, end, null);
551 }
552
553 public List<PollsVote> findByChoiceId(long choiceId, int start, int end,
554 OrderByComparator obc) throws SystemException {
555 boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
556 String finderClassName = PollsVote.class.getName();
557 String finderMethodName = "findByChoiceId";
558 String[] finderParams = new String[] {
559 Long.class.getName(),
560
561 "java.lang.Integer", "java.lang.Integer",
562 "com.liferay.portal.kernel.util.OrderByComparator"
563 };
564 Object[] finderArgs = new Object[] {
565 new Long(choiceId),
566
567 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
568 };
569
570 Object result = null;
571
572 if (finderClassNameCacheEnabled) {
573 result = FinderCacheUtil.getResult(finderClassName,
574 finderMethodName, finderParams, finderArgs, this);
575 }
576
577 if (result == null) {
578 Session session = null;
579
580 try {
581 session = openSession();
582
583 StringBuilder query = new StringBuilder();
584
585 query.append(
586 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
587
588 query.append("choiceId = ?");
589
590 query.append(" ");
591
592 if (obc != null) {
593 query.append("ORDER BY ");
594 query.append(obc.getOrderBy());
595 }
596
597 Query q = session.createQuery(query.toString());
598
599 QueryPos qPos = QueryPos.getInstance(q);
600
601 qPos.add(choiceId);
602
603 List<PollsVote> list = (List<PollsVote>)QueryUtil.list(q,
604 getDialect(), start, end);
605
606 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
607 finderClassName, finderMethodName, finderParams,
608 finderArgs, list);
609
610 return list;
611 }
612 catch (Exception e) {
613 throw processException(e);
614 }
615 finally {
616 closeSession(session);
617 }
618 }
619 else {
620 return (List<PollsVote>)result;
621 }
622 }
623
624 public PollsVote findByChoiceId_First(long choiceId, OrderByComparator obc)
625 throws NoSuchVoteException, SystemException {
626 List<PollsVote> list = findByChoiceId(choiceId, 0, 1, obc);
627
628 if (list.size() == 0) {
629 StringBuilder msg = new StringBuilder();
630
631 msg.append("No PollsVote exists with the key {");
632
633 msg.append("choiceId=" + choiceId);
634
635 msg.append(StringPool.CLOSE_CURLY_BRACE);
636
637 throw new NoSuchVoteException(msg.toString());
638 }
639 else {
640 return list.get(0);
641 }
642 }
643
644 public PollsVote findByChoiceId_Last(long choiceId, OrderByComparator obc)
645 throws NoSuchVoteException, SystemException {
646 int count = countByChoiceId(choiceId);
647
648 List<PollsVote> list = findByChoiceId(choiceId, count - 1, count, obc);
649
650 if (list.size() == 0) {
651 StringBuilder msg = new StringBuilder();
652
653 msg.append("No PollsVote exists with the key {");
654
655 msg.append("choiceId=" + choiceId);
656
657 msg.append(StringPool.CLOSE_CURLY_BRACE);
658
659 throw new NoSuchVoteException(msg.toString());
660 }
661 else {
662 return list.get(0);
663 }
664 }
665
666 public PollsVote[] findByChoiceId_PrevAndNext(long voteId, long choiceId,
667 OrderByComparator obc) throws NoSuchVoteException, SystemException {
668 PollsVote pollsVote = findByPrimaryKey(voteId);
669
670 int count = countByChoiceId(choiceId);
671
672 Session session = null;
673
674 try {
675 session = openSession();
676
677 StringBuilder query = new StringBuilder();
678
679 query.append(
680 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
681
682 query.append("choiceId = ?");
683
684 query.append(" ");
685
686 if (obc != null) {
687 query.append("ORDER BY ");
688 query.append(obc.getOrderBy());
689 }
690
691 Query q = session.createQuery(query.toString());
692
693 QueryPos qPos = QueryPos.getInstance(q);
694
695 qPos.add(choiceId);
696
697 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
698 pollsVote);
699
700 PollsVote[] array = new PollsVoteImpl[3];
701
702 array[0] = (PollsVote)objArray[0];
703 array[1] = (PollsVote)objArray[1];
704 array[2] = (PollsVote)objArray[2];
705
706 return array;
707 }
708 catch (Exception e) {
709 throw processException(e);
710 }
711 finally {
712 closeSession(session);
713 }
714 }
715
716 public PollsVote findByQ_U(long questionId, long userId)
717 throws NoSuchVoteException, SystemException {
718 PollsVote pollsVote = fetchByQ_U(questionId, userId);
719
720 if (pollsVote == null) {
721 StringBuilder msg = new StringBuilder();
722
723 msg.append("No PollsVote exists with the key {");
724
725 msg.append("questionId=" + questionId);
726
727 msg.append(", ");
728 msg.append("userId=" + userId);
729
730 msg.append(StringPool.CLOSE_CURLY_BRACE);
731
732 if (_log.isWarnEnabled()) {
733 _log.warn(msg.toString());
734 }
735
736 throw new NoSuchVoteException(msg.toString());
737 }
738
739 return pollsVote;
740 }
741
742 public PollsVote fetchByQ_U(long questionId, long userId)
743 throws SystemException {
744 boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
745 String finderClassName = PollsVote.class.getName();
746 String finderMethodName = "fetchByQ_U";
747 String[] finderParams = new String[] {
748 Long.class.getName(), Long.class.getName()
749 };
750 Object[] finderArgs = new Object[] {
751 new Long(questionId), new Long(userId)
752 };
753
754 Object result = null;
755
756 if (finderClassNameCacheEnabled) {
757 result = FinderCacheUtil.getResult(finderClassName,
758 finderMethodName, finderParams, finderArgs, this);
759 }
760
761 if (result == null) {
762 Session session = null;
763
764 try {
765 session = openSession();
766
767 StringBuilder query = new StringBuilder();
768
769 query.append(
770 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
771
772 query.append("questionId = ?");
773
774 query.append(" AND ");
775
776 query.append("userId = ?");
777
778 query.append(" ");
779
780 Query q = session.createQuery(query.toString());
781
782 QueryPos qPos = QueryPos.getInstance(q);
783
784 qPos.add(questionId);
785
786 qPos.add(userId);
787
788 List<PollsVote> list = q.list();
789
790 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
791 finderClassName, finderMethodName, finderParams,
792 finderArgs, list);
793
794 if (list.size() == 0) {
795 return null;
796 }
797 else {
798 return list.get(0);
799 }
800 }
801 catch (Exception e) {
802 throw processException(e);
803 }
804 finally {
805 closeSession(session);
806 }
807 }
808 else {
809 List<PollsVote> list = (List<PollsVote>)result;
810
811 if (list.size() == 0) {
812 return null;
813 }
814 else {
815 return list.get(0);
816 }
817 }
818 }
819
820 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
821 throws SystemException {
822 Session session = null;
823
824 try {
825 session = openSession();
826
827 dynamicQuery.compile(session);
828
829 return dynamicQuery.list();
830 }
831 catch (Exception e) {
832 throw processException(e);
833 }
834 finally {
835 closeSession(session);
836 }
837 }
838
839 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
840 int start, int end) throws SystemException {
841 Session session = null;
842
843 try {
844 session = openSession();
845
846 dynamicQuery.setLimit(start, end);
847
848 dynamicQuery.compile(session);
849
850 return dynamicQuery.list();
851 }
852 catch (Exception e) {
853 throw processException(e);
854 }
855 finally {
856 closeSession(session);
857 }
858 }
859
860 public List<PollsVote> findAll() throws SystemException {
861 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
862 }
863
864 public List<PollsVote> findAll(int start, int end)
865 throws SystemException {
866 return findAll(start, end, null);
867 }
868
869 public List<PollsVote> findAll(int start, int end, OrderByComparator obc)
870 throws SystemException {
871 boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
872 String finderClassName = PollsVote.class.getName();
873 String finderMethodName = "findAll";
874 String[] finderParams = new String[] {
875 "java.lang.Integer", "java.lang.Integer",
876 "com.liferay.portal.kernel.util.OrderByComparator"
877 };
878 Object[] finderArgs = new Object[] {
879 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
880 };
881
882 Object result = null;
883
884 if (finderClassNameCacheEnabled) {
885 result = FinderCacheUtil.getResult(finderClassName,
886 finderMethodName, finderParams, finderArgs, this);
887 }
888
889 if (result == null) {
890 Session session = null;
891
892 try {
893 session = openSession();
894
895 StringBuilder query = new StringBuilder();
896
897 query.append("FROM com.liferay.portlet.polls.model.PollsVote ");
898
899 if (obc != null) {
900 query.append("ORDER BY ");
901 query.append(obc.getOrderBy());
902 }
903
904 Query q = session.createQuery(query.toString());
905
906 List<PollsVote> list = null;
907
908 if (obc == null) {
909 list = (List<PollsVote>)QueryUtil.list(q, getDialect(),
910 start, end, false);
911
912 Collections.sort(list);
913 }
914 else {
915 list = (List<PollsVote>)QueryUtil.list(q, getDialect(),
916 start, end);
917 }
918
919 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
920 finderClassName, finderMethodName, finderParams,
921 finderArgs, list);
922
923 return list;
924 }
925 catch (Exception e) {
926 throw processException(e);
927 }
928 finally {
929 closeSession(session);
930 }
931 }
932 else {
933 return (List<PollsVote>)result;
934 }
935 }
936
937 public void removeByQuestionId(long questionId) throws SystemException {
938 for (PollsVote pollsVote : findByQuestionId(questionId)) {
939 remove(pollsVote);
940 }
941 }
942
943 public void removeByChoiceId(long choiceId) throws SystemException {
944 for (PollsVote pollsVote : findByChoiceId(choiceId)) {
945 remove(pollsVote);
946 }
947 }
948
949 public void removeByQ_U(long questionId, long userId)
950 throws NoSuchVoteException, SystemException {
951 PollsVote pollsVote = findByQ_U(questionId, userId);
952
953 remove(pollsVote);
954 }
955
956 public void removeAll() throws SystemException {
957 for (PollsVote pollsVote : findAll()) {
958 remove(pollsVote);
959 }
960 }
961
962 public int countByQuestionId(long questionId) throws SystemException {
963 boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
964 String finderClassName = PollsVote.class.getName();
965 String finderMethodName = "countByQuestionId";
966 String[] finderParams = new String[] { Long.class.getName() };
967 Object[] finderArgs = new Object[] { new Long(questionId) };
968
969 Object result = null;
970
971 if (finderClassNameCacheEnabled) {
972 result = FinderCacheUtil.getResult(finderClassName,
973 finderMethodName, finderParams, finderArgs, this);
974 }
975
976 if (result == null) {
977 Session session = null;
978
979 try {
980 session = openSession();
981
982 StringBuilder query = new StringBuilder();
983
984 query.append("SELECT COUNT(*) ");
985 query.append(
986 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
987
988 query.append("questionId = ?");
989
990 query.append(" ");
991
992 Query q = session.createQuery(query.toString());
993
994 QueryPos qPos = QueryPos.getInstance(q);
995
996 qPos.add(questionId);
997
998 Long count = null;
999
1000 Iterator<Long> itr = q.list().iterator();
1001
1002 if (itr.hasNext()) {
1003 count = itr.next();
1004 }
1005
1006 if (count == null) {
1007 count = new Long(0);
1008 }
1009
1010 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1011 finderClassName, finderMethodName, finderParams,
1012 finderArgs, count);
1013
1014 return count.intValue();
1015 }
1016 catch (Exception e) {
1017 throw processException(e);
1018 }
1019 finally {
1020 closeSession(session);
1021 }
1022 }
1023 else {
1024 return ((Long)result).intValue();
1025 }
1026 }
1027
1028 public int countByChoiceId(long choiceId) throws SystemException {
1029 boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
1030 String finderClassName = PollsVote.class.getName();
1031 String finderMethodName = "countByChoiceId";
1032 String[] finderParams = new String[] { Long.class.getName() };
1033 Object[] finderArgs = new Object[] { new Long(choiceId) };
1034
1035 Object result = null;
1036
1037 if (finderClassNameCacheEnabled) {
1038 result = FinderCacheUtil.getResult(finderClassName,
1039 finderMethodName, finderParams, finderArgs, this);
1040 }
1041
1042 if (result == null) {
1043 Session session = null;
1044
1045 try {
1046 session = openSession();
1047
1048 StringBuilder query = new StringBuilder();
1049
1050 query.append("SELECT COUNT(*) ");
1051 query.append(
1052 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
1053
1054 query.append("choiceId = ?");
1055
1056 query.append(" ");
1057
1058 Query q = session.createQuery(query.toString());
1059
1060 QueryPos qPos = QueryPos.getInstance(q);
1061
1062 qPos.add(choiceId);
1063
1064 Long count = null;
1065
1066 Iterator<Long> itr = q.list().iterator();
1067
1068 if (itr.hasNext()) {
1069 count = itr.next();
1070 }
1071
1072 if (count == null) {
1073 count = new Long(0);
1074 }
1075
1076 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1077 finderClassName, finderMethodName, finderParams,
1078 finderArgs, count);
1079
1080 return count.intValue();
1081 }
1082 catch (Exception e) {
1083 throw processException(e);
1084 }
1085 finally {
1086 closeSession(session);
1087 }
1088 }
1089 else {
1090 return ((Long)result).intValue();
1091 }
1092 }
1093
1094 public int countByQ_U(long questionId, long userId)
1095 throws SystemException {
1096 boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
1097 String finderClassName = PollsVote.class.getName();
1098 String finderMethodName = "countByQ_U";
1099 String[] finderParams = new String[] {
1100 Long.class.getName(), Long.class.getName()
1101 };
1102 Object[] finderArgs = new Object[] {
1103 new Long(questionId), new Long(userId)
1104 };
1105
1106 Object result = null;
1107
1108 if (finderClassNameCacheEnabled) {
1109 result = FinderCacheUtil.getResult(finderClassName,
1110 finderMethodName, finderParams, finderArgs, this);
1111 }
1112
1113 if (result == null) {
1114 Session session = null;
1115
1116 try {
1117 session = openSession();
1118
1119 StringBuilder query = new StringBuilder();
1120
1121 query.append("SELECT COUNT(*) ");
1122 query.append(
1123 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
1124
1125 query.append("questionId = ?");
1126
1127 query.append(" AND ");
1128
1129 query.append("userId = ?");
1130
1131 query.append(" ");
1132
1133 Query q = session.createQuery(query.toString());
1134
1135 QueryPos qPos = QueryPos.getInstance(q);
1136
1137 qPos.add(questionId);
1138
1139 qPos.add(userId);
1140
1141 Long count = null;
1142
1143 Iterator<Long> itr = q.list().iterator();
1144
1145 if (itr.hasNext()) {
1146 count = itr.next();
1147 }
1148
1149 if (count == null) {
1150 count = new Long(0);
1151 }
1152
1153 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1154 finderClassName, finderMethodName, finderParams,
1155 finderArgs, count);
1156
1157 return count.intValue();
1158 }
1159 catch (Exception e) {
1160 throw processException(e);
1161 }
1162 finally {
1163 closeSession(session);
1164 }
1165 }
1166 else {
1167 return ((Long)result).intValue();
1168 }
1169 }
1170
1171 public int countAll() throws SystemException {
1172 boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
1173 String finderClassName = PollsVote.class.getName();
1174 String finderMethodName = "countAll";
1175 String[] finderParams = new String[] { };
1176 Object[] finderArgs = new Object[] { };
1177
1178 Object result = null;
1179
1180 if (finderClassNameCacheEnabled) {
1181 result = FinderCacheUtil.getResult(finderClassName,
1182 finderMethodName, finderParams, finderArgs, this);
1183 }
1184
1185 if (result == null) {
1186 Session session = null;
1187
1188 try {
1189 session = openSession();
1190
1191 Query q = session.createQuery(
1192 "SELECT COUNT(*) FROM com.liferay.portlet.polls.model.PollsVote");
1193
1194 Long count = null;
1195
1196 Iterator<Long> itr = q.list().iterator();
1197
1198 if (itr.hasNext()) {
1199 count = itr.next();
1200 }
1201
1202 if (count == null) {
1203 count = new Long(0);
1204 }
1205
1206 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1207 finderClassName, finderMethodName, finderParams,
1208 finderArgs, count);
1209
1210 return count.intValue();
1211 }
1212 catch (Exception e) {
1213 throw processException(e);
1214 }
1215 finally {
1216 closeSession(session);
1217 }
1218 }
1219 else {
1220 return ((Long)result).intValue();
1221 }
1222 }
1223
1224 public void registerListener(ModelListener listener) {
1225 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1226
1227 listeners.add(listener);
1228
1229 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1230 }
1231
1232 public void unregisterListener(ModelListener listener) {
1233 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1234
1235 listeners.remove(listener);
1236
1237 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1238 }
1239
1240 public void afterPropertiesSet() {
1241 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1242 com.liferay.portal.util.PropsUtil.get(
1243 "value.object.listener.com.liferay.portlet.polls.model.PollsVote")));
1244
1245 if (listenerClassNames.length > 0) {
1246 try {
1247 List<ModelListener> listeners = new ArrayList<ModelListener>();
1248
1249 for (String listenerClassName : listenerClassNames) {
1250 listeners.add((ModelListener)Class.forName(
1251 listenerClassName).newInstance());
1252 }
1253
1254 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1255 }
1256 catch (Exception e) {
1257 _log.error(e);
1258 }
1259 }
1260 }
1261
1262 private static Log _log = LogFactory.getLog(PollsVotePersistenceImpl.class);
1263 private ModelListener[] _listeners = new ModelListener[0];
1264}