001
014
015 package com.liferay.portlet.polls.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.SQLQuery;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.CacheModel;
040 import com.liferay.portal.model.ModelListener;
041 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import com.liferay.portlet.polls.NoSuchQuestionException;
045 import com.liferay.portlet.polls.model.PollsQuestion;
046 import com.liferay.portlet.polls.model.impl.PollsQuestionImpl;
047 import com.liferay.portlet.polls.model.impl.PollsQuestionModelImpl;
048
049 import java.io.Serializable;
050
051 import java.util.ArrayList;
052 import java.util.Collections;
053 import java.util.List;
054
055
067 public class PollsQuestionPersistenceImpl extends BasePersistenceImpl<PollsQuestion>
068 implements PollsQuestionPersistence {
069
074 public static final String FINDER_CLASS_NAME_ENTITY = PollsQuestionImpl.class.getName();
075 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List1";
077 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078 ".List2";
079 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
080 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
081 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
082 "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
084 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
085 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
086 "findAll", new String[0]);
087 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
088 PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
089 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
091 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
092 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
093 "findByUuid",
094 new String[] {
095 String.class.getName(),
096
097 Integer.class.getName(), Integer.class.getName(),
098 OrderByComparator.class.getName()
099 });
100 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
101 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
102 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
103 "findByUuid", new String[] { String.class.getName() },
104 PollsQuestionModelImpl.UUID_COLUMN_BITMASK |
105 PollsQuestionModelImpl.CREATEDATE_COLUMN_BITMASK);
106 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
107 PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
108 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
109 new String[] { String.class.getName() });
110
111
118 public List<PollsQuestion> findByUuid(String uuid)
119 throws SystemException {
120 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
121 }
122
123
136 public List<PollsQuestion> findByUuid(String uuid, int start, int end)
137 throws SystemException {
138 return findByUuid(uuid, start, end, null);
139 }
140
141
155 public List<PollsQuestion> findByUuid(String uuid, int start, int end,
156 OrderByComparator orderByComparator) throws SystemException {
157 boolean pagination = true;
158 FinderPath finderPath = null;
159 Object[] finderArgs = null;
160
161 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
162 (orderByComparator == null)) {
163 pagination = false;
164 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
165 finderArgs = new Object[] { uuid };
166 }
167 else {
168 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
169 finderArgs = new Object[] { uuid, start, end, orderByComparator };
170 }
171
172 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
173 finderArgs, this);
174
175 if ((list != null) && !list.isEmpty()) {
176 for (PollsQuestion pollsQuestion : list) {
177 if (!Validator.equals(uuid, pollsQuestion.getUuid())) {
178 list = null;
179
180 break;
181 }
182 }
183 }
184
185 if (list == null) {
186 StringBundler query = null;
187
188 if (orderByComparator != null) {
189 query = new StringBundler(3 +
190 (orderByComparator.getOrderByFields().length * 3));
191 }
192 else {
193 query = new StringBundler(3);
194 }
195
196 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
197
198 if (uuid == null) {
199 query.append(_FINDER_COLUMN_UUID_UUID_1);
200 }
201 else {
202 if (uuid.equals(StringPool.BLANK)) {
203 query.append(_FINDER_COLUMN_UUID_UUID_3);
204 }
205 else {
206 query.append(_FINDER_COLUMN_UUID_UUID_2);
207 }
208 }
209
210 if (orderByComparator != null) {
211 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
212 orderByComparator);
213 }
214 else
215 if (pagination) {
216 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
217 }
218
219 String sql = query.toString();
220
221 Session session = null;
222
223 try {
224 session = openSession();
225
226 Query q = session.createQuery(sql);
227
228 QueryPos qPos = QueryPos.getInstance(q);
229
230 if (uuid != null) {
231 qPos.add(uuid);
232 }
233
234 if (!pagination) {
235 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
236 start, end, false);
237
238 Collections.sort(list);
239
240 list = new UnmodifiableList<PollsQuestion>(list);
241 }
242 else {
243 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
244 start, end);
245 }
246
247 cacheResult(list);
248
249 FinderCacheUtil.putResult(finderPath, finderArgs, list);
250 }
251 catch (Exception e) {
252 FinderCacheUtil.removeResult(finderPath, finderArgs);
253
254 throw processException(e);
255 }
256 finally {
257 closeSession(session);
258 }
259 }
260
261 return list;
262 }
263
264
273 public PollsQuestion findByUuid_First(String uuid,
274 OrderByComparator orderByComparator)
275 throws NoSuchQuestionException, SystemException {
276 PollsQuestion pollsQuestion = fetchByUuid_First(uuid, orderByComparator);
277
278 if (pollsQuestion != null) {
279 return pollsQuestion;
280 }
281
282 StringBundler msg = new StringBundler(4);
283
284 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
285
286 msg.append("uuid=");
287 msg.append(uuid);
288
289 msg.append(StringPool.CLOSE_CURLY_BRACE);
290
291 throw new NoSuchQuestionException(msg.toString());
292 }
293
294
302 public PollsQuestion fetchByUuid_First(String uuid,
303 OrderByComparator orderByComparator) throws SystemException {
304 List<PollsQuestion> list = findByUuid(uuid, 0, 1, orderByComparator);
305
306 if (!list.isEmpty()) {
307 return list.get(0);
308 }
309
310 return null;
311 }
312
313
322 public PollsQuestion findByUuid_Last(String uuid,
323 OrderByComparator orderByComparator)
324 throws NoSuchQuestionException, SystemException {
325 PollsQuestion pollsQuestion = fetchByUuid_Last(uuid, orderByComparator);
326
327 if (pollsQuestion != null) {
328 return pollsQuestion;
329 }
330
331 StringBundler msg = new StringBundler(4);
332
333 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
334
335 msg.append("uuid=");
336 msg.append(uuid);
337
338 msg.append(StringPool.CLOSE_CURLY_BRACE);
339
340 throw new NoSuchQuestionException(msg.toString());
341 }
342
343
351 public PollsQuestion fetchByUuid_Last(String uuid,
352 OrderByComparator orderByComparator) throws SystemException {
353 int count = countByUuid(uuid);
354
355 List<PollsQuestion> list = findByUuid(uuid, count - 1, count,
356 orderByComparator);
357
358 if (!list.isEmpty()) {
359 return list.get(0);
360 }
361
362 return null;
363 }
364
365
375 public PollsQuestion[] findByUuid_PrevAndNext(long questionId, String uuid,
376 OrderByComparator orderByComparator)
377 throws NoSuchQuestionException, SystemException {
378 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
379
380 Session session = null;
381
382 try {
383 session = openSession();
384
385 PollsQuestion[] array = new PollsQuestionImpl[3];
386
387 array[0] = getByUuid_PrevAndNext(session, pollsQuestion, uuid,
388 orderByComparator, true);
389
390 array[1] = pollsQuestion;
391
392 array[2] = getByUuid_PrevAndNext(session, pollsQuestion, uuid,
393 orderByComparator, false);
394
395 return array;
396 }
397 catch (Exception e) {
398 throw processException(e);
399 }
400 finally {
401 closeSession(session);
402 }
403 }
404
405 protected PollsQuestion getByUuid_PrevAndNext(Session session,
406 PollsQuestion pollsQuestion, String uuid,
407 OrderByComparator orderByComparator, boolean previous) {
408 StringBundler query = null;
409
410 if (orderByComparator != null) {
411 query = new StringBundler(6 +
412 (orderByComparator.getOrderByFields().length * 6));
413 }
414 else {
415 query = new StringBundler(3);
416 }
417
418 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
419
420 if (uuid == null) {
421 query.append(_FINDER_COLUMN_UUID_UUID_1);
422 }
423 else {
424 if (uuid.equals(StringPool.BLANK)) {
425 query.append(_FINDER_COLUMN_UUID_UUID_3);
426 }
427 else {
428 query.append(_FINDER_COLUMN_UUID_UUID_2);
429 }
430 }
431
432 if (orderByComparator != null) {
433 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
434
435 if (orderByConditionFields.length > 0) {
436 query.append(WHERE_AND);
437 }
438
439 for (int i = 0; i < orderByConditionFields.length; i++) {
440 query.append(_ORDER_BY_ENTITY_ALIAS);
441 query.append(orderByConditionFields[i]);
442
443 if ((i + 1) < orderByConditionFields.length) {
444 if (orderByComparator.isAscending() ^ previous) {
445 query.append(WHERE_GREATER_THAN_HAS_NEXT);
446 }
447 else {
448 query.append(WHERE_LESSER_THAN_HAS_NEXT);
449 }
450 }
451 else {
452 if (orderByComparator.isAscending() ^ previous) {
453 query.append(WHERE_GREATER_THAN);
454 }
455 else {
456 query.append(WHERE_LESSER_THAN);
457 }
458 }
459 }
460
461 query.append(ORDER_BY_CLAUSE);
462
463 String[] orderByFields = orderByComparator.getOrderByFields();
464
465 for (int i = 0; i < orderByFields.length; i++) {
466 query.append(_ORDER_BY_ENTITY_ALIAS);
467 query.append(orderByFields[i]);
468
469 if ((i + 1) < orderByFields.length) {
470 if (orderByComparator.isAscending() ^ previous) {
471 query.append(ORDER_BY_ASC_HAS_NEXT);
472 }
473 else {
474 query.append(ORDER_BY_DESC_HAS_NEXT);
475 }
476 }
477 else {
478 if (orderByComparator.isAscending() ^ previous) {
479 query.append(ORDER_BY_ASC);
480 }
481 else {
482 query.append(ORDER_BY_DESC);
483 }
484 }
485 }
486 }
487 else {
488 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
489 }
490
491 String sql = query.toString();
492
493 Query q = session.createQuery(sql);
494
495 q.setFirstResult(0);
496 q.setMaxResults(2);
497
498 QueryPos qPos = QueryPos.getInstance(q);
499
500 if (uuid != null) {
501 qPos.add(uuid);
502 }
503
504 if (orderByComparator != null) {
505 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
506
507 for (Object value : values) {
508 qPos.add(value);
509 }
510 }
511
512 List<PollsQuestion> list = q.list();
513
514 if (list.size() == 2) {
515 return list.get(1);
516 }
517 else {
518 return null;
519 }
520 }
521
522
528 public void removeByUuid(String uuid) throws SystemException {
529 for (PollsQuestion pollsQuestion : findByUuid(uuid, QueryUtil.ALL_POS,
530 QueryUtil.ALL_POS, null)) {
531 remove(pollsQuestion);
532 }
533 }
534
535
542 public int countByUuid(String uuid) throws SystemException {
543 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
544
545 Object[] finderArgs = new Object[] { uuid };
546
547 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
548 this);
549
550 if (count == null) {
551 StringBundler query = new StringBundler(2);
552
553 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
554
555 if (uuid == null) {
556 query.append(_FINDER_COLUMN_UUID_UUID_1);
557 }
558 else {
559 if (uuid.equals(StringPool.BLANK)) {
560 query.append(_FINDER_COLUMN_UUID_UUID_3);
561 }
562 else {
563 query.append(_FINDER_COLUMN_UUID_UUID_2);
564 }
565 }
566
567 String sql = query.toString();
568
569 Session session = null;
570
571 try {
572 session = openSession();
573
574 Query q = session.createQuery(sql);
575
576 QueryPos qPos = QueryPos.getInstance(q);
577
578 if (uuid != null) {
579 qPos.add(uuid);
580 }
581
582 count = (Long)q.uniqueResult();
583
584 FinderCacheUtil.putResult(finderPath, finderArgs, count);
585 }
586 catch (Exception e) {
587 FinderCacheUtil.removeResult(finderPath, finderArgs);
588
589 throw processException(e);
590 }
591 finally {
592 closeSession(session);
593 }
594 }
595
596 return count.intValue();
597 }
598
599 private static final String _FINDER_COLUMN_UUID_UUID_1 = "pollsQuestion.uuid IS NULL";
600 private static final String _FINDER_COLUMN_UUID_UUID_2 = "pollsQuestion.uuid = ?";
601 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?)";
602 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
603 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
604 PollsQuestionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
605 new String[] { String.class.getName(), Long.class.getName() },
606 PollsQuestionModelImpl.UUID_COLUMN_BITMASK |
607 PollsQuestionModelImpl.GROUPID_COLUMN_BITMASK);
608 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
609 PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
610 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
611 new String[] { String.class.getName(), Long.class.getName() });
612
613
622 public PollsQuestion findByUUID_G(String uuid, long groupId)
623 throws NoSuchQuestionException, SystemException {
624 PollsQuestion pollsQuestion = fetchByUUID_G(uuid, groupId);
625
626 if (pollsQuestion == null) {
627 StringBundler msg = new StringBundler(6);
628
629 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
630
631 msg.append("uuid=");
632 msg.append(uuid);
633
634 msg.append(", groupId=");
635 msg.append(groupId);
636
637 msg.append(StringPool.CLOSE_CURLY_BRACE);
638
639 if (_log.isWarnEnabled()) {
640 _log.warn(msg.toString());
641 }
642
643 throw new NoSuchQuestionException(msg.toString());
644 }
645
646 return pollsQuestion;
647 }
648
649
657 public PollsQuestion fetchByUUID_G(String uuid, long groupId)
658 throws SystemException {
659 return fetchByUUID_G(uuid, groupId, true);
660 }
661
662
671 public PollsQuestion fetchByUUID_G(String uuid, long groupId,
672 boolean retrieveFromCache) throws SystemException {
673 Object[] finderArgs = new Object[] { uuid, groupId };
674
675 Object result = null;
676
677 if (retrieveFromCache) {
678 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
679 finderArgs, this);
680 }
681
682 if (result instanceof PollsQuestion) {
683 PollsQuestion pollsQuestion = (PollsQuestion)result;
684
685 if (!Validator.equals(uuid, pollsQuestion.getUuid()) ||
686 (groupId != pollsQuestion.getGroupId())) {
687 result = null;
688 }
689 }
690
691 if (result == null) {
692 StringBundler query = new StringBundler(4);
693
694 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
695
696 if (uuid == null) {
697 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
698 }
699 else {
700 if (uuid.equals(StringPool.BLANK)) {
701 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
702 }
703 else {
704 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
705 }
706 }
707
708 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
709
710 String sql = query.toString();
711
712 Session session = null;
713
714 try {
715 session = openSession();
716
717 Query q = session.createQuery(sql);
718
719 QueryPos qPos = QueryPos.getInstance(q);
720
721 if (uuid != null) {
722 qPos.add(uuid);
723 }
724
725 qPos.add(groupId);
726
727 List<PollsQuestion> list = q.list();
728
729 if (list.isEmpty()) {
730 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
731 finderArgs, list);
732 }
733 else {
734 PollsQuestion pollsQuestion = list.get(0);
735
736 result = pollsQuestion;
737
738 cacheResult(pollsQuestion);
739
740 if ((pollsQuestion.getUuid() == null) ||
741 !pollsQuestion.getUuid().equals(uuid) ||
742 (pollsQuestion.getGroupId() != groupId)) {
743 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
744 finderArgs, pollsQuestion);
745 }
746 }
747 }
748 catch (Exception e) {
749 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
750 finderArgs);
751
752 throw processException(e);
753 }
754 finally {
755 closeSession(session);
756 }
757 }
758
759 if (result instanceof List<?>) {
760 return null;
761 }
762 else {
763 return (PollsQuestion)result;
764 }
765 }
766
767
775 public PollsQuestion removeByUUID_G(String uuid, long groupId)
776 throws NoSuchQuestionException, SystemException {
777 PollsQuestion pollsQuestion = findByUUID_G(uuid, groupId);
778
779 return remove(pollsQuestion);
780 }
781
782
790 public int countByUUID_G(String uuid, long groupId)
791 throws SystemException {
792 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
793
794 Object[] finderArgs = new Object[] { uuid, groupId };
795
796 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
797 this);
798
799 if (count == null) {
800 StringBundler query = new StringBundler(3);
801
802 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
803
804 if (uuid == null) {
805 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
806 }
807 else {
808 if (uuid.equals(StringPool.BLANK)) {
809 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
810 }
811 else {
812 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
813 }
814 }
815
816 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
817
818 String sql = query.toString();
819
820 Session session = null;
821
822 try {
823 session = openSession();
824
825 Query q = session.createQuery(sql);
826
827 QueryPos qPos = QueryPos.getInstance(q);
828
829 if (uuid != null) {
830 qPos.add(uuid);
831 }
832
833 qPos.add(groupId);
834
835 count = (Long)q.uniqueResult();
836
837 FinderCacheUtil.putResult(finderPath, finderArgs, count);
838 }
839 catch (Exception e) {
840 FinderCacheUtil.removeResult(finderPath, finderArgs);
841
842 throw processException(e);
843 }
844 finally {
845 closeSession(session);
846 }
847 }
848
849 return count.intValue();
850 }
851
852 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "pollsQuestion.uuid IS NULL AND ";
853 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "pollsQuestion.uuid = ? AND ";
854 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?) AND ";
855 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "pollsQuestion.groupId = ?";
856 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
857 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
858 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
859 "findByUuid_C",
860 new String[] {
861 String.class.getName(), Long.class.getName(),
862
863 Integer.class.getName(), Integer.class.getName(),
864 OrderByComparator.class.getName()
865 });
866 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
867 new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
868 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
869 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
870 "findByUuid_C",
871 new String[] { String.class.getName(), Long.class.getName() },
872 PollsQuestionModelImpl.UUID_COLUMN_BITMASK |
873 PollsQuestionModelImpl.COMPANYID_COLUMN_BITMASK |
874 PollsQuestionModelImpl.CREATEDATE_COLUMN_BITMASK);
875 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
876 PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
877 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
878 new String[] { String.class.getName(), Long.class.getName() });
879
880
888 public List<PollsQuestion> findByUuid_C(String uuid, long companyId)
889 throws SystemException {
890 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
891 QueryUtil.ALL_POS, null);
892 }
893
894
908 public List<PollsQuestion> findByUuid_C(String uuid, long companyId,
909 int start, int end) throws SystemException {
910 return findByUuid_C(uuid, companyId, start, end, null);
911 }
912
913
928 public List<PollsQuestion> findByUuid_C(String uuid, long companyId,
929 int start, int end, OrderByComparator orderByComparator)
930 throws SystemException {
931 boolean pagination = true;
932 FinderPath finderPath = null;
933 Object[] finderArgs = null;
934
935 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
936 (orderByComparator == null)) {
937 pagination = false;
938 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
939 finderArgs = new Object[] { uuid, companyId };
940 }
941 else {
942 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
943 finderArgs = new Object[] {
944 uuid, companyId,
945
946 start, end, orderByComparator
947 };
948 }
949
950 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
951 finderArgs, this);
952
953 if ((list != null) && !list.isEmpty()) {
954 for (PollsQuestion pollsQuestion : list) {
955 if (!Validator.equals(uuid, pollsQuestion.getUuid()) ||
956 (companyId != pollsQuestion.getCompanyId())) {
957 list = null;
958
959 break;
960 }
961 }
962 }
963
964 if (list == null) {
965 StringBundler query = null;
966
967 if (orderByComparator != null) {
968 query = new StringBundler(4 +
969 (orderByComparator.getOrderByFields().length * 3));
970 }
971 else {
972 query = new StringBundler(4);
973 }
974
975 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
976
977 if (uuid == null) {
978 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
979 }
980 else {
981 if (uuid.equals(StringPool.BLANK)) {
982 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
983 }
984 else {
985 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
986 }
987 }
988
989 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
990
991 if (orderByComparator != null) {
992 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
993 orderByComparator);
994 }
995 else
996 if (pagination) {
997 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
998 }
999
1000 String sql = query.toString();
1001
1002 Session session = null;
1003
1004 try {
1005 session = openSession();
1006
1007 Query q = session.createQuery(sql);
1008
1009 QueryPos qPos = QueryPos.getInstance(q);
1010
1011 if (uuid != null) {
1012 qPos.add(uuid);
1013 }
1014
1015 qPos.add(companyId);
1016
1017 if (!pagination) {
1018 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1019 start, end, false);
1020
1021 Collections.sort(list);
1022
1023 list = new UnmodifiableList<PollsQuestion>(list);
1024 }
1025 else {
1026 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1027 start, end);
1028 }
1029
1030 cacheResult(list);
1031
1032 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1033 }
1034 catch (Exception e) {
1035 FinderCacheUtil.removeResult(finderPath, finderArgs);
1036
1037 throw processException(e);
1038 }
1039 finally {
1040 closeSession(session);
1041 }
1042 }
1043
1044 return list;
1045 }
1046
1047
1057 public PollsQuestion findByUuid_C_First(String uuid, long companyId,
1058 OrderByComparator orderByComparator)
1059 throws NoSuchQuestionException, SystemException {
1060 PollsQuestion pollsQuestion = fetchByUuid_C_First(uuid, companyId,
1061 orderByComparator);
1062
1063 if (pollsQuestion != null) {
1064 return pollsQuestion;
1065 }
1066
1067 StringBundler msg = new StringBundler(6);
1068
1069 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1070
1071 msg.append("uuid=");
1072 msg.append(uuid);
1073
1074 msg.append(", companyId=");
1075 msg.append(companyId);
1076
1077 msg.append(StringPool.CLOSE_CURLY_BRACE);
1078
1079 throw new NoSuchQuestionException(msg.toString());
1080 }
1081
1082
1091 public PollsQuestion fetchByUuid_C_First(String uuid, long companyId,
1092 OrderByComparator orderByComparator) throws SystemException {
1093 List<PollsQuestion> list = findByUuid_C(uuid, companyId, 0, 1,
1094 orderByComparator);
1095
1096 if (!list.isEmpty()) {
1097 return list.get(0);
1098 }
1099
1100 return null;
1101 }
1102
1103
1113 public PollsQuestion findByUuid_C_Last(String uuid, long companyId,
1114 OrderByComparator orderByComparator)
1115 throws NoSuchQuestionException, SystemException {
1116 PollsQuestion pollsQuestion = fetchByUuid_C_Last(uuid, companyId,
1117 orderByComparator);
1118
1119 if (pollsQuestion != null) {
1120 return pollsQuestion;
1121 }
1122
1123 StringBundler msg = new StringBundler(6);
1124
1125 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1126
1127 msg.append("uuid=");
1128 msg.append(uuid);
1129
1130 msg.append(", companyId=");
1131 msg.append(companyId);
1132
1133 msg.append(StringPool.CLOSE_CURLY_BRACE);
1134
1135 throw new NoSuchQuestionException(msg.toString());
1136 }
1137
1138
1147 public PollsQuestion fetchByUuid_C_Last(String uuid, long companyId,
1148 OrderByComparator orderByComparator) throws SystemException {
1149 int count = countByUuid_C(uuid, companyId);
1150
1151 List<PollsQuestion> list = findByUuid_C(uuid, companyId, count - 1,
1152 count, orderByComparator);
1153
1154 if (!list.isEmpty()) {
1155 return list.get(0);
1156 }
1157
1158 return null;
1159 }
1160
1161
1172 public PollsQuestion[] findByUuid_C_PrevAndNext(long questionId,
1173 String uuid, long companyId, OrderByComparator orderByComparator)
1174 throws NoSuchQuestionException, SystemException {
1175 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
1176
1177 Session session = null;
1178
1179 try {
1180 session = openSession();
1181
1182 PollsQuestion[] array = new PollsQuestionImpl[3];
1183
1184 array[0] = getByUuid_C_PrevAndNext(session, pollsQuestion, uuid,
1185 companyId, orderByComparator, true);
1186
1187 array[1] = pollsQuestion;
1188
1189 array[2] = getByUuid_C_PrevAndNext(session, pollsQuestion, uuid,
1190 companyId, orderByComparator, false);
1191
1192 return array;
1193 }
1194 catch (Exception e) {
1195 throw processException(e);
1196 }
1197 finally {
1198 closeSession(session);
1199 }
1200 }
1201
1202 protected PollsQuestion getByUuid_C_PrevAndNext(Session session,
1203 PollsQuestion pollsQuestion, String uuid, long companyId,
1204 OrderByComparator orderByComparator, boolean previous) {
1205 StringBundler query = null;
1206
1207 if (orderByComparator != null) {
1208 query = new StringBundler(6 +
1209 (orderByComparator.getOrderByFields().length * 6));
1210 }
1211 else {
1212 query = new StringBundler(3);
1213 }
1214
1215 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1216
1217 if (uuid == null) {
1218 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1219 }
1220 else {
1221 if (uuid.equals(StringPool.BLANK)) {
1222 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1223 }
1224 else {
1225 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1226 }
1227 }
1228
1229 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1230
1231 if (orderByComparator != null) {
1232 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1233
1234 if (orderByConditionFields.length > 0) {
1235 query.append(WHERE_AND);
1236 }
1237
1238 for (int i = 0; i < orderByConditionFields.length; i++) {
1239 query.append(_ORDER_BY_ENTITY_ALIAS);
1240 query.append(orderByConditionFields[i]);
1241
1242 if ((i + 1) < orderByConditionFields.length) {
1243 if (orderByComparator.isAscending() ^ previous) {
1244 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1245 }
1246 else {
1247 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1248 }
1249 }
1250 else {
1251 if (orderByComparator.isAscending() ^ previous) {
1252 query.append(WHERE_GREATER_THAN);
1253 }
1254 else {
1255 query.append(WHERE_LESSER_THAN);
1256 }
1257 }
1258 }
1259
1260 query.append(ORDER_BY_CLAUSE);
1261
1262 String[] orderByFields = orderByComparator.getOrderByFields();
1263
1264 for (int i = 0; i < orderByFields.length; i++) {
1265 query.append(_ORDER_BY_ENTITY_ALIAS);
1266 query.append(orderByFields[i]);
1267
1268 if ((i + 1) < orderByFields.length) {
1269 if (orderByComparator.isAscending() ^ previous) {
1270 query.append(ORDER_BY_ASC_HAS_NEXT);
1271 }
1272 else {
1273 query.append(ORDER_BY_DESC_HAS_NEXT);
1274 }
1275 }
1276 else {
1277 if (orderByComparator.isAscending() ^ previous) {
1278 query.append(ORDER_BY_ASC);
1279 }
1280 else {
1281 query.append(ORDER_BY_DESC);
1282 }
1283 }
1284 }
1285 }
1286 else {
1287 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1288 }
1289
1290 String sql = query.toString();
1291
1292 Query q = session.createQuery(sql);
1293
1294 q.setFirstResult(0);
1295 q.setMaxResults(2);
1296
1297 QueryPos qPos = QueryPos.getInstance(q);
1298
1299 if (uuid != null) {
1300 qPos.add(uuid);
1301 }
1302
1303 qPos.add(companyId);
1304
1305 if (orderByComparator != null) {
1306 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
1307
1308 for (Object value : values) {
1309 qPos.add(value);
1310 }
1311 }
1312
1313 List<PollsQuestion> list = q.list();
1314
1315 if (list.size() == 2) {
1316 return list.get(1);
1317 }
1318 else {
1319 return null;
1320 }
1321 }
1322
1323
1330 public void removeByUuid_C(String uuid, long companyId)
1331 throws SystemException {
1332 for (PollsQuestion pollsQuestion : findByUuid_C(uuid, companyId,
1333 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1334 remove(pollsQuestion);
1335 }
1336 }
1337
1338
1346 public int countByUuid_C(String uuid, long companyId)
1347 throws SystemException {
1348 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1349
1350 Object[] finderArgs = new Object[] { uuid, companyId };
1351
1352 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1353 this);
1354
1355 if (count == null) {
1356 StringBundler query = new StringBundler(3);
1357
1358 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
1359
1360 if (uuid == null) {
1361 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1362 }
1363 else {
1364 if (uuid.equals(StringPool.BLANK)) {
1365 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1366 }
1367 else {
1368 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1369 }
1370 }
1371
1372 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1373
1374 String sql = query.toString();
1375
1376 Session session = null;
1377
1378 try {
1379 session = openSession();
1380
1381 Query q = session.createQuery(sql);
1382
1383 QueryPos qPos = QueryPos.getInstance(q);
1384
1385 if (uuid != null) {
1386 qPos.add(uuid);
1387 }
1388
1389 qPos.add(companyId);
1390
1391 count = (Long)q.uniqueResult();
1392
1393 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1394 }
1395 catch (Exception e) {
1396 FinderCacheUtil.removeResult(finderPath, finderArgs);
1397
1398 throw processException(e);
1399 }
1400 finally {
1401 closeSession(session);
1402 }
1403 }
1404
1405 return count.intValue();
1406 }
1407
1408 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "pollsQuestion.uuid IS NULL AND ";
1409 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "pollsQuestion.uuid = ? AND ";
1410 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?) AND ";
1411 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "pollsQuestion.companyId = ?";
1412 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
1413 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
1414 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1415 "findByGroupId",
1416 new String[] {
1417 Long.class.getName(),
1418
1419 Integer.class.getName(), Integer.class.getName(),
1420 OrderByComparator.class.getName()
1421 });
1422 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1423 new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
1424 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
1425 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1426 "findByGroupId", new String[] { Long.class.getName() },
1427 PollsQuestionModelImpl.GROUPID_COLUMN_BITMASK |
1428 PollsQuestionModelImpl.CREATEDATE_COLUMN_BITMASK);
1429 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
1430 PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1431 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1432 new String[] { Long.class.getName() });
1433
1434
1441 public List<PollsQuestion> findByGroupId(long groupId)
1442 throws SystemException {
1443 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1444 }
1445
1446
1459 public List<PollsQuestion> findByGroupId(long groupId, int start, int end)
1460 throws SystemException {
1461 return findByGroupId(groupId, start, end, null);
1462 }
1463
1464
1478 public List<PollsQuestion> findByGroupId(long groupId, int start, int end,
1479 OrderByComparator orderByComparator) throws SystemException {
1480 boolean pagination = true;
1481 FinderPath finderPath = null;
1482 Object[] finderArgs = null;
1483
1484 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1485 (orderByComparator == null)) {
1486 pagination = false;
1487 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1488 finderArgs = new Object[] { groupId };
1489 }
1490 else {
1491 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1492 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1493 }
1494
1495 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
1496 finderArgs, this);
1497
1498 if ((list != null) && !list.isEmpty()) {
1499 for (PollsQuestion pollsQuestion : list) {
1500 if ((groupId != pollsQuestion.getGroupId())) {
1501 list = null;
1502
1503 break;
1504 }
1505 }
1506 }
1507
1508 if (list == null) {
1509 StringBundler query = null;
1510
1511 if (orderByComparator != null) {
1512 query = new StringBundler(3 +
1513 (orderByComparator.getOrderByFields().length * 3));
1514 }
1515 else {
1516 query = new StringBundler(3);
1517 }
1518
1519 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1520
1521 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1522
1523 if (orderByComparator != null) {
1524 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1525 orderByComparator);
1526 }
1527 else
1528 if (pagination) {
1529 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1530 }
1531
1532 String sql = query.toString();
1533
1534 Session session = null;
1535
1536 try {
1537 session = openSession();
1538
1539 Query q = session.createQuery(sql);
1540
1541 QueryPos qPos = QueryPos.getInstance(q);
1542
1543 qPos.add(groupId);
1544
1545 if (!pagination) {
1546 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1547 start, end, false);
1548
1549 Collections.sort(list);
1550
1551 list = new UnmodifiableList<PollsQuestion>(list);
1552 }
1553 else {
1554 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1555 start, end);
1556 }
1557
1558 cacheResult(list);
1559
1560 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1561 }
1562 catch (Exception e) {
1563 FinderCacheUtil.removeResult(finderPath, finderArgs);
1564
1565 throw processException(e);
1566 }
1567 finally {
1568 closeSession(session);
1569 }
1570 }
1571
1572 return list;
1573 }
1574
1575
1584 public PollsQuestion findByGroupId_First(long groupId,
1585 OrderByComparator orderByComparator)
1586 throws NoSuchQuestionException, SystemException {
1587 PollsQuestion pollsQuestion = fetchByGroupId_First(groupId,
1588 orderByComparator);
1589
1590 if (pollsQuestion != null) {
1591 return pollsQuestion;
1592 }
1593
1594 StringBundler msg = new StringBundler(4);
1595
1596 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1597
1598 msg.append("groupId=");
1599 msg.append(groupId);
1600
1601 msg.append(StringPool.CLOSE_CURLY_BRACE);
1602
1603 throw new NoSuchQuestionException(msg.toString());
1604 }
1605
1606
1614 public PollsQuestion fetchByGroupId_First(long groupId,
1615 OrderByComparator orderByComparator) throws SystemException {
1616 List<PollsQuestion> list = findByGroupId(groupId, 0, 1,
1617 orderByComparator);
1618
1619 if (!list.isEmpty()) {
1620 return list.get(0);
1621 }
1622
1623 return null;
1624 }
1625
1626
1635 public PollsQuestion findByGroupId_Last(long groupId,
1636 OrderByComparator orderByComparator)
1637 throws NoSuchQuestionException, SystemException {
1638 PollsQuestion pollsQuestion = fetchByGroupId_Last(groupId,
1639 orderByComparator);
1640
1641 if (pollsQuestion != null) {
1642 return pollsQuestion;
1643 }
1644
1645 StringBundler msg = new StringBundler(4);
1646
1647 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1648
1649 msg.append("groupId=");
1650 msg.append(groupId);
1651
1652 msg.append(StringPool.CLOSE_CURLY_BRACE);
1653
1654 throw new NoSuchQuestionException(msg.toString());
1655 }
1656
1657
1665 public PollsQuestion fetchByGroupId_Last(long groupId,
1666 OrderByComparator orderByComparator) throws SystemException {
1667 int count = countByGroupId(groupId);
1668
1669 List<PollsQuestion> list = findByGroupId(groupId, count - 1, count,
1670 orderByComparator);
1671
1672 if (!list.isEmpty()) {
1673 return list.get(0);
1674 }
1675
1676 return null;
1677 }
1678
1679
1689 public PollsQuestion[] findByGroupId_PrevAndNext(long questionId,
1690 long groupId, OrderByComparator orderByComparator)
1691 throws NoSuchQuestionException, SystemException {
1692 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
1693
1694 Session session = null;
1695
1696 try {
1697 session = openSession();
1698
1699 PollsQuestion[] array = new PollsQuestionImpl[3];
1700
1701 array[0] = getByGroupId_PrevAndNext(session, pollsQuestion,
1702 groupId, orderByComparator, true);
1703
1704 array[1] = pollsQuestion;
1705
1706 array[2] = getByGroupId_PrevAndNext(session, pollsQuestion,
1707 groupId, orderByComparator, false);
1708
1709 return array;
1710 }
1711 catch (Exception e) {
1712 throw processException(e);
1713 }
1714 finally {
1715 closeSession(session);
1716 }
1717 }
1718
1719 protected PollsQuestion getByGroupId_PrevAndNext(Session session,
1720 PollsQuestion pollsQuestion, long groupId,
1721 OrderByComparator orderByComparator, boolean previous) {
1722 StringBundler query = null;
1723
1724 if (orderByComparator != null) {
1725 query = new StringBundler(6 +
1726 (orderByComparator.getOrderByFields().length * 6));
1727 }
1728 else {
1729 query = new StringBundler(3);
1730 }
1731
1732 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1733
1734 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1735
1736 if (orderByComparator != null) {
1737 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1738
1739 if (orderByConditionFields.length > 0) {
1740 query.append(WHERE_AND);
1741 }
1742
1743 for (int i = 0; i < orderByConditionFields.length; i++) {
1744 query.append(_ORDER_BY_ENTITY_ALIAS);
1745 query.append(orderByConditionFields[i]);
1746
1747 if ((i + 1) < orderByConditionFields.length) {
1748 if (orderByComparator.isAscending() ^ previous) {
1749 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1750 }
1751 else {
1752 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1753 }
1754 }
1755 else {
1756 if (orderByComparator.isAscending() ^ previous) {
1757 query.append(WHERE_GREATER_THAN);
1758 }
1759 else {
1760 query.append(WHERE_LESSER_THAN);
1761 }
1762 }
1763 }
1764
1765 query.append(ORDER_BY_CLAUSE);
1766
1767 String[] orderByFields = orderByComparator.getOrderByFields();
1768
1769 for (int i = 0; i < orderByFields.length; i++) {
1770 query.append(_ORDER_BY_ENTITY_ALIAS);
1771 query.append(orderByFields[i]);
1772
1773 if ((i + 1) < orderByFields.length) {
1774 if (orderByComparator.isAscending() ^ previous) {
1775 query.append(ORDER_BY_ASC_HAS_NEXT);
1776 }
1777 else {
1778 query.append(ORDER_BY_DESC_HAS_NEXT);
1779 }
1780 }
1781 else {
1782 if (orderByComparator.isAscending() ^ previous) {
1783 query.append(ORDER_BY_ASC);
1784 }
1785 else {
1786 query.append(ORDER_BY_DESC);
1787 }
1788 }
1789 }
1790 }
1791 else {
1792 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1793 }
1794
1795 String sql = query.toString();
1796
1797 Query q = session.createQuery(sql);
1798
1799 q.setFirstResult(0);
1800 q.setMaxResults(2);
1801
1802 QueryPos qPos = QueryPos.getInstance(q);
1803
1804 qPos.add(groupId);
1805
1806 if (orderByComparator != null) {
1807 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
1808
1809 for (Object value : values) {
1810 qPos.add(value);
1811 }
1812 }
1813
1814 List<PollsQuestion> list = q.list();
1815
1816 if (list.size() == 2) {
1817 return list.get(1);
1818 }
1819 else {
1820 return null;
1821 }
1822 }
1823
1824
1831 public List<PollsQuestion> filterFindByGroupId(long groupId)
1832 throws SystemException {
1833 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1834 QueryUtil.ALL_POS, null);
1835 }
1836
1837
1850 public List<PollsQuestion> filterFindByGroupId(long groupId, int start,
1851 int end) throws SystemException {
1852 return filterFindByGroupId(groupId, start, end, null);
1853 }
1854
1855
1869 public List<PollsQuestion> filterFindByGroupId(long groupId, int start,
1870 int end, OrderByComparator orderByComparator) throws SystemException {
1871 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1872 return findByGroupId(groupId, start, end, orderByComparator);
1873 }
1874
1875 StringBundler query = null;
1876
1877 if (orderByComparator != null) {
1878 query = new StringBundler(3 +
1879 (orderByComparator.getOrderByFields().length * 3));
1880 }
1881 else {
1882 query = new StringBundler(3);
1883 }
1884
1885 if (getDB().isSupportsInlineDistinct()) {
1886 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_WHERE);
1887 }
1888 else {
1889 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1);
1890 }
1891
1892 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1893
1894 if (!getDB().isSupportsInlineDistinct()) {
1895 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2);
1896 }
1897
1898 if (orderByComparator != null) {
1899 if (getDB().isSupportsInlineDistinct()) {
1900 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1901 orderByComparator);
1902 }
1903 else {
1904 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1905 orderByComparator);
1906 }
1907 }
1908 else {
1909 if (getDB().isSupportsInlineDistinct()) {
1910 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1911 }
1912 else {
1913 query.append(PollsQuestionModelImpl.ORDER_BY_SQL);
1914 }
1915 }
1916
1917 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1918 PollsQuestion.class.getName(),
1919 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1920
1921 Session session = null;
1922
1923 try {
1924 session = openSession();
1925
1926 SQLQuery q = session.createSQLQuery(sql);
1927
1928 if (getDB().isSupportsInlineDistinct()) {
1929 q.addEntity(_FILTER_ENTITY_ALIAS, PollsQuestionImpl.class);
1930 }
1931 else {
1932 q.addEntity(_FILTER_ENTITY_TABLE, PollsQuestionImpl.class);
1933 }
1934
1935 QueryPos qPos = QueryPos.getInstance(q);
1936
1937 qPos.add(groupId);
1938
1939 return (List<PollsQuestion>)QueryUtil.list(q, getDialect(), start,
1940 end);
1941 }
1942 catch (Exception e) {
1943 throw processException(e);
1944 }
1945 finally {
1946 closeSession(session);
1947 }
1948 }
1949
1950
1960 public PollsQuestion[] filterFindByGroupId_PrevAndNext(long questionId,
1961 long groupId, OrderByComparator orderByComparator)
1962 throws NoSuchQuestionException, SystemException {
1963 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1964 return findByGroupId_PrevAndNext(questionId, groupId,
1965 orderByComparator);
1966 }
1967
1968 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
1969
1970 Session session = null;
1971
1972 try {
1973 session = openSession();
1974
1975 PollsQuestion[] array = new PollsQuestionImpl[3];
1976
1977 array[0] = filterGetByGroupId_PrevAndNext(session, pollsQuestion,
1978 groupId, orderByComparator, true);
1979
1980 array[1] = pollsQuestion;
1981
1982 array[2] = filterGetByGroupId_PrevAndNext(session, pollsQuestion,
1983 groupId, orderByComparator, false);
1984
1985 return array;
1986 }
1987 catch (Exception e) {
1988 throw processException(e);
1989 }
1990 finally {
1991 closeSession(session);
1992 }
1993 }
1994
1995 protected PollsQuestion filterGetByGroupId_PrevAndNext(Session session,
1996 PollsQuestion pollsQuestion, long groupId,
1997 OrderByComparator orderByComparator, boolean previous) {
1998 StringBundler query = null;
1999
2000 if (orderByComparator != null) {
2001 query = new StringBundler(6 +
2002 (orderByComparator.getOrderByFields().length * 6));
2003 }
2004 else {
2005 query = new StringBundler(3);
2006 }
2007
2008 if (getDB().isSupportsInlineDistinct()) {
2009 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_WHERE);
2010 }
2011 else {
2012 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1);
2013 }
2014
2015 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2016
2017 if (!getDB().isSupportsInlineDistinct()) {
2018 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2);
2019 }
2020
2021 if (orderByComparator != null) {
2022 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2023
2024 if (orderByConditionFields.length > 0) {
2025 query.append(WHERE_AND);
2026 }
2027
2028 for (int i = 0; i < orderByConditionFields.length; i++) {
2029 if (getDB().isSupportsInlineDistinct()) {
2030 query.append(_ORDER_BY_ENTITY_ALIAS);
2031 }
2032 else {
2033 query.append(_ORDER_BY_ENTITY_TABLE);
2034 }
2035
2036 query.append(orderByConditionFields[i]);
2037
2038 if ((i + 1) < orderByConditionFields.length) {
2039 if (orderByComparator.isAscending() ^ previous) {
2040 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2041 }
2042 else {
2043 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2044 }
2045 }
2046 else {
2047 if (orderByComparator.isAscending() ^ previous) {
2048 query.append(WHERE_GREATER_THAN);
2049 }
2050 else {
2051 query.append(WHERE_LESSER_THAN);
2052 }
2053 }
2054 }
2055
2056 query.append(ORDER_BY_CLAUSE);
2057
2058 String[] orderByFields = orderByComparator.getOrderByFields();
2059
2060 for (int i = 0; i < orderByFields.length; i++) {
2061 if (getDB().isSupportsInlineDistinct()) {
2062 query.append(_ORDER_BY_ENTITY_ALIAS);
2063 }
2064 else {
2065 query.append(_ORDER_BY_ENTITY_TABLE);
2066 }
2067
2068 query.append(orderByFields[i]);
2069
2070 if ((i + 1) < orderByFields.length) {
2071 if (orderByComparator.isAscending() ^ previous) {
2072 query.append(ORDER_BY_ASC_HAS_NEXT);
2073 }
2074 else {
2075 query.append(ORDER_BY_DESC_HAS_NEXT);
2076 }
2077 }
2078 else {
2079 if (orderByComparator.isAscending() ^ previous) {
2080 query.append(ORDER_BY_ASC);
2081 }
2082 else {
2083 query.append(ORDER_BY_DESC);
2084 }
2085 }
2086 }
2087 }
2088 else {
2089 if (getDB().isSupportsInlineDistinct()) {
2090 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
2091 }
2092 else {
2093 query.append(PollsQuestionModelImpl.ORDER_BY_SQL);
2094 }
2095 }
2096
2097 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2098 PollsQuestion.class.getName(),
2099 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2100
2101 SQLQuery q = session.createSQLQuery(sql);
2102
2103 q.setFirstResult(0);
2104 q.setMaxResults(2);
2105
2106 if (getDB().isSupportsInlineDistinct()) {
2107 q.addEntity(_FILTER_ENTITY_ALIAS, PollsQuestionImpl.class);
2108 }
2109 else {
2110 q.addEntity(_FILTER_ENTITY_TABLE, PollsQuestionImpl.class);
2111 }
2112
2113 QueryPos qPos = QueryPos.getInstance(q);
2114
2115 qPos.add(groupId);
2116
2117 if (orderByComparator != null) {
2118 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
2119
2120 for (Object value : values) {
2121 qPos.add(value);
2122 }
2123 }
2124
2125 List<PollsQuestion> list = q.list();
2126
2127 if (list.size() == 2) {
2128 return list.get(1);
2129 }
2130 else {
2131 return null;
2132 }
2133 }
2134
2135
2141 public void removeByGroupId(long groupId) throws SystemException {
2142 for (PollsQuestion pollsQuestion : findByGroupId(groupId,
2143 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2144 remove(pollsQuestion);
2145 }
2146 }
2147
2148
2155 public int countByGroupId(long groupId) throws SystemException {
2156 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2157
2158 Object[] finderArgs = new Object[] { groupId };
2159
2160 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2161 this);
2162
2163 if (count == null) {
2164 StringBundler query = new StringBundler(2);
2165
2166 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
2167
2168 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2169
2170 String sql = query.toString();
2171
2172 Session session = null;
2173
2174 try {
2175 session = openSession();
2176
2177 Query q = session.createQuery(sql);
2178
2179 QueryPos qPos = QueryPos.getInstance(q);
2180
2181 qPos.add(groupId);
2182
2183 count = (Long)q.uniqueResult();
2184
2185 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2186 }
2187 catch (Exception e) {
2188 FinderCacheUtil.removeResult(finderPath, finderArgs);
2189
2190 throw processException(e);
2191 }
2192 finally {
2193 closeSession(session);
2194 }
2195 }
2196
2197 return count.intValue();
2198 }
2199
2200
2207 public int filterCountByGroupId(long groupId) throws SystemException {
2208 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2209 return countByGroupId(groupId);
2210 }
2211
2212 StringBundler query = new StringBundler(2);
2213
2214 query.append(_FILTER_SQL_COUNT_POLLSQUESTION_WHERE);
2215
2216 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2217
2218 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2219 PollsQuestion.class.getName(),
2220 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2221
2222 Session session = null;
2223
2224 try {
2225 session = openSession();
2226
2227 SQLQuery q = session.createSQLQuery(sql);
2228
2229 q.addScalar(COUNT_COLUMN_NAME,
2230 com.liferay.portal.kernel.dao.orm.Type.LONG);
2231
2232 QueryPos qPos = QueryPos.getInstance(q);
2233
2234 qPos.add(groupId);
2235
2236 Long count = (Long)q.uniqueResult();
2237
2238 return count.intValue();
2239 }
2240 catch (Exception e) {
2241 throw processException(e);
2242 }
2243 finally {
2244 closeSession(session);
2245 }
2246 }
2247
2248 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "pollsQuestion.groupId = ?";
2249
2250
2255 public void cacheResult(PollsQuestion pollsQuestion) {
2256 EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
2257 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
2258 pollsQuestion);
2259
2260 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2261 new Object[] {
2262 pollsQuestion.getUuid(),
2263 Long.valueOf(pollsQuestion.getGroupId())
2264 }, pollsQuestion);
2265
2266 pollsQuestion.resetOriginalValues();
2267 }
2268
2269
2274 public void cacheResult(List<PollsQuestion> pollsQuestions) {
2275 for (PollsQuestion pollsQuestion : pollsQuestions) {
2276 if (EntityCacheUtil.getResult(
2277 PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
2278 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey()) == null) {
2279 cacheResult(pollsQuestion);
2280 }
2281 else {
2282 pollsQuestion.resetOriginalValues();
2283 }
2284 }
2285 }
2286
2287
2294 @Override
2295 public void clearCache() {
2296 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2297 CacheRegistryUtil.clear(PollsQuestionImpl.class.getName());
2298 }
2299
2300 EntityCacheUtil.clearCache(PollsQuestionImpl.class.getName());
2301
2302 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2303 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2304 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2305 }
2306
2307
2314 @Override
2315 public void clearCache(PollsQuestion pollsQuestion) {
2316 EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
2317 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey());
2318
2319 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2320 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2321
2322 clearUniqueFindersCache(pollsQuestion);
2323 }
2324
2325 @Override
2326 public void clearCache(List<PollsQuestion> pollsQuestions) {
2327 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2328 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2329
2330 for (PollsQuestion pollsQuestion : pollsQuestions) {
2331 EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
2332 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey());
2333
2334 clearUniqueFindersCache(pollsQuestion);
2335 }
2336 }
2337
2338 protected void cacheUniqueFindersCache(PollsQuestion pollsQuestion) {
2339 if (pollsQuestion.isNew()) {
2340 Object[] args = new Object[] {
2341 pollsQuestion.getUuid(),
2342 Long.valueOf(pollsQuestion.getGroupId())
2343 };
2344
2345 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2346 Long.valueOf(1));
2347 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2348 pollsQuestion);
2349 }
2350 else {
2351 PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
2352
2353 if ((pollsQuestionModelImpl.getColumnBitmask() &
2354 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2355 Object[] args = new Object[] {
2356 pollsQuestion.getUuid(),
2357 Long.valueOf(pollsQuestion.getGroupId())
2358 };
2359
2360 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2361 Long.valueOf(1));
2362 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2363 pollsQuestion);
2364 }
2365 }
2366 }
2367
2368 protected void clearUniqueFindersCache(PollsQuestion pollsQuestion) {
2369 PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
2370
2371 Object[] args = new Object[] {
2372 pollsQuestion.getUuid(),
2373 Long.valueOf(pollsQuestion.getGroupId())
2374 };
2375
2376 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2377 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2378
2379 if ((pollsQuestionModelImpl.getColumnBitmask() &
2380 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2381 args = new Object[] {
2382 pollsQuestionModelImpl.getOriginalUuid(),
2383 Long.valueOf(pollsQuestionModelImpl.getOriginalGroupId())
2384 };
2385
2386 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2387 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2388 }
2389 }
2390
2391
2397 public PollsQuestion create(long questionId) {
2398 PollsQuestion pollsQuestion = new PollsQuestionImpl();
2399
2400 pollsQuestion.setNew(true);
2401 pollsQuestion.setPrimaryKey(questionId);
2402
2403 String uuid = PortalUUIDUtil.generate();
2404
2405 pollsQuestion.setUuid(uuid);
2406
2407 return pollsQuestion;
2408 }
2409
2410
2418 public PollsQuestion remove(long questionId)
2419 throws NoSuchQuestionException, SystemException {
2420 return remove(Long.valueOf(questionId));
2421 }
2422
2423
2431 @Override
2432 public PollsQuestion remove(Serializable primaryKey)
2433 throws NoSuchQuestionException, SystemException {
2434 Session session = null;
2435
2436 try {
2437 session = openSession();
2438
2439 PollsQuestion pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
2440 primaryKey);
2441
2442 if (pollsQuestion == null) {
2443 if (_log.isWarnEnabled()) {
2444 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2445 }
2446
2447 throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2448 primaryKey);
2449 }
2450
2451 return remove(pollsQuestion);
2452 }
2453 catch (NoSuchQuestionException nsee) {
2454 throw nsee;
2455 }
2456 catch (Exception e) {
2457 throw processException(e);
2458 }
2459 finally {
2460 closeSession(session);
2461 }
2462 }
2463
2464 @Override
2465 protected PollsQuestion removeImpl(PollsQuestion pollsQuestion)
2466 throws SystemException {
2467 pollsQuestion = toUnwrappedModel(pollsQuestion);
2468
2469 Session session = null;
2470
2471 try {
2472 session = openSession();
2473
2474 if (!session.contains(pollsQuestion)) {
2475 pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
2476 pollsQuestion.getPrimaryKeyObj());
2477 }
2478
2479 if (pollsQuestion != null) {
2480 session.delete(pollsQuestion);
2481 }
2482 }
2483 catch (Exception e) {
2484 throw processException(e);
2485 }
2486 finally {
2487 closeSession(session);
2488 }
2489
2490 if (pollsQuestion != null) {
2491 clearCache(pollsQuestion);
2492 }
2493
2494 return pollsQuestion;
2495 }
2496
2497 @Override
2498 public PollsQuestion updateImpl(
2499 com.liferay.portlet.polls.model.PollsQuestion pollsQuestion)
2500 throws SystemException {
2501 pollsQuestion = toUnwrappedModel(pollsQuestion);
2502
2503 boolean isNew = pollsQuestion.isNew();
2504
2505 PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
2506
2507 if (Validator.isNull(pollsQuestion.getUuid())) {
2508 String uuid = PortalUUIDUtil.generate();
2509
2510 pollsQuestion.setUuid(uuid);
2511 }
2512
2513 Session session = null;
2514
2515 try {
2516 session = openSession();
2517
2518 if (pollsQuestion.isNew()) {
2519 session.save(pollsQuestion);
2520
2521 pollsQuestion.setNew(false);
2522 }
2523 else {
2524 session.merge(pollsQuestion);
2525 }
2526 }
2527 catch (Exception e) {
2528 throw processException(e);
2529 }
2530 finally {
2531 closeSession(session);
2532 }
2533
2534 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2535
2536 if (isNew || !PollsQuestionModelImpl.COLUMN_BITMASK_ENABLED) {
2537 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2538 }
2539
2540 else {
2541 if ((pollsQuestionModelImpl.getColumnBitmask() &
2542 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2543 Object[] args = new Object[] {
2544 pollsQuestionModelImpl.getOriginalUuid()
2545 };
2546
2547 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2548 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2549 args);
2550
2551 args = new Object[] { pollsQuestionModelImpl.getUuid() };
2552
2553 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2554 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2555 args);
2556 }
2557
2558 if ((pollsQuestionModelImpl.getColumnBitmask() &
2559 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2560 Object[] args = new Object[] {
2561 pollsQuestionModelImpl.getOriginalUuid(),
2562 Long.valueOf(pollsQuestionModelImpl.getOriginalCompanyId())
2563 };
2564
2565 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2566 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2567 args);
2568
2569 args = new Object[] {
2570 pollsQuestionModelImpl.getUuid(),
2571 Long.valueOf(pollsQuestionModelImpl.getCompanyId())
2572 };
2573
2574 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2575 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2576 args);
2577 }
2578
2579 if ((pollsQuestionModelImpl.getColumnBitmask() &
2580 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2581 Object[] args = new Object[] {
2582 Long.valueOf(pollsQuestionModelImpl.getOriginalGroupId())
2583 };
2584
2585 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2586 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2587 args);
2588
2589 args = new Object[] {
2590 Long.valueOf(pollsQuestionModelImpl.getGroupId())
2591 };
2592
2593 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2594 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2595 args);
2596 }
2597 }
2598
2599 EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
2600 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
2601 pollsQuestion);
2602
2603 clearUniqueFindersCache(pollsQuestion);
2604 cacheUniqueFindersCache(pollsQuestion);
2605
2606 return pollsQuestion;
2607 }
2608
2609 protected PollsQuestion toUnwrappedModel(PollsQuestion pollsQuestion) {
2610 if (pollsQuestion instanceof PollsQuestionImpl) {
2611 return pollsQuestion;
2612 }
2613
2614 PollsQuestionImpl pollsQuestionImpl = new PollsQuestionImpl();
2615
2616 pollsQuestionImpl.setNew(pollsQuestion.isNew());
2617 pollsQuestionImpl.setPrimaryKey(pollsQuestion.getPrimaryKey());
2618
2619 pollsQuestionImpl.setUuid(pollsQuestion.getUuid());
2620 pollsQuestionImpl.setQuestionId(pollsQuestion.getQuestionId());
2621 pollsQuestionImpl.setGroupId(pollsQuestion.getGroupId());
2622 pollsQuestionImpl.setCompanyId(pollsQuestion.getCompanyId());
2623 pollsQuestionImpl.setUserId(pollsQuestion.getUserId());
2624 pollsQuestionImpl.setUserName(pollsQuestion.getUserName());
2625 pollsQuestionImpl.setCreateDate(pollsQuestion.getCreateDate());
2626 pollsQuestionImpl.setModifiedDate(pollsQuestion.getModifiedDate());
2627 pollsQuestionImpl.setTitle(pollsQuestion.getTitle());
2628 pollsQuestionImpl.setDescription(pollsQuestion.getDescription());
2629 pollsQuestionImpl.setExpirationDate(pollsQuestion.getExpirationDate());
2630 pollsQuestionImpl.setLastVoteDate(pollsQuestion.getLastVoteDate());
2631
2632 return pollsQuestionImpl;
2633 }
2634
2635
2643 @Override
2644 public PollsQuestion findByPrimaryKey(Serializable primaryKey)
2645 throws NoSuchModelException, SystemException {
2646 return findByPrimaryKey(((Long)primaryKey).longValue());
2647 }
2648
2649
2657 public PollsQuestion findByPrimaryKey(long questionId)
2658 throws NoSuchQuestionException, SystemException {
2659 PollsQuestion pollsQuestion = fetchByPrimaryKey(questionId);
2660
2661 if (pollsQuestion == null) {
2662 if (_log.isWarnEnabled()) {
2663 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + questionId);
2664 }
2665
2666 throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2667 questionId);
2668 }
2669
2670 return pollsQuestion;
2671 }
2672
2673
2680 @Override
2681 public PollsQuestion fetchByPrimaryKey(Serializable primaryKey)
2682 throws SystemException {
2683 return fetchByPrimaryKey(((Long)primaryKey).longValue());
2684 }
2685
2686
2693 public PollsQuestion fetchByPrimaryKey(long questionId)
2694 throws SystemException {
2695 PollsQuestion pollsQuestion = (PollsQuestion)EntityCacheUtil.getResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
2696 PollsQuestionImpl.class, questionId);
2697
2698 if (pollsQuestion == _nullPollsQuestion) {
2699 return null;
2700 }
2701
2702 if (pollsQuestion == null) {
2703 Session session = null;
2704
2705 try {
2706 session = openSession();
2707
2708 pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
2709 Long.valueOf(questionId));
2710
2711 if (pollsQuestion != null) {
2712 cacheResult(pollsQuestion);
2713 }
2714 else {
2715 EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
2716 PollsQuestionImpl.class, questionId, _nullPollsQuestion);
2717 }
2718 }
2719 catch (Exception e) {
2720 EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
2721 PollsQuestionImpl.class, questionId);
2722
2723 throw processException(e);
2724 }
2725 finally {
2726 closeSession(session);
2727 }
2728 }
2729
2730 return pollsQuestion;
2731 }
2732
2733
2739 public List<PollsQuestion> findAll() throws SystemException {
2740 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2741 }
2742
2743
2755 public List<PollsQuestion> findAll(int start, int end)
2756 throws SystemException {
2757 return findAll(start, end, null);
2758 }
2759
2760
2773 public List<PollsQuestion> findAll(int start, int end,
2774 OrderByComparator orderByComparator) throws SystemException {
2775 boolean pagination = true;
2776 FinderPath finderPath = null;
2777 Object[] finderArgs = null;
2778
2779 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2780 (orderByComparator == null)) {
2781 pagination = false;
2782 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2783 finderArgs = FINDER_ARGS_EMPTY;
2784 }
2785 else {
2786 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2787 finderArgs = new Object[] { start, end, orderByComparator };
2788 }
2789
2790 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
2791 finderArgs, this);
2792
2793 if (list == null) {
2794 StringBundler query = null;
2795 String sql = null;
2796
2797 if (orderByComparator != null) {
2798 query = new StringBundler(2 +
2799 (orderByComparator.getOrderByFields().length * 3));
2800
2801 query.append(_SQL_SELECT_POLLSQUESTION);
2802
2803 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2804 orderByComparator);
2805
2806 sql = query.toString();
2807 }
2808 else {
2809 sql = _SQL_SELECT_POLLSQUESTION;
2810
2811 if (pagination) {
2812 sql = sql.concat(PollsQuestionModelImpl.ORDER_BY_JPQL);
2813 }
2814 }
2815
2816 Session session = null;
2817
2818 try {
2819 session = openSession();
2820
2821 Query q = session.createQuery(sql);
2822
2823 if (!pagination) {
2824 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
2825 start, end, false);
2826
2827 Collections.sort(list);
2828
2829 list = new UnmodifiableList<PollsQuestion>(list);
2830 }
2831 else {
2832 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
2833 start, end);
2834 }
2835
2836 cacheResult(list);
2837
2838 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2839 }
2840 catch (Exception e) {
2841 FinderCacheUtil.removeResult(finderPath, finderArgs);
2842
2843 throw processException(e);
2844 }
2845 finally {
2846 closeSession(session);
2847 }
2848 }
2849
2850 return list;
2851 }
2852
2853
2858 public void removeAll() throws SystemException {
2859 for (PollsQuestion pollsQuestion : findAll()) {
2860 remove(pollsQuestion);
2861 }
2862 }
2863
2864
2870 public int countAll() throws SystemException {
2871 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2872 FINDER_ARGS_EMPTY, this);
2873
2874 if (count == null) {
2875 Session session = null;
2876
2877 try {
2878 session = openSession();
2879
2880 Query q = session.createQuery(_SQL_COUNT_POLLSQUESTION);
2881
2882 count = (Long)q.uniqueResult();
2883
2884 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2885 FINDER_ARGS_EMPTY, count);
2886 }
2887 catch (Exception e) {
2888 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2889 FINDER_ARGS_EMPTY);
2890
2891 throw processException(e);
2892 }
2893 finally {
2894 closeSession(session);
2895 }
2896 }
2897
2898 return count.intValue();
2899 }
2900
2901
2904 public void afterPropertiesSet() {
2905 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2906 com.liferay.portal.util.PropsUtil.get(
2907 "value.object.listener.com.liferay.portlet.polls.model.PollsQuestion")));
2908
2909 if (listenerClassNames.length > 0) {
2910 try {
2911 List<ModelListener<PollsQuestion>> listenersList = new ArrayList<ModelListener<PollsQuestion>>();
2912
2913 for (String listenerClassName : listenerClassNames) {
2914 listenersList.add((ModelListener<PollsQuestion>)InstanceFactory.newInstance(
2915 listenerClassName));
2916 }
2917
2918 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2919 }
2920 catch (Exception e) {
2921 _log.error(e);
2922 }
2923 }
2924 }
2925
2926 public void destroy() {
2927 EntityCacheUtil.removeCache(PollsQuestionImpl.class.getName());
2928 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2929 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2930 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2931 }
2932
2933 private static final String _SQL_SELECT_POLLSQUESTION = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion";
2934 private static final String _SQL_SELECT_POLLSQUESTION_WHERE = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion WHERE ";
2935 private static final String _SQL_COUNT_POLLSQUESTION = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion";
2936 private static final String _SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion WHERE ";
2937 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "pollsQuestion.questionId";
2938 private static final String _FILTER_SQL_SELECT_POLLSQUESTION_WHERE = "SELECT DISTINCT {pollsQuestion.*} FROM PollsQuestion pollsQuestion WHERE ";
2939 private static final String _FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1 =
2940 "SELECT {PollsQuestion.*} FROM (SELECT DISTINCT pollsQuestion.questionId FROM PollsQuestion pollsQuestion WHERE ";
2941 private static final String _FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2 =
2942 ") TEMP_TABLE INNER JOIN PollsQuestion ON TEMP_TABLE.questionId = PollsQuestion.questionId";
2943 private static final String _FILTER_SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(DISTINCT pollsQuestion.questionId) AS COUNT_VALUE FROM PollsQuestion pollsQuestion WHERE ";
2944 private static final String _FILTER_ENTITY_ALIAS = "pollsQuestion";
2945 private static final String _FILTER_ENTITY_TABLE = "PollsQuestion";
2946 private static final String _ORDER_BY_ENTITY_ALIAS = "pollsQuestion.";
2947 private static final String _ORDER_BY_ENTITY_TABLE = "PollsQuestion.";
2948 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsQuestion exists with the primary key ";
2949 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsQuestion exists with the key {";
2950 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2951 private static Log _log = LogFactoryUtil.getLog(PollsQuestionPersistenceImpl.class);
2952 private static PollsQuestion _nullPollsQuestion = new PollsQuestionImpl() {
2953 @Override
2954 public Object clone() {
2955 return this;
2956 }
2957
2958 @Override
2959 public CacheModel<PollsQuestion> toCacheModel() {
2960 return _nullPollsQuestionCacheModel;
2961 }
2962 };
2963
2964 private static CacheModel<PollsQuestion> _nullPollsQuestionCacheModel = new CacheModel<PollsQuestion>() {
2965 public PollsQuestion toEntityModel() {
2966 return _nullPollsQuestion;
2967 }
2968 };
2969 }