001
014
015 package com.liferay.portlet.polls.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.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.BatchSessionUtil;
041 import com.liferay.portal.service.persistence.ResourcePersistence;
042 import com.liferay.portal.service.persistence.UserPersistence;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import com.liferay.portlet.polls.NoSuchChoiceException;
046 import com.liferay.portlet.polls.model.PollsChoice;
047 import com.liferay.portlet.polls.model.impl.PollsChoiceImpl;
048 import com.liferay.portlet.polls.model.impl.PollsChoiceModelImpl;
049
050 import java.io.Serializable;
051
052 import java.util.ArrayList;
053 import java.util.Collections;
054 import java.util.List;
055
056
068 public class PollsChoicePersistenceImpl extends BasePersistenceImpl<PollsChoice>
069 implements PollsChoicePersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = PollsChoiceImpl.class.getName();
076 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List1";
078 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List2";
080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
081 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
082 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
083 new String[] {
084 String.class.getName(),
085
086 "java.lang.Integer", "java.lang.Integer",
087 "com.liferay.portal.kernel.util.OrderByComparator"
088 });
089 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
090 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
091 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
092 new String[] { String.class.getName() },
093 PollsChoiceModelImpl.UUID_COLUMN_BITMASK);
094 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
095 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
096 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
097 new String[] { String.class.getName() });
098 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_QUESTIONID =
099 new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
100 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
101 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByQuestionId",
102 new String[] {
103 Long.class.getName(),
104
105 "java.lang.Integer", "java.lang.Integer",
106 "com.liferay.portal.kernel.util.OrderByComparator"
107 });
108 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID =
109 new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
110 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
111 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByQuestionId",
112 new String[] { Long.class.getName() },
113 PollsChoiceModelImpl.QUESTIONID_COLUMN_BITMASK);
114 public static final FinderPath FINDER_PATH_COUNT_BY_QUESTIONID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
115 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
116 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByQuestionId",
117 new String[] { Long.class.getName() });
118 public static final FinderPath FINDER_PATH_FETCH_BY_Q_N = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
119 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
120 FINDER_CLASS_NAME_ENTITY, "fetchByQ_N",
121 new String[] { Long.class.getName(), String.class.getName() },
122 PollsChoiceModelImpl.QUESTIONID_COLUMN_BITMASK |
123 PollsChoiceModelImpl.NAME_COLUMN_BITMASK);
124 public static final FinderPath FINDER_PATH_COUNT_BY_Q_N = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
125 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
126 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByQ_N",
127 new String[] { Long.class.getName(), String.class.getName() });
128 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
129 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
130 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
131 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
132 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
133 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
134 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
135 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
136 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
137
138
143 public void cacheResult(PollsChoice pollsChoice) {
144 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
145 PollsChoiceImpl.class, pollsChoice.getPrimaryKey(), pollsChoice);
146
147 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
148 new Object[] {
149 Long.valueOf(pollsChoice.getQuestionId()),
150
151 pollsChoice.getName()
152 }, pollsChoice);
153
154 pollsChoice.resetOriginalValues();
155 }
156
157
162 public void cacheResult(List<PollsChoice> pollsChoices) {
163 for (PollsChoice pollsChoice : pollsChoices) {
164 if (EntityCacheUtil.getResult(
165 PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
166 PollsChoiceImpl.class, pollsChoice.getPrimaryKey()) == null) {
167 cacheResult(pollsChoice);
168 }
169 else {
170 pollsChoice.resetOriginalValues();
171 }
172 }
173 }
174
175
182 @Override
183 public void clearCache() {
184 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
185 CacheRegistryUtil.clear(PollsChoiceImpl.class.getName());
186 }
187
188 EntityCacheUtil.clearCache(PollsChoiceImpl.class.getName());
189
190 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
191 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
192 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
193 }
194
195
202 @Override
203 public void clearCache(PollsChoice pollsChoice) {
204 EntityCacheUtil.removeResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
205 PollsChoiceImpl.class, pollsChoice.getPrimaryKey());
206
207 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
208 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
209
210 clearUniqueFindersCache(pollsChoice);
211 }
212
213 @Override
214 public void clearCache(List<PollsChoice> pollsChoices) {
215 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
216 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
217
218 for (PollsChoice pollsChoice : pollsChoices) {
219 EntityCacheUtil.removeResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
220 PollsChoiceImpl.class, pollsChoice.getPrimaryKey());
221
222 clearUniqueFindersCache(pollsChoice);
223 }
224 }
225
226 protected void clearUniqueFindersCache(PollsChoice pollsChoice) {
227 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N,
228 new Object[] {
229 Long.valueOf(pollsChoice.getQuestionId()),
230
231 pollsChoice.getName()
232 });
233 }
234
235
241 public PollsChoice create(long choiceId) {
242 PollsChoice pollsChoice = new PollsChoiceImpl();
243
244 pollsChoice.setNew(true);
245 pollsChoice.setPrimaryKey(choiceId);
246
247 String uuid = PortalUUIDUtil.generate();
248
249 pollsChoice.setUuid(uuid);
250
251 return pollsChoice;
252 }
253
254
262 public PollsChoice remove(long choiceId)
263 throws NoSuchChoiceException, SystemException {
264 return remove(Long.valueOf(choiceId));
265 }
266
267
275 @Override
276 public PollsChoice remove(Serializable primaryKey)
277 throws NoSuchChoiceException, SystemException {
278 Session session = null;
279
280 try {
281 session = openSession();
282
283 PollsChoice pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
284 primaryKey);
285
286 if (pollsChoice == null) {
287 if (_log.isWarnEnabled()) {
288 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
289 }
290
291 throw new NoSuchChoiceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
292 primaryKey);
293 }
294
295 return remove(pollsChoice);
296 }
297 catch (NoSuchChoiceException nsee) {
298 throw nsee;
299 }
300 catch (Exception e) {
301 throw processException(e);
302 }
303 finally {
304 closeSession(session);
305 }
306 }
307
308 @Override
309 protected PollsChoice removeImpl(PollsChoice pollsChoice)
310 throws SystemException {
311 pollsChoice = toUnwrappedModel(pollsChoice);
312
313 Session session = null;
314
315 try {
316 session = openSession();
317
318 BatchSessionUtil.delete(session, pollsChoice);
319 }
320 catch (Exception e) {
321 throw processException(e);
322 }
323 finally {
324 closeSession(session);
325 }
326
327 clearCache(pollsChoice);
328
329 return pollsChoice;
330 }
331
332 @Override
333 public PollsChoice updateImpl(
334 com.liferay.portlet.polls.model.PollsChoice pollsChoice, boolean merge)
335 throws SystemException {
336 pollsChoice = toUnwrappedModel(pollsChoice);
337
338 boolean isNew = pollsChoice.isNew();
339
340 PollsChoiceModelImpl pollsChoiceModelImpl = (PollsChoiceModelImpl)pollsChoice;
341
342 if (Validator.isNull(pollsChoice.getUuid())) {
343 String uuid = PortalUUIDUtil.generate();
344
345 pollsChoice.setUuid(uuid);
346 }
347
348 Session session = null;
349
350 try {
351 session = openSession();
352
353 BatchSessionUtil.update(session, pollsChoice, merge);
354
355 pollsChoice.setNew(false);
356 }
357 catch (Exception e) {
358 throw processException(e);
359 }
360 finally {
361 closeSession(session);
362 }
363
364 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
365
366 if (isNew || !PollsChoiceModelImpl.COLUMN_BITMASK_ENABLED) {
367 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
368 }
369 else {
370 if ((pollsChoiceModelImpl.getColumnBitmask() &
371 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
372 Object[] args = new Object[] {
373 pollsChoiceModelImpl.getOriginalUuid()
374 };
375
376 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
377 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
378 args);
379
380 args = new Object[] { pollsChoiceModelImpl.getUuid() };
381
382 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
383 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
384 args);
385 }
386
387 if ((pollsChoiceModelImpl.getColumnBitmask() &
388 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID.getColumnBitmask()) != 0) {
389 Object[] args = new Object[] {
390 Long.valueOf(pollsChoiceModelImpl.getOriginalQuestionId())
391 };
392
393 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
394 args);
395 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
396 args);
397
398 args = new Object[] {
399 Long.valueOf(pollsChoiceModelImpl.getQuestionId())
400 };
401
402 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
403 args);
404 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
405 args);
406 }
407 }
408
409 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
410 PollsChoiceImpl.class, pollsChoice.getPrimaryKey(), pollsChoice);
411
412 if (isNew) {
413 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
414 new Object[] {
415 Long.valueOf(pollsChoice.getQuestionId()),
416
417 pollsChoice.getName()
418 }, pollsChoice);
419 }
420 else {
421 if ((pollsChoiceModelImpl.getColumnBitmask() &
422 FINDER_PATH_FETCH_BY_Q_N.getColumnBitmask()) != 0) {
423 Object[] args = new Object[] {
424 Long.valueOf(pollsChoiceModelImpl.getOriginalQuestionId()),
425
426 pollsChoiceModelImpl.getOriginalName()
427 };
428
429 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_Q_N, args);
430 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N, args);
431
432 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
433 new Object[] {
434 Long.valueOf(pollsChoice.getQuestionId()),
435
436 pollsChoice.getName()
437 }, pollsChoice);
438 }
439 }
440
441 return pollsChoice;
442 }
443
444 protected PollsChoice toUnwrappedModel(PollsChoice pollsChoice) {
445 if (pollsChoice instanceof PollsChoiceImpl) {
446 return pollsChoice;
447 }
448
449 PollsChoiceImpl pollsChoiceImpl = new PollsChoiceImpl();
450
451 pollsChoiceImpl.setNew(pollsChoice.isNew());
452 pollsChoiceImpl.setPrimaryKey(pollsChoice.getPrimaryKey());
453
454 pollsChoiceImpl.setUuid(pollsChoice.getUuid());
455 pollsChoiceImpl.setChoiceId(pollsChoice.getChoiceId());
456 pollsChoiceImpl.setQuestionId(pollsChoice.getQuestionId());
457 pollsChoiceImpl.setName(pollsChoice.getName());
458 pollsChoiceImpl.setDescription(pollsChoice.getDescription());
459
460 return pollsChoiceImpl;
461 }
462
463
471 @Override
472 public PollsChoice findByPrimaryKey(Serializable primaryKey)
473 throws NoSuchModelException, SystemException {
474 return findByPrimaryKey(((Long)primaryKey).longValue());
475 }
476
477
485 public PollsChoice findByPrimaryKey(long choiceId)
486 throws NoSuchChoiceException, SystemException {
487 PollsChoice pollsChoice = fetchByPrimaryKey(choiceId);
488
489 if (pollsChoice == null) {
490 if (_log.isWarnEnabled()) {
491 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + choiceId);
492 }
493
494 throw new NoSuchChoiceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
495 choiceId);
496 }
497
498 return pollsChoice;
499 }
500
501
508 @Override
509 public PollsChoice fetchByPrimaryKey(Serializable primaryKey)
510 throws SystemException {
511 return fetchByPrimaryKey(((Long)primaryKey).longValue());
512 }
513
514
521 public PollsChoice fetchByPrimaryKey(long choiceId)
522 throws SystemException {
523 PollsChoice pollsChoice = (PollsChoice)EntityCacheUtil.getResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
524 PollsChoiceImpl.class, choiceId);
525
526 if (pollsChoice == _nullPollsChoice) {
527 return null;
528 }
529
530 if (pollsChoice == null) {
531 Session session = null;
532
533 boolean hasException = false;
534
535 try {
536 session = openSession();
537
538 pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
539 Long.valueOf(choiceId));
540 }
541 catch (Exception e) {
542 hasException = true;
543
544 throw processException(e);
545 }
546 finally {
547 if (pollsChoice != null) {
548 cacheResult(pollsChoice);
549 }
550 else if (!hasException) {
551 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
552 PollsChoiceImpl.class, choiceId, _nullPollsChoice);
553 }
554
555 closeSession(session);
556 }
557 }
558
559 return pollsChoice;
560 }
561
562
569 public List<PollsChoice> findByUuid(String uuid) throws SystemException {
570 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
571 }
572
573
586 public List<PollsChoice> findByUuid(String uuid, int start, int end)
587 throws SystemException {
588 return findByUuid(uuid, start, end, null);
589 }
590
591
605 public List<PollsChoice> findByUuid(String uuid, int start, int end,
606 OrderByComparator orderByComparator) throws SystemException {
607 FinderPath finderPath = null;
608 Object[] finderArgs = null;
609
610 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
611 (orderByComparator == null)) {
612 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
613 finderArgs = new Object[] { uuid };
614 }
615 else {
616 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
617 finderArgs = new Object[] { uuid, start, end, orderByComparator };
618 }
619
620 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
621 finderArgs, this);
622
623 if ((list != null) && !list.isEmpty()) {
624 for (PollsChoice pollsChoice : list) {
625 if (!Validator.equals(uuid, pollsChoice.getUuid())) {
626 list = null;
627
628 break;
629 }
630 }
631 }
632
633 if (list == null) {
634 StringBundler query = null;
635
636 if (orderByComparator != null) {
637 query = new StringBundler(3 +
638 (orderByComparator.getOrderByFields().length * 3));
639 }
640 else {
641 query = new StringBundler(3);
642 }
643
644 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
645
646 if (uuid == null) {
647 query.append(_FINDER_COLUMN_UUID_UUID_1);
648 }
649 else {
650 if (uuid.equals(StringPool.BLANK)) {
651 query.append(_FINDER_COLUMN_UUID_UUID_3);
652 }
653 else {
654 query.append(_FINDER_COLUMN_UUID_UUID_2);
655 }
656 }
657
658 if (orderByComparator != null) {
659 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
660 orderByComparator);
661 }
662
663 else {
664 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
665 }
666
667 String sql = query.toString();
668
669 Session session = null;
670
671 try {
672 session = openSession();
673
674 Query q = session.createQuery(sql);
675
676 QueryPos qPos = QueryPos.getInstance(q);
677
678 if (uuid != null) {
679 qPos.add(uuid);
680 }
681
682 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
683 start, end);
684 }
685 catch (Exception e) {
686 throw processException(e);
687 }
688 finally {
689 if (list == null) {
690 FinderCacheUtil.removeResult(finderPath, finderArgs);
691 }
692 else {
693 cacheResult(list);
694
695 FinderCacheUtil.putResult(finderPath, finderArgs, list);
696 }
697
698 closeSession(session);
699 }
700 }
701
702 return list;
703 }
704
705
718 public PollsChoice findByUuid_First(String uuid,
719 OrderByComparator orderByComparator)
720 throws NoSuchChoiceException, SystemException {
721 List<PollsChoice> list = findByUuid(uuid, 0, 1, orderByComparator);
722
723 if (list.isEmpty()) {
724 StringBundler msg = new StringBundler(4);
725
726 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
727
728 msg.append("uuid=");
729 msg.append(uuid);
730
731 msg.append(StringPool.CLOSE_CURLY_BRACE);
732
733 throw new NoSuchChoiceException(msg.toString());
734 }
735 else {
736 return list.get(0);
737 }
738 }
739
740
753 public PollsChoice findByUuid_Last(String uuid,
754 OrderByComparator orderByComparator)
755 throws NoSuchChoiceException, SystemException {
756 int count = countByUuid(uuid);
757
758 List<PollsChoice> list = findByUuid(uuid, count - 1, count,
759 orderByComparator);
760
761 if (list.isEmpty()) {
762 StringBundler msg = new StringBundler(4);
763
764 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
765
766 msg.append("uuid=");
767 msg.append(uuid);
768
769 msg.append(StringPool.CLOSE_CURLY_BRACE);
770
771 throw new NoSuchChoiceException(msg.toString());
772 }
773 else {
774 return list.get(0);
775 }
776 }
777
778
792 public PollsChoice[] findByUuid_PrevAndNext(long choiceId, String uuid,
793 OrderByComparator orderByComparator)
794 throws NoSuchChoiceException, SystemException {
795 PollsChoice pollsChoice = findByPrimaryKey(choiceId);
796
797 Session session = null;
798
799 try {
800 session = openSession();
801
802 PollsChoice[] array = new PollsChoiceImpl[3];
803
804 array[0] = getByUuid_PrevAndNext(session, pollsChoice, uuid,
805 orderByComparator, true);
806
807 array[1] = pollsChoice;
808
809 array[2] = getByUuid_PrevAndNext(session, pollsChoice, uuid,
810 orderByComparator, false);
811
812 return array;
813 }
814 catch (Exception e) {
815 throw processException(e);
816 }
817 finally {
818 closeSession(session);
819 }
820 }
821
822 protected PollsChoice getByUuid_PrevAndNext(Session session,
823 PollsChoice pollsChoice, String uuid,
824 OrderByComparator orderByComparator, boolean previous) {
825 StringBundler query = null;
826
827 if (orderByComparator != null) {
828 query = new StringBundler(6 +
829 (orderByComparator.getOrderByFields().length * 6));
830 }
831 else {
832 query = new StringBundler(3);
833 }
834
835 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
836
837 if (uuid == null) {
838 query.append(_FINDER_COLUMN_UUID_UUID_1);
839 }
840 else {
841 if (uuid.equals(StringPool.BLANK)) {
842 query.append(_FINDER_COLUMN_UUID_UUID_3);
843 }
844 else {
845 query.append(_FINDER_COLUMN_UUID_UUID_2);
846 }
847 }
848
849 if (orderByComparator != null) {
850 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
851
852 if (orderByConditionFields.length > 0) {
853 query.append(WHERE_AND);
854 }
855
856 for (int i = 0; i < orderByConditionFields.length; i++) {
857 query.append(_ORDER_BY_ENTITY_ALIAS);
858 query.append(orderByConditionFields[i]);
859
860 if ((i + 1) < orderByConditionFields.length) {
861 if (orderByComparator.isAscending() ^ previous) {
862 query.append(WHERE_GREATER_THAN_HAS_NEXT);
863 }
864 else {
865 query.append(WHERE_LESSER_THAN_HAS_NEXT);
866 }
867 }
868 else {
869 if (orderByComparator.isAscending() ^ previous) {
870 query.append(WHERE_GREATER_THAN);
871 }
872 else {
873 query.append(WHERE_LESSER_THAN);
874 }
875 }
876 }
877
878 query.append(ORDER_BY_CLAUSE);
879
880 String[] orderByFields = orderByComparator.getOrderByFields();
881
882 for (int i = 0; i < orderByFields.length; i++) {
883 query.append(_ORDER_BY_ENTITY_ALIAS);
884 query.append(orderByFields[i]);
885
886 if ((i + 1) < orderByFields.length) {
887 if (orderByComparator.isAscending() ^ previous) {
888 query.append(ORDER_BY_ASC_HAS_NEXT);
889 }
890 else {
891 query.append(ORDER_BY_DESC_HAS_NEXT);
892 }
893 }
894 else {
895 if (orderByComparator.isAscending() ^ previous) {
896 query.append(ORDER_BY_ASC);
897 }
898 else {
899 query.append(ORDER_BY_DESC);
900 }
901 }
902 }
903 }
904
905 else {
906 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
907 }
908
909 String sql = query.toString();
910
911 Query q = session.createQuery(sql);
912
913 q.setFirstResult(0);
914 q.setMaxResults(2);
915
916 QueryPos qPos = QueryPos.getInstance(q);
917
918 if (uuid != null) {
919 qPos.add(uuid);
920 }
921
922 if (orderByComparator != null) {
923 Object[] values = orderByComparator.getOrderByConditionValues(pollsChoice);
924
925 for (Object value : values) {
926 qPos.add(value);
927 }
928 }
929
930 List<PollsChoice> list = q.list();
931
932 if (list.size() == 2) {
933 return list.get(1);
934 }
935 else {
936 return null;
937 }
938 }
939
940
947 public List<PollsChoice> findByQuestionId(long questionId)
948 throws SystemException {
949 return findByQuestionId(questionId, QueryUtil.ALL_POS,
950 QueryUtil.ALL_POS, null);
951 }
952
953
966 public List<PollsChoice> findByQuestionId(long questionId, int start,
967 int end) throws SystemException {
968 return findByQuestionId(questionId, start, end, null);
969 }
970
971
985 public List<PollsChoice> findByQuestionId(long questionId, int start,
986 int end, OrderByComparator orderByComparator) throws SystemException {
987 FinderPath finderPath = null;
988 Object[] finderArgs = null;
989
990 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
991 (orderByComparator == null)) {
992 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID;
993 finderArgs = new Object[] { questionId };
994 }
995 else {
996 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_QUESTIONID;
997 finderArgs = new Object[] { questionId, start, end, orderByComparator };
998 }
999
1000 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
1001 finderArgs, this);
1002
1003 if ((list != null) && !list.isEmpty()) {
1004 for (PollsChoice pollsChoice : list) {
1005 if ((questionId != pollsChoice.getQuestionId())) {
1006 list = null;
1007
1008 break;
1009 }
1010 }
1011 }
1012
1013 if (list == null) {
1014 StringBundler query = null;
1015
1016 if (orderByComparator != null) {
1017 query = new StringBundler(3 +
1018 (orderByComparator.getOrderByFields().length * 3));
1019 }
1020 else {
1021 query = new StringBundler(3);
1022 }
1023
1024 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
1025
1026 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1027
1028 if (orderByComparator != null) {
1029 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1030 orderByComparator);
1031 }
1032
1033 else {
1034 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
1035 }
1036
1037 String sql = query.toString();
1038
1039 Session session = null;
1040
1041 try {
1042 session = openSession();
1043
1044 Query q = session.createQuery(sql);
1045
1046 QueryPos qPos = QueryPos.getInstance(q);
1047
1048 qPos.add(questionId);
1049
1050 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1051 start, end);
1052 }
1053 catch (Exception e) {
1054 throw processException(e);
1055 }
1056 finally {
1057 if (list == null) {
1058 FinderCacheUtil.removeResult(finderPath, finderArgs);
1059 }
1060 else {
1061 cacheResult(list);
1062
1063 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1064 }
1065
1066 closeSession(session);
1067 }
1068 }
1069
1070 return list;
1071 }
1072
1073
1086 public PollsChoice findByQuestionId_First(long questionId,
1087 OrderByComparator orderByComparator)
1088 throws NoSuchChoiceException, SystemException {
1089 List<PollsChoice> list = findByQuestionId(questionId, 0, 1,
1090 orderByComparator);
1091
1092 if (list.isEmpty()) {
1093 StringBundler msg = new StringBundler(4);
1094
1095 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1096
1097 msg.append("questionId=");
1098 msg.append(questionId);
1099
1100 msg.append(StringPool.CLOSE_CURLY_BRACE);
1101
1102 throw new NoSuchChoiceException(msg.toString());
1103 }
1104 else {
1105 return list.get(0);
1106 }
1107 }
1108
1109
1122 public PollsChoice findByQuestionId_Last(long questionId,
1123 OrderByComparator orderByComparator)
1124 throws NoSuchChoiceException, SystemException {
1125 int count = countByQuestionId(questionId);
1126
1127 List<PollsChoice> list = findByQuestionId(questionId, count - 1, count,
1128 orderByComparator);
1129
1130 if (list.isEmpty()) {
1131 StringBundler msg = new StringBundler(4);
1132
1133 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1134
1135 msg.append("questionId=");
1136 msg.append(questionId);
1137
1138 msg.append(StringPool.CLOSE_CURLY_BRACE);
1139
1140 throw new NoSuchChoiceException(msg.toString());
1141 }
1142 else {
1143 return list.get(0);
1144 }
1145 }
1146
1147
1161 public PollsChoice[] findByQuestionId_PrevAndNext(long choiceId,
1162 long questionId, OrderByComparator orderByComparator)
1163 throws NoSuchChoiceException, SystemException {
1164 PollsChoice pollsChoice = findByPrimaryKey(choiceId);
1165
1166 Session session = null;
1167
1168 try {
1169 session = openSession();
1170
1171 PollsChoice[] array = new PollsChoiceImpl[3];
1172
1173 array[0] = getByQuestionId_PrevAndNext(session, pollsChoice,
1174 questionId, orderByComparator, true);
1175
1176 array[1] = pollsChoice;
1177
1178 array[2] = getByQuestionId_PrevAndNext(session, pollsChoice,
1179 questionId, orderByComparator, false);
1180
1181 return array;
1182 }
1183 catch (Exception e) {
1184 throw processException(e);
1185 }
1186 finally {
1187 closeSession(session);
1188 }
1189 }
1190
1191 protected PollsChoice getByQuestionId_PrevAndNext(Session session,
1192 PollsChoice pollsChoice, long questionId,
1193 OrderByComparator orderByComparator, boolean previous) {
1194 StringBundler query = null;
1195
1196 if (orderByComparator != null) {
1197 query = new StringBundler(6 +
1198 (orderByComparator.getOrderByFields().length * 6));
1199 }
1200 else {
1201 query = new StringBundler(3);
1202 }
1203
1204 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
1205
1206 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1207
1208 if (orderByComparator != null) {
1209 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1210
1211 if (orderByConditionFields.length > 0) {
1212 query.append(WHERE_AND);
1213 }
1214
1215 for (int i = 0; i < orderByConditionFields.length; i++) {
1216 query.append(_ORDER_BY_ENTITY_ALIAS);
1217 query.append(orderByConditionFields[i]);
1218
1219 if ((i + 1) < orderByConditionFields.length) {
1220 if (orderByComparator.isAscending() ^ previous) {
1221 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1222 }
1223 else {
1224 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1225 }
1226 }
1227 else {
1228 if (orderByComparator.isAscending() ^ previous) {
1229 query.append(WHERE_GREATER_THAN);
1230 }
1231 else {
1232 query.append(WHERE_LESSER_THAN);
1233 }
1234 }
1235 }
1236
1237 query.append(ORDER_BY_CLAUSE);
1238
1239 String[] orderByFields = orderByComparator.getOrderByFields();
1240
1241 for (int i = 0; i < orderByFields.length; i++) {
1242 query.append(_ORDER_BY_ENTITY_ALIAS);
1243 query.append(orderByFields[i]);
1244
1245 if ((i + 1) < orderByFields.length) {
1246 if (orderByComparator.isAscending() ^ previous) {
1247 query.append(ORDER_BY_ASC_HAS_NEXT);
1248 }
1249 else {
1250 query.append(ORDER_BY_DESC_HAS_NEXT);
1251 }
1252 }
1253 else {
1254 if (orderByComparator.isAscending() ^ previous) {
1255 query.append(ORDER_BY_ASC);
1256 }
1257 else {
1258 query.append(ORDER_BY_DESC);
1259 }
1260 }
1261 }
1262 }
1263
1264 else {
1265 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
1266 }
1267
1268 String sql = query.toString();
1269
1270 Query q = session.createQuery(sql);
1271
1272 q.setFirstResult(0);
1273 q.setMaxResults(2);
1274
1275 QueryPos qPos = QueryPos.getInstance(q);
1276
1277 qPos.add(questionId);
1278
1279 if (orderByComparator != null) {
1280 Object[] values = orderByComparator.getOrderByConditionValues(pollsChoice);
1281
1282 for (Object value : values) {
1283 qPos.add(value);
1284 }
1285 }
1286
1287 List<PollsChoice> list = q.list();
1288
1289 if (list.size() == 2) {
1290 return list.get(1);
1291 }
1292 else {
1293 return null;
1294 }
1295 }
1296
1297
1306 public PollsChoice findByQ_N(long questionId, String name)
1307 throws NoSuchChoiceException, SystemException {
1308 PollsChoice pollsChoice = fetchByQ_N(questionId, name);
1309
1310 if (pollsChoice == null) {
1311 StringBundler msg = new StringBundler(6);
1312
1313 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1314
1315 msg.append("questionId=");
1316 msg.append(questionId);
1317
1318 msg.append(", name=");
1319 msg.append(name);
1320
1321 msg.append(StringPool.CLOSE_CURLY_BRACE);
1322
1323 if (_log.isWarnEnabled()) {
1324 _log.warn(msg.toString());
1325 }
1326
1327 throw new NoSuchChoiceException(msg.toString());
1328 }
1329
1330 return pollsChoice;
1331 }
1332
1333
1341 public PollsChoice fetchByQ_N(long questionId, String name)
1342 throws SystemException {
1343 return fetchByQ_N(questionId, name, true);
1344 }
1345
1346
1355 public PollsChoice fetchByQ_N(long questionId, String name,
1356 boolean retrieveFromCache) throws SystemException {
1357 Object[] finderArgs = new Object[] { questionId, name };
1358
1359 Object result = null;
1360
1361 if (retrieveFromCache) {
1362 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_Q_N,
1363 finderArgs, this);
1364 }
1365
1366 if (result instanceof PollsChoice) {
1367 PollsChoice pollsChoice = (PollsChoice)result;
1368
1369 if ((questionId != pollsChoice.getQuestionId()) ||
1370 !Validator.equals(name, pollsChoice.getName())) {
1371 result = null;
1372 }
1373 }
1374
1375 if (result == null) {
1376 StringBundler query = new StringBundler(4);
1377
1378 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
1379
1380 query.append(_FINDER_COLUMN_Q_N_QUESTIONID_2);
1381
1382 if (name == null) {
1383 query.append(_FINDER_COLUMN_Q_N_NAME_1);
1384 }
1385 else {
1386 if (name.equals(StringPool.BLANK)) {
1387 query.append(_FINDER_COLUMN_Q_N_NAME_3);
1388 }
1389 else {
1390 query.append(_FINDER_COLUMN_Q_N_NAME_2);
1391 }
1392 }
1393
1394 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
1395
1396 String sql = query.toString();
1397
1398 Session session = null;
1399
1400 try {
1401 session = openSession();
1402
1403 Query q = session.createQuery(sql);
1404
1405 QueryPos qPos = QueryPos.getInstance(q);
1406
1407 qPos.add(questionId);
1408
1409 if (name != null) {
1410 qPos.add(name);
1411 }
1412
1413 List<PollsChoice> list = q.list();
1414
1415 result = list;
1416
1417 PollsChoice pollsChoice = null;
1418
1419 if (list.isEmpty()) {
1420 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
1421 finderArgs, list);
1422 }
1423 else {
1424 pollsChoice = list.get(0);
1425
1426 cacheResult(pollsChoice);
1427
1428 if ((pollsChoice.getQuestionId() != questionId) ||
1429 (pollsChoice.getName() == null) ||
1430 !pollsChoice.getName().equals(name)) {
1431 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
1432 finderArgs, pollsChoice);
1433 }
1434 }
1435
1436 return pollsChoice;
1437 }
1438 catch (Exception e) {
1439 throw processException(e);
1440 }
1441 finally {
1442 if (result == null) {
1443 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N,
1444 finderArgs);
1445 }
1446
1447 closeSession(session);
1448 }
1449 }
1450 else {
1451 if (result instanceof List<?>) {
1452 return null;
1453 }
1454 else {
1455 return (PollsChoice)result;
1456 }
1457 }
1458 }
1459
1460
1466 public List<PollsChoice> findAll() throws SystemException {
1467 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1468 }
1469
1470
1482 public List<PollsChoice> findAll(int start, int end)
1483 throws SystemException {
1484 return findAll(start, end, null);
1485 }
1486
1487
1500 public List<PollsChoice> findAll(int start, int end,
1501 OrderByComparator orderByComparator) throws SystemException {
1502 FinderPath finderPath = null;
1503 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1504
1505 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1506 (orderByComparator == null)) {
1507 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1508 finderArgs = FINDER_ARGS_EMPTY;
1509 }
1510 else {
1511 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1512 finderArgs = new Object[] { start, end, orderByComparator };
1513 }
1514
1515 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
1516 finderArgs, this);
1517
1518 if (list == null) {
1519 StringBundler query = null;
1520 String sql = null;
1521
1522 if (orderByComparator != null) {
1523 query = new StringBundler(2 +
1524 (orderByComparator.getOrderByFields().length * 3));
1525
1526 query.append(_SQL_SELECT_POLLSCHOICE);
1527
1528 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1529 orderByComparator);
1530
1531 sql = query.toString();
1532 }
1533 else {
1534 sql = _SQL_SELECT_POLLSCHOICE.concat(PollsChoiceModelImpl.ORDER_BY_JPQL);
1535 }
1536
1537 Session session = null;
1538
1539 try {
1540 session = openSession();
1541
1542 Query q = session.createQuery(sql);
1543
1544 if (orderByComparator == null) {
1545 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1546 start, end, false);
1547
1548 Collections.sort(list);
1549 }
1550 else {
1551 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1552 start, end);
1553 }
1554 }
1555 catch (Exception e) {
1556 throw processException(e);
1557 }
1558 finally {
1559 if (list == null) {
1560 FinderCacheUtil.removeResult(finderPath, finderArgs);
1561 }
1562 else {
1563 cacheResult(list);
1564
1565 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1566 }
1567
1568 closeSession(session);
1569 }
1570 }
1571
1572 return list;
1573 }
1574
1575
1581 public void removeByUuid(String uuid) throws SystemException {
1582 for (PollsChoice pollsChoice : findByUuid(uuid)) {
1583 remove(pollsChoice);
1584 }
1585 }
1586
1587
1593 public void removeByQuestionId(long questionId) throws SystemException {
1594 for (PollsChoice pollsChoice : findByQuestionId(questionId)) {
1595 remove(pollsChoice);
1596 }
1597 }
1598
1599
1606 public void removeByQ_N(long questionId, String name)
1607 throws NoSuchChoiceException, SystemException {
1608 PollsChoice pollsChoice = findByQ_N(questionId, name);
1609
1610 remove(pollsChoice);
1611 }
1612
1613
1618 public void removeAll() throws SystemException {
1619 for (PollsChoice pollsChoice : findAll()) {
1620 remove(pollsChoice);
1621 }
1622 }
1623
1624
1631 public int countByUuid(String uuid) throws SystemException {
1632 Object[] finderArgs = new Object[] { uuid };
1633
1634 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1635 finderArgs, this);
1636
1637 if (count == null) {
1638 StringBundler query = new StringBundler(2);
1639
1640 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
1641
1642 if (uuid == null) {
1643 query.append(_FINDER_COLUMN_UUID_UUID_1);
1644 }
1645 else {
1646 if (uuid.equals(StringPool.BLANK)) {
1647 query.append(_FINDER_COLUMN_UUID_UUID_3);
1648 }
1649 else {
1650 query.append(_FINDER_COLUMN_UUID_UUID_2);
1651 }
1652 }
1653
1654 String sql = query.toString();
1655
1656 Session session = null;
1657
1658 try {
1659 session = openSession();
1660
1661 Query q = session.createQuery(sql);
1662
1663 QueryPos qPos = QueryPos.getInstance(q);
1664
1665 if (uuid != null) {
1666 qPos.add(uuid);
1667 }
1668
1669 count = (Long)q.uniqueResult();
1670 }
1671 catch (Exception e) {
1672 throw processException(e);
1673 }
1674 finally {
1675 if (count == null) {
1676 count = Long.valueOf(0);
1677 }
1678
1679 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1680 finderArgs, count);
1681
1682 closeSession(session);
1683 }
1684 }
1685
1686 return count.intValue();
1687 }
1688
1689
1696 public int countByQuestionId(long questionId) throws SystemException {
1697 Object[] finderArgs = new Object[] { questionId };
1698
1699 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1700 finderArgs, this);
1701
1702 if (count == null) {
1703 StringBundler query = new StringBundler(2);
1704
1705 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
1706
1707 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1708
1709 String sql = query.toString();
1710
1711 Session session = null;
1712
1713 try {
1714 session = openSession();
1715
1716 Query q = session.createQuery(sql);
1717
1718 QueryPos qPos = QueryPos.getInstance(q);
1719
1720 qPos.add(questionId);
1721
1722 count = (Long)q.uniqueResult();
1723 }
1724 catch (Exception e) {
1725 throw processException(e);
1726 }
1727 finally {
1728 if (count == null) {
1729 count = Long.valueOf(0);
1730 }
1731
1732 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1733 finderArgs, count);
1734
1735 closeSession(session);
1736 }
1737 }
1738
1739 return count.intValue();
1740 }
1741
1742
1750 public int countByQ_N(long questionId, String name)
1751 throws SystemException {
1752 Object[] finderArgs = new Object[] { questionId, name };
1753
1754 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_Q_N,
1755 finderArgs, this);
1756
1757 if (count == null) {
1758 StringBundler query = new StringBundler(3);
1759
1760 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
1761
1762 query.append(_FINDER_COLUMN_Q_N_QUESTIONID_2);
1763
1764 if (name == null) {
1765 query.append(_FINDER_COLUMN_Q_N_NAME_1);
1766 }
1767 else {
1768 if (name.equals(StringPool.BLANK)) {
1769 query.append(_FINDER_COLUMN_Q_N_NAME_3);
1770 }
1771 else {
1772 query.append(_FINDER_COLUMN_Q_N_NAME_2);
1773 }
1774 }
1775
1776 String sql = query.toString();
1777
1778 Session session = null;
1779
1780 try {
1781 session = openSession();
1782
1783 Query q = session.createQuery(sql);
1784
1785 QueryPos qPos = QueryPos.getInstance(q);
1786
1787 qPos.add(questionId);
1788
1789 if (name != null) {
1790 qPos.add(name);
1791 }
1792
1793 count = (Long)q.uniqueResult();
1794 }
1795 catch (Exception e) {
1796 throw processException(e);
1797 }
1798 finally {
1799 if (count == null) {
1800 count = Long.valueOf(0);
1801 }
1802
1803 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_Q_N, finderArgs,
1804 count);
1805
1806 closeSession(session);
1807 }
1808 }
1809
1810 return count.intValue();
1811 }
1812
1813
1819 public int countAll() throws SystemException {
1820 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1821 FINDER_ARGS_EMPTY, this);
1822
1823 if (count == null) {
1824 Session session = null;
1825
1826 try {
1827 session = openSession();
1828
1829 Query q = session.createQuery(_SQL_COUNT_POLLSCHOICE);
1830
1831 count = (Long)q.uniqueResult();
1832 }
1833 catch (Exception e) {
1834 throw processException(e);
1835 }
1836 finally {
1837 if (count == null) {
1838 count = Long.valueOf(0);
1839 }
1840
1841 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1842 FINDER_ARGS_EMPTY, count);
1843
1844 closeSession(session);
1845 }
1846 }
1847
1848 return count.intValue();
1849 }
1850
1851
1854 public void afterPropertiesSet() {
1855 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1856 com.liferay.portal.util.PropsUtil.get(
1857 "value.object.listener.com.liferay.portlet.polls.model.PollsChoice")));
1858
1859 if (listenerClassNames.length > 0) {
1860 try {
1861 List<ModelListener<PollsChoice>> listenersList = new ArrayList<ModelListener<PollsChoice>>();
1862
1863 for (String listenerClassName : listenerClassNames) {
1864 listenersList.add((ModelListener<PollsChoice>)InstanceFactory.newInstance(
1865 listenerClassName));
1866 }
1867
1868 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1869 }
1870 catch (Exception e) {
1871 _log.error(e);
1872 }
1873 }
1874 }
1875
1876 public void destroy() {
1877 EntityCacheUtil.removeCache(PollsChoiceImpl.class.getName());
1878 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1879 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1880 }
1881
1882 @BeanReference(type = PollsChoicePersistence.class)
1883 protected PollsChoicePersistence pollsChoicePersistence;
1884 @BeanReference(type = PollsQuestionPersistence.class)
1885 protected PollsQuestionPersistence pollsQuestionPersistence;
1886 @BeanReference(type = PollsVotePersistence.class)
1887 protected PollsVotePersistence pollsVotePersistence;
1888 @BeanReference(type = ResourcePersistence.class)
1889 protected ResourcePersistence resourcePersistence;
1890 @BeanReference(type = UserPersistence.class)
1891 protected UserPersistence userPersistence;
1892 private static final String _SQL_SELECT_POLLSCHOICE = "SELECT pollsChoice FROM PollsChoice pollsChoice";
1893 private static final String _SQL_SELECT_POLLSCHOICE_WHERE = "SELECT pollsChoice FROM PollsChoice pollsChoice WHERE ";
1894 private static final String _SQL_COUNT_POLLSCHOICE = "SELECT COUNT(pollsChoice) FROM PollsChoice pollsChoice";
1895 private static final String _SQL_COUNT_POLLSCHOICE_WHERE = "SELECT COUNT(pollsChoice) FROM PollsChoice pollsChoice WHERE ";
1896 private static final String _FINDER_COLUMN_UUID_UUID_1 = "pollsChoice.uuid IS NULL";
1897 private static final String _FINDER_COLUMN_UUID_UUID_2 = "pollsChoice.uuid = ?";
1898 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(pollsChoice.uuid IS NULL OR pollsChoice.uuid = ?)";
1899 private static final String _FINDER_COLUMN_QUESTIONID_QUESTIONID_2 = "pollsChoice.questionId = ?";
1900 private static final String _FINDER_COLUMN_Q_N_QUESTIONID_2 = "pollsChoice.questionId = ? AND ";
1901 private static final String _FINDER_COLUMN_Q_N_NAME_1 = "pollsChoice.name IS NULL";
1902 private static final String _FINDER_COLUMN_Q_N_NAME_2 = "pollsChoice.name = ?";
1903 private static final String _FINDER_COLUMN_Q_N_NAME_3 = "(pollsChoice.name IS NULL OR pollsChoice.name = ?)";
1904 private static final String _ORDER_BY_ENTITY_ALIAS = "pollsChoice.";
1905 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsChoice exists with the primary key ";
1906 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsChoice exists with the key {";
1907 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1908 private static Log _log = LogFactoryUtil.getLog(PollsChoicePersistenceImpl.class);
1909 private static PollsChoice _nullPollsChoice = new PollsChoiceImpl() {
1910 @Override
1911 public Object clone() {
1912 return this;
1913 }
1914
1915 @Override
1916 public CacheModel<PollsChoice> toCacheModel() {
1917 return _nullPollsChoiceCacheModel;
1918 }
1919 };
1920
1921 private static CacheModel<PollsChoice> _nullPollsChoiceCacheModel = new CacheModel<PollsChoice>() {
1922 public PollsChoice toEntityModel() {
1923 return _nullPollsChoice;
1924 }
1925 };
1926 }