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_WITHOUT_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_WITH_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
370 else {
371 if ((pollsChoiceModelImpl.getColumnBitmask() &
372 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
373 Object[] args = new Object[] {
374 pollsChoiceModelImpl.getOriginalUuid()
375 };
376
377 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
378 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
379 args);
380
381 args = new Object[] { pollsChoiceModelImpl.getUuid() };
382
383 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
384 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
385 args);
386 }
387
388 if ((pollsChoiceModelImpl.getColumnBitmask() &
389 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID.getColumnBitmask()) != 0) {
390 Object[] args = new Object[] {
391 Long.valueOf(pollsChoiceModelImpl.getOriginalQuestionId())
392 };
393
394 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
395 args);
396 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
397 args);
398
399 args = new Object[] {
400 Long.valueOf(pollsChoiceModelImpl.getQuestionId())
401 };
402
403 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
404 args);
405 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
406 args);
407 }
408 }
409
410 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
411 PollsChoiceImpl.class, pollsChoice.getPrimaryKey(), pollsChoice);
412
413 if (isNew) {
414 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
415 new Object[] {
416 Long.valueOf(pollsChoice.getQuestionId()),
417
418 pollsChoice.getName()
419 }, pollsChoice);
420 }
421 else {
422 if ((pollsChoiceModelImpl.getColumnBitmask() &
423 FINDER_PATH_FETCH_BY_Q_N.getColumnBitmask()) != 0) {
424 Object[] args = new Object[] {
425 Long.valueOf(pollsChoiceModelImpl.getOriginalQuestionId()),
426
427 pollsChoiceModelImpl.getOriginalName()
428 };
429
430 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_Q_N, args);
431 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N, args);
432
433 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
434 new Object[] {
435 Long.valueOf(pollsChoice.getQuestionId()),
436
437 pollsChoice.getName()
438 }, pollsChoice);
439 }
440 }
441
442 return pollsChoice;
443 }
444
445 protected PollsChoice toUnwrappedModel(PollsChoice pollsChoice) {
446 if (pollsChoice instanceof PollsChoiceImpl) {
447 return pollsChoice;
448 }
449
450 PollsChoiceImpl pollsChoiceImpl = new PollsChoiceImpl();
451
452 pollsChoiceImpl.setNew(pollsChoice.isNew());
453 pollsChoiceImpl.setPrimaryKey(pollsChoice.getPrimaryKey());
454
455 pollsChoiceImpl.setUuid(pollsChoice.getUuid());
456 pollsChoiceImpl.setChoiceId(pollsChoice.getChoiceId());
457 pollsChoiceImpl.setQuestionId(pollsChoice.getQuestionId());
458 pollsChoiceImpl.setName(pollsChoice.getName());
459 pollsChoiceImpl.setDescription(pollsChoice.getDescription());
460
461 return pollsChoiceImpl;
462 }
463
464
472 @Override
473 public PollsChoice findByPrimaryKey(Serializable primaryKey)
474 throws NoSuchModelException, SystemException {
475 return findByPrimaryKey(((Long)primaryKey).longValue());
476 }
477
478
486 public PollsChoice findByPrimaryKey(long choiceId)
487 throws NoSuchChoiceException, SystemException {
488 PollsChoice pollsChoice = fetchByPrimaryKey(choiceId);
489
490 if (pollsChoice == null) {
491 if (_log.isWarnEnabled()) {
492 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + choiceId);
493 }
494
495 throw new NoSuchChoiceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
496 choiceId);
497 }
498
499 return pollsChoice;
500 }
501
502
509 @Override
510 public PollsChoice fetchByPrimaryKey(Serializable primaryKey)
511 throws SystemException {
512 return fetchByPrimaryKey(((Long)primaryKey).longValue());
513 }
514
515
522 public PollsChoice fetchByPrimaryKey(long choiceId)
523 throws SystemException {
524 PollsChoice pollsChoice = (PollsChoice)EntityCacheUtil.getResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
525 PollsChoiceImpl.class, choiceId);
526
527 if (pollsChoice == _nullPollsChoice) {
528 return null;
529 }
530
531 if (pollsChoice == null) {
532 Session session = null;
533
534 boolean hasException = false;
535
536 try {
537 session = openSession();
538
539 pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
540 Long.valueOf(choiceId));
541 }
542 catch (Exception e) {
543 hasException = true;
544
545 throw processException(e);
546 }
547 finally {
548 if (pollsChoice != null) {
549 cacheResult(pollsChoice);
550 }
551 else if (!hasException) {
552 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
553 PollsChoiceImpl.class, choiceId, _nullPollsChoice);
554 }
555
556 closeSession(session);
557 }
558 }
559
560 return pollsChoice;
561 }
562
563
570 public List<PollsChoice> findByUuid(String uuid) throws SystemException {
571 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
572 }
573
574
587 public List<PollsChoice> findByUuid(String uuid, int start, int end)
588 throws SystemException {
589 return findByUuid(uuid, start, end, null);
590 }
591
592
606 public List<PollsChoice> findByUuid(String uuid, int start, int end,
607 OrderByComparator orderByComparator) throws SystemException {
608 FinderPath finderPath = null;
609 Object[] finderArgs = null;
610
611 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
612 (orderByComparator == null)) {
613 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
614 finderArgs = new Object[] { uuid };
615 }
616 else {
617 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
618 finderArgs = new Object[] { uuid, start, end, orderByComparator };
619 }
620
621 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
622 finderArgs, this);
623
624 if (list == null) {
625 StringBundler query = null;
626
627 if (orderByComparator != null) {
628 query = new StringBundler(3 +
629 (orderByComparator.getOrderByFields().length * 3));
630 }
631 else {
632 query = new StringBundler(3);
633 }
634
635 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
636
637 if (uuid == null) {
638 query.append(_FINDER_COLUMN_UUID_UUID_1);
639 }
640 else {
641 if (uuid.equals(StringPool.BLANK)) {
642 query.append(_FINDER_COLUMN_UUID_UUID_3);
643 }
644 else {
645 query.append(_FINDER_COLUMN_UUID_UUID_2);
646 }
647 }
648
649 if (orderByComparator != null) {
650 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
651 orderByComparator);
652 }
653
654 else {
655 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
656 }
657
658 String sql = query.toString();
659
660 Session session = null;
661
662 try {
663 session = openSession();
664
665 Query q = session.createQuery(sql);
666
667 QueryPos qPos = QueryPos.getInstance(q);
668
669 if (uuid != null) {
670 qPos.add(uuid);
671 }
672
673 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
674 start, end);
675 }
676 catch (Exception e) {
677 throw processException(e);
678 }
679 finally {
680 if (list == null) {
681 FinderCacheUtil.removeResult(finderPath, finderArgs);
682 }
683 else {
684 cacheResult(list);
685
686 FinderCacheUtil.putResult(finderPath, finderArgs, list);
687 }
688
689 closeSession(session);
690 }
691 }
692
693 return list;
694 }
695
696
709 public PollsChoice findByUuid_First(String uuid,
710 OrderByComparator orderByComparator)
711 throws NoSuchChoiceException, SystemException {
712 List<PollsChoice> list = findByUuid(uuid, 0, 1, orderByComparator);
713
714 if (list.isEmpty()) {
715 StringBundler msg = new StringBundler(4);
716
717 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
718
719 msg.append("uuid=");
720 msg.append(uuid);
721
722 msg.append(StringPool.CLOSE_CURLY_BRACE);
723
724 throw new NoSuchChoiceException(msg.toString());
725 }
726 else {
727 return list.get(0);
728 }
729 }
730
731
744 public PollsChoice findByUuid_Last(String uuid,
745 OrderByComparator orderByComparator)
746 throws NoSuchChoiceException, SystemException {
747 int count = countByUuid(uuid);
748
749 List<PollsChoice> list = findByUuid(uuid, count - 1, count,
750 orderByComparator);
751
752 if (list.isEmpty()) {
753 StringBundler msg = new StringBundler(4);
754
755 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
756
757 msg.append("uuid=");
758 msg.append(uuid);
759
760 msg.append(StringPool.CLOSE_CURLY_BRACE);
761
762 throw new NoSuchChoiceException(msg.toString());
763 }
764 else {
765 return list.get(0);
766 }
767 }
768
769
783 public PollsChoice[] findByUuid_PrevAndNext(long choiceId, String uuid,
784 OrderByComparator orderByComparator)
785 throws NoSuchChoiceException, SystemException {
786 PollsChoice pollsChoice = findByPrimaryKey(choiceId);
787
788 Session session = null;
789
790 try {
791 session = openSession();
792
793 PollsChoice[] array = new PollsChoiceImpl[3];
794
795 array[0] = getByUuid_PrevAndNext(session, pollsChoice, uuid,
796 orderByComparator, true);
797
798 array[1] = pollsChoice;
799
800 array[2] = getByUuid_PrevAndNext(session, pollsChoice, uuid,
801 orderByComparator, false);
802
803 return array;
804 }
805 catch (Exception e) {
806 throw processException(e);
807 }
808 finally {
809 closeSession(session);
810 }
811 }
812
813 protected PollsChoice getByUuid_PrevAndNext(Session session,
814 PollsChoice pollsChoice, String uuid,
815 OrderByComparator orderByComparator, boolean previous) {
816 StringBundler query = null;
817
818 if (orderByComparator != null) {
819 query = new StringBundler(6 +
820 (orderByComparator.getOrderByFields().length * 6));
821 }
822 else {
823 query = new StringBundler(3);
824 }
825
826 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
827
828 if (uuid == null) {
829 query.append(_FINDER_COLUMN_UUID_UUID_1);
830 }
831 else {
832 if (uuid.equals(StringPool.BLANK)) {
833 query.append(_FINDER_COLUMN_UUID_UUID_3);
834 }
835 else {
836 query.append(_FINDER_COLUMN_UUID_UUID_2);
837 }
838 }
839
840 if (orderByComparator != null) {
841 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
842
843 if (orderByConditionFields.length > 0) {
844 query.append(WHERE_AND);
845 }
846
847 for (int i = 0; i < orderByConditionFields.length; i++) {
848 query.append(_ORDER_BY_ENTITY_ALIAS);
849 query.append(orderByConditionFields[i]);
850
851 if ((i + 1) < orderByConditionFields.length) {
852 if (orderByComparator.isAscending() ^ previous) {
853 query.append(WHERE_GREATER_THAN_HAS_NEXT);
854 }
855 else {
856 query.append(WHERE_LESSER_THAN_HAS_NEXT);
857 }
858 }
859 else {
860 if (orderByComparator.isAscending() ^ previous) {
861 query.append(WHERE_GREATER_THAN);
862 }
863 else {
864 query.append(WHERE_LESSER_THAN);
865 }
866 }
867 }
868
869 query.append(ORDER_BY_CLAUSE);
870
871 String[] orderByFields = orderByComparator.getOrderByFields();
872
873 for (int i = 0; i < orderByFields.length; i++) {
874 query.append(_ORDER_BY_ENTITY_ALIAS);
875 query.append(orderByFields[i]);
876
877 if ((i + 1) < orderByFields.length) {
878 if (orderByComparator.isAscending() ^ previous) {
879 query.append(ORDER_BY_ASC_HAS_NEXT);
880 }
881 else {
882 query.append(ORDER_BY_DESC_HAS_NEXT);
883 }
884 }
885 else {
886 if (orderByComparator.isAscending() ^ previous) {
887 query.append(ORDER_BY_ASC);
888 }
889 else {
890 query.append(ORDER_BY_DESC);
891 }
892 }
893 }
894 }
895
896 else {
897 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
898 }
899
900 String sql = query.toString();
901
902 Query q = session.createQuery(sql);
903
904 q.setFirstResult(0);
905 q.setMaxResults(2);
906
907 QueryPos qPos = QueryPos.getInstance(q);
908
909 if (uuid != null) {
910 qPos.add(uuid);
911 }
912
913 if (orderByComparator != null) {
914 Object[] values = orderByComparator.getOrderByConditionValues(pollsChoice);
915
916 for (Object value : values) {
917 qPos.add(value);
918 }
919 }
920
921 List<PollsChoice> list = q.list();
922
923 if (list.size() == 2) {
924 return list.get(1);
925 }
926 else {
927 return null;
928 }
929 }
930
931
938 public List<PollsChoice> findByQuestionId(long questionId)
939 throws SystemException {
940 return findByQuestionId(questionId, QueryUtil.ALL_POS,
941 QueryUtil.ALL_POS, null);
942 }
943
944
957 public List<PollsChoice> findByQuestionId(long questionId, int start,
958 int end) throws SystemException {
959 return findByQuestionId(questionId, start, end, null);
960 }
961
962
976 public List<PollsChoice> findByQuestionId(long questionId, int start,
977 int end, OrderByComparator orderByComparator) throws SystemException {
978 FinderPath finderPath = null;
979 Object[] finderArgs = null;
980
981 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
982 (orderByComparator == null)) {
983 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID;
984 finderArgs = new Object[] { questionId };
985 }
986 else {
987 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_QUESTIONID;
988 finderArgs = new Object[] { questionId, start, end, orderByComparator };
989 }
990
991 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
992 finderArgs, this);
993
994 if (list == null) {
995 StringBundler query = null;
996
997 if (orderByComparator != null) {
998 query = new StringBundler(3 +
999 (orderByComparator.getOrderByFields().length * 3));
1000 }
1001 else {
1002 query = new StringBundler(3);
1003 }
1004
1005 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
1006
1007 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1008
1009 if (orderByComparator != null) {
1010 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1011 orderByComparator);
1012 }
1013
1014 else {
1015 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
1016 }
1017
1018 String sql = query.toString();
1019
1020 Session session = null;
1021
1022 try {
1023 session = openSession();
1024
1025 Query q = session.createQuery(sql);
1026
1027 QueryPos qPos = QueryPos.getInstance(q);
1028
1029 qPos.add(questionId);
1030
1031 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1032 start, end);
1033 }
1034 catch (Exception e) {
1035 throw processException(e);
1036 }
1037 finally {
1038 if (list == null) {
1039 FinderCacheUtil.removeResult(finderPath, finderArgs);
1040 }
1041 else {
1042 cacheResult(list);
1043
1044 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1045 }
1046
1047 closeSession(session);
1048 }
1049 }
1050
1051 return list;
1052 }
1053
1054
1067 public PollsChoice findByQuestionId_First(long questionId,
1068 OrderByComparator orderByComparator)
1069 throws NoSuchChoiceException, SystemException {
1070 List<PollsChoice> list = findByQuestionId(questionId, 0, 1,
1071 orderByComparator);
1072
1073 if (list.isEmpty()) {
1074 StringBundler msg = new StringBundler(4);
1075
1076 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1077
1078 msg.append("questionId=");
1079 msg.append(questionId);
1080
1081 msg.append(StringPool.CLOSE_CURLY_BRACE);
1082
1083 throw new NoSuchChoiceException(msg.toString());
1084 }
1085 else {
1086 return list.get(0);
1087 }
1088 }
1089
1090
1103 public PollsChoice findByQuestionId_Last(long questionId,
1104 OrderByComparator orderByComparator)
1105 throws NoSuchChoiceException, SystemException {
1106 int count = countByQuestionId(questionId);
1107
1108 List<PollsChoice> list = findByQuestionId(questionId, count - 1, count,
1109 orderByComparator);
1110
1111 if (list.isEmpty()) {
1112 StringBundler msg = new StringBundler(4);
1113
1114 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1115
1116 msg.append("questionId=");
1117 msg.append(questionId);
1118
1119 msg.append(StringPool.CLOSE_CURLY_BRACE);
1120
1121 throw new NoSuchChoiceException(msg.toString());
1122 }
1123 else {
1124 return list.get(0);
1125 }
1126 }
1127
1128
1142 public PollsChoice[] findByQuestionId_PrevAndNext(long choiceId,
1143 long questionId, OrderByComparator orderByComparator)
1144 throws NoSuchChoiceException, SystemException {
1145 PollsChoice pollsChoice = findByPrimaryKey(choiceId);
1146
1147 Session session = null;
1148
1149 try {
1150 session = openSession();
1151
1152 PollsChoice[] array = new PollsChoiceImpl[3];
1153
1154 array[0] = getByQuestionId_PrevAndNext(session, pollsChoice,
1155 questionId, orderByComparator, true);
1156
1157 array[1] = pollsChoice;
1158
1159 array[2] = getByQuestionId_PrevAndNext(session, pollsChoice,
1160 questionId, orderByComparator, false);
1161
1162 return array;
1163 }
1164 catch (Exception e) {
1165 throw processException(e);
1166 }
1167 finally {
1168 closeSession(session);
1169 }
1170 }
1171
1172 protected PollsChoice getByQuestionId_PrevAndNext(Session session,
1173 PollsChoice pollsChoice, long questionId,
1174 OrderByComparator orderByComparator, boolean previous) {
1175 StringBundler query = null;
1176
1177 if (orderByComparator != null) {
1178 query = new StringBundler(6 +
1179 (orderByComparator.getOrderByFields().length * 6));
1180 }
1181 else {
1182 query = new StringBundler(3);
1183 }
1184
1185 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
1186
1187 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1188
1189 if (orderByComparator != null) {
1190 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1191
1192 if (orderByConditionFields.length > 0) {
1193 query.append(WHERE_AND);
1194 }
1195
1196 for (int i = 0; i < orderByConditionFields.length; i++) {
1197 query.append(_ORDER_BY_ENTITY_ALIAS);
1198 query.append(orderByConditionFields[i]);
1199
1200 if ((i + 1) < orderByConditionFields.length) {
1201 if (orderByComparator.isAscending() ^ previous) {
1202 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1203 }
1204 else {
1205 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1206 }
1207 }
1208 else {
1209 if (orderByComparator.isAscending() ^ previous) {
1210 query.append(WHERE_GREATER_THAN);
1211 }
1212 else {
1213 query.append(WHERE_LESSER_THAN);
1214 }
1215 }
1216 }
1217
1218 query.append(ORDER_BY_CLAUSE);
1219
1220 String[] orderByFields = orderByComparator.getOrderByFields();
1221
1222 for (int i = 0; i < orderByFields.length; i++) {
1223 query.append(_ORDER_BY_ENTITY_ALIAS);
1224 query.append(orderByFields[i]);
1225
1226 if ((i + 1) < orderByFields.length) {
1227 if (orderByComparator.isAscending() ^ previous) {
1228 query.append(ORDER_BY_ASC_HAS_NEXT);
1229 }
1230 else {
1231 query.append(ORDER_BY_DESC_HAS_NEXT);
1232 }
1233 }
1234 else {
1235 if (orderByComparator.isAscending() ^ previous) {
1236 query.append(ORDER_BY_ASC);
1237 }
1238 else {
1239 query.append(ORDER_BY_DESC);
1240 }
1241 }
1242 }
1243 }
1244
1245 else {
1246 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
1247 }
1248
1249 String sql = query.toString();
1250
1251 Query q = session.createQuery(sql);
1252
1253 q.setFirstResult(0);
1254 q.setMaxResults(2);
1255
1256 QueryPos qPos = QueryPos.getInstance(q);
1257
1258 qPos.add(questionId);
1259
1260 if (orderByComparator != null) {
1261 Object[] values = orderByComparator.getOrderByConditionValues(pollsChoice);
1262
1263 for (Object value : values) {
1264 qPos.add(value);
1265 }
1266 }
1267
1268 List<PollsChoice> list = q.list();
1269
1270 if (list.size() == 2) {
1271 return list.get(1);
1272 }
1273 else {
1274 return null;
1275 }
1276 }
1277
1278
1287 public PollsChoice findByQ_N(long questionId, String name)
1288 throws NoSuchChoiceException, SystemException {
1289 PollsChoice pollsChoice = fetchByQ_N(questionId, name);
1290
1291 if (pollsChoice == null) {
1292 StringBundler msg = new StringBundler(6);
1293
1294 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1295
1296 msg.append("questionId=");
1297 msg.append(questionId);
1298
1299 msg.append(", name=");
1300 msg.append(name);
1301
1302 msg.append(StringPool.CLOSE_CURLY_BRACE);
1303
1304 if (_log.isWarnEnabled()) {
1305 _log.warn(msg.toString());
1306 }
1307
1308 throw new NoSuchChoiceException(msg.toString());
1309 }
1310
1311 return pollsChoice;
1312 }
1313
1314
1322 public PollsChoice fetchByQ_N(long questionId, String name)
1323 throws SystemException {
1324 return fetchByQ_N(questionId, name, true);
1325 }
1326
1327
1336 public PollsChoice fetchByQ_N(long questionId, String name,
1337 boolean retrieveFromCache) throws SystemException {
1338 Object[] finderArgs = new Object[] { questionId, name };
1339
1340 Object result = null;
1341
1342 if (retrieveFromCache) {
1343 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_Q_N,
1344 finderArgs, this);
1345 }
1346
1347 if (result == null) {
1348 StringBundler query = new StringBundler(4);
1349
1350 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
1351
1352 query.append(_FINDER_COLUMN_Q_N_QUESTIONID_2);
1353
1354 if (name == null) {
1355 query.append(_FINDER_COLUMN_Q_N_NAME_1);
1356 }
1357 else {
1358 if (name.equals(StringPool.BLANK)) {
1359 query.append(_FINDER_COLUMN_Q_N_NAME_3);
1360 }
1361 else {
1362 query.append(_FINDER_COLUMN_Q_N_NAME_2);
1363 }
1364 }
1365
1366 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
1367
1368 String sql = query.toString();
1369
1370 Session session = null;
1371
1372 try {
1373 session = openSession();
1374
1375 Query q = session.createQuery(sql);
1376
1377 QueryPos qPos = QueryPos.getInstance(q);
1378
1379 qPos.add(questionId);
1380
1381 if (name != null) {
1382 qPos.add(name);
1383 }
1384
1385 List<PollsChoice> list = q.list();
1386
1387 result = list;
1388
1389 PollsChoice pollsChoice = null;
1390
1391 if (list.isEmpty()) {
1392 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
1393 finderArgs, list);
1394 }
1395 else {
1396 pollsChoice = list.get(0);
1397
1398 cacheResult(pollsChoice);
1399
1400 if ((pollsChoice.getQuestionId() != questionId) ||
1401 (pollsChoice.getName() == null) ||
1402 !pollsChoice.getName().equals(name)) {
1403 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
1404 finderArgs, pollsChoice);
1405 }
1406 }
1407
1408 return pollsChoice;
1409 }
1410 catch (Exception e) {
1411 throw processException(e);
1412 }
1413 finally {
1414 if (result == null) {
1415 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N,
1416 finderArgs);
1417 }
1418
1419 closeSession(session);
1420 }
1421 }
1422 else {
1423 if (result instanceof List<?>) {
1424 return null;
1425 }
1426 else {
1427 return (PollsChoice)result;
1428 }
1429 }
1430 }
1431
1432
1438 public List<PollsChoice> findAll() throws SystemException {
1439 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1440 }
1441
1442
1454 public List<PollsChoice> findAll(int start, int end)
1455 throws SystemException {
1456 return findAll(start, end, null);
1457 }
1458
1459
1472 public List<PollsChoice> findAll(int start, int end,
1473 OrderByComparator orderByComparator) throws SystemException {
1474 FinderPath finderPath = null;
1475 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1476
1477 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1478 (orderByComparator == null)) {
1479 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1480 finderArgs = FINDER_ARGS_EMPTY;
1481 }
1482 else {
1483 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1484 finderArgs = new Object[] { start, end, orderByComparator };
1485 }
1486
1487 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
1488 finderArgs, this);
1489
1490 if (list == null) {
1491 StringBundler query = null;
1492 String sql = null;
1493
1494 if (orderByComparator != null) {
1495 query = new StringBundler(2 +
1496 (orderByComparator.getOrderByFields().length * 3));
1497
1498 query.append(_SQL_SELECT_POLLSCHOICE);
1499
1500 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1501 orderByComparator);
1502
1503 sql = query.toString();
1504 }
1505 else {
1506 sql = _SQL_SELECT_POLLSCHOICE.concat(PollsChoiceModelImpl.ORDER_BY_JPQL);
1507 }
1508
1509 Session session = null;
1510
1511 try {
1512 session = openSession();
1513
1514 Query q = session.createQuery(sql);
1515
1516 if (orderByComparator == null) {
1517 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1518 start, end, false);
1519
1520 Collections.sort(list);
1521 }
1522 else {
1523 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1524 start, end);
1525 }
1526 }
1527 catch (Exception e) {
1528 throw processException(e);
1529 }
1530 finally {
1531 if (list == null) {
1532 FinderCacheUtil.removeResult(finderPath, finderArgs);
1533 }
1534 else {
1535 cacheResult(list);
1536
1537 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1538 }
1539
1540 closeSession(session);
1541 }
1542 }
1543
1544 return list;
1545 }
1546
1547
1553 public void removeByUuid(String uuid) throws SystemException {
1554 for (PollsChoice pollsChoice : findByUuid(uuid)) {
1555 remove(pollsChoice);
1556 }
1557 }
1558
1559
1565 public void removeByQuestionId(long questionId) throws SystemException {
1566 for (PollsChoice pollsChoice : findByQuestionId(questionId)) {
1567 remove(pollsChoice);
1568 }
1569 }
1570
1571
1578 public void removeByQ_N(long questionId, String name)
1579 throws NoSuchChoiceException, SystemException {
1580 PollsChoice pollsChoice = findByQ_N(questionId, name);
1581
1582 remove(pollsChoice);
1583 }
1584
1585
1590 public void removeAll() throws SystemException {
1591 for (PollsChoice pollsChoice : findAll()) {
1592 remove(pollsChoice);
1593 }
1594 }
1595
1596
1603 public int countByUuid(String uuid) throws SystemException {
1604 Object[] finderArgs = new Object[] { uuid };
1605
1606 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1607 finderArgs, this);
1608
1609 if (count == null) {
1610 StringBundler query = new StringBundler(2);
1611
1612 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
1613
1614 if (uuid == null) {
1615 query.append(_FINDER_COLUMN_UUID_UUID_1);
1616 }
1617 else {
1618 if (uuid.equals(StringPool.BLANK)) {
1619 query.append(_FINDER_COLUMN_UUID_UUID_3);
1620 }
1621 else {
1622 query.append(_FINDER_COLUMN_UUID_UUID_2);
1623 }
1624 }
1625
1626 String sql = query.toString();
1627
1628 Session session = null;
1629
1630 try {
1631 session = openSession();
1632
1633 Query q = session.createQuery(sql);
1634
1635 QueryPos qPos = QueryPos.getInstance(q);
1636
1637 if (uuid != null) {
1638 qPos.add(uuid);
1639 }
1640
1641 count = (Long)q.uniqueResult();
1642 }
1643 catch (Exception e) {
1644 throw processException(e);
1645 }
1646 finally {
1647 if (count == null) {
1648 count = Long.valueOf(0);
1649 }
1650
1651 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1652 finderArgs, count);
1653
1654 closeSession(session);
1655 }
1656 }
1657
1658 return count.intValue();
1659 }
1660
1661
1668 public int countByQuestionId(long questionId) throws SystemException {
1669 Object[] finderArgs = new Object[] { questionId };
1670
1671 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1672 finderArgs, this);
1673
1674 if (count == null) {
1675 StringBundler query = new StringBundler(2);
1676
1677 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
1678
1679 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1680
1681 String sql = query.toString();
1682
1683 Session session = null;
1684
1685 try {
1686 session = openSession();
1687
1688 Query q = session.createQuery(sql);
1689
1690 QueryPos qPos = QueryPos.getInstance(q);
1691
1692 qPos.add(questionId);
1693
1694 count = (Long)q.uniqueResult();
1695 }
1696 catch (Exception e) {
1697 throw processException(e);
1698 }
1699 finally {
1700 if (count == null) {
1701 count = Long.valueOf(0);
1702 }
1703
1704 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1705 finderArgs, count);
1706
1707 closeSession(session);
1708 }
1709 }
1710
1711 return count.intValue();
1712 }
1713
1714
1722 public int countByQ_N(long questionId, String name)
1723 throws SystemException {
1724 Object[] finderArgs = new Object[] { questionId, name };
1725
1726 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_Q_N,
1727 finderArgs, this);
1728
1729 if (count == null) {
1730 StringBundler query = new StringBundler(3);
1731
1732 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
1733
1734 query.append(_FINDER_COLUMN_Q_N_QUESTIONID_2);
1735
1736 if (name == null) {
1737 query.append(_FINDER_COLUMN_Q_N_NAME_1);
1738 }
1739 else {
1740 if (name.equals(StringPool.BLANK)) {
1741 query.append(_FINDER_COLUMN_Q_N_NAME_3);
1742 }
1743 else {
1744 query.append(_FINDER_COLUMN_Q_N_NAME_2);
1745 }
1746 }
1747
1748 String sql = query.toString();
1749
1750 Session session = null;
1751
1752 try {
1753 session = openSession();
1754
1755 Query q = session.createQuery(sql);
1756
1757 QueryPos qPos = QueryPos.getInstance(q);
1758
1759 qPos.add(questionId);
1760
1761 if (name != null) {
1762 qPos.add(name);
1763 }
1764
1765 count = (Long)q.uniqueResult();
1766 }
1767 catch (Exception e) {
1768 throw processException(e);
1769 }
1770 finally {
1771 if (count == null) {
1772 count = Long.valueOf(0);
1773 }
1774
1775 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_Q_N, finderArgs,
1776 count);
1777
1778 closeSession(session);
1779 }
1780 }
1781
1782 return count.intValue();
1783 }
1784
1785
1791 public int countAll() throws SystemException {
1792 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1793 FINDER_ARGS_EMPTY, this);
1794
1795 if (count == null) {
1796 Session session = null;
1797
1798 try {
1799 session = openSession();
1800
1801 Query q = session.createQuery(_SQL_COUNT_POLLSCHOICE);
1802
1803 count = (Long)q.uniqueResult();
1804 }
1805 catch (Exception e) {
1806 throw processException(e);
1807 }
1808 finally {
1809 if (count == null) {
1810 count = Long.valueOf(0);
1811 }
1812
1813 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1814 FINDER_ARGS_EMPTY, count);
1815
1816 closeSession(session);
1817 }
1818 }
1819
1820 return count.intValue();
1821 }
1822
1823
1826 public void afterPropertiesSet() {
1827 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1828 com.liferay.portal.util.PropsUtil.get(
1829 "value.object.listener.com.liferay.portlet.polls.model.PollsChoice")));
1830
1831 if (listenerClassNames.length > 0) {
1832 try {
1833 List<ModelListener<PollsChoice>> listenersList = new ArrayList<ModelListener<PollsChoice>>();
1834
1835 for (String listenerClassName : listenerClassNames) {
1836 listenersList.add((ModelListener<PollsChoice>)InstanceFactory.newInstance(
1837 listenerClassName));
1838 }
1839
1840 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1841 }
1842 catch (Exception e) {
1843 _log.error(e);
1844 }
1845 }
1846 }
1847
1848 public void destroy() {
1849 EntityCacheUtil.removeCache(PollsChoiceImpl.class.getName());
1850 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1851 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1852 }
1853
1854 @BeanReference(type = PollsChoicePersistence.class)
1855 protected PollsChoicePersistence pollsChoicePersistence;
1856 @BeanReference(type = PollsQuestionPersistence.class)
1857 protected PollsQuestionPersistence pollsQuestionPersistence;
1858 @BeanReference(type = PollsVotePersistence.class)
1859 protected PollsVotePersistence pollsVotePersistence;
1860 @BeanReference(type = ResourcePersistence.class)
1861 protected ResourcePersistence resourcePersistence;
1862 @BeanReference(type = UserPersistence.class)
1863 protected UserPersistence userPersistence;
1864 private static final String _SQL_SELECT_POLLSCHOICE = "SELECT pollsChoice FROM PollsChoice pollsChoice";
1865 private static final String _SQL_SELECT_POLLSCHOICE_WHERE = "SELECT pollsChoice FROM PollsChoice pollsChoice WHERE ";
1866 private static final String _SQL_COUNT_POLLSCHOICE = "SELECT COUNT(pollsChoice) FROM PollsChoice pollsChoice";
1867 private static final String _SQL_COUNT_POLLSCHOICE_WHERE = "SELECT COUNT(pollsChoice) FROM PollsChoice pollsChoice WHERE ";
1868 private static final String _FINDER_COLUMN_UUID_UUID_1 = "pollsChoice.uuid IS NULL";
1869 private static final String _FINDER_COLUMN_UUID_UUID_2 = "pollsChoice.uuid = ?";
1870 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(pollsChoice.uuid IS NULL OR pollsChoice.uuid = ?)";
1871 private static final String _FINDER_COLUMN_QUESTIONID_QUESTIONID_2 = "pollsChoice.questionId = ?";
1872 private static final String _FINDER_COLUMN_Q_N_QUESTIONID_2 = "pollsChoice.questionId = ? AND ";
1873 private static final String _FINDER_COLUMN_Q_N_NAME_1 = "pollsChoice.name IS NULL";
1874 private static final String _FINDER_COLUMN_Q_N_NAME_2 = "pollsChoice.name = ?";
1875 private static final String _FINDER_COLUMN_Q_N_NAME_3 = "(pollsChoice.name IS NULL OR pollsChoice.name = ?)";
1876 private static final String _ORDER_BY_ENTITY_ALIAS = "pollsChoice.";
1877 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsChoice exists with the primary key ";
1878 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsChoice exists with the key {";
1879 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1880 private static Log _log = LogFactoryUtil.getLog(PollsChoicePersistenceImpl.class);
1881 private static PollsChoice _nullPollsChoice = new PollsChoiceImpl() {
1882 @Override
1883 public Object clone() {
1884 return this;
1885 }
1886
1887 @Override
1888 public CacheModel<PollsChoice> toCacheModel() {
1889 return _nullPollsChoiceCacheModel;
1890 }
1891 };
1892
1893 private static CacheModel<PollsChoice> _nullPollsChoiceCacheModel = new CacheModel<PollsChoice>() {
1894 public PollsChoice toEntityModel() {
1895 return _nullPollsChoice;
1896 }
1897 };
1898 }