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