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