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.UserPersistence;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.polls.NoSuchChoiceException;
044 import com.liferay.portlet.polls.model.PollsChoice;
045 import com.liferay.portlet.polls.model.impl.PollsChoiceImpl;
046 import com.liferay.portlet.polls.model.impl.PollsChoiceModelImpl;
047
048 import java.io.Serializable;
049
050 import java.util.ArrayList;
051 import java.util.Collections;
052 import java.util.List;
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_BY_UUID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
079 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
080 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
081 new String[] {
082 String.class.getName(),
083
084 "java.lang.Integer", "java.lang.Integer",
085 "com.liferay.portal.kernel.util.OrderByComparator"
086 });
087 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
088 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
089 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
090 new String[] { String.class.getName() },
091 PollsChoiceModelImpl.UUID_COLUMN_BITMASK);
092 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
093 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
094 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
095 new String[] { String.class.getName() });
096 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_QUESTIONID =
097 new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
098 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
099 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByQuestionId",
100 new String[] {
101 Long.class.getName(),
102
103 "java.lang.Integer", "java.lang.Integer",
104 "com.liferay.portal.kernel.util.OrderByComparator"
105 });
106 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID =
107 new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
108 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
109 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByQuestionId",
110 new String[] { Long.class.getName() },
111 PollsChoiceModelImpl.QUESTIONID_COLUMN_BITMASK);
112 public static final FinderPath FINDER_PATH_COUNT_BY_QUESTIONID = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
113 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
114 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByQuestionId",
115 new String[] { Long.class.getName() });
116 public static final FinderPath FINDER_PATH_FETCH_BY_Q_N = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
117 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
118 FINDER_CLASS_NAME_ENTITY, "fetchByQ_N",
119 new String[] { Long.class.getName(), String.class.getName() },
120 PollsChoiceModelImpl.QUESTIONID_COLUMN_BITMASK |
121 PollsChoiceModelImpl.NAME_COLUMN_BITMASK);
122 public static final FinderPath FINDER_PATH_COUNT_BY_Q_N = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
123 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
124 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByQ_N",
125 new String[] { Long.class.getName(), String.class.getName() });
126 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
127 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
128 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
129 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
130 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, PollsChoiceImpl.class,
131 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
132 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
133 PollsChoiceModelImpl.FINDER_CACHE_ENABLED, Long.class,
134 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
135
136
141 public void cacheResult(PollsChoice pollsChoice) {
142 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
143 PollsChoiceImpl.class, pollsChoice.getPrimaryKey(), pollsChoice);
144
145 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
146 new Object[] {
147 Long.valueOf(pollsChoice.getQuestionId()),
148
149 pollsChoice.getName()
150 }, pollsChoice);
151
152 pollsChoice.resetOriginalValues();
153 }
154
155
160 public void cacheResult(List<PollsChoice> pollsChoices) {
161 for (PollsChoice pollsChoice : pollsChoices) {
162 if (EntityCacheUtil.getResult(
163 PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
164 PollsChoiceImpl.class, pollsChoice.getPrimaryKey()) == null) {
165 cacheResult(pollsChoice);
166 }
167 else {
168 pollsChoice.resetOriginalValues();
169 }
170 }
171 }
172
173
180 @Override
181 public void clearCache() {
182 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
183 CacheRegistryUtil.clear(PollsChoiceImpl.class.getName());
184 }
185
186 EntityCacheUtil.clearCache(PollsChoiceImpl.class.getName());
187
188 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
189 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
190 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
191 }
192
193
200 @Override
201 public void clearCache(PollsChoice pollsChoice) {
202 EntityCacheUtil.removeResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
203 PollsChoiceImpl.class, pollsChoice.getPrimaryKey());
204
205 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
206 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
207
208 clearUniqueFindersCache(pollsChoice);
209 }
210
211 @Override
212 public void clearCache(List<PollsChoice> pollsChoices) {
213 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
214 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
215
216 for (PollsChoice pollsChoice : pollsChoices) {
217 EntityCacheUtil.removeResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
218 PollsChoiceImpl.class, pollsChoice.getPrimaryKey());
219
220 clearUniqueFindersCache(pollsChoice);
221 }
222 }
223
224 protected void clearUniqueFindersCache(PollsChoice pollsChoice) {
225 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N,
226 new Object[] {
227 Long.valueOf(pollsChoice.getQuestionId()),
228
229 pollsChoice.getName()
230 });
231 }
232
233
239 public PollsChoice create(long choiceId) {
240 PollsChoice pollsChoice = new PollsChoiceImpl();
241
242 pollsChoice.setNew(true);
243 pollsChoice.setPrimaryKey(choiceId);
244
245 String uuid = PortalUUIDUtil.generate();
246
247 pollsChoice.setUuid(uuid);
248
249 return pollsChoice;
250 }
251
252
260 public PollsChoice remove(long choiceId)
261 throws NoSuchChoiceException, SystemException {
262 return remove(Long.valueOf(choiceId));
263 }
264
265
273 @Override
274 public PollsChoice remove(Serializable primaryKey)
275 throws NoSuchChoiceException, SystemException {
276 Session session = null;
277
278 try {
279 session = openSession();
280
281 PollsChoice pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
282 primaryKey);
283
284 if (pollsChoice == null) {
285 if (_log.isWarnEnabled()) {
286 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
287 }
288
289 throw new NoSuchChoiceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
290 primaryKey);
291 }
292
293 return remove(pollsChoice);
294 }
295 catch (NoSuchChoiceException nsee) {
296 throw nsee;
297 }
298 catch (Exception e) {
299 throw processException(e);
300 }
301 finally {
302 closeSession(session);
303 }
304 }
305
306 @Override
307 protected PollsChoice removeImpl(PollsChoice pollsChoice)
308 throws SystemException {
309 pollsChoice = toUnwrappedModel(pollsChoice);
310
311 Session session = null;
312
313 try {
314 session = openSession();
315
316 if (pollsChoice.isCachedModel()) {
317 pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
318 pollsChoice.getPrimaryKeyObj());
319 }
320
321 session.delete(pollsChoice);
322 }
323 catch (Exception e) {
324 throw processException(e);
325 }
326 finally {
327 closeSession(session);
328 }
329
330 clearCache(pollsChoice);
331
332 return pollsChoice;
333 }
334
335 @Override
336 public PollsChoice updateImpl(
337 com.liferay.portlet.polls.model.PollsChoice pollsChoice)
338 throws SystemException {
339 pollsChoice = toUnwrappedModel(pollsChoice);
340
341 boolean isNew = pollsChoice.isNew();
342
343 PollsChoiceModelImpl pollsChoiceModelImpl = (PollsChoiceModelImpl)pollsChoice;
344
345 if (Validator.isNull(pollsChoice.getUuid())) {
346 String uuid = PortalUUIDUtil.generate();
347
348 pollsChoice.setUuid(uuid);
349 }
350
351 Session session = null;
352
353 try {
354 session = openSession();
355
356 if (pollsChoice.isNew()) {
357 session.save(pollsChoice);
358
359 pollsChoice.setNew(false);
360 }
361 else {
362 session.merge(pollsChoice);
363 }
364 }
365 catch (Exception e) {
366 throw processException(e);
367 }
368 finally {
369 closeSession(session);
370 }
371
372 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
373
374 if (isNew || !PollsChoiceModelImpl.COLUMN_BITMASK_ENABLED) {
375 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
376 }
377
378 else {
379 if ((pollsChoiceModelImpl.getColumnBitmask() &
380 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
381 Object[] args = new Object[] {
382 pollsChoiceModelImpl.getOriginalUuid()
383 };
384
385 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
386 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
387 args);
388
389 args = new Object[] { pollsChoiceModelImpl.getUuid() };
390
391 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
392 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
393 args);
394 }
395
396 if ((pollsChoiceModelImpl.getColumnBitmask() &
397 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID.getColumnBitmask()) != 0) {
398 Object[] args = new Object[] {
399 Long.valueOf(pollsChoiceModelImpl.getOriginalQuestionId())
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 args = new Object[] {
408 Long.valueOf(pollsChoiceModelImpl.getQuestionId())
409 };
410
411 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_QUESTIONID,
412 args);
413 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID,
414 args);
415 }
416 }
417
418 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
419 PollsChoiceImpl.class, pollsChoice.getPrimaryKey(), pollsChoice);
420
421 if (isNew) {
422 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
423 new Object[] {
424 Long.valueOf(pollsChoice.getQuestionId()),
425
426 pollsChoice.getName()
427 }, pollsChoice);
428 }
429 else {
430 if ((pollsChoiceModelImpl.getColumnBitmask() &
431 FINDER_PATH_FETCH_BY_Q_N.getColumnBitmask()) != 0) {
432 Object[] args = new Object[] {
433 Long.valueOf(pollsChoiceModelImpl.getOriginalQuestionId()),
434
435 pollsChoiceModelImpl.getOriginalName()
436 };
437
438 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_Q_N, args);
439
440 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N, args);
441
442 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
443 new Object[] {
444 Long.valueOf(pollsChoice.getQuestionId()),
445
446 pollsChoice.getName()
447 }, pollsChoice);
448 }
449 }
450
451 return pollsChoice;
452 }
453
454 protected PollsChoice toUnwrappedModel(PollsChoice pollsChoice) {
455 if (pollsChoice instanceof PollsChoiceImpl) {
456 return pollsChoice;
457 }
458
459 PollsChoiceImpl pollsChoiceImpl = new PollsChoiceImpl();
460
461 pollsChoiceImpl.setNew(pollsChoice.isNew());
462 pollsChoiceImpl.setPrimaryKey(pollsChoice.getPrimaryKey());
463
464 pollsChoiceImpl.setUuid(pollsChoice.getUuid());
465 pollsChoiceImpl.setChoiceId(pollsChoice.getChoiceId());
466 pollsChoiceImpl.setQuestionId(pollsChoice.getQuestionId());
467 pollsChoiceImpl.setName(pollsChoice.getName());
468 pollsChoiceImpl.setDescription(pollsChoice.getDescription());
469
470 return pollsChoiceImpl;
471 }
472
473
481 @Override
482 public PollsChoice findByPrimaryKey(Serializable primaryKey)
483 throws NoSuchModelException, SystemException {
484 return findByPrimaryKey(((Long)primaryKey).longValue());
485 }
486
487
495 public PollsChoice findByPrimaryKey(long choiceId)
496 throws NoSuchChoiceException, SystemException {
497 PollsChoice pollsChoice = fetchByPrimaryKey(choiceId);
498
499 if (pollsChoice == null) {
500 if (_log.isWarnEnabled()) {
501 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + choiceId);
502 }
503
504 throw new NoSuchChoiceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
505 choiceId);
506 }
507
508 return pollsChoice;
509 }
510
511
518 @Override
519 public PollsChoice fetchByPrimaryKey(Serializable primaryKey)
520 throws SystemException {
521 return fetchByPrimaryKey(((Long)primaryKey).longValue());
522 }
523
524
531 public PollsChoice fetchByPrimaryKey(long choiceId)
532 throws SystemException {
533 PollsChoice pollsChoice = (PollsChoice)EntityCacheUtil.getResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
534 PollsChoiceImpl.class, choiceId);
535
536 if (pollsChoice == _nullPollsChoice) {
537 return null;
538 }
539
540 if (pollsChoice == null) {
541 Session session = null;
542
543 boolean hasException = false;
544
545 try {
546 session = openSession();
547
548 pollsChoice = (PollsChoice)session.get(PollsChoiceImpl.class,
549 Long.valueOf(choiceId));
550 }
551 catch (Exception e) {
552 hasException = true;
553
554 throw processException(e);
555 }
556 finally {
557 if (pollsChoice != null) {
558 cacheResult(pollsChoice);
559 }
560 else if (!hasException) {
561 EntityCacheUtil.putResult(PollsChoiceModelImpl.ENTITY_CACHE_ENABLED,
562 PollsChoiceImpl.class, choiceId, _nullPollsChoice);
563 }
564
565 closeSession(session);
566 }
567 }
568
569 return pollsChoice;
570 }
571
572
579 public List<PollsChoice> findByUuid(String uuid) throws SystemException {
580 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
581 }
582
583
596 public List<PollsChoice> findByUuid(String uuid, int start, int end)
597 throws SystemException {
598 return findByUuid(uuid, start, end, null);
599 }
600
601
615 public List<PollsChoice> findByUuid(String uuid, int start, int end,
616 OrderByComparator orderByComparator) throws SystemException {
617 FinderPath finderPath = null;
618 Object[] finderArgs = null;
619
620 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
621 (orderByComparator == null)) {
622 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
623 finderArgs = new Object[] { uuid };
624 }
625 else {
626 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
627 finderArgs = new Object[] { uuid, start, end, orderByComparator };
628 }
629
630 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
631 finderArgs, this);
632
633 if ((list != null) && !list.isEmpty()) {
634 for (PollsChoice pollsChoice : list) {
635 if (!Validator.equals(uuid, pollsChoice.getUuid())) {
636 list = null;
637
638 break;
639 }
640 }
641 }
642
643 if (list == null) {
644 StringBundler query = null;
645
646 if (orderByComparator != null) {
647 query = new StringBundler(3 +
648 (orderByComparator.getOrderByFields().length * 3));
649 }
650 else {
651 query = new StringBundler(3);
652 }
653
654 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
655
656 if (uuid == null) {
657 query.append(_FINDER_COLUMN_UUID_UUID_1);
658 }
659 else {
660 if (uuid.equals(StringPool.BLANK)) {
661 query.append(_FINDER_COLUMN_UUID_UUID_3);
662 }
663 else {
664 query.append(_FINDER_COLUMN_UUID_UUID_2);
665 }
666 }
667
668 if (orderByComparator != null) {
669 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
670 orderByComparator);
671 }
672
673 else {
674 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
675 }
676
677 String sql = query.toString();
678
679 Session session = null;
680
681 try {
682 session = openSession();
683
684 Query q = session.createQuery(sql);
685
686 QueryPos qPos = QueryPos.getInstance(q);
687
688 if (uuid != null) {
689 qPos.add(uuid);
690 }
691
692 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
693 start, end);
694 }
695 catch (Exception e) {
696 throw processException(e);
697 }
698 finally {
699 if (list == null) {
700 FinderCacheUtil.removeResult(finderPath, finderArgs);
701 }
702 else {
703 cacheResult(list);
704
705 FinderCacheUtil.putResult(finderPath, finderArgs, list);
706 }
707
708 closeSession(session);
709 }
710 }
711
712 return list;
713 }
714
715
724 public PollsChoice findByUuid_First(String uuid,
725 OrderByComparator orderByComparator)
726 throws NoSuchChoiceException, SystemException {
727 PollsChoice pollsChoice = fetchByUuid_First(uuid, orderByComparator);
728
729 if (pollsChoice != null) {
730 return pollsChoice;
731 }
732
733 StringBundler msg = new StringBundler(4);
734
735 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
736
737 msg.append("uuid=");
738 msg.append(uuid);
739
740 msg.append(StringPool.CLOSE_CURLY_BRACE);
741
742 throw new NoSuchChoiceException(msg.toString());
743 }
744
745
753 public PollsChoice fetchByUuid_First(String uuid,
754 OrderByComparator orderByComparator) throws SystemException {
755 List<PollsChoice> list = findByUuid(uuid, 0, 1, orderByComparator);
756
757 if (!list.isEmpty()) {
758 return list.get(0);
759 }
760
761 return null;
762 }
763
764
773 public PollsChoice findByUuid_Last(String uuid,
774 OrderByComparator orderByComparator)
775 throws NoSuchChoiceException, SystemException {
776 PollsChoice pollsChoice = fetchByUuid_Last(uuid, orderByComparator);
777
778 if (pollsChoice != null) {
779 return pollsChoice;
780 }
781
782 StringBundler msg = new StringBundler(4);
783
784 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
785
786 msg.append("uuid=");
787 msg.append(uuid);
788
789 msg.append(StringPool.CLOSE_CURLY_BRACE);
790
791 throw new NoSuchChoiceException(msg.toString());
792 }
793
794
802 public PollsChoice fetchByUuid_Last(String uuid,
803 OrderByComparator orderByComparator) throws SystemException {
804 int count = countByUuid(uuid);
805
806 List<PollsChoice> list = findByUuid(uuid, count - 1, count,
807 orderByComparator);
808
809 if (!list.isEmpty()) {
810 return list.get(0);
811 }
812
813 return null;
814 }
815
816
826 public PollsChoice[] findByUuid_PrevAndNext(long choiceId, String uuid,
827 OrderByComparator orderByComparator)
828 throws NoSuchChoiceException, SystemException {
829 PollsChoice pollsChoice = findByPrimaryKey(choiceId);
830
831 Session session = null;
832
833 try {
834 session = openSession();
835
836 PollsChoice[] array = new PollsChoiceImpl[3];
837
838 array[0] = getByUuid_PrevAndNext(session, pollsChoice, uuid,
839 orderByComparator, true);
840
841 array[1] = pollsChoice;
842
843 array[2] = getByUuid_PrevAndNext(session, pollsChoice, uuid,
844 orderByComparator, false);
845
846 return array;
847 }
848 catch (Exception e) {
849 throw processException(e);
850 }
851 finally {
852 closeSession(session);
853 }
854 }
855
856 protected PollsChoice getByUuid_PrevAndNext(Session session,
857 PollsChoice pollsChoice, String uuid,
858 OrderByComparator orderByComparator, boolean previous) {
859 StringBundler query = null;
860
861 if (orderByComparator != null) {
862 query = new StringBundler(6 +
863 (orderByComparator.getOrderByFields().length * 6));
864 }
865 else {
866 query = new StringBundler(3);
867 }
868
869 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
870
871 if (uuid == null) {
872 query.append(_FINDER_COLUMN_UUID_UUID_1);
873 }
874 else {
875 if (uuid.equals(StringPool.BLANK)) {
876 query.append(_FINDER_COLUMN_UUID_UUID_3);
877 }
878 else {
879 query.append(_FINDER_COLUMN_UUID_UUID_2);
880 }
881 }
882
883 if (orderByComparator != null) {
884 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
885
886 if (orderByConditionFields.length > 0) {
887 query.append(WHERE_AND);
888 }
889
890 for (int i = 0; i < orderByConditionFields.length; i++) {
891 query.append(_ORDER_BY_ENTITY_ALIAS);
892 query.append(orderByConditionFields[i]);
893
894 if ((i + 1) < orderByConditionFields.length) {
895 if (orderByComparator.isAscending() ^ previous) {
896 query.append(WHERE_GREATER_THAN_HAS_NEXT);
897 }
898 else {
899 query.append(WHERE_LESSER_THAN_HAS_NEXT);
900 }
901 }
902 else {
903 if (orderByComparator.isAscending() ^ previous) {
904 query.append(WHERE_GREATER_THAN);
905 }
906 else {
907 query.append(WHERE_LESSER_THAN);
908 }
909 }
910 }
911
912 query.append(ORDER_BY_CLAUSE);
913
914 String[] orderByFields = orderByComparator.getOrderByFields();
915
916 for (int i = 0; i < orderByFields.length; i++) {
917 query.append(_ORDER_BY_ENTITY_ALIAS);
918 query.append(orderByFields[i]);
919
920 if ((i + 1) < orderByFields.length) {
921 if (orderByComparator.isAscending() ^ previous) {
922 query.append(ORDER_BY_ASC_HAS_NEXT);
923 }
924 else {
925 query.append(ORDER_BY_DESC_HAS_NEXT);
926 }
927 }
928 else {
929 if (orderByComparator.isAscending() ^ previous) {
930 query.append(ORDER_BY_ASC);
931 }
932 else {
933 query.append(ORDER_BY_DESC);
934 }
935 }
936 }
937 }
938
939 else {
940 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
941 }
942
943 String sql = query.toString();
944
945 Query q = session.createQuery(sql);
946
947 q.setFirstResult(0);
948 q.setMaxResults(2);
949
950 QueryPos qPos = QueryPos.getInstance(q);
951
952 if (uuid != null) {
953 qPos.add(uuid);
954 }
955
956 if (orderByComparator != null) {
957 Object[] values = orderByComparator.getOrderByConditionValues(pollsChoice);
958
959 for (Object value : values) {
960 qPos.add(value);
961 }
962 }
963
964 List<PollsChoice> list = q.list();
965
966 if (list.size() == 2) {
967 return list.get(1);
968 }
969 else {
970 return null;
971 }
972 }
973
974
981 public List<PollsChoice> findByQuestionId(long questionId)
982 throws SystemException {
983 return findByQuestionId(questionId, QueryUtil.ALL_POS,
984 QueryUtil.ALL_POS, null);
985 }
986
987
1000 public List<PollsChoice> findByQuestionId(long questionId, int start,
1001 int end) throws SystemException {
1002 return findByQuestionId(questionId, start, end, null);
1003 }
1004
1005
1019 public List<PollsChoice> findByQuestionId(long questionId, int start,
1020 int end, OrderByComparator orderByComparator) throws SystemException {
1021 FinderPath finderPath = null;
1022 Object[] finderArgs = null;
1023
1024 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1025 (orderByComparator == null)) {
1026 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_QUESTIONID;
1027 finderArgs = new Object[] { questionId };
1028 }
1029 else {
1030 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_QUESTIONID;
1031 finderArgs = new Object[] { questionId, start, end, orderByComparator };
1032 }
1033
1034 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
1035 finderArgs, this);
1036
1037 if ((list != null) && !list.isEmpty()) {
1038 for (PollsChoice pollsChoice : list) {
1039 if ((questionId != pollsChoice.getQuestionId())) {
1040 list = null;
1041
1042 break;
1043 }
1044 }
1045 }
1046
1047 if (list == null) {
1048 StringBundler query = null;
1049
1050 if (orderByComparator != null) {
1051 query = new StringBundler(3 +
1052 (orderByComparator.getOrderByFields().length * 3));
1053 }
1054 else {
1055 query = new StringBundler(3);
1056 }
1057
1058 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
1059
1060 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1061
1062 if (orderByComparator != null) {
1063 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1064 orderByComparator);
1065 }
1066
1067 else {
1068 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
1069 }
1070
1071 String sql = query.toString();
1072
1073 Session session = null;
1074
1075 try {
1076 session = openSession();
1077
1078 Query q = session.createQuery(sql);
1079
1080 QueryPos qPos = QueryPos.getInstance(q);
1081
1082 qPos.add(questionId);
1083
1084 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1085 start, end);
1086 }
1087 catch (Exception e) {
1088 throw processException(e);
1089 }
1090 finally {
1091 if (list == null) {
1092 FinderCacheUtil.removeResult(finderPath, finderArgs);
1093 }
1094 else {
1095 cacheResult(list);
1096
1097 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1098 }
1099
1100 closeSession(session);
1101 }
1102 }
1103
1104 return list;
1105 }
1106
1107
1116 public PollsChoice findByQuestionId_First(long questionId,
1117 OrderByComparator orderByComparator)
1118 throws NoSuchChoiceException, SystemException {
1119 PollsChoice pollsChoice = fetchByQuestionId_First(questionId,
1120 orderByComparator);
1121
1122 if (pollsChoice != null) {
1123 return pollsChoice;
1124 }
1125
1126 StringBundler msg = new StringBundler(4);
1127
1128 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1129
1130 msg.append("questionId=");
1131 msg.append(questionId);
1132
1133 msg.append(StringPool.CLOSE_CURLY_BRACE);
1134
1135 throw new NoSuchChoiceException(msg.toString());
1136 }
1137
1138
1146 public PollsChoice fetchByQuestionId_First(long questionId,
1147 OrderByComparator orderByComparator) throws SystemException {
1148 List<PollsChoice> list = findByQuestionId(questionId, 0, 1,
1149 orderByComparator);
1150
1151 if (!list.isEmpty()) {
1152 return list.get(0);
1153 }
1154
1155 return null;
1156 }
1157
1158
1167 public PollsChoice findByQuestionId_Last(long questionId,
1168 OrderByComparator orderByComparator)
1169 throws NoSuchChoiceException, SystemException {
1170 PollsChoice pollsChoice = fetchByQuestionId_Last(questionId,
1171 orderByComparator);
1172
1173 if (pollsChoice != null) {
1174 return pollsChoice;
1175 }
1176
1177 StringBundler msg = new StringBundler(4);
1178
1179 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1180
1181 msg.append("questionId=");
1182 msg.append(questionId);
1183
1184 msg.append(StringPool.CLOSE_CURLY_BRACE);
1185
1186 throw new NoSuchChoiceException(msg.toString());
1187 }
1188
1189
1197 public PollsChoice fetchByQuestionId_Last(long questionId,
1198 OrderByComparator orderByComparator) throws SystemException {
1199 int count = countByQuestionId(questionId);
1200
1201 List<PollsChoice> list = findByQuestionId(questionId, count - 1, count,
1202 orderByComparator);
1203
1204 if (!list.isEmpty()) {
1205 return list.get(0);
1206 }
1207
1208 return null;
1209 }
1210
1211
1221 public PollsChoice[] findByQuestionId_PrevAndNext(long choiceId,
1222 long questionId, OrderByComparator orderByComparator)
1223 throws NoSuchChoiceException, SystemException {
1224 PollsChoice pollsChoice = findByPrimaryKey(choiceId);
1225
1226 Session session = null;
1227
1228 try {
1229 session = openSession();
1230
1231 PollsChoice[] array = new PollsChoiceImpl[3];
1232
1233 array[0] = getByQuestionId_PrevAndNext(session, pollsChoice,
1234 questionId, orderByComparator, true);
1235
1236 array[1] = pollsChoice;
1237
1238 array[2] = getByQuestionId_PrevAndNext(session, pollsChoice,
1239 questionId, orderByComparator, false);
1240
1241 return array;
1242 }
1243 catch (Exception e) {
1244 throw processException(e);
1245 }
1246 finally {
1247 closeSession(session);
1248 }
1249 }
1250
1251 protected PollsChoice getByQuestionId_PrevAndNext(Session session,
1252 PollsChoice pollsChoice, long questionId,
1253 OrderByComparator orderByComparator, boolean previous) {
1254 StringBundler query = null;
1255
1256 if (orderByComparator != null) {
1257 query = new StringBundler(6 +
1258 (orderByComparator.getOrderByFields().length * 6));
1259 }
1260 else {
1261 query = new StringBundler(3);
1262 }
1263
1264 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
1265
1266 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1267
1268 if (orderByComparator != null) {
1269 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1270
1271 if (orderByConditionFields.length > 0) {
1272 query.append(WHERE_AND);
1273 }
1274
1275 for (int i = 0; i < orderByConditionFields.length; i++) {
1276 query.append(_ORDER_BY_ENTITY_ALIAS);
1277 query.append(orderByConditionFields[i]);
1278
1279 if ((i + 1) < orderByConditionFields.length) {
1280 if (orderByComparator.isAscending() ^ previous) {
1281 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1282 }
1283 else {
1284 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1285 }
1286 }
1287 else {
1288 if (orderByComparator.isAscending() ^ previous) {
1289 query.append(WHERE_GREATER_THAN);
1290 }
1291 else {
1292 query.append(WHERE_LESSER_THAN);
1293 }
1294 }
1295 }
1296
1297 query.append(ORDER_BY_CLAUSE);
1298
1299 String[] orderByFields = orderByComparator.getOrderByFields();
1300
1301 for (int i = 0; i < orderByFields.length; i++) {
1302 query.append(_ORDER_BY_ENTITY_ALIAS);
1303 query.append(orderByFields[i]);
1304
1305 if ((i + 1) < orderByFields.length) {
1306 if (orderByComparator.isAscending() ^ previous) {
1307 query.append(ORDER_BY_ASC_HAS_NEXT);
1308 }
1309 else {
1310 query.append(ORDER_BY_DESC_HAS_NEXT);
1311 }
1312 }
1313 else {
1314 if (orderByComparator.isAscending() ^ previous) {
1315 query.append(ORDER_BY_ASC);
1316 }
1317 else {
1318 query.append(ORDER_BY_DESC);
1319 }
1320 }
1321 }
1322 }
1323
1324 else {
1325 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
1326 }
1327
1328 String sql = query.toString();
1329
1330 Query q = session.createQuery(sql);
1331
1332 q.setFirstResult(0);
1333 q.setMaxResults(2);
1334
1335 QueryPos qPos = QueryPos.getInstance(q);
1336
1337 qPos.add(questionId);
1338
1339 if (orderByComparator != null) {
1340 Object[] values = orderByComparator.getOrderByConditionValues(pollsChoice);
1341
1342 for (Object value : values) {
1343 qPos.add(value);
1344 }
1345 }
1346
1347 List<PollsChoice> list = q.list();
1348
1349 if (list.size() == 2) {
1350 return list.get(1);
1351 }
1352 else {
1353 return null;
1354 }
1355 }
1356
1357
1366 public PollsChoice findByQ_N(long questionId, String name)
1367 throws NoSuchChoiceException, SystemException {
1368 PollsChoice pollsChoice = fetchByQ_N(questionId, name);
1369
1370 if (pollsChoice == null) {
1371 StringBundler msg = new StringBundler(6);
1372
1373 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1374
1375 msg.append("questionId=");
1376 msg.append(questionId);
1377
1378 msg.append(", name=");
1379 msg.append(name);
1380
1381 msg.append(StringPool.CLOSE_CURLY_BRACE);
1382
1383 if (_log.isWarnEnabled()) {
1384 _log.warn(msg.toString());
1385 }
1386
1387 throw new NoSuchChoiceException(msg.toString());
1388 }
1389
1390 return pollsChoice;
1391 }
1392
1393
1401 public PollsChoice fetchByQ_N(long questionId, String name)
1402 throws SystemException {
1403 return fetchByQ_N(questionId, name, true);
1404 }
1405
1406
1415 public PollsChoice fetchByQ_N(long questionId, String name,
1416 boolean retrieveFromCache) throws SystemException {
1417 Object[] finderArgs = new Object[] { questionId, name };
1418
1419 Object result = null;
1420
1421 if (retrieveFromCache) {
1422 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_Q_N,
1423 finderArgs, this);
1424 }
1425
1426 if (result instanceof PollsChoice) {
1427 PollsChoice pollsChoice = (PollsChoice)result;
1428
1429 if ((questionId != pollsChoice.getQuestionId()) ||
1430 !Validator.equals(name, pollsChoice.getName())) {
1431 result = null;
1432 }
1433 }
1434
1435 if (result == null) {
1436 StringBundler query = new StringBundler(4);
1437
1438 query.append(_SQL_SELECT_POLLSCHOICE_WHERE);
1439
1440 query.append(_FINDER_COLUMN_Q_N_QUESTIONID_2);
1441
1442 if (name == null) {
1443 query.append(_FINDER_COLUMN_Q_N_NAME_1);
1444 }
1445 else {
1446 if (name.equals(StringPool.BLANK)) {
1447 query.append(_FINDER_COLUMN_Q_N_NAME_3);
1448 }
1449 else {
1450 query.append(_FINDER_COLUMN_Q_N_NAME_2);
1451 }
1452 }
1453
1454 query.append(PollsChoiceModelImpl.ORDER_BY_JPQL);
1455
1456 String sql = query.toString();
1457
1458 Session session = null;
1459
1460 try {
1461 session = openSession();
1462
1463 Query q = session.createQuery(sql);
1464
1465 QueryPos qPos = QueryPos.getInstance(q);
1466
1467 qPos.add(questionId);
1468
1469 if (name != null) {
1470 qPos.add(name);
1471 }
1472
1473 List<PollsChoice> list = q.list();
1474
1475 result = list;
1476
1477 PollsChoice pollsChoice = null;
1478
1479 if (list.isEmpty()) {
1480 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
1481 finderArgs, list);
1482 }
1483 else {
1484 pollsChoice = list.get(0);
1485
1486 cacheResult(pollsChoice);
1487
1488 if ((pollsChoice.getQuestionId() != questionId) ||
1489 (pollsChoice.getName() == null) ||
1490 !pollsChoice.getName().equals(name)) {
1491 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_N,
1492 finderArgs, pollsChoice);
1493 }
1494 }
1495
1496 return pollsChoice;
1497 }
1498 catch (Exception e) {
1499 throw processException(e);
1500 }
1501 finally {
1502 if (result == null) {
1503 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_N,
1504 finderArgs);
1505 }
1506
1507 closeSession(session);
1508 }
1509 }
1510 else {
1511 if (result instanceof List<?>) {
1512 return null;
1513 }
1514 else {
1515 return (PollsChoice)result;
1516 }
1517 }
1518 }
1519
1520
1526 public List<PollsChoice> findAll() throws SystemException {
1527 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1528 }
1529
1530
1542 public List<PollsChoice> findAll(int start, int end)
1543 throws SystemException {
1544 return findAll(start, end, null);
1545 }
1546
1547
1560 public List<PollsChoice> findAll(int start, int end,
1561 OrderByComparator orderByComparator) throws SystemException {
1562 FinderPath finderPath = null;
1563 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1564
1565 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1566 (orderByComparator == null)) {
1567 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1568 finderArgs = FINDER_ARGS_EMPTY;
1569 }
1570 else {
1571 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1572 finderArgs = new Object[] { start, end, orderByComparator };
1573 }
1574
1575 List<PollsChoice> list = (List<PollsChoice>)FinderCacheUtil.getResult(finderPath,
1576 finderArgs, this);
1577
1578 if (list == null) {
1579 StringBundler query = null;
1580 String sql = null;
1581
1582 if (orderByComparator != null) {
1583 query = new StringBundler(2 +
1584 (orderByComparator.getOrderByFields().length * 3));
1585
1586 query.append(_SQL_SELECT_POLLSCHOICE);
1587
1588 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1589 orderByComparator);
1590
1591 sql = query.toString();
1592 }
1593 else {
1594 sql = _SQL_SELECT_POLLSCHOICE.concat(PollsChoiceModelImpl.ORDER_BY_JPQL);
1595 }
1596
1597 Session session = null;
1598
1599 try {
1600 session = openSession();
1601
1602 Query q = session.createQuery(sql);
1603
1604 if (orderByComparator == null) {
1605 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1606 start, end, false);
1607
1608 Collections.sort(list);
1609 }
1610 else {
1611 list = (List<PollsChoice>)QueryUtil.list(q, getDialect(),
1612 start, end);
1613 }
1614 }
1615 catch (Exception e) {
1616 throw processException(e);
1617 }
1618 finally {
1619 if (list == null) {
1620 FinderCacheUtil.removeResult(finderPath, finderArgs);
1621 }
1622 else {
1623 cacheResult(list);
1624
1625 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1626 }
1627
1628 closeSession(session);
1629 }
1630 }
1631
1632 return list;
1633 }
1634
1635
1641 public void removeByUuid(String uuid) throws SystemException {
1642 for (PollsChoice pollsChoice : findByUuid(uuid)) {
1643 remove(pollsChoice);
1644 }
1645 }
1646
1647
1653 public void removeByQuestionId(long questionId) throws SystemException {
1654 for (PollsChoice pollsChoice : findByQuestionId(questionId)) {
1655 remove(pollsChoice);
1656 }
1657 }
1658
1659
1667 public PollsChoice removeByQ_N(long questionId, String name)
1668 throws NoSuchChoiceException, SystemException {
1669 PollsChoice pollsChoice = findByQ_N(questionId, name);
1670
1671 return remove(pollsChoice);
1672 }
1673
1674
1679 public void removeAll() throws SystemException {
1680 for (PollsChoice pollsChoice : findAll()) {
1681 remove(pollsChoice);
1682 }
1683 }
1684
1685
1692 public int countByUuid(String uuid) throws SystemException {
1693 Object[] finderArgs = new Object[] { uuid };
1694
1695 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1696 finderArgs, this);
1697
1698 if (count == null) {
1699 StringBundler query = new StringBundler(2);
1700
1701 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
1702
1703 if (uuid == null) {
1704 query.append(_FINDER_COLUMN_UUID_UUID_1);
1705 }
1706 else {
1707 if (uuid.equals(StringPool.BLANK)) {
1708 query.append(_FINDER_COLUMN_UUID_UUID_3);
1709 }
1710 else {
1711 query.append(_FINDER_COLUMN_UUID_UUID_2);
1712 }
1713 }
1714
1715 String sql = query.toString();
1716
1717 Session session = null;
1718
1719 try {
1720 session = openSession();
1721
1722 Query q = session.createQuery(sql);
1723
1724 QueryPos qPos = QueryPos.getInstance(q);
1725
1726 if (uuid != null) {
1727 qPos.add(uuid);
1728 }
1729
1730 count = (Long)q.uniqueResult();
1731 }
1732 catch (Exception e) {
1733 throw processException(e);
1734 }
1735 finally {
1736 if (count == null) {
1737 count = Long.valueOf(0);
1738 }
1739
1740 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1741 finderArgs, count);
1742
1743 closeSession(session);
1744 }
1745 }
1746
1747 return count.intValue();
1748 }
1749
1750
1757 public int countByQuestionId(long questionId) throws SystemException {
1758 Object[] finderArgs = new Object[] { questionId };
1759
1760 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1761 finderArgs, this);
1762
1763 if (count == null) {
1764 StringBundler query = new StringBundler(2);
1765
1766 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
1767
1768 query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1769
1770 String sql = query.toString();
1771
1772 Session session = null;
1773
1774 try {
1775 session = openSession();
1776
1777 Query q = session.createQuery(sql);
1778
1779 QueryPos qPos = QueryPos.getInstance(q);
1780
1781 qPos.add(questionId);
1782
1783 count = (Long)q.uniqueResult();
1784 }
1785 catch (Exception e) {
1786 throw processException(e);
1787 }
1788 finally {
1789 if (count == null) {
1790 count = Long.valueOf(0);
1791 }
1792
1793 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1794 finderArgs, count);
1795
1796 closeSession(session);
1797 }
1798 }
1799
1800 return count.intValue();
1801 }
1802
1803
1811 public int countByQ_N(long questionId, String name)
1812 throws SystemException {
1813 Object[] finderArgs = new Object[] { questionId, name };
1814
1815 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_Q_N,
1816 finderArgs, this);
1817
1818 if (count == null) {
1819 StringBundler query = new StringBundler(3);
1820
1821 query.append(_SQL_COUNT_POLLSCHOICE_WHERE);
1822
1823 query.append(_FINDER_COLUMN_Q_N_QUESTIONID_2);
1824
1825 if (name == null) {
1826 query.append(_FINDER_COLUMN_Q_N_NAME_1);
1827 }
1828 else {
1829 if (name.equals(StringPool.BLANK)) {
1830 query.append(_FINDER_COLUMN_Q_N_NAME_3);
1831 }
1832 else {
1833 query.append(_FINDER_COLUMN_Q_N_NAME_2);
1834 }
1835 }
1836
1837 String sql = query.toString();
1838
1839 Session session = null;
1840
1841 try {
1842 session = openSession();
1843
1844 Query q = session.createQuery(sql);
1845
1846 QueryPos qPos = QueryPos.getInstance(q);
1847
1848 qPos.add(questionId);
1849
1850 if (name != null) {
1851 qPos.add(name);
1852 }
1853
1854 count = (Long)q.uniqueResult();
1855 }
1856 catch (Exception e) {
1857 throw processException(e);
1858 }
1859 finally {
1860 if (count == null) {
1861 count = Long.valueOf(0);
1862 }
1863
1864 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_Q_N, finderArgs,
1865 count);
1866
1867 closeSession(session);
1868 }
1869 }
1870
1871 return count.intValue();
1872 }
1873
1874
1880 public int countAll() throws SystemException {
1881 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1882 FINDER_ARGS_EMPTY, this);
1883
1884 if (count == null) {
1885 Session session = null;
1886
1887 try {
1888 session = openSession();
1889
1890 Query q = session.createQuery(_SQL_COUNT_POLLSCHOICE);
1891
1892 count = (Long)q.uniqueResult();
1893 }
1894 catch (Exception e) {
1895 throw processException(e);
1896 }
1897 finally {
1898 if (count == null) {
1899 count = Long.valueOf(0);
1900 }
1901
1902 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1903 FINDER_ARGS_EMPTY, count);
1904
1905 closeSession(session);
1906 }
1907 }
1908
1909 return count.intValue();
1910 }
1911
1912
1915 public void afterPropertiesSet() {
1916 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1917 com.liferay.portal.util.PropsUtil.get(
1918 "value.object.listener.com.liferay.portlet.polls.model.PollsChoice")));
1919
1920 if (listenerClassNames.length > 0) {
1921 try {
1922 List<ModelListener<PollsChoice>> listenersList = new ArrayList<ModelListener<PollsChoice>>();
1923
1924 for (String listenerClassName : listenerClassNames) {
1925 listenersList.add((ModelListener<PollsChoice>)InstanceFactory.newInstance(
1926 listenerClassName));
1927 }
1928
1929 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1930 }
1931 catch (Exception e) {
1932 _log.error(e);
1933 }
1934 }
1935 }
1936
1937 public void destroy() {
1938 EntityCacheUtil.removeCache(PollsChoiceImpl.class.getName());
1939 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1940 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1941 }
1942
1943 @BeanReference(type = PollsChoicePersistence.class)
1944 protected PollsChoicePersistence pollsChoicePersistence;
1945 @BeanReference(type = PollsQuestionPersistence.class)
1946 protected PollsQuestionPersistence pollsQuestionPersistence;
1947 @BeanReference(type = PollsVotePersistence.class)
1948 protected PollsVotePersistence pollsVotePersistence;
1949 @BeanReference(type = UserPersistence.class)
1950 protected UserPersistence userPersistence;
1951 private static final String _SQL_SELECT_POLLSCHOICE = "SELECT pollsChoice FROM PollsChoice pollsChoice";
1952 private static final String _SQL_SELECT_POLLSCHOICE_WHERE = "SELECT pollsChoice FROM PollsChoice pollsChoice WHERE ";
1953 private static final String _SQL_COUNT_POLLSCHOICE = "SELECT COUNT(pollsChoice) FROM PollsChoice pollsChoice";
1954 private static final String _SQL_COUNT_POLLSCHOICE_WHERE = "SELECT COUNT(pollsChoice) FROM PollsChoice pollsChoice WHERE ";
1955 private static final String _FINDER_COLUMN_UUID_UUID_1 = "pollsChoice.uuid IS NULL";
1956 private static final String _FINDER_COLUMN_UUID_UUID_2 = "pollsChoice.uuid = ?";
1957 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(pollsChoice.uuid IS NULL OR pollsChoice.uuid = ?)";
1958 private static final String _FINDER_COLUMN_QUESTIONID_QUESTIONID_2 = "pollsChoice.questionId = ?";
1959 private static final String _FINDER_COLUMN_Q_N_QUESTIONID_2 = "pollsChoice.questionId = ? AND ";
1960 private static final String _FINDER_COLUMN_Q_N_NAME_1 = "pollsChoice.name IS NULL";
1961 private static final String _FINDER_COLUMN_Q_N_NAME_2 = "pollsChoice.name = ?";
1962 private static final String _FINDER_COLUMN_Q_N_NAME_3 = "(pollsChoice.name IS NULL OR pollsChoice.name = ?)";
1963 private static final String _ORDER_BY_ENTITY_ALIAS = "pollsChoice.";
1964 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsChoice exists with the primary key ";
1965 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsChoice exists with the key {";
1966 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1967 private static Log _log = LogFactoryUtil.getLog(PollsChoicePersistenceImpl.class);
1968 private static PollsChoice _nullPollsChoice = new PollsChoiceImpl() {
1969 @Override
1970 public Object clone() {
1971 return this;
1972 }
1973
1974 @Override
1975 public CacheModel<PollsChoice> toCacheModel() {
1976 return _nullPollsChoiceCacheModel;
1977 }
1978 };
1979
1980 private static CacheModel<PollsChoice> _nullPollsChoiceCacheModel = new CacheModel<PollsChoice>() {
1981 public PollsChoice toEntityModel() {
1982 return _nullPollsChoice;
1983 }
1984 };
1985 }