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