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