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.Session;
025 import com.liferay.portal.kernel.exception.SystemException;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.GetterUtil;
029 import com.liferay.portal.kernel.util.InstanceFactory;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.SetUtil;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041
042 import com.liferay.portlet.polls.NoSuchChoiceException;
043 import com.liferay.portlet.polls.model.PollsChoice;
044 import com.liferay.portlet.polls.model.impl.PollsChoiceImpl;
045 import com.liferay.portlet.polls.model.impl.PollsChoiceModelImpl;
046
047 import java.io.Serializable;
048
049 import java.util.ArrayList;
050 import java.util.Collections;
051 import java.util.List;
052 import java.util.Set;
053
054
066 public class PollsChoicePersistenceImpl extends BasePersistenceImpl<PollsChoice>
067 implements PollsChoicePersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = PollsChoiceImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
079 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
080 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
082 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
085 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
088 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
090 new String[] {
091 String.class.getName(),
092
093 Integer.class.getName(), Integer.class.getName(),
094 OrderByComparator.class.getName()
095 });
096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
097 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
099 new String[] { String.class.getName() },
100 PollsChoiceModelImpl.UUID_COLUMN_BITMASK |
101 PollsChoiceModelImpl.QUESTIONID_COLUMN_BITMASK |
102 PollsChoiceModelImpl.NAME_COLUMN_BITMASK);
103 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
104 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
106 new String[] { String.class.getName() });
107
108
115 @Override
116 public List<PollsChoice> findByUuid(String uuid) throws SystemException {
117 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118 }
119
120
133 @Override
134 public List<PollsChoice> findByUuid(String uuid, int start, int end)
135 throws SystemException {
136 return findByUuid(uuid, start, end, null);
137 }
138
139
153 @Override
154 public List<PollsChoice> findByUuid(String uuid, int start, int end,
155 OrderByComparator orderByComparator) throws SystemException {
156 boolean pagination = true;
157 FinderPath finderPath = null;
158 Object[] finderArgs = null;
159
160 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
161 (orderByComparator == null)) {
162 pagination = false;
163 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
164 finderArgs = new Object[] { uuid };
165 }
166 else {
167 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
168 finderArgs = new Object[] { uuid, start, end, orderByComparator };
169 }
170
171 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
172 finderArgs, this);
173
174 if ((list != null) && !list.isEmpty()) {
175 for (PollsChoice pollsChoice : list) {
176 if (!Validator.equals(uuid, pollsChoice.getUuid())) {
177 list = null;
178
179 break;
180 }
181 }
182 }
183
184 if (list == null) {
185 StringBundler query = null;
186
187 if (orderByComparator != null) {
188 query = new StringBundler(3 +
189 (orderByComparator.getOrderByFields().length * 3));
190 }
191 else {
192 query = new StringBundler(3);
193 }
194
195 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
196
197 boolean bindUuid = false;
198
199 if (uuid == null) {
200 query.append(_FINDER_COLUMN_UUID_UUID_1);
201 }
202 else if (uuid.equals(StringPool.BLANK)) {
203 query.append(_FINDER_COLUMN_UUID_UUID_3);
204 }
205 else {
206 bindUuid = true;
207
208 query.append(_FINDER_COLUMN_UUID_UUID_2);
209 }
210
211 if (orderByComparator != null) {
212 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
213 orderByComparator);
214 }
215 else
216 if (pagination) {
217 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
218 }
219
220 String sql = query.toString();
221
222 Session session = null;
223
224 try {
225 session = openSession();
226
227 Query q = session.createQuery(sql);
228
229 QueryPos qPos = QueryPos.getInstance(q);
230
231 if (bindUuid) {
232 qPos.add(uuid);
233 }
234
235 if (!pagination) {
236 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
237 start, end, false);
238
239 Collections.sort(list);
240
241 list = new UnmodifiableList<PollsChoice>(list);
242 }
243 else {
244 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
245 start, end);
246 }
247
248 cacheResult(list);
249
250 FinderCacheUtil.putResult(finderPath, finderArgs, list);
251 }
252 catch (Exception e) {
253 FinderCacheUtil.removeResult(finderPath, finderArgs);
254
255 throw processException(e);
256 }
257 finally {
258 closeSession(session);
259 }
260 }
261
262 return list;
263 }
264
265
274 @Override
275 public PollsChoice findByUuid_First(String uuid,
276 OrderByComparator orderByComparator)
277 throws NoSuchChoiceException, SystemException {
278 PollsChoice pollsChoice = fetchByUuid_First(uuid, orderByComparator);
279
280 if (pollsChoice != null) {
281 return pollsChoice;
282 }
283
284 StringBundler msg = new StringBundler(4);
285
286 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
287
288 msg.append("uuid=");
289 msg.append(uuid);
290
291 msg.append(StringPool.CLOSE_CURLY_BRACE);
292
293 throw new NoSuchChoiceException(msg.toString());
294 }
295
296
304 @Override
305 public PollsChoice fetchByUuid_First(String uuid,
306 OrderByComparator orderByComparator) throws SystemException {
307 List<PollsChoice> list = findByUuid(uuid, 0, 1, orderByComparator);
308
309 if (!list.isEmpty()) {
310 return list.get(0);
311 }
312
313 return null;
314 }
315
316
325 @Override
326 public PollsChoice findByUuid_Last(String uuid,
327 OrderByComparator orderByComparator)
328 throws NoSuchChoiceException, SystemException {
329 PollsChoice pollsChoice = fetchByUuid_Last(uuid, orderByComparator);
330
331 if (pollsChoice != null) {
332 return pollsChoice;
333 }
334
335 StringBundler msg = new StringBundler(4);
336
337 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
338
339 msg.append("uuid=");
340 msg.append(uuid);
341
342 msg.append(StringPool.CLOSE_CURLY_BRACE);
343
344 throw new NoSuchChoiceException(msg.toString());
345 }
346
347
355 @Override
356 public PollsChoice fetchByUuid_Last(String uuid,
357 OrderByComparator orderByComparator) throws SystemException {
358 int count = countByUuid(uuid);
359
360 if (count == 0) {
361 return null;
362 }
363
364 List<PollsChoice> list = findByUuid(uuid, count - 1, count,
365 orderByComparator);
366
367 if (!list.isEmpty()) {
368 return list.get(0);
369 }
370
371 return null;
372 }
373
374
384 @Override
385 public PollsChoice[] findByUuid_PrevAndNext(long choiceId, String uuid,
386 OrderByComparator orderByComparator)
387 throws NoSuchChoiceException, SystemException {
388 PollsChoice pollsChoice = findByPrimaryKey(choiceId);
389
390 Session session = null;
391
392 try {
393 session = openSession();
394
395 PollsChoice[] array = new PollsChoiceImpl[3];
396
397 array[0] = getByUuid_PrevAndNext(session, pollsChoice, uuid,
398 orderByComparator, true);
399
400 array[1] = pollsChoice;
401
402 array[2] = getByUuid_PrevAndNext(session, pollsChoice, uuid,
403 orderByComparator, false);
404
405 return array;
406 }
407 catch (Exception e) {
408 throw processException(e);
409 }
410 finally {
411 closeSession(session);
412 }
413 }
414
415 protected PollsChoice getByUuid_PrevAndNext(Session session,
416 PollsChoice pollsChoice, String uuid,
417 OrderByComparator orderByComparator, boolean previous) {
418 StringBundler query = null;
419
420 if (orderByComparator != null) {
421 query = new StringBundler(6 +
422 (orderByComparator.getOrderByFields().length * 6));
423 }
424 else {
425 query = new StringBundler(3);
426 }
427
428 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
429
430 boolean bindUuid = false;
431
432 if (uuid == null) {
433 query.append(_FINDER_COLUMN_UUID_UUID_1);
434 }
435 else if (uuid.equals(StringPool.BLANK)) {
436 query.append(_FINDER_COLUMN_UUID_UUID_3);
437 }
438 else {
439 bindUuid = true;
440
441 query.append(_FINDER_COLUMN_UUID_UUID_2);
442 }
443
444 if (orderByComparator != null) {
445 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
446
447 if (orderByConditionFields.length > 0) {
448 query.append(WHERE_AND);
449 }
450
451 for (int i = 0; i < orderByConditionFields.length; i++) {
452 query.append(_ORDER_BY_ENTITY_ALIAS);
453 query.append(orderByConditionFields[i]);
454
455 if ((i + 1) < orderByConditionFields.length) {
456 if (orderByComparator.isAscending() ^ previous) {
457 query.append(WHERE_GREATER_THAN_HAS_NEXT);
458 }
459 else {
460 query.append(WHERE_LESSER_THAN_HAS_NEXT);
461 }
462 }
463 else {
464 if (orderByComparator.isAscending() ^ previous) {
465 query.append(WHERE_GREATER_THAN);
466 }
467 else {
468 query.append(WHERE_LESSER_THAN);
469 }
470 }
471 }
472
473 query.append(ORDER_BY_CLAUSE);
474
475 String[] orderByFields = orderByComparator.getOrderByFields();
476
477 for (int i = 0; i < orderByFields.length; i++) {
478 query.append(_ORDER_BY_ENTITY_ALIAS);
479 query.append(orderByFields[i]);
480
481 if ((i + 1) < orderByFields.length) {
482 if (orderByComparator.isAscending() ^ previous) {
483 query.append(ORDER_BY_ASC_HAS_NEXT);
484 }
485 else {
486 query.append(ORDER_BY_DESC_HAS_NEXT);
487 }
488 }
489 else {
490 if (orderByComparator.isAscending() ^ previous) {
491 query.append(ORDER_BY_ASC);
492 }
493 else {
494 query.append(ORDER_BY_DESC);
495 }
496 }
497 }
498 }
499 else {
500 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
501 }
502
503 String sql = query.toString();
504
505 Query q = session.createQuery(sql);
506
507 q.setFirstResult(0);
508 q.setMaxResults(2);
509
510 QueryPos qPos = QueryPos.getInstance(q);
511
512 if (bindUuid) {
513 qPos.add(uuid);
514 }
515
516 if (orderByComparator != null) {
517 Object[] values = orderByComparator.getOrderByConditionValues(pollsChoice);
518
519 for (Object value : values) {
520 qPos.add(value);
521 }
522 }
523
524 List<PollsChoice> list = q.list();
525
526 if (list.size() == 2) {
527 return list.get(1);
528 }
529 else {
530 return null;
531 }
532 }
533
534
540 @Override
541 public void removeByUuid(String uuid) throws SystemException {
542 for (PollsChoice pollsChoice : findByUuid(uuid, QueryUtil.ALL_POS,
543 QueryUtil.ALL_POS, null)) {
544 remove(pollsChoice);
545 }
546 }
547
548
555 @Override
556 public int countByUuid(String uuid) throws SystemException {
557 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
558
559 Object[] finderArgs = new Object[] { uuid };
560
561 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
562 this);
563
564 if (count == null) {
565 StringBundler query = new StringBundler(2);
566
567 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
568
569 boolean bindUuid = false;
570
571 if (uuid == null) {
572 query.append(_FINDER_COLUMN_UUID_UUID_1);
573 }
574 else if (uuid.equals(StringPool.BLANK)) {
575 query.append(_FINDER_COLUMN_UUID_UUID_3);
576 }
577 else {
578 bindUuid = true;
579
580 query.append(_FINDER_COLUMN_UUID_UUID_2);
581 }
582
583 String sql = query.toString();
584
585 Session session = null;
586
587 try {
588 session = openSession();
589
590 Query q = session.createQuery(sql);
591
592 QueryPos qPos = QueryPos.getInstance(q);
593
594 if (bindUuid) {
595 qPos.add(uuid);
596 }
597
598 count = (Long)q.uniqueResult();
599
600 FinderCacheUtil.putResult(finderPath, finderArgs, count);
601 }
602 catch (Exception e) {
603 FinderCacheUtil.removeResult(finderPath, finderArgs);
604
605 throw processException(e);
606 }
607 finally {
608 closeSession(session);
609 }
610 }
611
612 return count.intValue();
613 }
614
615 private static final String _FINDER_COLUMN_UUID_UUID_1 = "pollsChoice.uuid IS NULL";
616 private static final String _FINDER_COLUMN_UUID_UUID_2 = "pollsChoice.uuid = ?";
617 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(pollsChoice.uuid IS NULL OR pollsChoice.uuid = '')";
618 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
619 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
620 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
621 new String[] { String.class.getName(), Long.class.getName() },
622 PollsChoiceModelImpl.UUID_COLUMN_BITMASK |
623 PollsChoiceModelImpl.GROUPID_COLUMN_BITMASK);
624 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
625 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
626 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
627 new String[] { String.class.getName(), Long.class.getName() });
628
629
638 @Override
639 public PollsChoice findByUUID_G(String uuid, long groupId)
640 throws NoSuchChoiceException, SystemException {
641 PollsChoice pollsChoice = fetchByUUID_G(uuid, groupId);
642
643 if (pollsChoice == null) {
644 StringBundler msg = new StringBundler(6);
645
646 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
647
648 msg.append("uuid=");
649 msg.append(uuid);
650
651 msg.append(", groupId=");
652 msg.append(groupId);
653
654 msg.append(StringPool.CLOSE_CURLY_BRACE);
655
656 if (_log.isWarnEnabled()) {
657 _log.warn(msg.toString());
658 }
659
660 throw new NoSuchChoiceException(msg.toString());
661 }
662
663 return pollsChoice;
664 }
665
666
674 @Override
675 public PollsChoice fetchByUUID_G(String uuid, long groupId)
676 throws SystemException {
677 return fetchByUUID_G(uuid, groupId, true);
678 }
679
680
689 @Override
690 public PollsChoice fetchByUUID_G(String uuid, long groupId,
691 boolean retrieveFromCache) throws SystemException {
692 Object[] finderArgs = new Object[] { uuid, groupId };
693
694 Object result = null;
695
696 if (retrieveFromCache) {
697 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
698 finderArgs, this);
699 }
700
701 if (result instanceof PollsChoice) {
702 PollsChoice pollsChoice = (PollsChoice)result;
703
704 if (!Validator.equals(uuid, pollsChoice.getUuid()) ||
705 (groupId != pollsChoice.getGroupId())) {
706 result = null;
707 }
708 }
709
710 if (result == null) {
711 StringBundler query = new StringBundler(4);
712
713 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
714
715 boolean bindUuid = false;
716
717 if (uuid == null) {
718 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
719 }
720 else if (uuid.equals(StringPool.BLANK)) {
721 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
722 }
723 else {
724 bindUuid = true;
725
726 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
727 }
728
729 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
730
731 String sql = query.toString();
732
733 Session session = null;
734
735 try {
736 session = openSession();
737
738 Query q = session.createQuery(sql);
739
740 QueryPos qPos = QueryPos.getInstance(q);
741
742 if (bindUuid) {
743 qPos.add(uuid);
744 }
745
746 qPos.add(groupId);
747
748 List<PollsChoice> list = q.list();
749
750 if (list.isEmpty()) {
751 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
752 finderArgs, list);
753 }
754 else {
755 PollsChoice pollsChoice = list.get(0);
756
757 result = pollsChoice;
758
759 cacheResult(pollsChoice);
760
761 if ((pollsChoice.getUuid() == null) ||
762 !pollsChoice.getUuid().equals(uuid) ||
763 (pollsChoice.getGroupId() != groupId)) {
764 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
765 finderArgs, pollsChoice);
766 }
767 }
768 }
769 catch (Exception e) {
770 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
771 finderArgs);
772
773 throw processException(e);
774 }
775 finally {
776 closeSession(session);
777 }
778 }
779
780 if (result instanceof List<?>) {
781 return null;
782 }
783 else {
784 return (PollsChoice)result;
785 }
786 }
787
788
796 @Override
797 public PollsChoice removeByUUID_G(String uuid, long groupId)
798 throws NoSuchChoiceException, SystemException {
799 PollsChoice pollsChoice = findByUUID_G(uuid, groupId);
800
801 return remove(pollsChoice);
802 }
803
804
812 @Override
813 public int countByUUID_G(String uuid, long groupId)
814 throws SystemException {
815 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
816
817 Object[] finderArgs = new Object[] { uuid, groupId };
818
819 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
820 this);
821
822 if (count == null) {
823 StringBundler query = new StringBundler(3);
824
825 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
826
827 boolean bindUuid = false;
828
829 if (uuid == null) {
830 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
831 }
832 else if (uuid.equals(StringPool.BLANK)) {
833 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
834 }
835 else {
836 bindUuid = true;
837
838 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
839 }
840
841 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
842
843 String sql = query.toString();
844
845 Session session = null;
846
847 try {
848 session = openSession();
849
850 Query q = session.createQuery(sql);
851
852 QueryPos qPos = QueryPos.getInstance(q);
853
854 if (bindUuid) {
855 qPos.add(uuid);
856 }
857
858 qPos.add(groupId);
859
860 count = (Long)q.uniqueResult();
861
862 FinderCacheUtil.putResult(finderPath, finderArgs, count);
863 }
864 catch (Exception e) {
865 FinderCacheUtil.removeResult(finderPath, finderArgs);
866
867 throw processException(e);
868 }
869 finally {
870 closeSession(session);
871 }
872 }
873
874 return count.intValue();
875 }
876
877 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "pollsChoice.uuid IS NULL AND ";
878 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "pollsChoice.uuid = ? AND ";
879 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(pollsChoice.uuid IS NULL OR pollsChoice.uuid = '') AND ";
880 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "pollsChoice.groupId = ?";
881 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
882 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
883 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
884 new String[] {
885 String.class.getName(), Long.class.getName(),
886
887 Integer.class.getName(), Integer.class.getName(),
888 OrderByComparator.class.getName()
889 });
890 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
891 new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
892 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
893 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
894 new String[] { String.class.getName(), Long.class.getName() },
895 PollsChoiceModelImpl.UUID_COLUMN_BITMASK |
896 PollsChoiceModelImpl.COMPANYID_COLUMN_BITMASK |
897 PollsChoiceModelImpl.QUESTIONID_COLUMN_BITMASK |
898 PollsChoiceModelImpl.NAME_COLUMN_BITMASK);
899 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
900 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
901 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
902 new String[] { String.class.getName(), Long.class.getName() });
903
904
912 @Override
913 public List<PollsChoice> findByUuid_C(String uuid, long companyId)
914 throws SystemException {
915 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
916 QueryUtil.ALL_POS, null);
917 }
918
919
933 @Override
934 public List<PollsChoice> findByUuid_C(String uuid, long companyId,
935 int start, int end) throws SystemException {
936 return findByUuid_C(uuid, companyId, start, end, null);
937 }
938
939
954 @Override
955 public List<PollsChoice> findByUuid_C(String uuid, long companyId,
956 int start, int end, OrderByComparator orderByComparator)
957 throws SystemException {
958 boolean pagination = true;
959 FinderPath finderPath = null;
960 Object[] finderArgs = null;
961
962 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
963 (orderByComparator == null)) {
964 pagination = false;
965 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
966 finderArgs = new Object[] { uuid, companyId };
967 }
968 else {
969 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
970 finderArgs = new Object[] {
971 uuid, companyId,
972
973 start, end, orderByComparator
974 };
975 }
976
977 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
978 finderArgs, this);
979
980 if ((list != null) && !list.isEmpty()) {
981 for (PollsChoice pollsChoice : list) {
982 if (!Validator.equals(uuid, pollsChoice.getUuid()) ||
983 (companyId != pollsChoice.getCompanyId())) {
984 list = null;
985
986 break;
987 }
988 }
989 }
990
991 if (list == null) {
992 StringBundler query = null;
993
994 if (orderByComparator != null) {
995 query = new StringBundler(4 +
996 (orderByComparator.getOrderByFields().length * 3));
997 }
998 else {
999 query = new StringBundler(4);
1000 }
1001
1002 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
1003
1004 boolean bindUuid = false;
1005
1006 if (uuid == null) {
1007 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1008 }
1009 else if (uuid.equals(StringPool.BLANK)) {
1010 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1011 }
1012 else {
1013 bindUuid = true;
1014
1015 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1016 }
1017
1018 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1019
1020 if (orderByComparator != null) {
1021 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1022 orderByComparator);
1023 }
1024 else
1025 if (pagination) {
1026 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
1027 }
1028
1029 String sql = query.toString();
1030
1031 Session session = null;
1032
1033 try {
1034 session = openSession();
1035
1036 Query q = session.createQuery(sql);
1037
1038 QueryPos qPos = QueryPos.getInstance(q);
1039
1040 if (bindUuid) {
1041 qPos.add(uuid);
1042 }
1043
1044 qPos.add(companyId);
1045
1046 if (!pagination) {
1047 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1048 start, end, false);
1049
1050 Collections.sort(list);
1051
1052 list = new UnmodifiableList<PollsChoice>(list);
1053 }
1054 else {
1055 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1056 start, end);
1057 }
1058
1059 cacheResult(list);
1060
1061 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1062 }
1063 catch (Exception e) {
1064 FinderCacheUtil.removeResult(finderPath, finderArgs);
1065
1066 throw processException(e);
1067 }
1068 finally {
1069 closeSession(session);
1070 }
1071 }
1072
1073 return list;
1074 }
1075
1076
1086 @Override
1087 public PollsChoice findByUuid_C_First(String uuid, long companyId,
1088 OrderByComparator orderByComparator)
1089 throws NoSuchChoiceException, SystemException {
1090 PollsChoice pollsChoice = fetchByUuid_C_First(uuid, companyId,
1091 orderByComparator);
1092
1093 if (pollsChoice != null) {
1094 return pollsChoice;
1095 }
1096
1097 StringBundler msg = new StringBundler(6);
1098
1099 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1100
1101 msg.append("uuid=");
1102 msg.append(uuid);
1103
1104 msg.append(", companyId=");
1105 msg.append(companyId);
1106
1107 msg.append(StringPool.CLOSE_CURLY_BRACE);
1108
1109 throw new NoSuchChoiceException(msg.toString());
1110 }
1111
1112
1121 @Override
1122 public PollsChoice fetchByUuid_C_First(String uuid, long companyId,
1123 OrderByComparator orderByComparator) throws SystemException {
1124 List<PollsChoice> list = findByUuid_C(uuid, companyId, 0, 1,
1125 orderByComparator);
1126
1127 if (!list.isEmpty()) {
1128 return list.get(0);
1129 }
1130
1131 return null;
1132 }
1133
1134
1144 @Override
1145 public PollsChoice findByUuid_C_Last(String uuid, long companyId,
1146 OrderByComparator orderByComparator)
1147 throws NoSuchChoiceException, SystemException {
1148 PollsChoice pollsChoice = fetchByUuid_C_Last(uuid, companyId,
1149 orderByComparator);
1150
1151 if (pollsChoice != null) {
1152 return pollsChoice;
1153 }
1154
1155 StringBundler msg = new StringBundler(6);
1156
1157 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1158
1159 msg.append("uuid=");
1160 msg.append(uuid);
1161
1162 msg.append(", companyId=");
1163 msg.append(companyId);
1164
1165 msg.append(StringPool.CLOSE_CURLY_BRACE);
1166
1167 throw new NoSuchChoiceException(msg.toString());
1168 }
1169
1170
1179 @Override
1180 public PollsChoice fetchByUuid_C_Last(String uuid, long companyId,
1181 OrderByComparator orderByComparator) throws SystemException {
1182 int count = countByUuid_C(uuid, companyId);
1183
1184 if (count == 0) {
1185 return null;
1186 }
1187
1188 List<PollsChoice> list = findByUuid_C(uuid, companyId, count - 1,
1189 count, orderByComparator);
1190
1191 if (!list.isEmpty()) {
1192 return list.get(0);
1193 }
1194
1195 return null;
1196 }
1197
1198
1209 @Override
1210 public PollsChoice[] findByUuid_C_PrevAndNext(long choiceId, String uuid,
1211 long companyId, OrderByComparator orderByComparator)
1212 throws NoSuchChoiceException, SystemException {
1213 PollsChoice pollsChoice = findByPrimaryKey(choiceId);
1214
1215 Session session = null;
1216
1217 try {
1218 session = openSession();
1219
1220 PollsChoice[] array = new PollsChoiceImpl[3];
1221
1222 array[0] = getByUuid_C_PrevAndNext(session, pollsChoice, uuid,
1223 companyId, orderByComparator, true);
1224
1225 array[1] = pollsChoice;
1226
1227 array[2] = getByUuid_C_PrevAndNext(session, pollsChoice, uuid,
1228 companyId, orderByComparator, false);
1229
1230 return array;
1231 }
1232 catch (Exception e) {
1233 throw processException(e);
1234 }
1235 finally {
1236 closeSession(session);
1237 }
1238 }
1239
1240 protected PollsChoice getByUuid_C_PrevAndNext(Session session,
1241 PollsChoice pollsChoice, String uuid, long companyId,
1242 OrderByComparator orderByComparator, boolean previous) {
1243 StringBundler query = null;
1244
1245 if (orderByComparator != null) {
1246 query = new StringBundler(6 +
1247 (orderByComparator.getOrderByFields().length * 6));
1248 }
1249 else {
1250 query = new StringBundler(3);
1251 }
1252
1253 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
1254
1255 boolean bindUuid = false;
1256
1257 if (uuid == null) {
1258 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1259 }
1260 else if (uuid.equals(StringPool.BLANK)) {
1261 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1262 }
1263 else {
1264 bindUuid = true;
1265
1266 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1267 }
1268
1269 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1270
1271 if (orderByComparator != null) {
1272 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1273
1274 if (orderByConditionFields.length > 0) {
1275 query.append(WHERE_AND);
1276 }
1277
1278 for (int i = 0; i < orderByConditionFields.length; i++) {
1279 query.append(_ORDER_BY_ENTITY_ALIAS);
1280 query.append(orderByConditionFields[i]);
1281
1282 if ((i + 1) < orderByConditionFields.length) {
1283 if (orderByComparator.isAscending() ^ previous) {
1284 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1285 }
1286 else {
1287 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1288 }
1289 }
1290 else {
1291 if (orderByComparator.isAscending() ^ previous) {
1292 query.append(WHERE_GREATER_THAN);
1293 }
1294 else {
1295 query.append(WHERE_LESSER_THAN);
1296 }
1297 }
1298 }
1299
1300 query.append(ORDER_BY_CLAUSE);
1301
1302 String[] orderByFields = orderByComparator.getOrderByFields();
1303
1304 for (int i = 0; i < orderByFields.length; i++) {
1305 query.append(_ORDER_BY_ENTITY_ALIAS);
1306 query.append(orderByFields[i]);
1307
1308 if ((i + 1) < orderByFields.length) {
1309 if (orderByComparator.isAscending() ^ previous) {
1310 query.append(ORDER_BY_ASC_HAS_NEXT);
1311 }
1312 else {
1313 query.append(ORDER_BY_DESC_HAS_NEXT);
1314 }
1315 }
1316 else {
1317 if (orderByComparator.isAscending() ^ previous) {
1318 query.append(ORDER_BY_ASC);
1319 }
1320 else {
1321 query.append(ORDER_BY_DESC);
1322 }
1323 }
1324 }
1325 }
1326 else {
1327 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
1328 }
1329
1330 String sql = query.toString();
1331
1332 Query q = session.createQuery(sql);
1333
1334 q.setFirstResult(0);
1335 q.setMaxResults(2);
1336
1337 QueryPos qPos = QueryPos.getInstance(q);
1338
1339 if (bindUuid) {
1340 qPos.add(uuid);
1341 }
1342
1343 qPos.add(companyId);
1344
1345 if (orderByComparator != null) {
1346 Object[] values = orderByComparator.getOrderByConditionValues(pollsChoice);
1347
1348 for (Object value : values) {
1349 qPos.add(value);
1350 }
1351 }
1352
1353 List<PollsChoice> list = q.list();
1354
1355 if (list.size() == 2) {
1356 return list.get(1);
1357 }
1358 else {
1359 return null;
1360 }
1361 }
1362
1363
1370 @Override
1371 public void removeByUuid_C(String uuid, long companyId)
1372 throws SystemException {
1373 for (PollsChoice pollsChoice : findByUuid_C(uuid, companyId,
1374 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1375 remove(pollsChoice);
1376 }
1377 }
1378
1379
1387 @Override
1388 public int countByUuid_C(String uuid, long companyId)
1389 throws SystemException {
1390 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1391
1392 Object[] finderArgs = new Object[] { uuid, companyId };
1393
1394 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1395 this);
1396
1397 if (count == null) {
1398 StringBundler query = new StringBundler(3);
1399
1400 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
1401
1402 boolean bindUuid = false;
1403
1404 if (uuid == null) {
1405 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1406 }
1407 else if (uuid.equals(StringPool.BLANK)) {
1408 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1409 }
1410 else {
1411 bindUuid = true;
1412
1413 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1414 }
1415
1416 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1417
1418 String sql = query.toString();
1419
1420 Session session = null;
1421
1422 try {
1423 session = openSession();
1424
1425 Query q = session.createQuery(sql);
1426
1427 QueryPos qPos = QueryPos.getInstance(q);
1428
1429 if (bindUuid) {
1430 qPos.add(uuid);
1431 }
1432
1433 qPos.add(companyId);
1434
1435 count = (Long)q.uniqueResult();
1436
1437 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1438 }
1439 catch (Exception e) {
1440 FinderCacheUtil.removeResult(finderPath, finderArgs);
1441
1442 throw processException(e);
1443 }
1444 finally {
1445 closeSession(session);
1446 }
1447 }
1448
1449 return count.intValue();
1450 }
1451
1452 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "pollsChoice.uuid IS NULL AND ";
1453 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "pollsChoice.uuid = ? AND ";
1454 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(pollsChoice.uuid IS NULL OR pollsChoice.uuid = '') AND ";
1455 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "pollsChoice.companyId = ?";
1456 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_QUESTIONID =
1457 new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
1458 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
1459 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByQuestionId",
1460 new String[] {
1461 Long.class.getName(),
1462
1463 Integer.class.getName(), Integer.class.getName(),
1464 OrderByComparator.class.getName()
1465 });
1466 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID =
1467 new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
1468 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
1469 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByQuestionId",
1470 new String[] { Long.class.getName() },
1471 PollsChoiceModelImpl.QUESTIONID_COLUMN_BITMASK |
1472 PollsChoiceModelImpl.NAME_COLUMN_BITMASK);
1473 public static final FinderPath FINDER_PATH_COUNT_BY_QUESTIONID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
1474 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
1475 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByQuestionId",
1476 new String[] { Long.class.getName() });
1477
1478
1485 @Override
1486 public List<PollsChoice> findByQuestionId(long questionId)
1487 throws SystemException {
1488 return findByQuestionId(questionId, QueryUtil.ALL_POS,
1489 QueryUtil.ALL_POS, null);
1490 }
1491
1492
1505 @Override
1506 public List<PollsChoice> findByQuestionId(long questionId, int start,
1507 int end) throws SystemException {
1508 return findByQuestionId(questionId, start, end, null);
1509 }
1510
1511
1525 @Override
1526 public List<PollsChoice> findByQuestionId(long questionId, int start,
1527 int end, OrderByComparator orderByComparator) throws SystemException {
1528 boolean pagination = true;
1529 FinderPath finderPath = null;
1530 Object[] finderArgs = null;
1531
1532 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1533 (orderByComparator == null)) {
1534 pagination = false;
1535 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID;
1536 finderArgs = new Object[] { questionId };
1537 }
1538 else {
1539 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_QUESTIONID;
1540 finderArgs = new Object[] { questionId, start, end, orderByComparator };
1541 }
1542
1543 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
1544 finderArgs, this);
1545
1546 if ((list != null) && !list.isEmpty()) {
1547 for (PollsChoice pollsChoice : list) {
1548 if ((questionId != pollsChoice.getQuestionId())) {
1549 list = null;
1550
1551 break;
1552 }
1553 }
1554 }
1555
1556 if (list == null) {
1557 StringBundler query = null;
1558
1559 if (orderByComparator != null) {
1560 query = new StringBundler(3 +
1561 (orderByComparator.getOrderByFields().length * 3));
1562 }
1563 else {
1564 query = new StringBundler(3);
1565 }
1566
1567 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
1568
1569 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1570
1571 if (orderByComparator != null) {
1572 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1573 orderByComparator);
1574 }
1575 else
1576 if (pagination) {
1577 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
1578 }
1579
1580 String sql = query.toString();
1581
1582 Session session = null;
1583
1584 try {
1585 session = openSession();
1586
1587 Query q = session.createQuery(sql);
1588
1589 QueryPos qPos = QueryPos.getInstance(q);
1590
1591 qPos.add(questionId);
1592
1593 if (!pagination) {
1594 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1595 start, end, false);
1596
1597 Collections.sort(list);
1598
1599 list = new UnmodifiableList<PollsChoice>(list);
1600 }
1601 else {
1602 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1603 start, end);
1604 }
1605
1606 cacheResult(list);
1607
1608 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1609 }
1610 catch (Exception e) {
1611 FinderCacheUtil.removeResult(finderPath, finderArgs);
1612
1613 throw processException(e);
1614 }
1615 finally {
1616 closeSession(session);
1617 }
1618 }
1619
1620 return list;
1621 }
1622
1623
1632 @Override
1633 public PollsChoice findByQuestionId_First(long questionId,
1634 OrderByComparator orderByComparator)
1635 throws NoSuchChoiceException, SystemException {
1636 PollsChoice pollsChoice = fetchByQuestionId_First(questionId,
1637 orderByComparator);
1638
1639 if (pollsChoice != null) {
1640 return pollsChoice;
1641 }
1642
1643 StringBundler msg = new StringBundler(4);
1644
1645 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1646
1647 msg.append("questionId=");
1648 msg.append(questionId);
1649
1650 msg.append(StringPool.CLOSE_CURLY_BRACE);
1651
1652 throw new NoSuchChoiceException(msg.toString());
1653 }
1654
1655
1663 @Override
1664 public PollsChoice fetchByQuestionId_First(long questionId,
1665 OrderByComparator orderByComparator) throws SystemException {
1666 List<PollsChoice> list = findByQuestionId(questionId, 0, 1,
1667 orderByComparator);
1668
1669 if (!list.isEmpty()) {
1670 return list.get(0);
1671 }
1672
1673 return null;
1674 }
1675
1676
1685 @Override
1686 public PollsChoice findByQuestionId_Last(long questionId,
1687 OrderByComparator orderByComparator)
1688 throws NoSuchChoiceException, SystemException {
1689 PollsChoice pollsChoice = fetchByQuestionId_Last(questionId,
1690 orderByComparator);
1691
1692 if (pollsChoice != null) {
1693 return pollsChoice;
1694 }
1695
1696 StringBundler msg = new StringBundler(4);
1697
1698 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1699
1700 msg.append("questionId=");
1701 msg.append(questionId);
1702
1703 msg.append(StringPool.CLOSE_CURLY_BRACE);
1704
1705 throw new NoSuchChoiceException(msg.toString());
1706 }
1707
1708
1716 @Override
1717 public PollsChoice fetchByQuestionId_Last(long questionId,
1718 OrderByComparator orderByComparator) throws SystemException {
1719 int count = countByQuestionId(questionId);
1720
1721 if (count == 0) {
1722 return null;
1723 }
1724
1725 List<PollsChoice> list = findByQuestionId(questionId, count - 1, count,
1726 orderByComparator);
1727
1728 if (!list.isEmpty()) {
1729 return list.get(0);
1730 }
1731
1732 return null;
1733 }
1734
1735
1745 @Override
1746 public PollsChoice[] findByQuestionId_PrevAndNext(long choiceId,
1747 long questionId, OrderByComparator orderByComparator)
1748 throws NoSuchChoiceException, SystemException {
1749 PollsChoice pollsChoice = findByPrimaryKey(choiceId);
1750
1751 Session session = null;
1752
1753 try {
1754 session = openSession();
1755
1756 PollsChoice[] array = new PollsChoiceImpl[3];
1757
1758 array[0] = getByQuestionId_PrevAndNext(session, pollsChoice,
1759 questionId, orderByComparator, true);
1760
1761 array[1] = pollsChoice;
1762
1763 array[2] = getByQuestionId_PrevAndNext(session, pollsChoice,
1764 questionId, orderByComparator, false);
1765
1766 return array;
1767 }
1768 catch (Exception e) {
1769 throw processException(e);
1770 }
1771 finally {
1772 closeSession(session);
1773 }
1774 }
1775
1776 protected PollsChoice getByQuestionId_PrevAndNext(Session session,
1777 PollsChoice pollsChoice, long questionId,
1778 OrderByComparator orderByComparator, boolean previous) {
1779 StringBundler query = null;
1780
1781 if (orderByComparator != null) {
1782 query = new StringBundler(6 +
1783 (orderByComparator.getOrderByFields().length * 6));
1784 }
1785 else {
1786 query = new StringBundler(3);
1787 }
1788
1789 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
1790
1791 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1792
1793 if (orderByComparator != null) {
1794 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1795
1796 if (orderByConditionFields.length > 0) {
1797 query.append(WHERE_AND);
1798 }
1799
1800 for (int i = 0; i < orderByConditionFields.length; i++) {
1801 query.append(_ORDER_BY_ENTITY_ALIAS);
1802 query.append(orderByConditionFields[i]);
1803
1804 if ((i + 1) < orderByConditionFields.length) {
1805 if (orderByComparator.isAscending() ^ previous) {
1806 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1807 }
1808 else {
1809 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1810 }
1811 }
1812 else {
1813 if (orderByComparator.isAscending() ^ previous) {
1814 query.append(WHERE_GREATER_THAN);
1815 }
1816 else {
1817 query.append(WHERE_LESSER_THAN);
1818 }
1819 }
1820 }
1821
1822 query.append(ORDER_BY_CLAUSE);
1823
1824 String[] orderByFields = orderByComparator.getOrderByFields();
1825
1826 for (int i = 0; i < orderByFields.length; i++) {
1827 query.append(_ORDER_BY_ENTITY_ALIAS);
1828 query.append(orderByFields[i]);
1829
1830 if ((i + 1) < orderByFields.length) {
1831 if (orderByComparator.isAscending() ^ previous) {
1832 query.append(ORDER_BY_ASC_HAS_NEXT);
1833 }
1834 else {
1835 query.append(ORDER_BY_DESC_HAS_NEXT);
1836 }
1837 }
1838 else {
1839 if (orderByComparator.isAscending() ^ previous) {
1840 query.append(ORDER_BY_ASC);
1841 }
1842 else {
1843 query.append(ORDER_BY_DESC);
1844 }
1845 }
1846 }
1847 }
1848 else {
1849 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
1850 }
1851
1852 String sql = query.toString();
1853
1854 Query q = session.createQuery(sql);
1855
1856 q.setFirstResult(0);
1857 q.setMaxResults(2);
1858
1859 QueryPos qPos = QueryPos.getInstance(q);
1860
1861 qPos.add(questionId);
1862
1863 if (orderByComparator != null) {
1864 Object[] values = orderByComparator.getOrderByConditionValues(pollsChoice);
1865
1866 for (Object value : values) {
1867 qPos.add(value);
1868 }
1869 }
1870
1871 List<PollsChoice> list = q.list();
1872
1873 if (list.size() == 2) {
1874 return list.get(1);
1875 }
1876 else {
1877 return null;
1878 }
1879 }
1880
1881
1887 @Override
1888 public void removeByQuestionId(long questionId) throws SystemException {
1889 for (PollsChoice pollsChoice : findByQuestionId(questionId,
1890 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1891 remove(pollsChoice);
1892 }
1893 }
1894
1895
1902 @Override
1903 public int countByQuestionId(long questionId) throws SystemException {
1904 FinderPath finderPath = FINDER_PATH_COUNT_BY_QUESTIONID;
1905
1906 Object[] finderArgs = new Object[] { questionId };
1907
1908 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1909 this);
1910
1911 if (count == null) {
1912 StringBundler query = new StringBundler(2);
1913
1914 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
1915
1916 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1917
1918 String sql = query.toString();
1919
1920 Session session = null;
1921
1922 try {
1923 session = openSession();
1924
1925 Query q = session.createQuery(sql);
1926
1927 QueryPos qPos = QueryPos.getInstance(q);
1928
1929 qPos.add(questionId);
1930
1931 count = (Long)q.uniqueResult();
1932
1933 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1934 }
1935 catch (Exception e) {
1936 FinderCacheUtil.removeResult(finderPath, finderArgs);
1937
1938 throw processException(e);
1939 }
1940 finally {
1941 closeSession(session);
1942 }
1943 }
1944
1945 return count.intValue();
1946 }
1947
1948 private static final String _FINDER_COLUMN_QUESTIONID_QUESTIONID_2 = "pollsChoice.questionId = ?";
1949 public static final FinderPath FINDER_PATH_FETCH_BY_Q_N = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
1950 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
1951 FINDER_CLASS_NAME_ENTITY, "fetchByQ_N",
1952 new String[] { Long.class.getName(), String.class.getName() },
1953 PollsChoiceModelImpl.QUESTIONID_COLUMN_BITMASK |
1954 PollsChoiceModelImpl.NAME_COLUMN_BITMASK);
1955 public static final FinderPath FINDER_PATH_COUNT_BY_Q_N = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
1956 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
1957 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByQ_N",
1958 new String[] { Long.class.getName(), String.class.getName() });
1959
1960
1969 @Override
1970 public PollsChoice findByQ_N(long questionId, String name)
1971 throws NoSuchChoiceException, SystemException {
1972 PollsChoice pollsChoice = fetchByQ_N(questionId, name);
1973
1974 if (pollsChoice == null) {
1975 StringBundler msg = new StringBundler(6);
1976
1977 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1978
1979 msg.append("questionId=");
1980 msg.append(questionId);
1981
1982 msg.append(", name=");
1983 msg.append(name);
1984
1985 msg.append(StringPool.CLOSE_CURLY_BRACE);
1986
1987 if (_log.isWarnEnabled()) {
1988 _log.warn(msg.toString());
1989 }
1990
1991 throw new NoSuchChoiceException(msg.toString());
1992 }
1993
1994 return pollsChoice;
1995 }
1996
1997
2005 @Override
2006 public PollsChoice fetchByQ_N(long questionId, String name)
2007 throws SystemException {
2008 return fetchByQ_N(questionId, name, true);
2009 }
2010
2011
2020 @Override
2021 public PollsChoice fetchByQ_N(long questionId, String name,
2022 boolean retrieveFromCache) throws SystemException {
2023 Object[] finderArgs = new Object[] { questionId, name };
2024
2025 Object result = null;
2026
2027 if (retrieveFromCache) {
2028 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_Q_N,
2029 finderArgs, this);
2030 }
2031
2032 if (result instanceof PollsChoice) {
2033 PollsChoice pollsChoice = (PollsChoice)result;
2034
2035 if ((questionId != pollsChoice.getQuestionId()) ||
2036 !Validator.equals(name, pollsChoice.getName())) {
2037 result = null;
2038 }
2039 }
2040
2041 if (result == null) {
2042 StringBundler query = new StringBundler(4);
2043
2044 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
2045
2046 query.append(_FINDER_COLUMN_Q_N_QUESTIONID_2);
2047
2048 boolean bindName = false;
2049
2050 if (name == null) {
2051 query.append(_FINDER_COLUMN_Q_N_NAME_1);
2052 }
2053 else if (name.equals(StringPool.BLANK)) {
2054 query.append(_FINDER_COLUMN_Q_N_NAME_3);
2055 }
2056 else {
2057 bindName = true;
2058
2059 query.append(_FINDER_COLUMN_Q_N_NAME_2);
2060 }
2061
2062 String sql = query.toString();
2063
2064 Session session = null;
2065
2066 try {
2067 session = openSession();
2068
2069 Query q = session.createQuery(sql);
2070
2071 QueryPos qPos = QueryPos.getInstance(q);
2072
2073 qPos.add(questionId);
2074
2075 if (bindName) {
2076 qPos.add(name);
2077 }
2078
2079 List<PollsChoice> list = q.list();
2080
2081 if (list.isEmpty()) {
2082 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
2083 finderArgs, list);
2084 }
2085 else {
2086 PollsChoice pollsChoice = list.get(0);
2087
2088 result = pollsChoice;
2089
2090 cacheResult(pollsChoice);
2091
2092 if ((pollsChoice.getQuestionId() != questionId) ||
2093 (pollsChoice.getName() == null) ||
2094 !pollsChoice.getName().equals(name)) {
2095 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
2096 finderArgs, pollsChoice);
2097 }
2098 }
2099 }
2100 catch (Exception e) {
2101 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N,
2102 finderArgs);
2103
2104 throw processException(e);
2105 }
2106 finally {
2107 closeSession(session);
2108 }
2109 }
2110
2111 if (result instanceof List<?>) {
2112 return null;
2113 }
2114 else {
2115 return (PollsChoice)result;
2116 }
2117 }
2118
2119
2127 @Override
2128 public PollsChoice removeByQ_N(long questionId, String name)
2129 throws NoSuchChoiceException, SystemException {
2130 PollsChoice pollsChoice = findByQ_N(questionId, name);
2131
2132 return remove(pollsChoice);
2133 }
2134
2135
2143 @Override
2144 public int countByQ_N(long questionId, String name)
2145 throws SystemException {
2146 FinderPath finderPath = FINDER_PATH_COUNT_BY_Q_N;
2147
2148 Object[] finderArgs = new Object[] { questionId, name };
2149
2150 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2151 this);
2152
2153 if (count == null) {
2154 StringBundler query = new StringBundler(3);
2155
2156 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
2157
2158 query.append(_FINDER_COLUMN_Q_N_QUESTIONID_2);
2159
2160 boolean bindName = false;
2161
2162 if (name == null) {
2163 query.append(_FINDER_COLUMN_Q_N_NAME_1);
2164 }
2165 else if (name.equals(StringPool.BLANK)) {
2166 query.append(_FINDER_COLUMN_Q_N_NAME_3);
2167 }
2168 else {
2169 bindName = true;
2170
2171 query.append(_FINDER_COLUMN_Q_N_NAME_2);
2172 }
2173
2174 String sql = query.toString();
2175
2176 Session session = null;
2177
2178 try {
2179 session = openSession();
2180
2181 Query q = session.createQuery(sql);
2182
2183 QueryPos qPos = QueryPos.getInstance(q);
2184
2185 qPos.add(questionId);
2186
2187 if (bindName) {
2188 qPos.add(name);
2189 }
2190
2191 count = (Long)q.uniqueResult();
2192
2193 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2194 }
2195 catch (Exception e) {
2196 FinderCacheUtil.removeResult(finderPath, finderArgs);
2197
2198 throw processException(e);
2199 }
2200 finally {
2201 closeSession(session);
2202 }
2203 }
2204
2205 return count.intValue();
2206 }
2207
2208 private static final String _FINDER_COLUMN_Q_N_QUESTIONID_2 = "pollsChoice.questionId = ? AND ";
2209 private static final String _FINDER_COLUMN_Q_N_NAME_1 = "pollsChoice.name IS NULL";
2210 private static final String _FINDER_COLUMN_Q_N_NAME_2 = "pollsChoice.name = ?";
2211 private static final String _FINDER_COLUMN_Q_N_NAME_3 = "(pollsChoice.name IS NULL OR pollsChoice.name = '')";
2212
2213
2218 @Override
2219 public void cacheResult(PollsChoice pollsChoice) {
2220 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
2221 PollsChoiceImpl.class, pollsChoice.getPrimaryKey(), pollsChoice);
2222
2223 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2224 new Object[] { pollsChoice.getUuid(), pollsChoice.getGroupId() },
2225 pollsChoice);
2226
2227 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
2228 new Object[] { pollsChoice.getQuestionId(), pollsChoice.getName() },
2229 pollsChoice);
2230
2231 pollsChoice.resetOriginalValues();
2232 }
2233
2234
2239 @Override
2240 public void cacheResult(List<PollsChoice> pollsChoices) {
2241 for (PollsChoice pollsChoice : pollsChoices) {
2242 if (EntityCacheUtil.getResult(
2243 PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
2244 PollsChoiceImpl.class, pollsChoice.getPrimaryKey()) == null) {
2245 cacheResult(pollsChoice);
2246 }
2247 else {
2248 pollsChoice.resetOriginalValues();
2249 }
2250 }
2251 }
2252
2253
2260 @Override
2261 public void clearCache() {
2262 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2263 CacheRegistryUtil.clear(PollsChoiceImpl.class.getName());
2264 }
2265
2266 EntityCacheUtil.clearCache(PollsChoiceImpl.class.getName());
2267
2268 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2269 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2270 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2271 }
2272
2273
2280 @Override
2281 public void clearCache(PollsChoice pollsChoice) {
2282 EntityCacheUtil.removeResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
2283 PollsChoiceImpl.class, pollsChoice.getPrimaryKey());
2284
2285 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2286 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2287
2288 clearUniqueFindersCache(pollsChoice);
2289 }
2290
2291 @Override
2292 public void clearCache(List<PollsChoice> pollsChoices) {
2293 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2294 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2295
2296 for (PollsChoice pollsChoice : pollsChoices) {
2297 EntityCacheUtil.removeResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
2298 PollsChoiceImpl.class, pollsChoice.getPrimaryKey());
2299
2300 clearUniqueFindersCache(pollsChoice);
2301 }
2302 }
2303
2304 protected void cacheUniqueFindersCache(PollsChoice pollsChoice) {
2305 if (pollsChoice.isNew()) {
2306 Object[] args = new Object[] {
2307 pollsChoice.getUuid(), pollsChoice.getGroupId()
2308 };
2309
2310 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2311 Long.valueOf(1));
2312 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2313 pollsChoice);
2314
2315 args = new Object[] {
2316 pollsChoice.getQuestionId(), pollsChoice.getName()
2317 };
2318
2319 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_Q_N, args,
2320 Long.valueOf(1));
2321 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N, args,
2322 pollsChoice);
2323 }
2324 else {
2325 PollsChoiceModelImpl pollsChoiceModelImpl = (PollsChoiceModelImpl)pollsChoice;
2326
2327 if ((pollsChoiceModelImpl.getColumnBitmask() &
2328 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2329 Object[] args = new Object[] {
2330 pollsChoice.getUuid(), pollsChoice.getGroupId()
2331 };
2332
2333 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2334 Long.valueOf(1));
2335 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2336 pollsChoice);
2337 }
2338
2339 if ((pollsChoiceModelImpl.getColumnBitmask() &
2340 FINDER_PATH_FETCH_BY_Q_N.getColumnBitmask()) != 0) {
2341 Object[] args = new Object[] {
2342 pollsChoice.getQuestionId(), pollsChoice.getName()
2343 };
2344
2345 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_Q_N, args,
2346 Long.valueOf(1));
2347 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N, args,
2348 pollsChoice);
2349 }
2350 }
2351 }
2352
2353 protected void clearUniqueFindersCache(PollsChoice pollsChoice) {
2354 PollsChoiceModelImpl pollsChoiceModelImpl = (PollsChoiceModelImpl)pollsChoice;
2355
2356 Object[] args = new Object[] {
2357 pollsChoice.getUuid(), pollsChoice.getGroupId()
2358 };
2359
2360 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2361 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2362
2363 if ((pollsChoiceModelImpl.getColumnBitmask() &
2364 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2365 args = new Object[] {
2366 pollsChoiceModelImpl.getOriginalUuid(),
2367 pollsChoiceModelImpl.getOriginalGroupId()
2368 };
2369
2370 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2371 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2372 }
2373
2374 args = new Object[] { pollsChoice.getQuestionId(), pollsChoice.getName() };
2375
2376 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_Q_N, args);
2377 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N, args);
2378
2379 if ((pollsChoiceModelImpl.getColumnBitmask() &
2380 FINDER_PATH_FETCH_BY_Q_N.getColumnBitmask()) != 0) {
2381 args = new Object[] {
2382 pollsChoiceModelImpl.getOriginalQuestionId(),
2383 pollsChoiceModelImpl.getOriginalName()
2384 };
2385
2386 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_Q_N, args);
2387 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N, args);
2388 }
2389 }
2390
2391
2397 @Override
2398 public PollsChoice create(long choiceId) {
2399 PollsChoice pollsChoice = new PollsChoiceImpl();
2400
2401 pollsChoice.setNew(true);
2402 pollsChoice.setPrimaryKey(choiceId);
2403
2404 String uuid = PortalUUIDUtil.generate();
2405
2406 pollsChoice.setUuid(uuid);
2407
2408 return pollsChoice;
2409 }
2410
2411
2419 @Override
2420 public PollsChoice remove(long choiceId)
2421 throws NoSuchChoiceException, SystemException {
2422 return remove((Serializable)choiceId);
2423 }
2424
2425
2433 @Override
2434 public PollsChoice remove(Serializable primaryKey)
2435 throws NoSuchChoiceException, SystemException {
2436 Session session = null;
2437
2438 try {
2439 session = openSession();
2440
2441 PollsChoice pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
2442 primaryKey);
2443
2444 if (pollsChoice == null) {
2445 if (_log.isWarnEnabled()) {
2446 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2447 }
2448
2449 throw new NoSuchChoiceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2450 primaryKey);
2451 }
2452
2453 return remove(pollsChoice);
2454 }
2455 catch (NoSuchChoiceException nsee) {
2456 throw nsee;
2457 }
2458 catch (Exception e) {
2459 throw processException(e);
2460 }
2461 finally {
2462 closeSession(session);
2463 }
2464 }
2465
2466 @Override
2467 protected PollsChoice removeImpl(PollsChoice pollsChoice)
2468 throws SystemException {
2469 pollsChoice = toUnwrappedModel(pollsChoice);
2470
2471 Session session = null;
2472
2473 try {
2474 session = openSession();
2475
2476 if (!session.contains(pollsChoice)) {
2477 pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
2478 pollsChoice.getPrimaryKeyObj());
2479 }
2480
2481 if (pollsChoice != null) {
2482 session.delete(pollsChoice);
2483 }
2484 }
2485 catch (Exception e) {
2486 throw processException(e);
2487 }
2488 finally {
2489 closeSession(session);
2490 }
2491
2492 if (pollsChoice != null) {
2493 clearCache(pollsChoice);
2494 }
2495
2496 return pollsChoice;
2497 }
2498
2499 @Override
2500 public PollsChoice updateImpl(
2501 com.liferay.portlet.polls.model.PollsChoice pollsChoice)
2502 throws SystemException {
2503 pollsChoice = toUnwrappedModel(pollsChoice);
2504
2505 boolean isNew = pollsChoice.isNew();
2506
2507 PollsChoiceModelImpl pollsChoiceModelImpl = (PollsChoiceModelImpl)pollsChoice;
2508
2509 if (Validator.isNull(pollsChoice.getUuid())) {
2510 String uuid = PortalUUIDUtil.generate();
2511
2512 pollsChoice.setUuid(uuid);
2513 }
2514
2515 Session session = null;
2516
2517 try {
2518 session = openSession();
2519
2520 if (pollsChoice.isNew()) {
2521 session.save(pollsChoice);
2522
2523 pollsChoice.setNew(false);
2524 }
2525 else {
2526 session.merge(pollsChoice);
2527 }
2528 }
2529 catch (Exception e) {
2530 throw processException(e);
2531 }
2532 finally {
2533 closeSession(session);
2534 }
2535
2536 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2537
2538 if (isNew || !PollsChoiceModelImpl.COLUMN_BITMASK_ENABLED) {
2539 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2540 }
2541
2542 else {
2543 if ((pollsChoiceModelImpl.getColumnBitmask() &
2544 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2545 Object[] args = new Object[] {
2546 pollsChoiceModelImpl.getOriginalUuid()
2547 };
2548
2549 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2550 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2551 args);
2552
2553 args = new Object[] { pollsChoiceModelImpl.getUuid() };
2554
2555 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2556 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2557 args);
2558 }
2559
2560 if ((pollsChoiceModelImpl.getColumnBitmask() &
2561 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2562 Object[] args = new Object[] {
2563 pollsChoiceModelImpl.getOriginalUuid(),
2564 pollsChoiceModelImpl.getOriginalCompanyId()
2565 };
2566
2567 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2568 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2569 args);
2570
2571 args = new Object[] {
2572 pollsChoiceModelImpl.getUuid(),
2573 pollsChoiceModelImpl.getCompanyId()
2574 };
2575
2576 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2577 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2578 args);
2579 }
2580
2581 if ((pollsChoiceModelImpl.getColumnBitmask() &
2582 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID.getColumnBitmask()) != 0) {
2583 Object[] args = new Object[] {
2584 pollsChoiceModelImpl.getOriginalQuestionId()
2585 };
2586
2587 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
2588 args);
2589 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
2590 args);
2591
2592 args = new Object[] { pollsChoiceModelImpl.getQuestionId() };
2593
2594 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
2595 args);
2596 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
2597 args);
2598 }
2599 }
2600
2601 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
2602 PollsChoiceImpl.class, pollsChoice.getPrimaryKey(), pollsChoice);
2603
2604 clearUniqueFindersCache(pollsChoice);
2605 cacheUniqueFindersCache(pollsChoice);
2606
2607 return pollsChoice;
2608 }
2609
2610 protected PollsChoice toUnwrappedModel(PollsChoice pollsChoice) {
2611 if (pollsChoice instanceof PollsChoiceImpl) {
2612 return pollsChoice;
2613 }
2614
2615 PollsChoiceImpl pollsChoiceImpl = new PollsChoiceImpl();
2616
2617 pollsChoiceImpl.setNew(pollsChoice.isNew());
2618 pollsChoiceImpl.setPrimaryKey(pollsChoice.getPrimaryKey());
2619
2620 pollsChoiceImpl.setUuid(pollsChoice.getUuid());
2621 pollsChoiceImpl.setChoiceId(pollsChoice.getChoiceId());
2622 pollsChoiceImpl.setGroupId(pollsChoice.getGroupId());
2623 pollsChoiceImpl.setCompanyId(pollsChoice.getCompanyId());
2624 pollsChoiceImpl.setUserId(pollsChoice.getUserId());
2625 pollsChoiceImpl.setUserName(pollsChoice.getUserName());
2626 pollsChoiceImpl.setCreateDate(pollsChoice.getCreateDate());
2627 pollsChoiceImpl.setModifiedDate(pollsChoice.getModifiedDate());
2628 pollsChoiceImpl.setQuestionId(pollsChoice.getQuestionId());
2629 pollsChoiceImpl.setName(pollsChoice.getName());
2630 pollsChoiceImpl.setDescription(pollsChoice.getDescription());
2631
2632 return pollsChoiceImpl;
2633 }
2634
2635
2643 @Override
2644 public PollsChoice findByPrimaryKey(Serializable primaryKey)
2645 throws NoSuchChoiceException, SystemException {
2646 PollsChoice pollsChoice = fetchByPrimaryKey(primaryKey);
2647
2648 if (pollsChoice == null) {
2649 if (_log.isWarnEnabled()) {
2650 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2651 }
2652
2653 throw new NoSuchChoiceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2654 primaryKey);
2655 }
2656
2657 return pollsChoice;
2658 }
2659
2660
2668 @Override
2669 public PollsChoice findByPrimaryKey(long choiceId)
2670 throws NoSuchChoiceException, SystemException {
2671 return findByPrimaryKey((Serializable)choiceId);
2672 }
2673
2674
2681 @Override
2682 public PollsChoice fetchByPrimaryKey(Serializable primaryKey)
2683 throws SystemException {
2684 PollsChoice pollsChoice = (PollsChoice)EntityCacheUtil.getResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
2685 PollsChoiceImpl.class, primaryKey);
2686
2687 if (pollsChoice == _nullPollsChoice) {
2688 return null;
2689 }
2690
2691 if (pollsChoice == null) {
2692 Session session = null;
2693
2694 try {
2695 session = openSession();
2696
2697 pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
2698 primaryKey);
2699
2700 if (pollsChoice != null) {
2701 cacheResult(pollsChoice);
2702 }
2703 else {
2704 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
2705 PollsChoiceImpl.class, primaryKey, _nullPollsChoice);
2706 }
2707 }
2708 catch (Exception e) {
2709 EntityCacheUtil.removeResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
2710 PollsChoiceImpl.class, primaryKey);
2711
2712 throw processException(e);
2713 }
2714 finally {
2715 closeSession(session);
2716 }
2717 }
2718
2719 return pollsChoice;
2720 }
2721
2722
2729 @Override
2730 public PollsChoice fetchByPrimaryKey(long choiceId)
2731 throws SystemException {
2732 return fetchByPrimaryKey((Serializable)choiceId);
2733 }
2734
2735
2741 @Override
2742 public List<PollsChoice> findAll() throws SystemException {
2743 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2744 }
2745
2746
2758 @Override
2759 public List<PollsChoice> findAll(int start, int end)
2760 throws SystemException {
2761 return findAll(start, end, null);
2762 }
2763
2764
2777 @Override
2778 public List<PollsChoice> findAll(int start, int end,
2779 OrderByComparator orderByComparator) throws SystemException {
2780 boolean pagination = true;
2781 FinderPath finderPath = null;
2782 Object[] finderArgs = null;
2783
2784 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2785 (orderByComparator == null)) {
2786 pagination = false;
2787 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2788 finderArgs = FINDER_ARGS_EMPTY;
2789 }
2790 else {
2791 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2792 finderArgs = new Object[] { start, end, orderByComparator };
2793 }
2794
2795 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
2796 finderArgs, this);
2797
2798 if (list == null) {
2799 StringBundler query = null;
2800 String sql = null;
2801
2802 if (orderByComparator != null) {
2803 query = new StringBundler(2 +
2804 (orderByComparator.getOrderByFields().length * 3));
2805
2806 query.append(_SQL_SELECT_POLLSCHOICE);
2807
2808 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2809 orderByComparator);
2810
2811 sql = query.toString();
2812 }
2813 else {
2814 sql = _SQL_SELECT_POLLSCHOICE;
2815
2816 if (pagination) {
2817 sql = sql.concat(PollsChoiceModelImpl.ORDER_BY_JPQL);
2818 }
2819 }
2820
2821 Session session = null;
2822
2823 try {
2824 session = openSession();
2825
2826 Query q = session.createQuery(sql);
2827
2828 if (!pagination) {
2829 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
2830 start, end, false);
2831
2832 Collections.sort(list);
2833
2834 list = new UnmodifiableList<PollsChoice>(list);
2835 }
2836 else {
2837 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
2838 start, end);
2839 }
2840
2841 cacheResult(list);
2842
2843 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2844 }
2845 catch (Exception e) {
2846 FinderCacheUtil.removeResult(finderPath, finderArgs);
2847
2848 throw processException(e);
2849 }
2850 finally {
2851 closeSession(session);
2852 }
2853 }
2854
2855 return list;
2856 }
2857
2858
2863 @Override
2864 public void removeAll() throws SystemException {
2865 for (PollsChoice pollsChoice : findAll()) {
2866 remove(pollsChoice);
2867 }
2868 }
2869
2870
2876 @Override
2877 public int countAll() throws SystemException {
2878 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2879 FINDER_ARGS_EMPTY, this);
2880
2881 if (count == null) {
2882 Session session = null;
2883
2884 try {
2885 session = openSession();
2886
2887 Query q = session.createQuery(_SQL_COUNT_POLLSCHOICE);
2888
2889 count = (Long)q.uniqueResult();
2890
2891 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2892 FINDER_ARGS_EMPTY, count);
2893 }
2894 catch (Exception e) {
2895 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2896 FINDER_ARGS_EMPTY);
2897
2898 throw processException(e);
2899 }
2900 finally {
2901 closeSession(session);
2902 }
2903 }
2904
2905 return count.intValue();
2906 }
2907
2908 @Override
2909 protected Set<String> getBadColumnNames() {
2910 return _badColumnNames;
2911 }
2912
2913
2916 public void afterPropertiesSet() {
2917 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2918 com.liferay.portal.util.PropsUtil.get(
2919 "value.object.listener.com.liferay.portlet.polls.model.PollsChoice")));
2920
2921 if (listenerClassNames.length > 0) {
2922 try {
2923 List<ModelListener<PollsChoice>> listenersList = new ArrayList<ModelListener<PollsChoice>>();
2924
2925 for (String listenerClassName : listenerClassNames) {
2926 listenersList.add((ModelListener<PollsChoice>)InstanceFactory.newInstance(
2927 getClassLoader(), listenerClassName));
2928 }
2929
2930 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2931 }
2932 catch (Exception e) {
2933 _log.error(e);
2934 }
2935 }
2936 }
2937
2938 public void destroy() {
2939 EntityCacheUtil.removeCache(PollsChoiceImpl.class.getName());
2940 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2941 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2942 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2943 }
2944
2945 private static final String _SQL_SELECT_POLLSCHOICE = "SELECT pollsChoice FROM PollsChoice pollsChoice";
2946 private static final String _SQL_SELECT_POLLSCHOICE_WHERE = "SELECT pollsChoice FROM PollsChoice pollsChoice WHERE ";
2947 private static final String _SQL_COUNT_POLLSCHOICE = "SELECT COUNT(pollsChoice) FROM PollsChoice pollsChoice";
2948 private static final String _SQL_COUNT_POLLSCHOICE_WHERE = "SELECT COUNT(pollsChoice) FROM PollsChoice pollsChoice WHERE ";
2949 private static final String _ORDER_BY_ENTITY_ALIAS = "pollsChoice.";
2950 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsChoice exists with the primary key ";
2951 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsChoice exists with the key {";
2952 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2953 private static Log _log = LogFactoryUtil.getLog(PollsChoicePersistenceImpl.class);
2954 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2955 "uuid"
2956 });
2957 private static PollsChoice _nullPollsChoice = new PollsChoiceImpl() {
2958 @Override
2959 public Object clone() {
2960 return this;
2961 }
2962
2963 @Override
2964 public CacheModel<PollsChoice> toCacheModel() {
2965 return _nullPollsChoiceCacheModel;
2966 }
2967 };
2968
2969 private static CacheModel<PollsChoice> _nullPollsChoiceCacheModel = new CacheModel<PollsChoice>() {
2970 @Override
2971 public PollsChoice toEntityModel() {
2972 return _nullPollsChoice;
2973 }
2974 };
2975 }