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.OrderByComparator;
29 import com.liferay.portal.kernel.util.StringMaker;
30 import com.liferay.portal.kernel.util.StringPool;
31 import com.liferay.portal.service.persistence.BasePersistence;
32 import com.liferay.portal.spring.hibernate.FinderCache;
33 import com.liferay.portal.spring.hibernate.HibernateUtil;
34
35 import com.liferay.portlet.polls.NoSuchVoteException;
36 import com.liferay.portlet.polls.model.PollsVote;
37 import com.liferay.portlet.polls.model.impl.PollsVoteImpl;
38
39 import com.liferay.util.dao.hibernate.QueryUtil;
40
41 import org.apache.commons.logging.Log;
42 import org.apache.commons.logging.LogFactory;
43
44 import org.hibernate.Query;
45 import org.hibernate.Session;
46
47 import java.util.Collections;
48 import java.util.Iterator;
49 import java.util.List;
50
51
57 public class PollsVotePersistenceImpl extends BasePersistence
58 implements PollsVotePersistence {
59 public PollsVote create(long voteId) {
60 PollsVote pollsVote = new PollsVoteImpl();
61 pollsVote.setNew(true);
62 pollsVote.setPrimaryKey(voteId);
63
64 return pollsVote;
65 }
66
67 public PollsVote remove(long voteId)
68 throws NoSuchVoteException, SystemException {
69 Session session = null;
70
71 try {
72 session = openSession();
73
74 PollsVote pollsVote = (PollsVote)session.get(PollsVoteImpl.class,
75 new Long(voteId));
76
77 if (pollsVote == null) {
78 if (_log.isWarnEnabled()) {
79 _log.warn("No PollsVote exists with the primary key " +
80 voteId);
81 }
82
83 throw new NoSuchVoteException(
84 "No PollsVote exists with the primary key " + voteId);
85 }
86
87 return remove(pollsVote);
88 }
89 catch (NoSuchVoteException nsee) {
90 throw nsee;
91 }
92 catch (Exception e) {
93 throw HibernateUtil.processException(e);
94 }
95 finally {
96 closeSession(session);
97 }
98 }
99
100 public PollsVote remove(PollsVote pollsVote) throws SystemException {
101 Session session = null;
102
103 try {
104 session = openSession();
105 session.delete(pollsVote);
106 session.flush();
107
108 return pollsVote;
109 }
110 catch (Exception e) {
111 throw HibernateUtil.processException(e);
112 }
113 finally {
114 closeSession(session);
115 FinderCache.clearCache(PollsVote.class.getName());
116 }
117 }
118
119 public PollsVote update(com.liferay.portlet.polls.model.PollsVote pollsVote)
120 throws SystemException {
121 return update(pollsVote, false);
122 }
123
124 public PollsVote update(
125 com.liferay.portlet.polls.model.PollsVote pollsVote, boolean merge)
126 throws SystemException {
127 Session session = null;
128
129 try {
130 session = openSession();
131
132 if (merge) {
133 session.merge(pollsVote);
134 }
135 else {
136 if (pollsVote.isNew()) {
137 session.save(pollsVote);
138 }
139 }
140
141 session.flush();
142 pollsVote.setNew(false);
143
144 return pollsVote;
145 }
146 catch (Exception e) {
147 throw HibernateUtil.processException(e);
148 }
149 finally {
150 closeSession(session);
151 FinderCache.clearCache(PollsVote.class.getName());
152 }
153 }
154
155 public PollsVote findByPrimaryKey(long voteId)
156 throws NoSuchVoteException, SystemException {
157 PollsVote pollsVote = fetchByPrimaryKey(voteId);
158
159 if (pollsVote == null) {
160 if (_log.isWarnEnabled()) {
161 _log.warn("No PollsVote exists with the primary key " + voteId);
162 }
163
164 throw new NoSuchVoteException(
165 "No PollsVote exists with the primary key " + voteId);
166 }
167
168 return pollsVote;
169 }
170
171 public PollsVote fetchByPrimaryKey(long voteId) throws SystemException {
172 Session session = null;
173
174 try {
175 session = openSession();
176
177 return (PollsVote)session.get(PollsVoteImpl.class, new Long(voteId));
178 }
179 catch (Exception e) {
180 throw HibernateUtil.processException(e);
181 }
182 finally {
183 closeSession(session);
184 }
185 }
186
187 public List findByQuestionId(long questionId) throws SystemException {
188 String finderClassName = PollsVote.class.getName();
189 String finderMethodName = "findByQuestionId";
190 String[] finderParams = new String[] { Long.class.getName() };
191 Object[] finderArgs = new Object[] { new Long(questionId) };
192 Object result = FinderCache.getResult(finderClassName,
193 finderMethodName, finderParams, finderArgs, getSessionFactory());
194
195 if (result == null) {
196 Session session = null;
197
198 try {
199 session = openSession();
200
201 StringMaker query = new StringMaker();
202 query.append(
203 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
204 query.append("questionId = ?");
205 query.append(" ");
206
207 Query q = session.createQuery(query.toString());
208 int queryPos = 0;
209 q.setLong(queryPos++, questionId);
210
211 List list = q.list();
212 FinderCache.putResult(finderClassName, finderMethodName,
213 finderParams, finderArgs, list);
214
215 return list;
216 }
217 catch (Exception e) {
218 throw HibernateUtil.processException(e);
219 }
220 finally {
221 closeSession(session);
222 }
223 }
224 else {
225 return (List)result;
226 }
227 }
228
229 public List findByQuestionId(long questionId, int begin, int end)
230 throws SystemException {
231 return findByQuestionId(questionId, begin, end, null);
232 }
233
234 public List findByQuestionId(long questionId, int begin, int end,
235 OrderByComparator obc) throws SystemException {
236 String finderClassName = PollsVote.class.getName();
237 String finderMethodName = "findByQuestionId";
238 String[] finderParams = new String[] {
239 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
240 "com.liferay.portal.kernel.util.OrderByComparator"
241 };
242 Object[] finderArgs = new Object[] {
243 new Long(questionId), String.valueOf(begin), String.valueOf(end),
244 String.valueOf(obc)
245 };
246 Object result = FinderCache.getResult(finderClassName,
247 finderMethodName, finderParams, finderArgs, getSessionFactory());
248
249 if (result == null) {
250 Session session = null;
251
252 try {
253 session = openSession();
254
255 StringMaker query = new StringMaker();
256 query.append(
257 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
258 query.append("questionId = ?");
259 query.append(" ");
260
261 if (obc != null) {
262 query.append("ORDER BY ");
263 query.append(obc.getOrderBy());
264 }
265
266 Query q = session.createQuery(query.toString());
267 int queryPos = 0;
268 q.setLong(queryPos++, questionId);
269
270 List list = QueryUtil.list(q, getDialect(), begin, end);
271 FinderCache.putResult(finderClassName, finderMethodName,
272 finderParams, finderArgs, list);
273
274 return list;
275 }
276 catch (Exception e) {
277 throw HibernateUtil.processException(e);
278 }
279 finally {
280 closeSession(session);
281 }
282 }
283 else {
284 return (List)result;
285 }
286 }
287
288 public PollsVote findByQuestionId_First(long questionId,
289 OrderByComparator obc) throws NoSuchVoteException, SystemException {
290 List list = findByQuestionId(questionId, 0, 1, obc);
291
292 if (list.size() == 0) {
293 StringMaker msg = new StringMaker();
294 msg.append("No PollsVote exists with the key ");
295 msg.append(StringPool.OPEN_CURLY_BRACE);
296 msg.append("questionId=");
297 msg.append(questionId);
298 msg.append(StringPool.CLOSE_CURLY_BRACE);
299 throw new NoSuchVoteException(msg.toString());
300 }
301 else {
302 return (PollsVote)list.get(0);
303 }
304 }
305
306 public PollsVote findByQuestionId_Last(long questionId,
307 OrderByComparator obc) throws NoSuchVoteException, SystemException {
308 int count = countByQuestionId(questionId);
309 List list = findByQuestionId(questionId, count - 1, count, obc);
310
311 if (list.size() == 0) {
312 StringMaker msg = new StringMaker();
313 msg.append("No PollsVote exists with the key ");
314 msg.append(StringPool.OPEN_CURLY_BRACE);
315 msg.append("questionId=");
316 msg.append(questionId);
317 msg.append(StringPool.CLOSE_CURLY_BRACE);
318 throw new NoSuchVoteException(msg.toString());
319 }
320 else {
321 return (PollsVote)list.get(0);
322 }
323 }
324
325 public PollsVote[] findByQuestionId_PrevAndNext(long voteId,
326 long questionId, OrderByComparator obc)
327 throws NoSuchVoteException, SystemException {
328 PollsVote pollsVote = findByPrimaryKey(voteId);
329 int count = countByQuestionId(questionId);
330 Session session = null;
331
332 try {
333 session = openSession();
334
335 StringMaker query = new StringMaker();
336 query.append(
337 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
338 query.append("questionId = ?");
339 query.append(" ");
340
341 if (obc != null) {
342 query.append("ORDER BY ");
343 query.append(obc.getOrderBy());
344 }
345
346 Query q = session.createQuery(query.toString());
347 int queryPos = 0;
348 q.setLong(queryPos++, questionId);
349
350 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
351 pollsVote);
352 PollsVote[] array = new PollsVoteImpl[3];
353 array[0] = (PollsVote)objArray[0];
354 array[1] = (PollsVote)objArray[1];
355 array[2] = (PollsVote)objArray[2];
356
357 return array;
358 }
359 catch (Exception e) {
360 throw HibernateUtil.processException(e);
361 }
362 finally {
363 closeSession(session);
364 }
365 }
366
367 public List findByChoiceId(long choiceId) throws SystemException {
368 String finderClassName = PollsVote.class.getName();
369 String finderMethodName = "findByChoiceId";
370 String[] finderParams = new String[] { Long.class.getName() };
371 Object[] finderArgs = new Object[] { new Long(choiceId) };
372 Object result = FinderCache.getResult(finderClassName,
373 finderMethodName, finderParams, finderArgs, getSessionFactory());
374
375 if (result == null) {
376 Session session = null;
377
378 try {
379 session = openSession();
380
381 StringMaker query = new StringMaker();
382 query.append(
383 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
384 query.append("choiceId = ?");
385 query.append(" ");
386
387 Query q = session.createQuery(query.toString());
388 int queryPos = 0;
389 q.setLong(queryPos++, choiceId);
390
391 List list = q.list();
392 FinderCache.putResult(finderClassName, finderMethodName,
393 finderParams, finderArgs, list);
394
395 return list;
396 }
397 catch (Exception e) {
398 throw HibernateUtil.processException(e);
399 }
400 finally {
401 closeSession(session);
402 }
403 }
404 else {
405 return (List)result;
406 }
407 }
408
409 public List findByChoiceId(long choiceId, int begin, int end)
410 throws SystemException {
411 return findByChoiceId(choiceId, begin, end, null);
412 }
413
414 public List findByChoiceId(long choiceId, int begin, int end,
415 OrderByComparator obc) throws SystemException {
416 String finderClassName = PollsVote.class.getName();
417 String finderMethodName = "findByChoiceId";
418 String[] finderParams = new String[] {
419 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
420 "com.liferay.portal.kernel.util.OrderByComparator"
421 };
422 Object[] finderArgs = new Object[] {
423 new Long(choiceId), String.valueOf(begin), String.valueOf(end),
424 String.valueOf(obc)
425 };
426 Object result = FinderCache.getResult(finderClassName,
427 finderMethodName, finderParams, finderArgs, getSessionFactory());
428
429 if (result == null) {
430 Session session = null;
431
432 try {
433 session = openSession();
434
435 StringMaker query = new StringMaker();
436 query.append(
437 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
438 query.append("choiceId = ?");
439 query.append(" ");
440
441 if (obc != null) {
442 query.append("ORDER BY ");
443 query.append(obc.getOrderBy());
444 }
445
446 Query q = session.createQuery(query.toString());
447 int queryPos = 0;
448 q.setLong(queryPos++, choiceId);
449
450 List list = QueryUtil.list(q, getDialect(), begin, end);
451 FinderCache.putResult(finderClassName, finderMethodName,
452 finderParams, finderArgs, list);
453
454 return list;
455 }
456 catch (Exception e) {
457 throw HibernateUtil.processException(e);
458 }
459 finally {
460 closeSession(session);
461 }
462 }
463 else {
464 return (List)result;
465 }
466 }
467
468 public PollsVote findByChoiceId_First(long choiceId, OrderByComparator obc)
469 throws NoSuchVoteException, SystemException {
470 List list = findByChoiceId(choiceId, 0, 1, obc);
471
472 if (list.size() == 0) {
473 StringMaker msg = new StringMaker();
474 msg.append("No PollsVote exists with the key ");
475 msg.append(StringPool.OPEN_CURLY_BRACE);
476 msg.append("choiceId=");
477 msg.append(choiceId);
478 msg.append(StringPool.CLOSE_CURLY_BRACE);
479 throw new NoSuchVoteException(msg.toString());
480 }
481 else {
482 return (PollsVote)list.get(0);
483 }
484 }
485
486 public PollsVote findByChoiceId_Last(long choiceId, OrderByComparator obc)
487 throws NoSuchVoteException, SystemException {
488 int count = countByChoiceId(choiceId);
489 List list = findByChoiceId(choiceId, count - 1, count, obc);
490
491 if (list.size() == 0) {
492 StringMaker msg = new StringMaker();
493 msg.append("No PollsVote exists with the key ");
494 msg.append(StringPool.OPEN_CURLY_BRACE);
495 msg.append("choiceId=");
496 msg.append(choiceId);
497 msg.append(StringPool.CLOSE_CURLY_BRACE);
498 throw new NoSuchVoteException(msg.toString());
499 }
500 else {
501 return (PollsVote)list.get(0);
502 }
503 }
504
505 public PollsVote[] findByChoiceId_PrevAndNext(long voteId, long choiceId,
506 OrderByComparator obc) throws NoSuchVoteException, SystemException {
507 PollsVote pollsVote = findByPrimaryKey(voteId);
508 int count = countByChoiceId(choiceId);
509 Session session = null;
510
511 try {
512 session = openSession();
513
514 StringMaker query = new StringMaker();
515 query.append(
516 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
517 query.append("choiceId = ?");
518 query.append(" ");
519
520 if (obc != null) {
521 query.append("ORDER BY ");
522 query.append(obc.getOrderBy());
523 }
524
525 Query q = session.createQuery(query.toString());
526 int queryPos = 0;
527 q.setLong(queryPos++, choiceId);
528
529 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
530 pollsVote);
531 PollsVote[] array = new PollsVoteImpl[3];
532 array[0] = (PollsVote)objArray[0];
533 array[1] = (PollsVote)objArray[1];
534 array[2] = (PollsVote)objArray[2];
535
536 return array;
537 }
538 catch (Exception e) {
539 throw HibernateUtil.processException(e);
540 }
541 finally {
542 closeSession(session);
543 }
544 }
545
546 public PollsVote findByQ_U(long questionId, long userId)
547 throws NoSuchVoteException, SystemException {
548 PollsVote pollsVote = fetchByQ_U(questionId, userId);
549
550 if (pollsVote == null) {
551 StringMaker msg = new StringMaker();
552 msg.append("No PollsVote exists with the key ");
553 msg.append(StringPool.OPEN_CURLY_BRACE);
554 msg.append("questionId=");
555 msg.append(questionId);
556 msg.append(", ");
557 msg.append("userId=");
558 msg.append(userId);
559 msg.append(StringPool.CLOSE_CURLY_BRACE);
560
561 if (_log.isWarnEnabled()) {
562 _log.warn(msg.toString());
563 }
564
565 throw new NoSuchVoteException(msg.toString());
566 }
567
568 return pollsVote;
569 }
570
571 public PollsVote fetchByQ_U(long questionId, long userId)
572 throws SystemException {
573 String finderClassName = PollsVote.class.getName();
574 String finderMethodName = "fetchByQ_U";
575 String[] finderParams = new String[] {
576 Long.class.getName(), Long.class.getName()
577 };
578 Object[] finderArgs = new Object[] {
579 new Long(questionId), new Long(userId)
580 };
581 Object result = FinderCache.getResult(finderClassName,
582 finderMethodName, finderParams, finderArgs, getSessionFactory());
583
584 if (result == null) {
585 Session session = null;
586
587 try {
588 session = openSession();
589
590 StringMaker query = new StringMaker();
591 query.append(
592 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
593 query.append("questionId = ?");
594 query.append(" AND ");
595 query.append("userId = ?");
596 query.append(" ");
597
598 Query q = session.createQuery(query.toString());
599 int queryPos = 0;
600 q.setLong(queryPos++, questionId);
601 q.setLong(queryPos++, userId);
602
603 List list = q.list();
604 FinderCache.putResult(finderClassName, finderMethodName,
605 finderParams, finderArgs, list);
606
607 if (list.size() == 0) {
608 return null;
609 }
610 else {
611 return (PollsVote)list.get(0);
612 }
613 }
614 catch (Exception e) {
615 throw HibernateUtil.processException(e);
616 }
617 finally {
618 closeSession(session);
619 }
620 }
621 else {
622 List list = (List)result;
623
624 if (list.size() == 0) {
625 return null;
626 }
627 else {
628 return (PollsVote)list.get(0);
629 }
630 }
631 }
632
633 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
634 throws SystemException {
635 Session session = null;
636
637 try {
638 session = openSession();
639
640 DynamicQuery query = queryInitializer.initialize(session);
641
642 return query.list();
643 }
644 catch (Exception e) {
645 throw HibernateUtil.processException(e);
646 }
647 finally {
648 closeSession(session);
649 }
650 }
651
652 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
653 int begin, int end) throws SystemException {
654 Session session = null;
655
656 try {
657 session = openSession();
658
659 DynamicQuery query = queryInitializer.initialize(session);
660 query.setLimit(begin, end);
661
662 return query.list();
663 }
664 catch (Exception e) {
665 throw HibernateUtil.processException(e);
666 }
667 finally {
668 closeSession(session);
669 }
670 }
671
672 public List findAll() throws SystemException {
673 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
674 }
675
676 public List findAll(int begin, int end) throws SystemException {
677 return findAll(begin, end, null);
678 }
679
680 public List findAll(int begin, int end, OrderByComparator obc)
681 throws SystemException {
682 String finderClassName = PollsVote.class.getName();
683 String finderMethodName = "findAll";
684 String[] finderParams = new String[] {
685 "java.lang.Integer", "java.lang.Integer",
686 "com.liferay.portal.kernel.util.OrderByComparator"
687 };
688 Object[] finderArgs = new Object[] {
689 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
690 };
691 Object result = FinderCache.getResult(finderClassName,
692 finderMethodName, finderParams, finderArgs, getSessionFactory());
693
694 if (result == null) {
695 Session session = null;
696
697 try {
698 session = openSession();
699
700 StringMaker query = new StringMaker();
701 query.append("FROM com.liferay.portlet.polls.model.PollsVote ");
702
703 if (obc != null) {
704 query.append("ORDER BY ");
705 query.append(obc.getOrderBy());
706 }
707
708 Query q = session.createQuery(query.toString());
709 List list = QueryUtil.list(q, getDialect(), begin, end);
710
711 if (obc == null) {
712 Collections.sort(list);
713 }
714
715 FinderCache.putResult(finderClassName, finderMethodName,
716 finderParams, finderArgs, list);
717
718 return list;
719 }
720 catch (Exception e) {
721 throw HibernateUtil.processException(e);
722 }
723 finally {
724 closeSession(session);
725 }
726 }
727 else {
728 return (List)result;
729 }
730 }
731
732 public void removeByQuestionId(long questionId) throws SystemException {
733 Iterator itr = findByQuestionId(questionId).iterator();
734
735 while (itr.hasNext()) {
736 PollsVote pollsVote = (PollsVote)itr.next();
737 remove(pollsVote);
738 }
739 }
740
741 public void removeByChoiceId(long choiceId) throws SystemException {
742 Iterator itr = findByChoiceId(choiceId).iterator();
743
744 while (itr.hasNext()) {
745 PollsVote pollsVote = (PollsVote)itr.next();
746 remove(pollsVote);
747 }
748 }
749
750 public void removeByQ_U(long questionId, long userId)
751 throws NoSuchVoteException, SystemException {
752 PollsVote pollsVote = findByQ_U(questionId, userId);
753 remove(pollsVote);
754 }
755
756 public void removeAll() throws SystemException {
757 Iterator itr = findAll().iterator();
758
759 while (itr.hasNext()) {
760 remove((PollsVote)itr.next());
761 }
762 }
763
764 public int countByQuestionId(long questionId) throws SystemException {
765 String finderClassName = PollsVote.class.getName();
766 String finderMethodName = "countByQuestionId";
767 String[] finderParams = new String[] { Long.class.getName() };
768 Object[] finderArgs = new Object[] { new Long(questionId) };
769 Object result = FinderCache.getResult(finderClassName,
770 finderMethodName, finderParams, finderArgs, getSessionFactory());
771
772 if (result == null) {
773 Session session = null;
774
775 try {
776 session = openSession();
777
778 StringMaker query = new StringMaker();
779 query.append("SELECT COUNT(*) ");
780 query.append(
781 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
782 query.append("questionId = ?");
783 query.append(" ");
784
785 Query q = session.createQuery(query.toString());
786 int queryPos = 0;
787 q.setLong(queryPos++, questionId);
788
789 Long count = null;
790 Iterator itr = q.list().iterator();
791
792 if (itr.hasNext()) {
793 count = (Long)itr.next();
794 }
795
796 if (count == null) {
797 count = new Long(0);
798 }
799
800 FinderCache.putResult(finderClassName, finderMethodName,
801 finderParams, finderArgs, count);
802
803 return count.intValue();
804 }
805 catch (Exception e) {
806 throw HibernateUtil.processException(e);
807 }
808 finally {
809 closeSession(session);
810 }
811 }
812 else {
813 return ((Long)result).intValue();
814 }
815 }
816
817 public int countByChoiceId(long choiceId) throws SystemException {
818 String finderClassName = PollsVote.class.getName();
819 String finderMethodName = "countByChoiceId";
820 String[] finderParams = new String[] { Long.class.getName() };
821 Object[] finderArgs = new Object[] { new Long(choiceId) };
822 Object result = FinderCache.getResult(finderClassName,
823 finderMethodName, finderParams, finderArgs, getSessionFactory());
824
825 if (result == null) {
826 Session session = null;
827
828 try {
829 session = openSession();
830
831 StringMaker query = new StringMaker();
832 query.append("SELECT COUNT(*) ");
833 query.append(
834 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
835 query.append("choiceId = ?");
836 query.append(" ");
837
838 Query q = session.createQuery(query.toString());
839 int queryPos = 0;
840 q.setLong(queryPos++, choiceId);
841
842 Long count = null;
843 Iterator itr = q.list().iterator();
844
845 if (itr.hasNext()) {
846 count = (Long)itr.next();
847 }
848
849 if (count == null) {
850 count = new Long(0);
851 }
852
853 FinderCache.putResult(finderClassName, finderMethodName,
854 finderParams, finderArgs, count);
855
856 return count.intValue();
857 }
858 catch (Exception e) {
859 throw HibernateUtil.processException(e);
860 }
861 finally {
862 closeSession(session);
863 }
864 }
865 else {
866 return ((Long)result).intValue();
867 }
868 }
869
870 public int countByQ_U(long questionId, long userId)
871 throws SystemException {
872 String finderClassName = PollsVote.class.getName();
873 String finderMethodName = "countByQ_U";
874 String[] finderParams = new String[] {
875 Long.class.getName(), Long.class.getName()
876 };
877 Object[] finderArgs = new Object[] {
878 new Long(questionId), new Long(userId)
879 };
880 Object result = FinderCache.getResult(finderClassName,
881 finderMethodName, finderParams, finderArgs, getSessionFactory());
882
883 if (result == null) {
884 Session session = null;
885
886 try {
887 session = openSession();
888
889 StringMaker query = new StringMaker();
890 query.append("SELECT COUNT(*) ");
891 query.append(
892 "FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
893 query.append("questionId = ?");
894 query.append(" AND ");
895 query.append("userId = ?");
896 query.append(" ");
897
898 Query q = session.createQuery(query.toString());
899 int queryPos = 0;
900 q.setLong(queryPos++, questionId);
901 q.setLong(queryPos++, userId);
902
903 Long count = null;
904 Iterator itr = q.list().iterator();
905
906 if (itr.hasNext()) {
907 count = (Long)itr.next();
908 }
909
910 if (count == null) {
911 count = new Long(0);
912 }
913
914 FinderCache.putResult(finderClassName, finderMethodName,
915 finderParams, finderArgs, count);
916
917 return count.intValue();
918 }
919 catch (Exception e) {
920 throw HibernateUtil.processException(e);
921 }
922 finally {
923 closeSession(session);
924 }
925 }
926 else {
927 return ((Long)result).intValue();
928 }
929 }
930
931 public int countAll() throws SystemException {
932 String finderClassName = PollsVote.class.getName();
933 String finderMethodName = "countAll";
934 String[] finderParams = new String[] { };
935 Object[] finderArgs = new Object[] { };
936 Object result = FinderCache.getResult(finderClassName,
937 finderMethodName, finderParams, finderArgs, getSessionFactory());
938
939 if (result == null) {
940 Session session = null;
941
942 try {
943 session = openSession();
944
945 StringMaker query = new StringMaker();
946 query.append("SELECT COUNT(*) ");
947 query.append("FROM com.liferay.portlet.polls.model.PollsVote");
948
949 Query q = session.createQuery(query.toString());
950 Long count = null;
951 Iterator itr = q.list().iterator();
952
953 if (itr.hasNext()) {
954 count = (Long)itr.next();
955 }
956
957 if (count == null) {
958 count = new Long(0);
959 }
960
961 FinderCache.putResult(finderClassName, finderMethodName,
962 finderParams, finderArgs, count);
963
964 return count.intValue();
965 }
966 catch (Exception e) {
967 throw HibernateUtil.processException(e);
968 }
969 finally {
970 closeSession(session);
971 }
972 }
973 else {
974 return ((Long)result).intValue();
975 }
976 }
977
978 protected void initDao() {
979 }
980
981 private static Log _log = LogFactory.getLog(PollsVotePersistenceImpl.class);
982 }