001
014
015 package com.liferay.portlet.polls.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.SQLQuery;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.SetUtil;
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 import java.util.Set;
055
056
068 public class PollsQuestionPersistenceImpl extends BasePersistenceImpl<PollsQuestion>
069 implements PollsQuestionPersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = PollsQuestionImpl.class.getName();
076 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List1";
078 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List2";
080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
081 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
082 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
083 "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
085 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
086 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
087 "findAll", new String[0]);
088 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
089 PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
092 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
093 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
094 "findByUuid",
095 new String[] {
096 String.class.getName(),
097
098 Integer.class.getName(), Integer.class.getName(),
099 OrderByComparator.class.getName()
100 });
101 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
102 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
103 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
104 "findByUuid", new String[] { String.class.getName() },
105 PollsQuestionModelImpl.UUID_COLUMN_BITMASK |
106 PollsQuestionModelImpl.CREATEDATE_COLUMN_BITMASK);
107 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
108 PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
109 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
110 new String[] { String.class.getName() });
111
112
119 @Override
120 public List<PollsQuestion> findByUuid(String uuid)
121 throws SystemException {
122 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
123 }
124
125
138 @Override
139 public List<PollsQuestion> findByUuid(String uuid, int start, int end)
140 throws SystemException {
141 return findByUuid(uuid, start, end, null);
142 }
143
144
158 @Override
159 public List<PollsQuestion> findByUuid(String uuid, int start, int end,
160 OrderByComparator orderByComparator) throws SystemException {
161 boolean pagination = true;
162 FinderPath finderPath = null;
163 Object[] finderArgs = null;
164
165 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
166 (orderByComparator == null)) {
167 pagination = false;
168 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
169 finderArgs = new Object[] { uuid };
170 }
171 else {
172 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
173 finderArgs = new Object[] { uuid, start, end, orderByComparator };
174 }
175
176 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
177 finderArgs, this);
178
179 if ((list != null) && !list.isEmpty()) {
180 for (PollsQuestion pollsQuestion : list) {
181 if (!Validator.equals(uuid, pollsQuestion.getUuid())) {
182 list = null;
183
184 break;
185 }
186 }
187 }
188
189 if (list == null) {
190 StringBundler query = null;
191
192 if (orderByComparator != null) {
193 query = new StringBundler(3 +
194 (orderByComparator.getOrderByFields().length * 3));
195 }
196 else {
197 query = new StringBundler(3);
198 }
199
200 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
201
202 boolean bindUuid = false;
203
204 if (uuid == null) {
205 query.append(_FINDER_COLUMN_UUID_UUID_1);
206 }
207 else if (uuid.equals(StringPool.BLANK)) {
208 query.append(_FINDER_COLUMN_UUID_UUID_3);
209 }
210 else {
211 bindUuid = true;
212
213 query.append(_FINDER_COLUMN_UUID_UUID_2);
214 }
215
216 if (orderByComparator != null) {
217 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
218 orderByComparator);
219 }
220 else
221 if (pagination) {
222 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
223 }
224
225 String sql = query.toString();
226
227 Session session = null;
228
229 try {
230 session = openSession();
231
232 Query q = session.createQuery(sql);
233
234 QueryPos qPos = QueryPos.getInstance(q);
235
236 if (bindUuid) {
237 qPos.add(uuid);
238 }
239
240 if (!pagination) {
241 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
242 start, end, false);
243
244 Collections.sort(list);
245
246 list = new UnmodifiableList<PollsQuestion>(list);
247 }
248 else {
249 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
250 start, end);
251 }
252
253 cacheResult(list);
254
255 FinderCacheUtil.putResult(finderPath, finderArgs, list);
256 }
257 catch (Exception e) {
258 FinderCacheUtil.removeResult(finderPath, finderArgs);
259
260 throw processException(e);
261 }
262 finally {
263 closeSession(session);
264 }
265 }
266
267 return list;
268 }
269
270
279 @Override
280 public PollsQuestion findByUuid_First(String uuid,
281 OrderByComparator orderByComparator)
282 throws NoSuchQuestionException, SystemException {
283 PollsQuestion pollsQuestion = fetchByUuid_First(uuid, orderByComparator);
284
285 if (pollsQuestion != null) {
286 return pollsQuestion;
287 }
288
289 StringBundler msg = new StringBundler(4);
290
291 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
292
293 msg.append("uuid=");
294 msg.append(uuid);
295
296 msg.append(StringPool.CLOSE_CURLY_BRACE);
297
298 throw new NoSuchQuestionException(msg.toString());
299 }
300
301
309 @Override
310 public PollsQuestion fetchByUuid_First(String uuid,
311 OrderByComparator orderByComparator) throws SystemException {
312 List<PollsQuestion> list = findByUuid(uuid, 0, 1, orderByComparator);
313
314 if (!list.isEmpty()) {
315 return list.get(0);
316 }
317
318 return null;
319 }
320
321
330 @Override
331 public PollsQuestion findByUuid_Last(String uuid,
332 OrderByComparator orderByComparator)
333 throws NoSuchQuestionException, SystemException {
334 PollsQuestion pollsQuestion = fetchByUuid_Last(uuid, orderByComparator);
335
336 if (pollsQuestion != null) {
337 return pollsQuestion;
338 }
339
340 StringBundler msg = new StringBundler(4);
341
342 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
343
344 msg.append("uuid=");
345 msg.append(uuid);
346
347 msg.append(StringPool.CLOSE_CURLY_BRACE);
348
349 throw new NoSuchQuestionException(msg.toString());
350 }
351
352
360 @Override
361 public PollsQuestion fetchByUuid_Last(String uuid,
362 OrderByComparator orderByComparator) throws SystemException {
363 int count = countByUuid(uuid);
364
365 if (count == 0) {
366 return null;
367 }
368
369 List<PollsQuestion> list = findByUuid(uuid, count - 1, count,
370 orderByComparator);
371
372 if (!list.isEmpty()) {
373 return list.get(0);
374 }
375
376 return null;
377 }
378
379
389 @Override
390 public PollsQuestion[] findByUuid_PrevAndNext(long questionId, String uuid,
391 OrderByComparator orderByComparator)
392 throws NoSuchQuestionException, SystemException {
393 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
394
395 Session session = null;
396
397 try {
398 session = openSession();
399
400 PollsQuestion[] array = new PollsQuestionImpl[3];
401
402 array[0] = getByUuid_PrevAndNext(session, pollsQuestion, uuid,
403 orderByComparator, true);
404
405 array[1] = pollsQuestion;
406
407 array[2] = getByUuid_PrevAndNext(session, pollsQuestion, uuid,
408 orderByComparator, false);
409
410 return array;
411 }
412 catch (Exception e) {
413 throw processException(e);
414 }
415 finally {
416 closeSession(session);
417 }
418 }
419
420 protected PollsQuestion getByUuid_PrevAndNext(Session session,
421 PollsQuestion pollsQuestion, String uuid,
422 OrderByComparator orderByComparator, boolean previous) {
423 StringBundler query = null;
424
425 if (orderByComparator != null) {
426 query = new StringBundler(6 +
427 (orderByComparator.getOrderByFields().length * 6));
428 }
429 else {
430 query = new StringBundler(3);
431 }
432
433 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
434
435 boolean bindUuid = false;
436
437 if (uuid == null) {
438 query.append(_FINDER_COLUMN_UUID_UUID_1);
439 }
440 else if (uuid.equals(StringPool.BLANK)) {
441 query.append(_FINDER_COLUMN_UUID_UUID_3);
442 }
443 else {
444 bindUuid = true;
445
446 query.append(_FINDER_COLUMN_UUID_UUID_2);
447 }
448
449 if (orderByComparator != null) {
450 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
451
452 if (orderByConditionFields.length > 0) {
453 query.append(WHERE_AND);
454 }
455
456 for (int i = 0; i < orderByConditionFields.length; i++) {
457 query.append(_ORDER_BY_ENTITY_ALIAS);
458 query.append(orderByConditionFields[i]);
459
460 if ((i + 1) < orderByConditionFields.length) {
461 if (orderByComparator.isAscending() ^ previous) {
462 query.append(WHERE_GREATER_THAN_HAS_NEXT);
463 }
464 else {
465 query.append(WHERE_LESSER_THAN_HAS_NEXT);
466 }
467 }
468 else {
469 if (orderByComparator.isAscending() ^ previous) {
470 query.append(WHERE_GREATER_THAN);
471 }
472 else {
473 query.append(WHERE_LESSER_THAN);
474 }
475 }
476 }
477
478 query.append(ORDER_BY_CLAUSE);
479
480 String[] orderByFields = orderByComparator.getOrderByFields();
481
482 for (int i = 0; i < orderByFields.length; i++) {
483 query.append(_ORDER_BY_ENTITY_ALIAS);
484 query.append(orderByFields[i]);
485
486 if ((i + 1) < orderByFields.length) {
487 if (orderByComparator.isAscending() ^ previous) {
488 query.append(ORDER_BY_ASC_HAS_NEXT);
489 }
490 else {
491 query.append(ORDER_BY_DESC_HAS_NEXT);
492 }
493 }
494 else {
495 if (orderByComparator.isAscending() ^ previous) {
496 query.append(ORDER_BY_ASC);
497 }
498 else {
499 query.append(ORDER_BY_DESC);
500 }
501 }
502 }
503 }
504 else {
505 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
506 }
507
508 String sql = query.toString();
509
510 Query q = session.createQuery(sql);
511
512 q.setFirstResult(0);
513 q.setMaxResults(2);
514
515 QueryPos qPos = QueryPos.getInstance(q);
516
517 if (bindUuid) {
518 qPos.add(uuid);
519 }
520
521 if (orderByComparator != null) {
522 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
523
524 for (Object value : values) {
525 qPos.add(value);
526 }
527 }
528
529 List<PollsQuestion> list = q.list();
530
531 if (list.size() == 2) {
532 return list.get(1);
533 }
534 else {
535 return null;
536 }
537 }
538
539
545 @Override
546 public void removeByUuid(String uuid) throws SystemException {
547 for (PollsQuestion pollsQuestion : findByUuid(uuid, QueryUtil.ALL_POS,
548 QueryUtil.ALL_POS, null)) {
549 remove(pollsQuestion);
550 }
551 }
552
553
560 @Override
561 public int countByUuid(String uuid) throws SystemException {
562 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
563
564 Object[] finderArgs = new Object[] { uuid };
565
566 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
567 this);
568
569 if (count == null) {
570 StringBundler query = new StringBundler(2);
571
572 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
573
574 boolean bindUuid = false;
575
576 if (uuid == null) {
577 query.append(_FINDER_COLUMN_UUID_UUID_1);
578 }
579 else if (uuid.equals(StringPool.BLANK)) {
580 query.append(_FINDER_COLUMN_UUID_UUID_3);
581 }
582 else {
583 bindUuid = true;
584
585 query.append(_FINDER_COLUMN_UUID_UUID_2);
586 }
587
588 String sql = query.toString();
589
590 Session session = null;
591
592 try {
593 session = openSession();
594
595 Query q = session.createQuery(sql);
596
597 QueryPos qPos = QueryPos.getInstance(q);
598
599 if (bindUuid) {
600 qPos.add(uuid);
601 }
602
603 count = (Long)q.uniqueResult();
604
605 FinderCacheUtil.putResult(finderPath, finderArgs, count);
606 }
607 catch (Exception e) {
608 FinderCacheUtil.removeResult(finderPath, finderArgs);
609
610 throw processException(e);
611 }
612 finally {
613 closeSession(session);
614 }
615 }
616
617 return count.intValue();
618 }
619
620 private static final String _FINDER_COLUMN_UUID_UUID_1 = "pollsQuestion.uuid IS NULL";
621 private static final String _FINDER_COLUMN_UUID_UUID_2 = "pollsQuestion.uuid = ?";
622 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = '')";
623 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
624 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
625 PollsQuestionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
626 new String[] { String.class.getName(), Long.class.getName() },
627 PollsQuestionModelImpl.UUID_COLUMN_BITMASK |
628 PollsQuestionModelImpl.GROUPID_COLUMN_BITMASK);
629 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
630 PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
631 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
632 new String[] { String.class.getName(), Long.class.getName() });
633
634
643 @Override
644 public PollsQuestion findByUUID_G(String uuid, long groupId)
645 throws NoSuchQuestionException, SystemException {
646 PollsQuestion pollsQuestion = fetchByUUID_G(uuid, groupId);
647
648 if (pollsQuestion == null) {
649 StringBundler msg = new StringBundler(6);
650
651 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
652
653 msg.append("uuid=");
654 msg.append(uuid);
655
656 msg.append(", groupId=");
657 msg.append(groupId);
658
659 msg.append(StringPool.CLOSE_CURLY_BRACE);
660
661 if (_log.isWarnEnabled()) {
662 _log.warn(msg.toString());
663 }
664
665 throw new NoSuchQuestionException(msg.toString());
666 }
667
668 return pollsQuestion;
669 }
670
671
679 @Override
680 public PollsQuestion fetchByUUID_G(String uuid, long groupId)
681 throws SystemException {
682 return fetchByUUID_G(uuid, groupId, true);
683 }
684
685
694 @Override
695 public PollsQuestion fetchByUUID_G(String uuid, long groupId,
696 boolean retrieveFromCache) throws SystemException {
697 Object[] finderArgs = new Object[] { uuid, groupId };
698
699 Object result = null;
700
701 if (retrieveFromCache) {
702 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
703 finderArgs, this);
704 }
705
706 if (result instanceof PollsQuestion) {
707 PollsQuestion pollsQuestion = (PollsQuestion)result;
708
709 if (!Validator.equals(uuid, pollsQuestion.getUuid()) ||
710 (groupId != pollsQuestion.getGroupId())) {
711 result = null;
712 }
713 }
714
715 if (result == null) {
716 StringBundler query = new StringBundler(4);
717
718 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
719
720 boolean bindUuid = false;
721
722 if (uuid == null) {
723 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
724 }
725 else if (uuid.equals(StringPool.BLANK)) {
726 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
727 }
728 else {
729 bindUuid = true;
730
731 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
732 }
733
734 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
735
736 String sql = query.toString();
737
738 Session session = null;
739
740 try {
741 session = openSession();
742
743 Query q = session.createQuery(sql);
744
745 QueryPos qPos = QueryPos.getInstance(q);
746
747 if (bindUuid) {
748 qPos.add(uuid);
749 }
750
751 qPos.add(groupId);
752
753 List<PollsQuestion> list = q.list();
754
755 if (list.isEmpty()) {
756 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
757 finderArgs, list);
758 }
759 else {
760 PollsQuestion pollsQuestion = list.get(0);
761
762 result = pollsQuestion;
763
764 cacheResult(pollsQuestion);
765
766 if ((pollsQuestion.getUuid() == null) ||
767 !pollsQuestion.getUuid().equals(uuid) ||
768 (pollsQuestion.getGroupId() != groupId)) {
769 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
770 finderArgs, pollsQuestion);
771 }
772 }
773 }
774 catch (Exception e) {
775 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
776 finderArgs);
777
778 throw processException(e);
779 }
780 finally {
781 closeSession(session);
782 }
783 }
784
785 if (result instanceof List<?>) {
786 return null;
787 }
788 else {
789 return (PollsQuestion)result;
790 }
791 }
792
793
801 @Override
802 public PollsQuestion removeByUUID_G(String uuid, long groupId)
803 throws NoSuchQuestionException, SystemException {
804 PollsQuestion pollsQuestion = findByUUID_G(uuid, groupId);
805
806 return remove(pollsQuestion);
807 }
808
809
817 @Override
818 public int countByUUID_G(String uuid, long groupId)
819 throws SystemException {
820 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
821
822 Object[] finderArgs = new Object[] { uuid, groupId };
823
824 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
825 this);
826
827 if (count == null) {
828 StringBundler query = new StringBundler(3);
829
830 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
831
832 boolean bindUuid = false;
833
834 if (uuid == null) {
835 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
836 }
837 else if (uuid.equals(StringPool.BLANK)) {
838 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
839 }
840 else {
841 bindUuid = true;
842
843 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
844 }
845
846 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
847
848 String sql = query.toString();
849
850 Session session = null;
851
852 try {
853 session = openSession();
854
855 Query q = session.createQuery(sql);
856
857 QueryPos qPos = QueryPos.getInstance(q);
858
859 if (bindUuid) {
860 qPos.add(uuid);
861 }
862
863 qPos.add(groupId);
864
865 count = (Long)q.uniqueResult();
866
867 FinderCacheUtil.putResult(finderPath, finderArgs, count);
868 }
869 catch (Exception e) {
870 FinderCacheUtil.removeResult(finderPath, finderArgs);
871
872 throw processException(e);
873 }
874 finally {
875 closeSession(session);
876 }
877 }
878
879 return count.intValue();
880 }
881
882 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "pollsQuestion.uuid IS NULL AND ";
883 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "pollsQuestion.uuid = ? AND ";
884 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = '') AND ";
885 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "pollsQuestion.groupId = ?";
886 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
887 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
888 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
889 "findByUuid_C",
890 new String[] {
891 String.class.getName(), Long.class.getName(),
892
893 Integer.class.getName(), Integer.class.getName(),
894 OrderByComparator.class.getName()
895 });
896 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
897 new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
898 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
899 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
900 "findByUuid_C",
901 new String[] { String.class.getName(), Long.class.getName() },
902 PollsQuestionModelImpl.UUID_COLUMN_BITMASK |
903 PollsQuestionModelImpl.COMPANYID_COLUMN_BITMASK |
904 PollsQuestionModelImpl.CREATEDATE_COLUMN_BITMASK);
905 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
906 PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
907 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
908 new String[] { String.class.getName(), Long.class.getName() });
909
910
918 @Override
919 public List<PollsQuestion> findByUuid_C(String uuid, long companyId)
920 throws SystemException {
921 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
922 QueryUtil.ALL_POS, null);
923 }
924
925
939 @Override
940 public List<PollsQuestion> findByUuid_C(String uuid, long companyId,
941 int start, int end) throws SystemException {
942 return findByUuid_C(uuid, companyId, start, end, null);
943 }
944
945
960 @Override
961 public List<PollsQuestion> findByUuid_C(String uuid, long companyId,
962 int start, int end, OrderByComparator orderByComparator)
963 throws SystemException {
964 boolean pagination = true;
965 FinderPath finderPath = null;
966 Object[] finderArgs = null;
967
968 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
969 (orderByComparator == null)) {
970 pagination = false;
971 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
972 finderArgs = new Object[] { uuid, companyId };
973 }
974 else {
975 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
976 finderArgs = new Object[] {
977 uuid, companyId,
978
979 start, end, orderByComparator
980 };
981 }
982
983 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
984 finderArgs, this);
985
986 if ((list != null) && !list.isEmpty()) {
987 for (PollsQuestion pollsQuestion : list) {
988 if (!Validator.equals(uuid, pollsQuestion.getUuid()) ||
989 (companyId != pollsQuestion.getCompanyId())) {
990 list = null;
991
992 break;
993 }
994 }
995 }
996
997 if (list == null) {
998 StringBundler query = null;
999
1000 if (orderByComparator != null) {
1001 query = new StringBundler(4 +
1002 (orderByComparator.getOrderByFields().length * 3));
1003 }
1004 else {
1005 query = new StringBundler(4);
1006 }
1007
1008 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1009
1010 boolean bindUuid = false;
1011
1012 if (uuid == null) {
1013 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1014 }
1015 else if (uuid.equals(StringPool.BLANK)) {
1016 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1017 }
1018 else {
1019 bindUuid = true;
1020
1021 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1022 }
1023
1024 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1025
1026 if (orderByComparator != null) {
1027 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1028 orderByComparator);
1029 }
1030 else
1031 if (pagination) {
1032 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1033 }
1034
1035 String sql = query.toString();
1036
1037 Session session = null;
1038
1039 try {
1040 session = openSession();
1041
1042 Query q = session.createQuery(sql);
1043
1044 QueryPos qPos = QueryPos.getInstance(q);
1045
1046 if (bindUuid) {
1047 qPos.add(uuid);
1048 }
1049
1050 qPos.add(companyId);
1051
1052 if (!pagination) {
1053 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1054 start, end, false);
1055
1056 Collections.sort(list);
1057
1058 list = new UnmodifiableList<PollsQuestion>(list);
1059 }
1060 else {
1061 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1062 start, end);
1063 }
1064
1065 cacheResult(list);
1066
1067 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1068 }
1069 catch (Exception e) {
1070 FinderCacheUtil.removeResult(finderPath, finderArgs);
1071
1072 throw processException(e);
1073 }
1074 finally {
1075 closeSession(session);
1076 }
1077 }
1078
1079 return list;
1080 }
1081
1082
1092 @Override
1093 public PollsQuestion findByUuid_C_First(String uuid, long companyId,
1094 OrderByComparator orderByComparator)
1095 throws NoSuchQuestionException, SystemException {
1096 PollsQuestion pollsQuestion = fetchByUuid_C_First(uuid, companyId,
1097 orderByComparator);
1098
1099 if (pollsQuestion != null) {
1100 return pollsQuestion;
1101 }
1102
1103 StringBundler msg = new StringBundler(6);
1104
1105 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1106
1107 msg.append("uuid=");
1108 msg.append(uuid);
1109
1110 msg.append(", companyId=");
1111 msg.append(companyId);
1112
1113 msg.append(StringPool.CLOSE_CURLY_BRACE);
1114
1115 throw new NoSuchQuestionException(msg.toString());
1116 }
1117
1118
1127 @Override
1128 public PollsQuestion fetchByUuid_C_First(String uuid, long companyId,
1129 OrderByComparator orderByComparator) throws SystemException {
1130 List<PollsQuestion> list = findByUuid_C(uuid, companyId, 0, 1,
1131 orderByComparator);
1132
1133 if (!list.isEmpty()) {
1134 return list.get(0);
1135 }
1136
1137 return null;
1138 }
1139
1140
1150 @Override
1151 public PollsQuestion findByUuid_C_Last(String uuid, long companyId,
1152 OrderByComparator orderByComparator)
1153 throws NoSuchQuestionException, SystemException {
1154 PollsQuestion pollsQuestion = fetchByUuid_C_Last(uuid, companyId,
1155 orderByComparator);
1156
1157 if (pollsQuestion != null) {
1158 return pollsQuestion;
1159 }
1160
1161 StringBundler msg = new StringBundler(6);
1162
1163 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1164
1165 msg.append("uuid=");
1166 msg.append(uuid);
1167
1168 msg.append(", companyId=");
1169 msg.append(companyId);
1170
1171 msg.append(StringPool.CLOSE_CURLY_BRACE);
1172
1173 throw new NoSuchQuestionException(msg.toString());
1174 }
1175
1176
1185 @Override
1186 public PollsQuestion fetchByUuid_C_Last(String uuid, long companyId,
1187 OrderByComparator orderByComparator) throws SystemException {
1188 int count = countByUuid_C(uuid, companyId);
1189
1190 if (count == 0) {
1191 return null;
1192 }
1193
1194 List<PollsQuestion> list = findByUuid_C(uuid, companyId, count - 1,
1195 count, orderByComparator);
1196
1197 if (!list.isEmpty()) {
1198 return list.get(0);
1199 }
1200
1201 return null;
1202 }
1203
1204
1215 @Override
1216 public PollsQuestion[] findByUuid_C_PrevAndNext(long questionId,
1217 String uuid, long companyId, OrderByComparator orderByComparator)
1218 throws NoSuchQuestionException, SystemException {
1219 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
1220
1221 Session session = null;
1222
1223 try {
1224 session = openSession();
1225
1226 PollsQuestion[] array = new PollsQuestionImpl[3];
1227
1228 array[0] = getByUuid_C_PrevAndNext(session, pollsQuestion, uuid,
1229 companyId, orderByComparator, true);
1230
1231 array[1] = pollsQuestion;
1232
1233 array[2] = getByUuid_C_PrevAndNext(session, pollsQuestion, uuid,
1234 companyId, orderByComparator, false);
1235
1236 return array;
1237 }
1238 catch (Exception e) {
1239 throw processException(e);
1240 }
1241 finally {
1242 closeSession(session);
1243 }
1244 }
1245
1246 protected PollsQuestion getByUuid_C_PrevAndNext(Session session,
1247 PollsQuestion pollsQuestion, String uuid, long companyId,
1248 OrderByComparator orderByComparator, boolean previous) {
1249 StringBundler query = null;
1250
1251 if (orderByComparator != null) {
1252 query = new StringBundler(6 +
1253 (orderByComparator.getOrderByFields().length * 6));
1254 }
1255 else {
1256 query = new StringBundler(3);
1257 }
1258
1259 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1260
1261 boolean bindUuid = false;
1262
1263 if (uuid == null) {
1264 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1265 }
1266 else if (uuid.equals(StringPool.BLANK)) {
1267 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1268 }
1269 else {
1270 bindUuid = true;
1271
1272 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1273 }
1274
1275 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1276
1277 if (orderByComparator != null) {
1278 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1279
1280 if (orderByConditionFields.length > 0) {
1281 query.append(WHERE_AND);
1282 }
1283
1284 for (int i = 0; i < orderByConditionFields.length; i++) {
1285 query.append(_ORDER_BY_ENTITY_ALIAS);
1286 query.append(orderByConditionFields[i]);
1287
1288 if ((i + 1) < orderByConditionFields.length) {
1289 if (orderByComparator.isAscending() ^ previous) {
1290 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1291 }
1292 else {
1293 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1294 }
1295 }
1296 else {
1297 if (orderByComparator.isAscending() ^ previous) {
1298 query.append(WHERE_GREATER_THAN);
1299 }
1300 else {
1301 query.append(WHERE_LESSER_THAN);
1302 }
1303 }
1304 }
1305
1306 query.append(ORDER_BY_CLAUSE);
1307
1308 String[] orderByFields = orderByComparator.getOrderByFields();
1309
1310 for (int i = 0; i < orderByFields.length; i++) {
1311 query.append(_ORDER_BY_ENTITY_ALIAS);
1312 query.append(orderByFields[i]);
1313
1314 if ((i + 1) < orderByFields.length) {
1315 if (orderByComparator.isAscending() ^ previous) {
1316 query.append(ORDER_BY_ASC_HAS_NEXT);
1317 }
1318 else {
1319 query.append(ORDER_BY_DESC_HAS_NEXT);
1320 }
1321 }
1322 else {
1323 if (orderByComparator.isAscending() ^ previous) {
1324 query.append(ORDER_BY_ASC);
1325 }
1326 else {
1327 query.append(ORDER_BY_DESC);
1328 }
1329 }
1330 }
1331 }
1332 else {
1333 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1334 }
1335
1336 String sql = query.toString();
1337
1338 Query q = session.createQuery(sql);
1339
1340 q.setFirstResult(0);
1341 q.setMaxResults(2);
1342
1343 QueryPos qPos = QueryPos.getInstance(q);
1344
1345 if (bindUuid) {
1346 qPos.add(uuid);
1347 }
1348
1349 qPos.add(companyId);
1350
1351 if (orderByComparator != null) {
1352 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
1353
1354 for (Object value : values) {
1355 qPos.add(value);
1356 }
1357 }
1358
1359 List<PollsQuestion> list = q.list();
1360
1361 if (list.size() == 2) {
1362 return list.get(1);
1363 }
1364 else {
1365 return null;
1366 }
1367 }
1368
1369
1376 @Override
1377 public void removeByUuid_C(String uuid, long companyId)
1378 throws SystemException {
1379 for (PollsQuestion pollsQuestion : findByUuid_C(uuid, companyId,
1380 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1381 remove(pollsQuestion);
1382 }
1383 }
1384
1385
1393 @Override
1394 public int countByUuid_C(String uuid, long companyId)
1395 throws SystemException {
1396 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1397
1398 Object[] finderArgs = new Object[] { uuid, companyId };
1399
1400 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1401 this);
1402
1403 if (count == null) {
1404 StringBundler query = new StringBundler(3);
1405
1406 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
1407
1408 boolean bindUuid = false;
1409
1410 if (uuid == null) {
1411 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1412 }
1413 else if (uuid.equals(StringPool.BLANK)) {
1414 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1415 }
1416 else {
1417 bindUuid = true;
1418
1419 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1420 }
1421
1422 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1423
1424 String sql = query.toString();
1425
1426 Session session = null;
1427
1428 try {
1429 session = openSession();
1430
1431 Query q = session.createQuery(sql);
1432
1433 QueryPos qPos = QueryPos.getInstance(q);
1434
1435 if (bindUuid) {
1436 qPos.add(uuid);
1437 }
1438
1439 qPos.add(companyId);
1440
1441 count = (Long)q.uniqueResult();
1442
1443 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1444 }
1445 catch (Exception e) {
1446 FinderCacheUtil.removeResult(finderPath, finderArgs);
1447
1448 throw processException(e);
1449 }
1450 finally {
1451 closeSession(session);
1452 }
1453 }
1454
1455 return count.intValue();
1456 }
1457
1458 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "pollsQuestion.uuid IS NULL AND ";
1459 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "pollsQuestion.uuid = ? AND ";
1460 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = '') AND ";
1461 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "pollsQuestion.companyId = ?";
1462 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
1463 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
1464 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1465 "findByGroupId",
1466 new String[] {
1467 Long.class.getName(),
1468
1469 Integer.class.getName(), Integer.class.getName(),
1470 OrderByComparator.class.getName()
1471 });
1472 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1473 new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
1474 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
1475 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1476 "findByGroupId", new String[] { Long.class.getName() },
1477 PollsQuestionModelImpl.GROUPID_COLUMN_BITMASK |
1478 PollsQuestionModelImpl.CREATEDATE_COLUMN_BITMASK);
1479 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
1480 PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1481 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1482 new String[] { Long.class.getName() });
1483
1484
1491 @Override
1492 public List<PollsQuestion> findByGroupId(long groupId)
1493 throws SystemException {
1494 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1495 }
1496
1497
1510 @Override
1511 public List<PollsQuestion> findByGroupId(long groupId, int start, int end)
1512 throws SystemException {
1513 return findByGroupId(groupId, start, end, null);
1514 }
1515
1516
1530 @Override
1531 public List<PollsQuestion> findByGroupId(long groupId, int start, int end,
1532 OrderByComparator orderByComparator) throws SystemException {
1533 boolean pagination = true;
1534 FinderPath finderPath = null;
1535 Object[] finderArgs = null;
1536
1537 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1538 (orderByComparator == null)) {
1539 pagination = false;
1540 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1541 finderArgs = new Object[] { groupId };
1542 }
1543 else {
1544 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1545 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1546 }
1547
1548 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
1549 finderArgs, this);
1550
1551 if ((list != null) && !list.isEmpty()) {
1552 for (PollsQuestion pollsQuestion : list) {
1553 if ((groupId != pollsQuestion.getGroupId())) {
1554 list = null;
1555
1556 break;
1557 }
1558 }
1559 }
1560
1561 if (list == null) {
1562 StringBundler query = null;
1563
1564 if (orderByComparator != null) {
1565 query = new StringBundler(3 +
1566 (orderByComparator.getOrderByFields().length * 3));
1567 }
1568 else {
1569 query = new StringBundler(3);
1570 }
1571
1572 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1573
1574 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1575
1576 if (orderByComparator != null) {
1577 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1578 orderByComparator);
1579 }
1580 else
1581 if (pagination) {
1582 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1583 }
1584
1585 String sql = query.toString();
1586
1587 Session session = null;
1588
1589 try {
1590 session = openSession();
1591
1592 Query q = session.createQuery(sql);
1593
1594 QueryPos qPos = QueryPos.getInstance(q);
1595
1596 qPos.add(groupId);
1597
1598 if (!pagination) {
1599 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1600 start, end, false);
1601
1602 Collections.sort(list);
1603
1604 list = new UnmodifiableList<PollsQuestion>(list);
1605 }
1606 else {
1607 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1608 start, end);
1609 }
1610
1611 cacheResult(list);
1612
1613 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1614 }
1615 catch (Exception e) {
1616 FinderCacheUtil.removeResult(finderPath, finderArgs);
1617
1618 throw processException(e);
1619 }
1620 finally {
1621 closeSession(session);
1622 }
1623 }
1624
1625 return list;
1626 }
1627
1628
1637 @Override
1638 public PollsQuestion findByGroupId_First(long groupId,
1639 OrderByComparator orderByComparator)
1640 throws NoSuchQuestionException, SystemException {
1641 PollsQuestion pollsQuestion = fetchByGroupId_First(groupId,
1642 orderByComparator);
1643
1644 if (pollsQuestion != null) {
1645 return pollsQuestion;
1646 }
1647
1648 StringBundler msg = new StringBundler(4);
1649
1650 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1651
1652 msg.append("groupId=");
1653 msg.append(groupId);
1654
1655 msg.append(StringPool.CLOSE_CURLY_BRACE);
1656
1657 throw new NoSuchQuestionException(msg.toString());
1658 }
1659
1660
1668 @Override
1669 public PollsQuestion fetchByGroupId_First(long groupId,
1670 OrderByComparator orderByComparator) throws SystemException {
1671 List<PollsQuestion> list = findByGroupId(groupId, 0, 1,
1672 orderByComparator);
1673
1674 if (!list.isEmpty()) {
1675 return list.get(0);
1676 }
1677
1678 return null;
1679 }
1680
1681
1690 @Override
1691 public PollsQuestion findByGroupId_Last(long groupId,
1692 OrderByComparator orderByComparator)
1693 throws NoSuchQuestionException, SystemException {
1694 PollsQuestion pollsQuestion = fetchByGroupId_Last(groupId,
1695 orderByComparator);
1696
1697 if (pollsQuestion != null) {
1698 return pollsQuestion;
1699 }
1700
1701 StringBundler msg = new StringBundler(4);
1702
1703 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1704
1705 msg.append("groupId=");
1706 msg.append(groupId);
1707
1708 msg.append(StringPool.CLOSE_CURLY_BRACE);
1709
1710 throw new NoSuchQuestionException(msg.toString());
1711 }
1712
1713
1721 @Override
1722 public PollsQuestion fetchByGroupId_Last(long groupId,
1723 OrderByComparator orderByComparator) throws SystemException {
1724 int count = countByGroupId(groupId);
1725
1726 if (count == 0) {
1727 return null;
1728 }
1729
1730 List<PollsQuestion> list = findByGroupId(groupId, count - 1, count,
1731 orderByComparator);
1732
1733 if (!list.isEmpty()) {
1734 return list.get(0);
1735 }
1736
1737 return null;
1738 }
1739
1740
1750 @Override
1751 public PollsQuestion[] findByGroupId_PrevAndNext(long questionId,
1752 long groupId, OrderByComparator orderByComparator)
1753 throws NoSuchQuestionException, SystemException {
1754 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
1755
1756 Session session = null;
1757
1758 try {
1759 session = openSession();
1760
1761 PollsQuestion[] array = new PollsQuestionImpl[3];
1762
1763 array[0] = getByGroupId_PrevAndNext(session, pollsQuestion,
1764 groupId, orderByComparator, true);
1765
1766 array[1] = pollsQuestion;
1767
1768 array[2] = getByGroupId_PrevAndNext(session, pollsQuestion,
1769 groupId, orderByComparator, false);
1770
1771 return array;
1772 }
1773 catch (Exception e) {
1774 throw processException(e);
1775 }
1776 finally {
1777 closeSession(session);
1778 }
1779 }
1780
1781 protected PollsQuestion getByGroupId_PrevAndNext(Session session,
1782 PollsQuestion pollsQuestion, long groupId,
1783 OrderByComparator orderByComparator, boolean previous) {
1784 StringBundler query = null;
1785
1786 if (orderByComparator != null) {
1787 query = new StringBundler(6 +
1788 (orderByComparator.getOrderByFields().length * 6));
1789 }
1790 else {
1791 query = new StringBundler(3);
1792 }
1793
1794 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1795
1796 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1797
1798 if (orderByComparator != null) {
1799 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1800
1801 if (orderByConditionFields.length > 0) {
1802 query.append(WHERE_AND);
1803 }
1804
1805 for (int i = 0; i < orderByConditionFields.length; i++) {
1806 query.append(_ORDER_BY_ENTITY_ALIAS);
1807 query.append(orderByConditionFields[i]);
1808
1809 if ((i + 1) < orderByConditionFields.length) {
1810 if (orderByComparator.isAscending() ^ previous) {
1811 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1812 }
1813 else {
1814 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1815 }
1816 }
1817 else {
1818 if (orderByComparator.isAscending() ^ previous) {
1819 query.append(WHERE_GREATER_THAN);
1820 }
1821 else {
1822 query.append(WHERE_LESSER_THAN);
1823 }
1824 }
1825 }
1826
1827 query.append(ORDER_BY_CLAUSE);
1828
1829 String[] orderByFields = orderByComparator.getOrderByFields();
1830
1831 for (int i = 0; i < orderByFields.length; i++) {
1832 query.append(_ORDER_BY_ENTITY_ALIAS);
1833 query.append(orderByFields[i]);
1834
1835 if ((i + 1) < orderByFields.length) {
1836 if (orderByComparator.isAscending() ^ previous) {
1837 query.append(ORDER_BY_ASC_HAS_NEXT);
1838 }
1839 else {
1840 query.append(ORDER_BY_DESC_HAS_NEXT);
1841 }
1842 }
1843 else {
1844 if (orderByComparator.isAscending() ^ previous) {
1845 query.append(ORDER_BY_ASC);
1846 }
1847 else {
1848 query.append(ORDER_BY_DESC);
1849 }
1850 }
1851 }
1852 }
1853 else {
1854 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1855 }
1856
1857 String sql = query.toString();
1858
1859 Query q = session.createQuery(sql);
1860
1861 q.setFirstResult(0);
1862 q.setMaxResults(2);
1863
1864 QueryPos qPos = QueryPos.getInstance(q);
1865
1866 qPos.add(groupId);
1867
1868 if (orderByComparator != null) {
1869 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
1870
1871 for (Object value : values) {
1872 qPos.add(value);
1873 }
1874 }
1875
1876 List<PollsQuestion> list = q.list();
1877
1878 if (list.size() == 2) {
1879 return list.get(1);
1880 }
1881 else {
1882 return null;
1883 }
1884 }
1885
1886
1893 @Override
1894 public List<PollsQuestion> filterFindByGroupId(long groupId)
1895 throws SystemException {
1896 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1897 QueryUtil.ALL_POS, null);
1898 }
1899
1900
1913 @Override
1914 public List<PollsQuestion> filterFindByGroupId(long groupId, int start,
1915 int end) throws SystemException {
1916 return filterFindByGroupId(groupId, start, end, null);
1917 }
1918
1919
1933 @Override
1934 public List<PollsQuestion> filterFindByGroupId(long groupId, int start,
1935 int end, OrderByComparator orderByComparator) throws SystemException {
1936 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1937 return findByGroupId(groupId, start, end, orderByComparator);
1938 }
1939
1940 StringBundler query = null;
1941
1942 if (orderByComparator != null) {
1943 query = new StringBundler(3 +
1944 (orderByComparator.getOrderByFields().length * 3));
1945 }
1946 else {
1947 query = new StringBundler(3);
1948 }
1949
1950 if (getDB().isSupportsInlineDistinct()) {
1951 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_WHERE);
1952 }
1953 else {
1954 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1);
1955 }
1956
1957 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1958
1959 if (!getDB().isSupportsInlineDistinct()) {
1960 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2);
1961 }
1962
1963 if (orderByComparator != null) {
1964 if (getDB().isSupportsInlineDistinct()) {
1965 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1966 orderByComparator, true);
1967 }
1968 else {
1969 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1970 orderByComparator, true);
1971 }
1972 }
1973 else {
1974 if (getDB().isSupportsInlineDistinct()) {
1975 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1976 }
1977 else {
1978 query.append(PollsQuestionModelImpl.ORDER_BY_SQL);
1979 }
1980 }
1981
1982 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1983 PollsQuestion.class.getName(),
1984 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1985
1986 Session session = null;
1987
1988 try {
1989 session = openSession();
1990
1991 SQLQuery q = session.createSQLQuery(sql);
1992
1993 if (getDB().isSupportsInlineDistinct()) {
1994 q.addEntity(_FILTER_ENTITY_ALIAS, PollsQuestionImpl.class);
1995 }
1996 else {
1997 q.addEntity(_FILTER_ENTITY_TABLE, PollsQuestionImpl.class);
1998 }
1999
2000 QueryPos qPos = QueryPos.getInstance(q);
2001
2002 qPos.add(groupId);
2003
2004 return (List<PollsQuestion>)QueryUtil.list(q, getDialect(), start,
2005 end);
2006 }
2007 catch (Exception e) {
2008 throw processException(e);
2009 }
2010 finally {
2011 closeSession(session);
2012 }
2013 }
2014
2015
2025 @Override
2026 public PollsQuestion[] filterFindByGroupId_PrevAndNext(long questionId,
2027 long groupId, OrderByComparator orderByComparator)
2028 throws NoSuchQuestionException, SystemException {
2029 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2030 return findByGroupId_PrevAndNext(questionId, groupId,
2031 orderByComparator);
2032 }
2033
2034 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
2035
2036 Session session = null;
2037
2038 try {
2039 session = openSession();
2040
2041 PollsQuestion[] array = new PollsQuestionImpl[3];
2042
2043 array[0] = filterGetByGroupId_PrevAndNext(session, pollsQuestion,
2044 groupId, orderByComparator, true);
2045
2046 array[1] = pollsQuestion;
2047
2048 array[2] = filterGetByGroupId_PrevAndNext(session, pollsQuestion,
2049 groupId, orderByComparator, false);
2050
2051 return array;
2052 }
2053 catch (Exception e) {
2054 throw processException(e);
2055 }
2056 finally {
2057 closeSession(session);
2058 }
2059 }
2060
2061 protected PollsQuestion filterGetByGroupId_PrevAndNext(Session session,
2062 PollsQuestion pollsQuestion, long groupId,
2063 OrderByComparator orderByComparator, boolean previous) {
2064 StringBundler query = null;
2065
2066 if (orderByComparator != null) {
2067 query = new StringBundler(6 +
2068 (orderByComparator.getOrderByFields().length * 6));
2069 }
2070 else {
2071 query = new StringBundler(3);
2072 }
2073
2074 if (getDB().isSupportsInlineDistinct()) {
2075 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_WHERE);
2076 }
2077 else {
2078 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1);
2079 }
2080
2081 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2082
2083 if (!getDB().isSupportsInlineDistinct()) {
2084 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2);
2085 }
2086
2087 if (orderByComparator != null) {
2088 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2089
2090 if (orderByConditionFields.length > 0) {
2091 query.append(WHERE_AND);
2092 }
2093
2094 for (int i = 0; i < orderByConditionFields.length; i++) {
2095 if (getDB().isSupportsInlineDistinct()) {
2096 query.append(_ORDER_BY_ENTITY_ALIAS);
2097 }
2098 else {
2099 query.append(_ORDER_BY_ENTITY_TABLE);
2100 }
2101
2102 query.append(orderByConditionFields[i]);
2103
2104 if ((i + 1) < orderByConditionFields.length) {
2105 if (orderByComparator.isAscending() ^ previous) {
2106 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2107 }
2108 else {
2109 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2110 }
2111 }
2112 else {
2113 if (orderByComparator.isAscending() ^ previous) {
2114 query.append(WHERE_GREATER_THAN);
2115 }
2116 else {
2117 query.append(WHERE_LESSER_THAN);
2118 }
2119 }
2120 }
2121
2122 query.append(ORDER_BY_CLAUSE);
2123
2124 String[] orderByFields = orderByComparator.getOrderByFields();
2125
2126 for (int i = 0; i < orderByFields.length; i++) {
2127 if (getDB().isSupportsInlineDistinct()) {
2128 query.append(_ORDER_BY_ENTITY_ALIAS);
2129 }
2130 else {
2131 query.append(_ORDER_BY_ENTITY_TABLE);
2132 }
2133
2134 query.append(orderByFields[i]);
2135
2136 if ((i + 1) < orderByFields.length) {
2137 if (orderByComparator.isAscending() ^ previous) {
2138 query.append(ORDER_BY_ASC_HAS_NEXT);
2139 }
2140 else {
2141 query.append(ORDER_BY_DESC_HAS_NEXT);
2142 }
2143 }
2144 else {
2145 if (orderByComparator.isAscending() ^ previous) {
2146 query.append(ORDER_BY_ASC);
2147 }
2148 else {
2149 query.append(ORDER_BY_DESC);
2150 }
2151 }
2152 }
2153 }
2154 else {
2155 if (getDB().isSupportsInlineDistinct()) {
2156 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
2157 }
2158 else {
2159 query.append(PollsQuestionModelImpl.ORDER_BY_SQL);
2160 }
2161 }
2162
2163 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2164 PollsQuestion.class.getName(),
2165 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2166
2167 SQLQuery q = session.createSQLQuery(sql);
2168
2169 q.setFirstResult(0);
2170 q.setMaxResults(2);
2171
2172 if (getDB().isSupportsInlineDistinct()) {
2173 q.addEntity(_FILTER_ENTITY_ALIAS, PollsQuestionImpl.class);
2174 }
2175 else {
2176 q.addEntity(_FILTER_ENTITY_TABLE, PollsQuestionImpl.class);
2177 }
2178
2179 QueryPos qPos = QueryPos.getInstance(q);
2180
2181 qPos.add(groupId);
2182
2183 if (orderByComparator != null) {
2184 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
2185
2186 for (Object value : values) {
2187 qPos.add(value);
2188 }
2189 }
2190
2191 List<PollsQuestion> list = q.list();
2192
2193 if (list.size() == 2) {
2194 return list.get(1);
2195 }
2196 else {
2197 return null;
2198 }
2199 }
2200
2201
2207 @Override
2208 public void removeByGroupId(long groupId) throws SystemException {
2209 for (PollsQuestion pollsQuestion : findByGroupId(groupId,
2210 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2211 remove(pollsQuestion);
2212 }
2213 }
2214
2215
2222 @Override
2223 public int countByGroupId(long groupId) throws SystemException {
2224 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2225
2226 Object[] finderArgs = new Object[] { groupId };
2227
2228 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2229 this);
2230
2231 if (count == null) {
2232 StringBundler query = new StringBundler(2);
2233
2234 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
2235
2236 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2237
2238 String sql = query.toString();
2239
2240 Session session = null;
2241
2242 try {
2243 session = openSession();
2244
2245 Query q = session.createQuery(sql);
2246
2247 QueryPos qPos = QueryPos.getInstance(q);
2248
2249 qPos.add(groupId);
2250
2251 count = (Long)q.uniqueResult();
2252
2253 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2254 }
2255 catch (Exception e) {
2256 FinderCacheUtil.removeResult(finderPath, finderArgs);
2257
2258 throw processException(e);
2259 }
2260 finally {
2261 closeSession(session);
2262 }
2263 }
2264
2265 return count.intValue();
2266 }
2267
2268
2275 @Override
2276 public int filterCountByGroupId(long groupId) throws SystemException {
2277 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2278 return countByGroupId(groupId);
2279 }
2280
2281 StringBundler query = new StringBundler(2);
2282
2283 query.append(_FILTER_SQL_COUNT_POLLSQUESTION_WHERE);
2284
2285 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2286
2287 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2288 PollsQuestion.class.getName(),
2289 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2290
2291 Session session = null;
2292
2293 try {
2294 session = openSession();
2295
2296 SQLQuery q = session.createSQLQuery(sql);
2297
2298 q.addScalar(COUNT_COLUMN_NAME,
2299 com.liferay.portal.kernel.dao.orm.Type.LONG);
2300
2301 QueryPos qPos = QueryPos.getInstance(q);
2302
2303 qPos.add(groupId);
2304
2305 Long count = (Long)q.uniqueResult();
2306
2307 return count.intValue();
2308 }
2309 catch (Exception e) {
2310 throw processException(e);
2311 }
2312 finally {
2313 closeSession(session);
2314 }
2315 }
2316
2317 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "pollsQuestion.groupId = ?";
2318
2319 public PollsQuestionPersistenceImpl() {
2320 setModelClass(PollsQuestion.class);
2321 }
2322
2323
2328 @Override
2329 public void cacheResult(PollsQuestion pollsQuestion) {
2330 EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
2331 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
2332 pollsQuestion);
2333
2334 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2335 new Object[] { pollsQuestion.getUuid(), pollsQuestion.getGroupId() },
2336 pollsQuestion);
2337
2338 pollsQuestion.resetOriginalValues();
2339 }
2340
2341
2346 @Override
2347 public void cacheResult(List<PollsQuestion> pollsQuestions) {
2348 for (PollsQuestion pollsQuestion : pollsQuestions) {
2349 if (EntityCacheUtil.getResult(
2350 PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
2351 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey()) == null) {
2352 cacheResult(pollsQuestion);
2353 }
2354 else {
2355 pollsQuestion.resetOriginalValues();
2356 }
2357 }
2358 }
2359
2360
2367 @Override
2368 public void clearCache() {
2369 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2370 CacheRegistryUtil.clear(PollsQuestionImpl.class.getName());
2371 }
2372
2373 EntityCacheUtil.clearCache(PollsQuestionImpl.class.getName());
2374
2375 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2376 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2377 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2378 }
2379
2380
2387 @Override
2388 public void clearCache(PollsQuestion pollsQuestion) {
2389 EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
2390 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey());
2391
2392 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2393 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2394
2395 clearUniqueFindersCache(pollsQuestion);
2396 }
2397
2398 @Override
2399 public void clearCache(List<PollsQuestion> pollsQuestions) {
2400 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2401 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2402
2403 for (PollsQuestion pollsQuestion : pollsQuestions) {
2404 EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
2405 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey());
2406
2407 clearUniqueFindersCache(pollsQuestion);
2408 }
2409 }
2410
2411 protected void cacheUniqueFindersCache(PollsQuestion pollsQuestion) {
2412 if (pollsQuestion.isNew()) {
2413 Object[] args = new Object[] {
2414 pollsQuestion.getUuid(), pollsQuestion.getGroupId()
2415 };
2416
2417 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2418 Long.valueOf(1));
2419 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2420 pollsQuestion);
2421 }
2422 else {
2423 PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
2424
2425 if ((pollsQuestionModelImpl.getColumnBitmask() &
2426 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2427 Object[] args = new Object[] {
2428 pollsQuestion.getUuid(), pollsQuestion.getGroupId()
2429 };
2430
2431 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2432 Long.valueOf(1));
2433 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2434 pollsQuestion);
2435 }
2436 }
2437 }
2438
2439 protected void clearUniqueFindersCache(PollsQuestion pollsQuestion) {
2440 PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
2441
2442 Object[] args = new Object[] {
2443 pollsQuestion.getUuid(), pollsQuestion.getGroupId()
2444 };
2445
2446 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2447 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2448
2449 if ((pollsQuestionModelImpl.getColumnBitmask() &
2450 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2451 args = new Object[] {
2452 pollsQuestionModelImpl.getOriginalUuid(),
2453 pollsQuestionModelImpl.getOriginalGroupId()
2454 };
2455
2456 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2457 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2458 }
2459 }
2460
2461
2467 @Override
2468 public PollsQuestion create(long questionId) {
2469 PollsQuestion pollsQuestion = new PollsQuestionImpl();
2470
2471 pollsQuestion.setNew(true);
2472 pollsQuestion.setPrimaryKey(questionId);
2473
2474 String uuid = PortalUUIDUtil.generate();
2475
2476 pollsQuestion.setUuid(uuid);
2477
2478 return pollsQuestion;
2479 }
2480
2481
2489 @Override
2490 public PollsQuestion remove(long questionId)
2491 throws NoSuchQuestionException, SystemException {
2492 return remove((Serializable)questionId);
2493 }
2494
2495
2503 @Override
2504 public PollsQuestion remove(Serializable primaryKey)
2505 throws NoSuchQuestionException, SystemException {
2506 Session session = null;
2507
2508 try {
2509 session = openSession();
2510
2511 PollsQuestion pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
2512 primaryKey);
2513
2514 if (pollsQuestion == null) {
2515 if (_log.isWarnEnabled()) {
2516 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2517 }
2518
2519 throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2520 primaryKey);
2521 }
2522
2523 return remove(pollsQuestion);
2524 }
2525 catch (NoSuchQuestionException nsee) {
2526 throw nsee;
2527 }
2528 catch (Exception e) {
2529 throw processException(e);
2530 }
2531 finally {
2532 closeSession(session);
2533 }
2534 }
2535
2536 @Override
2537 protected PollsQuestion removeImpl(PollsQuestion pollsQuestion)
2538 throws SystemException {
2539 pollsQuestion = toUnwrappedModel(pollsQuestion);
2540
2541 Session session = null;
2542
2543 try {
2544 session = openSession();
2545
2546 if (!session.contains(pollsQuestion)) {
2547 pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
2548 pollsQuestion.getPrimaryKeyObj());
2549 }
2550
2551 if (pollsQuestion != null) {
2552 session.delete(pollsQuestion);
2553 }
2554 }
2555 catch (Exception e) {
2556 throw processException(e);
2557 }
2558 finally {
2559 closeSession(session);
2560 }
2561
2562 if (pollsQuestion != null) {
2563 clearCache(pollsQuestion);
2564 }
2565
2566 return pollsQuestion;
2567 }
2568
2569 @Override
2570 public PollsQuestion updateImpl(
2571 com.liferay.portlet.polls.model.PollsQuestion pollsQuestion)
2572 throws SystemException {
2573 pollsQuestion = toUnwrappedModel(pollsQuestion);
2574
2575 boolean isNew = pollsQuestion.isNew();
2576
2577 PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
2578
2579 if (Validator.isNull(pollsQuestion.getUuid())) {
2580 String uuid = PortalUUIDUtil.generate();
2581
2582 pollsQuestion.setUuid(uuid);
2583 }
2584
2585 Session session = null;
2586
2587 try {
2588 session = openSession();
2589
2590 if (pollsQuestion.isNew()) {
2591 session.save(pollsQuestion);
2592
2593 pollsQuestion.setNew(false);
2594 }
2595 else {
2596 session.merge(pollsQuestion);
2597 }
2598 }
2599 catch (Exception e) {
2600 throw processException(e);
2601 }
2602 finally {
2603 closeSession(session);
2604 }
2605
2606 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2607
2608 if (isNew || !PollsQuestionModelImpl.COLUMN_BITMASK_ENABLED) {
2609 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2610 }
2611
2612 else {
2613 if ((pollsQuestionModelImpl.getColumnBitmask() &
2614 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2615 Object[] args = new Object[] {
2616 pollsQuestionModelImpl.getOriginalUuid()
2617 };
2618
2619 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2620 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2621 args);
2622
2623 args = new Object[] { pollsQuestionModelImpl.getUuid() };
2624
2625 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2626 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2627 args);
2628 }
2629
2630 if ((pollsQuestionModelImpl.getColumnBitmask() &
2631 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2632 Object[] args = new Object[] {
2633 pollsQuestionModelImpl.getOriginalUuid(),
2634 pollsQuestionModelImpl.getOriginalCompanyId()
2635 };
2636
2637 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2638 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2639 args);
2640
2641 args = new Object[] {
2642 pollsQuestionModelImpl.getUuid(),
2643 pollsQuestionModelImpl.getCompanyId()
2644 };
2645
2646 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2647 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2648 args);
2649 }
2650
2651 if ((pollsQuestionModelImpl.getColumnBitmask() &
2652 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2653 Object[] args = new Object[] {
2654 pollsQuestionModelImpl.getOriginalGroupId()
2655 };
2656
2657 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2658 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2659 args);
2660
2661 args = new Object[] { pollsQuestionModelImpl.getGroupId() };
2662
2663 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2664 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2665 args);
2666 }
2667 }
2668
2669 EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
2670 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
2671 pollsQuestion);
2672
2673 clearUniqueFindersCache(pollsQuestion);
2674 cacheUniqueFindersCache(pollsQuestion);
2675
2676 return pollsQuestion;
2677 }
2678
2679 protected PollsQuestion toUnwrappedModel(PollsQuestion pollsQuestion) {
2680 if (pollsQuestion instanceof PollsQuestionImpl) {
2681 return pollsQuestion;
2682 }
2683
2684 PollsQuestionImpl pollsQuestionImpl = new PollsQuestionImpl();
2685
2686 pollsQuestionImpl.setNew(pollsQuestion.isNew());
2687 pollsQuestionImpl.setPrimaryKey(pollsQuestion.getPrimaryKey());
2688
2689 pollsQuestionImpl.setUuid(pollsQuestion.getUuid());
2690 pollsQuestionImpl.setQuestionId(pollsQuestion.getQuestionId());
2691 pollsQuestionImpl.setGroupId(pollsQuestion.getGroupId());
2692 pollsQuestionImpl.setCompanyId(pollsQuestion.getCompanyId());
2693 pollsQuestionImpl.setUserId(pollsQuestion.getUserId());
2694 pollsQuestionImpl.setUserName(pollsQuestion.getUserName());
2695 pollsQuestionImpl.setCreateDate(pollsQuestion.getCreateDate());
2696 pollsQuestionImpl.setModifiedDate(pollsQuestion.getModifiedDate());
2697 pollsQuestionImpl.setTitle(pollsQuestion.getTitle());
2698 pollsQuestionImpl.setDescription(pollsQuestion.getDescription());
2699 pollsQuestionImpl.setExpirationDate(pollsQuestion.getExpirationDate());
2700 pollsQuestionImpl.setLastVoteDate(pollsQuestion.getLastVoteDate());
2701
2702 return pollsQuestionImpl;
2703 }
2704
2705
2713 @Override
2714 public PollsQuestion findByPrimaryKey(Serializable primaryKey)
2715 throws NoSuchQuestionException, SystemException {
2716 PollsQuestion pollsQuestion = fetchByPrimaryKey(primaryKey);
2717
2718 if (pollsQuestion == null) {
2719 if (_log.isWarnEnabled()) {
2720 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2721 }
2722
2723 throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2724 primaryKey);
2725 }
2726
2727 return pollsQuestion;
2728 }
2729
2730
2738 @Override
2739 public PollsQuestion findByPrimaryKey(long questionId)
2740 throws NoSuchQuestionException, SystemException {
2741 return findByPrimaryKey((Serializable)questionId);
2742 }
2743
2744
2751 @Override
2752 public PollsQuestion fetchByPrimaryKey(Serializable primaryKey)
2753 throws SystemException {
2754 PollsQuestion pollsQuestion = (PollsQuestion)EntityCacheUtil.getResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
2755 PollsQuestionImpl.class, primaryKey);
2756
2757 if (pollsQuestion == _nullPollsQuestion) {
2758 return null;
2759 }
2760
2761 if (pollsQuestion == null) {
2762 Session session = null;
2763
2764 try {
2765 session = openSession();
2766
2767 pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
2768 primaryKey);
2769
2770 if (pollsQuestion != null) {
2771 cacheResult(pollsQuestion);
2772 }
2773 else {
2774 EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
2775 PollsQuestionImpl.class, primaryKey, _nullPollsQuestion);
2776 }
2777 }
2778 catch (Exception e) {
2779 EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
2780 PollsQuestionImpl.class, primaryKey);
2781
2782 throw processException(e);
2783 }
2784 finally {
2785 closeSession(session);
2786 }
2787 }
2788
2789 return pollsQuestion;
2790 }
2791
2792
2799 @Override
2800 public PollsQuestion fetchByPrimaryKey(long questionId)
2801 throws SystemException {
2802 return fetchByPrimaryKey((Serializable)questionId);
2803 }
2804
2805
2811 @Override
2812 public List<PollsQuestion> findAll() throws SystemException {
2813 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2814 }
2815
2816
2828 @Override
2829 public List<PollsQuestion> findAll(int start, int end)
2830 throws SystemException {
2831 return findAll(start, end, null);
2832 }
2833
2834
2847 @Override
2848 public List<PollsQuestion> findAll(int start, int end,
2849 OrderByComparator orderByComparator) throws SystemException {
2850 boolean pagination = true;
2851 FinderPath finderPath = null;
2852 Object[] finderArgs = null;
2853
2854 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2855 (orderByComparator == null)) {
2856 pagination = false;
2857 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2858 finderArgs = FINDER_ARGS_EMPTY;
2859 }
2860 else {
2861 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2862 finderArgs = new Object[] { start, end, orderByComparator };
2863 }
2864
2865 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
2866 finderArgs, this);
2867
2868 if (list == null) {
2869 StringBundler query = null;
2870 String sql = null;
2871
2872 if (orderByComparator != null) {
2873 query = new StringBundler(2 +
2874 (orderByComparator.getOrderByFields().length * 3));
2875
2876 query.append(_SQL_SELECT_POLLSQUESTION);
2877
2878 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2879 orderByComparator);
2880
2881 sql = query.toString();
2882 }
2883 else {
2884 sql = _SQL_SELECT_POLLSQUESTION;
2885
2886 if (pagination) {
2887 sql = sql.concat(PollsQuestionModelImpl.ORDER_BY_JPQL);
2888 }
2889 }
2890
2891 Session session = null;
2892
2893 try {
2894 session = openSession();
2895
2896 Query q = session.createQuery(sql);
2897
2898 if (!pagination) {
2899 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
2900 start, end, false);
2901
2902 Collections.sort(list);
2903
2904 list = new UnmodifiableList<PollsQuestion>(list);
2905 }
2906 else {
2907 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
2908 start, end);
2909 }
2910
2911 cacheResult(list);
2912
2913 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2914 }
2915 catch (Exception e) {
2916 FinderCacheUtil.removeResult(finderPath, finderArgs);
2917
2918 throw processException(e);
2919 }
2920 finally {
2921 closeSession(session);
2922 }
2923 }
2924
2925 return list;
2926 }
2927
2928
2933 @Override
2934 public void removeAll() throws SystemException {
2935 for (PollsQuestion pollsQuestion : findAll()) {
2936 remove(pollsQuestion);
2937 }
2938 }
2939
2940
2946 @Override
2947 public int countAll() throws SystemException {
2948 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2949 FINDER_ARGS_EMPTY, this);
2950
2951 if (count == null) {
2952 Session session = null;
2953
2954 try {
2955 session = openSession();
2956
2957 Query q = session.createQuery(_SQL_COUNT_POLLSQUESTION);
2958
2959 count = (Long)q.uniqueResult();
2960
2961 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2962 FINDER_ARGS_EMPTY, count);
2963 }
2964 catch (Exception e) {
2965 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2966 FINDER_ARGS_EMPTY);
2967
2968 throw processException(e);
2969 }
2970 finally {
2971 closeSession(session);
2972 }
2973 }
2974
2975 return count.intValue();
2976 }
2977
2978 @Override
2979 protected Set<String> getBadColumnNames() {
2980 return _badColumnNames;
2981 }
2982
2983
2986 public void afterPropertiesSet() {
2987 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2988 com.liferay.portal.util.PropsUtil.get(
2989 "value.object.listener.com.liferay.portlet.polls.model.PollsQuestion")));
2990
2991 if (listenerClassNames.length > 0) {
2992 try {
2993 List<ModelListener<PollsQuestion>> listenersList = new ArrayList<ModelListener<PollsQuestion>>();
2994
2995 for (String listenerClassName : listenerClassNames) {
2996 listenersList.add((ModelListener<PollsQuestion>)InstanceFactory.newInstance(
2997 getClassLoader(), listenerClassName));
2998 }
2999
3000 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3001 }
3002 catch (Exception e) {
3003 _log.error(e);
3004 }
3005 }
3006 }
3007
3008 public void destroy() {
3009 EntityCacheUtil.removeCache(PollsQuestionImpl.class.getName());
3010 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3011 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3012 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3013 }
3014
3015 private static final String _SQL_SELECT_POLLSQUESTION = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion";
3016 private static final String _SQL_SELECT_POLLSQUESTION_WHERE = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion WHERE ";
3017 private static final String _SQL_COUNT_POLLSQUESTION = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion";
3018 private static final String _SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion WHERE ";
3019 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "pollsQuestion.questionId";
3020 private static final String _FILTER_SQL_SELECT_POLLSQUESTION_WHERE = "SELECT DISTINCT {pollsQuestion.*} FROM PollsQuestion pollsQuestion WHERE ";
3021 private static final String _FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1 =
3022 "SELECT {PollsQuestion.*} FROM (SELECT DISTINCT pollsQuestion.questionId FROM PollsQuestion pollsQuestion WHERE ";
3023 private static final String _FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2 =
3024 ") TEMP_TABLE INNER JOIN PollsQuestion ON TEMP_TABLE.questionId = PollsQuestion.questionId";
3025 private static final String _FILTER_SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(DISTINCT pollsQuestion.questionId) AS COUNT_VALUE FROM PollsQuestion pollsQuestion WHERE ";
3026 private static final String _FILTER_ENTITY_ALIAS = "pollsQuestion";
3027 private static final String _FILTER_ENTITY_TABLE = "PollsQuestion";
3028 private static final String _ORDER_BY_ENTITY_ALIAS = "pollsQuestion.";
3029 private static final String _ORDER_BY_ENTITY_TABLE = "PollsQuestion.";
3030 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsQuestion exists with the primary key ";
3031 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsQuestion exists with the key {";
3032 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3033 private static Log _log = LogFactoryUtil.getLog(PollsQuestionPersistenceImpl.class);
3034 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3035 "uuid"
3036 });
3037 private static PollsQuestion _nullPollsQuestion = new PollsQuestionImpl() {
3038 @Override
3039 public Object clone() {
3040 return this;
3041 }
3042
3043 @Override
3044 public CacheModel<PollsQuestion> toCacheModel() {
3045 return _nullPollsQuestionCacheModel;
3046 }
3047 };
3048
3049 private static CacheModel<PollsQuestion> _nullPollsQuestionCacheModel = new CacheModel<PollsQuestion>() {
3050 @Override
3051 public PollsQuestion toEntityModel() {
3052 return _nullPollsQuestion;
3053 }
3054 };
3055 }