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