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 public PollsChoicePersistenceImpl() {
2214 setModelClass(PollsChoice.class);
2215 }
2216
2217
2222 @Override
2223 public void cacheResult(PollsChoice pollsChoice) {
2224 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
2225 PollsChoiceImpl.class, pollsChoice.getPrimaryKey(), pollsChoice);
2226
2227 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2228 new Object[] { pollsChoice.getUuid(), pollsChoice.getGroupId() },
2229 pollsChoice);
2230
2231 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
2232 new Object[] { pollsChoice.getQuestionId(), pollsChoice.getName() },
2233 pollsChoice);
2234
2235 pollsChoice.resetOriginalValues();
2236 }
2237
2238
2243 @Override
2244 public void cacheResult(List<PollsChoice> pollsChoices) {
2245 for (PollsChoice pollsChoice : pollsChoices) {
2246 if (EntityCacheUtil.getResult(
2247 PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
2248 PollsChoiceImpl.class, pollsChoice.getPrimaryKey()) == null) {
2249 cacheResult(pollsChoice);
2250 }
2251 else {
2252 pollsChoice.resetOriginalValues();
2253 }
2254 }
2255 }
2256
2257
2264 @Override
2265 public void clearCache() {
2266 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2267 CacheRegistryUtil.clear(PollsChoiceImpl.class.getName());
2268 }
2269
2270 EntityCacheUtil.clearCache(PollsChoiceImpl.class.getName());
2271
2272 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2273 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2274 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2275 }
2276
2277
2284 @Override
2285 public void clearCache(PollsChoice pollsChoice) {
2286 EntityCacheUtil.removeResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
2287 PollsChoiceImpl.class, pollsChoice.getPrimaryKey());
2288
2289 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2290 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2291
2292 clearUniqueFindersCache(pollsChoice);
2293 }
2294
2295 @Override
2296 public void clearCache(List<PollsChoice> pollsChoices) {
2297 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2298 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2299
2300 for (PollsChoice pollsChoice : pollsChoices) {
2301 EntityCacheUtil.removeResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
2302 PollsChoiceImpl.class, pollsChoice.getPrimaryKey());
2303
2304 clearUniqueFindersCache(pollsChoice);
2305 }
2306 }
2307
2308 protected void cacheUniqueFindersCache(PollsChoice pollsChoice) {
2309 if (pollsChoice.isNew()) {
2310 Object[] args = new Object[] {
2311 pollsChoice.getUuid(), pollsChoice.getGroupId()
2312 };
2313
2314 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2315 Long.valueOf(1));
2316 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2317 pollsChoice);
2318
2319 args = new Object[] {
2320 pollsChoice.getQuestionId(), pollsChoice.getName()
2321 };
2322
2323 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_Q_N, args,
2324 Long.valueOf(1));
2325 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N, args,
2326 pollsChoice);
2327 }
2328 else {
2329 PollsChoiceModelImpl pollsChoiceModelImpl = (PollsChoiceModelImpl)pollsChoice;
2330
2331 if ((pollsChoiceModelImpl.getColumnBitmask() &
2332 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2333 Object[] args = new Object[] {
2334 pollsChoice.getUuid(), pollsChoice.getGroupId()
2335 };
2336
2337 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2338 Long.valueOf(1));
2339 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2340 pollsChoice);
2341 }
2342
2343 if ((pollsChoiceModelImpl.getColumnBitmask() &
2344 FINDER_PATH_FETCH_BY_Q_N.getColumnBitmask()) != 0) {
2345 Object[] args = new Object[] {
2346 pollsChoice.getQuestionId(), pollsChoice.getName()
2347 };
2348
2349 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_Q_N, args,
2350 Long.valueOf(1));
2351 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N, args,
2352 pollsChoice);
2353 }
2354 }
2355 }
2356
2357 protected void clearUniqueFindersCache(PollsChoice pollsChoice) {
2358 PollsChoiceModelImpl pollsChoiceModelImpl = (PollsChoiceModelImpl)pollsChoice;
2359
2360 Object[] args = new Object[] {
2361 pollsChoice.getUuid(), pollsChoice.getGroupId()
2362 };
2363
2364 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2365 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2366
2367 if ((pollsChoiceModelImpl.getColumnBitmask() &
2368 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2369 args = new Object[] {
2370 pollsChoiceModelImpl.getOriginalUuid(),
2371 pollsChoiceModelImpl.getOriginalGroupId()
2372 };
2373
2374 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2375 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2376 }
2377
2378 args = new Object[] { pollsChoice.getQuestionId(), pollsChoice.getName() };
2379
2380 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_Q_N, args);
2381 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N, args);
2382
2383 if ((pollsChoiceModelImpl.getColumnBitmask() &
2384 FINDER_PATH_FETCH_BY_Q_N.getColumnBitmask()) != 0) {
2385 args = new Object[] {
2386 pollsChoiceModelImpl.getOriginalQuestionId(),
2387 pollsChoiceModelImpl.getOriginalName()
2388 };
2389
2390 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_Q_N, args);
2391 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N, args);
2392 }
2393 }
2394
2395
2401 @Override
2402 public PollsChoice create(long choiceId) {
2403 PollsChoice pollsChoice = new PollsChoiceImpl();
2404
2405 pollsChoice.setNew(true);
2406 pollsChoice.setPrimaryKey(choiceId);
2407
2408 String uuid = PortalUUIDUtil.generate();
2409
2410 pollsChoice.setUuid(uuid);
2411
2412 return pollsChoice;
2413 }
2414
2415
2423 @Override
2424 public PollsChoice remove(long choiceId)
2425 throws NoSuchChoiceException, SystemException {
2426 return remove((Serializable)choiceId);
2427 }
2428
2429
2437 @Override
2438 public PollsChoice remove(Serializable primaryKey)
2439 throws NoSuchChoiceException, SystemException {
2440 Session session = null;
2441
2442 try {
2443 session = openSession();
2444
2445 PollsChoice pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
2446 primaryKey);
2447
2448 if (pollsChoice == null) {
2449 if (_log.isWarnEnabled()) {
2450 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2451 }
2452
2453 throw new NoSuchChoiceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2454 primaryKey);
2455 }
2456
2457 return remove(pollsChoice);
2458 }
2459 catch (NoSuchChoiceException nsee) {
2460 throw nsee;
2461 }
2462 catch (Exception e) {
2463 throw processException(e);
2464 }
2465 finally {
2466 closeSession(session);
2467 }
2468 }
2469
2470 @Override
2471 protected PollsChoice removeImpl(PollsChoice pollsChoice)
2472 throws SystemException {
2473 pollsChoice = toUnwrappedModel(pollsChoice);
2474
2475 Session session = null;
2476
2477 try {
2478 session = openSession();
2479
2480 if (!session.contains(pollsChoice)) {
2481 pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
2482 pollsChoice.getPrimaryKeyObj());
2483 }
2484
2485 if (pollsChoice != null) {
2486 session.delete(pollsChoice);
2487 }
2488 }
2489 catch (Exception e) {
2490 throw processException(e);
2491 }
2492 finally {
2493 closeSession(session);
2494 }
2495
2496 if (pollsChoice != null) {
2497 clearCache(pollsChoice);
2498 }
2499
2500 return pollsChoice;
2501 }
2502
2503 @Override
2504 public PollsChoice updateImpl(
2505 com.liferay.portlet.polls.model.PollsChoice pollsChoice)
2506 throws SystemException {
2507 pollsChoice = toUnwrappedModel(pollsChoice);
2508
2509 boolean isNew = pollsChoice.isNew();
2510
2511 PollsChoiceModelImpl pollsChoiceModelImpl = (PollsChoiceModelImpl)pollsChoice;
2512
2513 if (Validator.isNull(pollsChoice.getUuid())) {
2514 String uuid = PortalUUIDUtil.generate();
2515
2516 pollsChoice.setUuid(uuid);
2517 }
2518
2519 Session session = null;
2520
2521 try {
2522 session = openSession();
2523
2524 if (pollsChoice.isNew()) {
2525 session.save(pollsChoice);
2526
2527 pollsChoice.setNew(false);
2528 }
2529 else {
2530 session.merge(pollsChoice);
2531 }
2532 }
2533 catch (Exception e) {
2534 throw processException(e);
2535 }
2536 finally {
2537 closeSession(session);
2538 }
2539
2540 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2541
2542 if (isNew || !PollsChoiceModelImpl.COLUMN_BITMASK_ENABLED) {
2543 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2544 }
2545
2546 else {
2547 if ((pollsChoiceModelImpl.getColumnBitmask() &
2548 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2549 Object[] args = new Object[] {
2550 pollsChoiceModelImpl.getOriginalUuid()
2551 };
2552
2553 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2554 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2555 args);
2556
2557 args = new Object[] { pollsChoiceModelImpl.getUuid() };
2558
2559 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2560 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2561 args);
2562 }
2563
2564 if ((pollsChoiceModelImpl.getColumnBitmask() &
2565 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2566 Object[] args = new Object[] {
2567 pollsChoiceModelImpl.getOriginalUuid(),
2568 pollsChoiceModelImpl.getOriginalCompanyId()
2569 };
2570
2571 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2572 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2573 args);
2574
2575 args = new Object[] {
2576 pollsChoiceModelImpl.getUuid(),
2577 pollsChoiceModelImpl.getCompanyId()
2578 };
2579
2580 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2581 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2582 args);
2583 }
2584
2585 if ((pollsChoiceModelImpl.getColumnBitmask() &
2586 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID.getColumnBitmask()) != 0) {
2587 Object[] args = new Object[] {
2588 pollsChoiceModelImpl.getOriginalQuestionId()
2589 };
2590
2591 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
2592 args);
2593 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
2594 args);
2595
2596 args = new Object[] { pollsChoiceModelImpl.getQuestionId() };
2597
2598 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
2599 args);
2600 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
2601 args);
2602 }
2603 }
2604
2605 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
2606 PollsChoiceImpl.class, pollsChoice.getPrimaryKey(), pollsChoice);
2607
2608 clearUniqueFindersCache(pollsChoice);
2609 cacheUniqueFindersCache(pollsChoice);
2610
2611 return pollsChoice;
2612 }
2613
2614 protected PollsChoice toUnwrappedModel(PollsChoice pollsChoice) {
2615 if (pollsChoice instanceof PollsChoiceImpl) {
2616 return pollsChoice;
2617 }
2618
2619 PollsChoiceImpl pollsChoiceImpl = new PollsChoiceImpl();
2620
2621 pollsChoiceImpl.setNew(pollsChoice.isNew());
2622 pollsChoiceImpl.setPrimaryKey(pollsChoice.getPrimaryKey());
2623
2624 pollsChoiceImpl.setUuid(pollsChoice.getUuid());
2625 pollsChoiceImpl.setChoiceId(pollsChoice.getChoiceId());
2626 pollsChoiceImpl.setGroupId(pollsChoice.getGroupId());
2627 pollsChoiceImpl.setCompanyId(pollsChoice.getCompanyId());
2628 pollsChoiceImpl.setUserId(pollsChoice.getUserId());
2629 pollsChoiceImpl.setUserName(pollsChoice.getUserName());
2630 pollsChoiceImpl.setCreateDate(pollsChoice.getCreateDate());
2631 pollsChoiceImpl.setModifiedDate(pollsChoice.getModifiedDate());
2632 pollsChoiceImpl.setQuestionId(pollsChoice.getQuestionId());
2633 pollsChoiceImpl.setName(pollsChoice.getName());
2634 pollsChoiceImpl.setDescription(pollsChoice.getDescription());
2635
2636 return pollsChoiceImpl;
2637 }
2638
2639
2647 @Override
2648 public PollsChoice findByPrimaryKey(Serializable primaryKey)
2649 throws NoSuchChoiceException, SystemException {
2650 PollsChoice pollsChoice = fetchByPrimaryKey(primaryKey);
2651
2652 if (pollsChoice == null) {
2653 if (_log.isWarnEnabled()) {
2654 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2655 }
2656
2657 throw new NoSuchChoiceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2658 primaryKey);
2659 }
2660
2661 return pollsChoice;
2662 }
2663
2664
2672 @Override
2673 public PollsChoice findByPrimaryKey(long choiceId)
2674 throws NoSuchChoiceException, SystemException {
2675 return findByPrimaryKey((Serializable)choiceId);
2676 }
2677
2678
2685 @Override
2686 public PollsChoice fetchByPrimaryKey(Serializable primaryKey)
2687 throws SystemException {
2688 PollsChoice pollsChoice = (PollsChoice)EntityCacheUtil.getResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
2689 PollsChoiceImpl.class, primaryKey);
2690
2691 if (pollsChoice == _nullPollsChoice) {
2692 return null;
2693 }
2694
2695 if (pollsChoice == null) {
2696 Session session = null;
2697
2698 try {
2699 session = openSession();
2700
2701 pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
2702 primaryKey);
2703
2704 if (pollsChoice != null) {
2705 cacheResult(pollsChoice);
2706 }
2707 else {
2708 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
2709 PollsChoiceImpl.class, primaryKey, _nullPollsChoice);
2710 }
2711 }
2712 catch (Exception e) {
2713 EntityCacheUtil.removeResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
2714 PollsChoiceImpl.class, primaryKey);
2715
2716 throw processException(e);
2717 }
2718 finally {
2719 closeSession(session);
2720 }
2721 }
2722
2723 return pollsChoice;
2724 }
2725
2726
2733 @Override
2734 public PollsChoice fetchByPrimaryKey(long choiceId)
2735 throws SystemException {
2736 return fetchByPrimaryKey((Serializable)choiceId);
2737 }
2738
2739
2745 @Override
2746 public List<PollsChoice> findAll() throws SystemException {
2747 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2748 }
2749
2750
2762 @Override
2763 public List<PollsChoice> findAll(int start, int end)
2764 throws SystemException {
2765 return findAll(start, end, null);
2766 }
2767
2768
2781 @Override
2782 public List<PollsChoice> findAll(int start, int end,
2783 OrderByComparator orderByComparator) throws SystemException {
2784 boolean pagination = true;
2785 FinderPath finderPath = null;
2786 Object[] finderArgs = null;
2787
2788 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2789 (orderByComparator == null)) {
2790 pagination = false;
2791 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2792 finderArgs = FINDER_ARGS_EMPTY;
2793 }
2794 else {
2795 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2796 finderArgs = new Object[] { start, end, orderByComparator };
2797 }
2798
2799 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
2800 finderArgs, this);
2801
2802 if (list == null) {
2803 StringBundler query = null;
2804 String sql = null;
2805
2806 if (orderByComparator != null) {
2807 query = new StringBundler(2 +
2808 (orderByComparator.getOrderByFields().length * 3));
2809
2810 query.append(_SQL_SELECT_POLLSCHOICE);
2811
2812 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2813 orderByComparator);
2814
2815 sql = query.toString();
2816 }
2817 else {
2818 sql = _SQL_SELECT_POLLSCHOICE;
2819
2820 if (pagination) {
2821 sql = sql.concat(PollsChoiceModelImpl.ORDER_BY_JPQL);
2822 }
2823 }
2824
2825 Session session = null;
2826
2827 try {
2828 session = openSession();
2829
2830 Query q = session.createQuery(sql);
2831
2832 if (!pagination) {
2833 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
2834 start, end, false);
2835
2836 Collections.sort(list);
2837
2838 list = new UnmodifiableList<PollsChoice>(list);
2839 }
2840 else {
2841 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
2842 start, end);
2843 }
2844
2845 cacheResult(list);
2846
2847 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2848 }
2849 catch (Exception e) {
2850 FinderCacheUtil.removeResult(finderPath, finderArgs);
2851
2852 throw processException(e);
2853 }
2854 finally {
2855 closeSession(session);
2856 }
2857 }
2858
2859 return list;
2860 }
2861
2862
2867 @Override
2868 public void removeAll() throws SystemException {
2869 for (PollsChoice pollsChoice : findAll()) {
2870 remove(pollsChoice);
2871 }
2872 }
2873
2874
2880 @Override
2881 public int countAll() throws SystemException {
2882 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2883 FINDER_ARGS_EMPTY, this);
2884
2885 if (count == null) {
2886 Session session = null;
2887
2888 try {
2889 session = openSession();
2890
2891 Query q = session.createQuery(_SQL_COUNT_POLLSCHOICE);
2892
2893 count = (Long)q.uniqueResult();
2894
2895 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2896 FINDER_ARGS_EMPTY, count);
2897 }
2898 catch (Exception e) {
2899 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2900 FINDER_ARGS_EMPTY);
2901
2902 throw processException(e);
2903 }
2904 finally {
2905 closeSession(session);
2906 }
2907 }
2908
2909 return count.intValue();
2910 }
2911
2912 @Override
2913 protected Set<String> getBadColumnNames() {
2914 return _badColumnNames;
2915 }
2916
2917
2920 public void afterPropertiesSet() {
2921 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2922 com.liferay.portal.util.PropsUtil.get(
2923 "value.object.listener.com.liferay.portlet.polls.model.PollsChoice")));
2924
2925 if (listenerClassNames.length > 0) {
2926 try {
2927 List<ModelListener<PollsChoice>> listenersList = new ArrayList<ModelListener<PollsChoice>>();
2928
2929 for (String listenerClassName : listenerClassNames) {
2930 listenersList.add((ModelListener<PollsChoice>)InstanceFactory.newInstance(
2931 getClassLoader(), listenerClassName));
2932 }
2933
2934 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2935 }
2936 catch (Exception e) {
2937 _log.error(e);
2938 }
2939 }
2940 }
2941
2942 public void destroy() {
2943 EntityCacheUtil.removeCache(PollsChoiceImpl.class.getName());
2944 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2945 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2946 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2947 }
2948
2949 private static final String _SQL_SELECT_POLLSCHOICE = "SELECT pollsChoice FROM PollsChoice pollsChoice";
2950 private static final String _SQL_SELECT_POLLSCHOICE_WHERE = "SELECT pollsChoice FROM PollsChoice pollsChoice WHERE ";
2951 private static final String _SQL_COUNT_POLLSCHOICE = "SELECT COUNT(pollsChoice) FROM PollsChoice pollsChoice";
2952 private static final String _SQL_COUNT_POLLSCHOICE_WHERE = "SELECT COUNT(pollsChoice) FROM PollsChoice pollsChoice WHERE ";
2953 private static final String _ORDER_BY_ENTITY_ALIAS = "pollsChoice.";
2954 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsChoice exists with the primary key ";
2955 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsChoice exists with the key {";
2956 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2957 private static Log _log = LogFactoryUtil.getLog(PollsChoicePersistenceImpl.class);
2958 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2959 "uuid"
2960 });
2961 private static PollsChoice _nullPollsChoice = new PollsChoiceImpl() {
2962 @Override
2963 public Object clone() {
2964 return this;
2965 }
2966
2967 @Override
2968 public CacheModel<PollsChoice> toCacheModel() {
2969 return _nullPollsChoiceCacheModel;
2970 }
2971 };
2972
2973 private static CacheModel<PollsChoice> _nullPollsChoiceCacheModel = new CacheModel<PollsChoice>() {
2974 @Override
2975 public PollsChoice toEntityModel() {
2976 return _nullPollsChoice;
2977 }
2978 };
2979 }