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