1
22
23 package com.liferay.portlet.polls.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.bean.InitializingBean;
27 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
28 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
29 import com.liferay.portal.kernel.dao.orm.Query;
30 import com.liferay.portal.kernel.dao.orm.QueryPos;
31 import com.liferay.portal.kernel.dao.orm.QueryUtil;
32 import com.liferay.portal.kernel.dao.orm.Session;
33 import com.liferay.portal.kernel.util.GetterUtil;
34 import com.liferay.portal.kernel.util.ListUtil;
35 import com.liferay.portal.kernel.util.OrderByComparator;
36 import com.liferay.portal.kernel.util.StringPool;
37 import com.liferay.portal.kernel.util.StringUtil;
38 import com.liferay.portal.model.ModelListener;
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, InitializingBean {
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 session.delete(pollsVote);
130
131 session.flush();
132
133 return pollsVote;
134 }
135 catch (Exception e) {
136 throw processException(e);
137 }
138 finally {
139 closeSession(session);
140
141 FinderCacheUtil.clearCache(PollsVote.class.getName());
142 }
143 }
144
145
148 public PollsVote update(PollsVote pollsVote) throws SystemException {
149 if (_log.isWarnEnabled()) {
150 _log.warn(
151 "Using the deprecated update(PollsVote pollsVote) method. Use update(PollsVote pollsVote, boolean merge) instead.");
152 }
153
154 return update(pollsVote, false);
155 }
156
157
170 public PollsVote update(PollsVote pollsVote, boolean merge)
171 throws SystemException {
172 boolean isNew = pollsVote.isNew();
173
174 if (_listeners.length > 0) {
175 for (ModelListener listener : _listeners) {
176 if (isNew) {
177 listener.onBeforeCreate(pollsVote);
178 }
179 else {
180 listener.onBeforeUpdate(pollsVote);
181 }
182 }
183 }
184
185 pollsVote = updateImpl(pollsVote, merge);
186
187 if (_listeners.length > 0) {
188 for (ModelListener listener : _listeners) {
189 if (isNew) {
190 listener.onAfterCreate(pollsVote);
191 }
192 else {
193 listener.onAfterUpdate(pollsVote);
194 }
195 }
196 }
197
198 return pollsVote;
199 }
200
201 public PollsVote updateImpl(
202 com.liferay.portlet.polls.model.PollsVote pollsVote, boolean merge)
203 throws SystemException {
204 Session session = null;
205
206 try {
207 session = openSession();
208
209 if (merge) {
210 session.merge(pollsVote);
211 }
212 else {
213 if (pollsVote.isNew()) {
214 session.save(pollsVote);
215 }
216 }
217
218 session.flush();
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 = (List<PollsVote>)QueryUtil.list(q,
907 getDialect(), start, end);
908
909 if (obc == null) {
910 Collections.sort(list);
911 }
912
913 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
914 finderClassName, finderMethodName, finderParams,
915 finderArgs, list);
916
917 return list;
918 }
919 catch (Exception e) {
920 throw processException(e);
921 }
922 finally {
923 closeSession(session);
924 }
925 }
926 else {
927 return (List<PollsVote>)result;
928 }
929 }
930
931 public void removeByQuestionId(long questionId) throws SystemException {
932 for (PollsVote pollsVote : findByQuestionId(questionId)) {
933 remove(pollsVote);
934 }
935 }
936
937 public void removeByChoiceId(long choiceId) throws SystemException {
938 for (PollsVote pollsVote : findByChoiceId(choiceId)) {
939 remove(pollsVote);
940 }
941 }
942
943 public void removeByQ_U(long questionId, long userId)
944 throws NoSuchVoteException, SystemException {
945 PollsVote pollsVote = findByQ_U(questionId, userId);
946
947 remove(pollsVote);
948 }
949
950 public void removeAll() throws SystemException {
951 for (PollsVote pollsVote : findAll()) {
952 remove(pollsVote);
953 }
954 }
955
956 public int countByQuestionId(long questionId) throws SystemException {
957 boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
958 String finderClassName = PollsVote.class.getName();
959 String finderMethodName = "countByQuestionId";
960 String[] finderParams = new String[] { Long.class.getName() };
961 Object[] finderArgs = new Object[] { new Long(questionId) };
962
963 Object result = null;
964
965 if (finderClassNameCacheEnabled) {
966 result = FinderCacheUtil.getResult(finderClassName,
967 finderMethodName, finderParams, finderArgs, this);
968 }
969
970 if (result == null) {
971 Session session = null;
972
973 try {
974 session = openSession();
975
976 StringBuilder query = new StringBuilder();
977
978 query.append("SELECT COUNT(*) ");
979 query.append(
980 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
981
982 query.append("questionId = ?");
983
984 query.append(" ");
985
986 Query q = session.createQuery(query.toString());
987
988 QueryPos qPos = QueryPos.getInstance(q);
989
990 qPos.add(questionId);
991
992 Long count = null;
993
994 Iterator<Long> itr = q.list().iterator();
995
996 if (itr.hasNext()) {
997 count = itr.next();
998 }
999
1000 if (count == null) {
1001 count = new Long(0);
1002 }
1003
1004 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1005 finderClassName, finderMethodName, finderParams,
1006 finderArgs, count);
1007
1008 return count.intValue();
1009 }
1010 catch (Exception e) {
1011 throw processException(e);
1012 }
1013 finally {
1014 closeSession(session);
1015 }
1016 }
1017 else {
1018 return ((Long)result).intValue();
1019 }
1020 }
1021
1022 public int countByChoiceId(long choiceId) throws SystemException {
1023 boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
1024 String finderClassName = PollsVote.class.getName();
1025 String finderMethodName = "countByChoiceId";
1026 String[] finderParams = new String[] { Long.class.getName() };
1027 Object[] finderArgs = new Object[] { new Long(choiceId) };
1028
1029 Object result = null;
1030
1031 if (finderClassNameCacheEnabled) {
1032 result = FinderCacheUtil.getResult(finderClassName,
1033 finderMethodName, finderParams, finderArgs, this);
1034 }
1035
1036 if (result == null) {
1037 Session session = null;
1038
1039 try {
1040 session = openSession();
1041
1042 StringBuilder query = new StringBuilder();
1043
1044 query.append("SELECT COUNT(*) ");
1045 query.append(
1046 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
1047
1048 query.append("choiceId = ?");
1049
1050 query.append(" ");
1051
1052 Query q = session.createQuery(query.toString());
1053
1054 QueryPos qPos = QueryPos.getInstance(q);
1055
1056 qPos.add(choiceId);
1057
1058 Long count = null;
1059
1060 Iterator<Long> itr = q.list().iterator();
1061
1062 if (itr.hasNext()) {
1063 count = itr.next();
1064 }
1065
1066 if (count == null) {
1067 count = new Long(0);
1068 }
1069
1070 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1071 finderClassName, finderMethodName, finderParams,
1072 finderArgs, count);
1073
1074 return count.intValue();
1075 }
1076 catch (Exception e) {
1077 throw processException(e);
1078 }
1079 finally {
1080 closeSession(session);
1081 }
1082 }
1083 else {
1084 return ((Long)result).intValue();
1085 }
1086 }
1087
1088 public int countByQ_U(long questionId, long userId)
1089 throws SystemException {
1090 boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
1091 String finderClassName = PollsVote.class.getName();
1092 String finderMethodName = "countByQ_U";
1093 String[] finderParams = new String[] {
1094 Long.class.getName(), Long.class.getName()
1095 };
1096 Object[] finderArgs = new Object[] {
1097 new Long(questionId), new Long(userId)
1098 };
1099
1100 Object result = null;
1101
1102 if (finderClassNameCacheEnabled) {
1103 result = FinderCacheUtil.getResult(finderClassName,
1104 finderMethodName, finderParams, finderArgs, this);
1105 }
1106
1107 if (result == null) {
1108 Session session = null;
1109
1110 try {
1111 session = openSession();
1112
1113 StringBuilder query = new StringBuilder();
1114
1115 query.append("SELECT COUNT(*) ");
1116 query.append(
1117 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
1118
1119 query.append("questionId = ?");
1120
1121 query.append(" AND ");
1122
1123 query.append("userId = ?");
1124
1125 query.append(" ");
1126
1127 Query q = session.createQuery(query.toString());
1128
1129 QueryPos qPos = QueryPos.getInstance(q);
1130
1131 qPos.add(questionId);
1132
1133 qPos.add(userId);
1134
1135 Long count = null;
1136
1137 Iterator<Long> itr = q.list().iterator();
1138
1139 if (itr.hasNext()) {
1140 count = itr.next();
1141 }
1142
1143 if (count == null) {
1144 count = new Long(0);
1145 }
1146
1147 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1148 finderClassName, finderMethodName, finderParams,
1149 finderArgs, count);
1150
1151 return count.intValue();
1152 }
1153 catch (Exception e) {
1154 throw processException(e);
1155 }
1156 finally {
1157 closeSession(session);
1158 }
1159 }
1160 else {
1161 return ((Long)result).intValue();
1162 }
1163 }
1164
1165 public int countAll() throws SystemException {
1166 boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
1167 String finderClassName = PollsVote.class.getName();
1168 String finderMethodName = "countAll";
1169 String[] finderParams = new String[] { };
1170 Object[] finderArgs = new Object[] { };
1171
1172 Object result = null;
1173
1174 if (finderClassNameCacheEnabled) {
1175 result = FinderCacheUtil.getResult(finderClassName,
1176 finderMethodName, finderParams, finderArgs, this);
1177 }
1178
1179 if (result == null) {
1180 Session session = null;
1181
1182 try {
1183 session = openSession();
1184
1185 Query q = session.createQuery(
1186 "SELECT COUNT(*) FROM com.liferay.portlet.polls.model.PollsVote");
1187
1188 Long count = null;
1189
1190 Iterator<Long> itr = q.list().iterator();
1191
1192 if (itr.hasNext()) {
1193 count = itr.next();
1194 }
1195
1196 if (count == null) {
1197 count = new Long(0);
1198 }
1199
1200 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1201 finderClassName, finderMethodName, finderParams,
1202 finderArgs, count);
1203
1204 return count.intValue();
1205 }
1206 catch (Exception e) {
1207 throw processException(e);
1208 }
1209 finally {
1210 closeSession(session);
1211 }
1212 }
1213 else {
1214 return ((Long)result).intValue();
1215 }
1216 }
1217
1218 public void registerListener(ModelListener listener) {
1219 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1220
1221 listeners.add(listener);
1222
1223 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1224 }
1225
1226 public void unregisterListener(ModelListener listener) {
1227 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1228
1229 listeners.remove(listener);
1230
1231 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1232 }
1233
1234 public void afterPropertiesSet() {
1235 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1236 com.liferay.portal.util.PropsUtil.get(
1237 "value.object.listener.com.liferay.portlet.polls.model.PollsVote")));
1238
1239 if (listenerClassNames.length > 0) {
1240 try {
1241 List<ModelListener> listeners = new ArrayList<ModelListener>();
1242
1243 for (String listenerClassName : listenerClassNames) {
1244 listeners.add((ModelListener)Class.forName(
1245 listenerClassName).newInstance());
1246 }
1247
1248 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1249 }
1250 catch (Exception e) {
1251 _log.error(e);
1252 }
1253 }
1254 }
1255
1256 private static Log _log = LogFactory.getLog(PollsVotePersistenceImpl.class);
1257 private ModelListener[] _listeners = new ModelListener[0];
1258}