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