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.SQLQuery;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.CacheModel;
040 import com.liferay.portal.model.ModelListener;
041 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042 import com.liferay.portal.service.persistence.BatchSessionUtil;
043 import com.liferay.portal.service.persistence.ResourcePersistence;
044 import com.liferay.portal.service.persistence.UserPersistence;
045 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046
047 import com.liferay.portlet.polls.NoSuchQuestionException;
048 import com.liferay.portlet.polls.model.PollsQuestion;
049 import com.liferay.portlet.polls.model.impl.PollsQuestionImpl;
050 import com.liferay.portlet.polls.model.impl.PollsQuestionModelImpl;
051
052 import java.io.Serializable;
053
054 import java.util.ArrayList;
055 import java.util.Collections;
056 import java.util.List;
057
058
070 public class PollsQuestionPersistenceImpl extends BasePersistenceImpl<PollsQuestion>
071 implements PollsQuestionPersistence {
072
077 public static final String FINDER_CLASS_NAME_ENTITY = PollsQuestionImpl.class.getName();
078 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List1";
080 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081 ".List2";
082 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
083 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
084 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
085 "findByUuid",
086 new String[] {
087 String.class.getName(),
088
089 "java.lang.Integer", "java.lang.Integer",
090 "com.liferay.portal.kernel.util.OrderByComparator"
091 });
092 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
093 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
094 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
095 "findByUuid", new String[] { String.class.getName() },
096 PollsQuestionModelImpl.UUID_COLUMN_BITMASK);
097 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
098 PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
100 new String[] { String.class.getName() });
101 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
102 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
103 PollsQuestionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
104 new String[] { String.class.getName(), Long.class.getName() },
105 PollsQuestionModelImpl.UUID_COLUMN_BITMASK |
106 PollsQuestionModelImpl.GROUPID_COLUMN_BITMASK);
107 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
108 PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
109 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
110 new String[] { String.class.getName(), Long.class.getName() });
111 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
112 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
113 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
114 "findByGroupId",
115 new String[] {
116 Long.class.getName(),
117
118 "java.lang.Integer", "java.lang.Integer",
119 "com.liferay.portal.kernel.util.OrderByComparator"
120 });
121 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
122 new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
123 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
124 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
125 "findByGroupId", new String[] { Long.class.getName() },
126 PollsQuestionModelImpl.GROUPID_COLUMN_BITMASK);
127 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
128 PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
129 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
130 new String[] { Long.class.getName() });
131 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
132 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
133 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
134 "findAll", new String[0]);
135 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
136 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
137 PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
138 "findAll", new String[0]);
139 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
140 PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
141 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
142
143
148 public void cacheResult(PollsQuestion pollsQuestion) {
149 EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
150 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
151 pollsQuestion);
152
153 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
154 new Object[] {
155 pollsQuestion.getUuid(),
156 Long.valueOf(pollsQuestion.getGroupId())
157 }, pollsQuestion);
158
159 pollsQuestion.resetOriginalValues();
160 }
161
162
167 public void cacheResult(List<PollsQuestion> pollsQuestions) {
168 for (PollsQuestion pollsQuestion : pollsQuestions) {
169 if (EntityCacheUtil.getResult(
170 PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
171 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey()) == null) {
172 cacheResult(pollsQuestion);
173 }
174 else {
175 pollsQuestion.resetOriginalValues();
176 }
177 }
178 }
179
180
187 @Override
188 public void clearCache() {
189 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
190 CacheRegistryUtil.clear(PollsQuestionImpl.class.getName());
191 }
192
193 EntityCacheUtil.clearCache(PollsQuestionImpl.class.getName());
194
195 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
196 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
197 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
198 }
199
200
207 @Override
208 public void clearCache(PollsQuestion pollsQuestion) {
209 EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
210 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey());
211
212 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
213 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
214
215 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
216 new Object[] {
217 pollsQuestion.getUuid(),
218 Long.valueOf(pollsQuestion.getGroupId())
219 });
220 }
221
222
228 public PollsQuestion create(long questionId) {
229 PollsQuestion pollsQuestion = new PollsQuestionImpl();
230
231 pollsQuestion.setNew(true);
232 pollsQuestion.setPrimaryKey(questionId);
233
234 String uuid = PortalUUIDUtil.generate();
235
236 pollsQuestion.setUuid(uuid);
237
238 return pollsQuestion;
239 }
240
241
249 @Override
250 public PollsQuestion remove(Serializable primaryKey)
251 throws NoSuchModelException, SystemException {
252 return remove(((Long)primaryKey).longValue());
253 }
254
255
263 public PollsQuestion remove(long questionId)
264 throws NoSuchQuestionException, SystemException {
265 Session session = null;
266
267 try {
268 session = openSession();
269
270 PollsQuestion pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
271 Long.valueOf(questionId));
272
273 if (pollsQuestion == null) {
274 if (_log.isWarnEnabled()) {
275 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + questionId);
276 }
277
278 throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
279 questionId);
280 }
281
282 return pollsQuestionPersistence.remove(pollsQuestion);
283 }
284 catch (NoSuchQuestionException nsee) {
285 throw nsee;
286 }
287 catch (Exception e) {
288 throw processException(e);
289 }
290 finally {
291 closeSession(session);
292 }
293 }
294
295
302 @Override
303 public PollsQuestion remove(PollsQuestion pollsQuestion)
304 throws SystemException {
305 return super.remove(pollsQuestion);
306 }
307
308 @Override
309 protected PollsQuestion removeImpl(PollsQuestion pollsQuestion)
310 throws SystemException {
311 pollsQuestion = toUnwrappedModel(pollsQuestion);
312
313 Session session = null;
314
315 try {
316 session = openSession();
317
318 BatchSessionUtil.delete(session, pollsQuestion);
319 }
320 catch (Exception e) {
321 throw processException(e);
322 }
323 finally {
324 closeSession(session);
325 }
326
327 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
328 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
329
330 PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
331
332 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
333 new Object[] {
334 pollsQuestionModelImpl.getUuid(),
335 Long.valueOf(pollsQuestionModelImpl.getGroupId())
336 });
337
338 EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
339 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey());
340
341 return pollsQuestion;
342 }
343
344 @Override
345 public PollsQuestion updateImpl(
346 com.liferay.portlet.polls.model.PollsQuestion pollsQuestion,
347 boolean merge) throws SystemException {
348 pollsQuestion = toUnwrappedModel(pollsQuestion);
349
350 boolean isNew = pollsQuestion.isNew();
351
352 PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
353
354 if (Validator.isNull(pollsQuestion.getUuid())) {
355 String uuid = PortalUUIDUtil.generate();
356
357 pollsQuestion.setUuid(uuid);
358 }
359
360 Session session = null;
361
362 try {
363 session = openSession();
364
365 BatchSessionUtil.update(session, pollsQuestion, merge);
366
367 pollsQuestion.setNew(false);
368 }
369 catch (Exception e) {
370 throw processException(e);
371 }
372 finally {
373 closeSession(session);
374 }
375
376 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
377
378 if (isNew || !PollsQuestionModelImpl.COLUMN_BITMASK_ENABLED) {
379 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
380 }
381
382 else {
383 if ((pollsQuestionModelImpl.getColumnBitmask() &
384 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
385 Object[] args = new Object[] {
386 pollsQuestionModelImpl.getOriginalUuid()
387 };
388
389 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
390 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
391 args);
392
393 args = new Object[] { pollsQuestionModelImpl.getUuid() };
394
395 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
396 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
397 args);
398 }
399
400 if ((pollsQuestionModelImpl.getColumnBitmask() &
401 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
402 Object[] args = new Object[] {
403 Long.valueOf(pollsQuestionModelImpl.getOriginalGroupId())
404 };
405
406 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
407 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
408 args);
409
410 args = new Object[] {
411 Long.valueOf(pollsQuestionModelImpl.getGroupId())
412 };
413
414 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
415 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
416 args);
417 }
418 }
419
420 EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
421 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
422 pollsQuestion);
423
424 if (isNew) {
425 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
426 new Object[] {
427 pollsQuestion.getUuid(),
428 Long.valueOf(pollsQuestion.getGroupId())
429 }, pollsQuestion);
430 }
431 else {
432 if ((pollsQuestionModelImpl.getColumnBitmask() &
433 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
434 Object[] args = new Object[] {
435 pollsQuestionModelImpl.getOriginalUuid(),
436 Long.valueOf(pollsQuestionModelImpl.getOriginalGroupId())
437 };
438
439 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
440 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
441
442 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
443 new Object[] {
444 pollsQuestion.getUuid(),
445 Long.valueOf(pollsQuestion.getGroupId())
446 }, pollsQuestion);
447 }
448 }
449
450 return pollsQuestion;
451 }
452
453 protected PollsQuestion toUnwrappedModel(PollsQuestion pollsQuestion) {
454 if (pollsQuestion instanceof PollsQuestionImpl) {
455 return pollsQuestion;
456 }
457
458 PollsQuestionImpl pollsQuestionImpl = new PollsQuestionImpl();
459
460 pollsQuestionImpl.setNew(pollsQuestion.isNew());
461 pollsQuestionImpl.setPrimaryKey(pollsQuestion.getPrimaryKey());
462
463 pollsQuestionImpl.setUuid(pollsQuestion.getUuid());
464 pollsQuestionImpl.setQuestionId(pollsQuestion.getQuestionId());
465 pollsQuestionImpl.setGroupId(pollsQuestion.getGroupId());
466 pollsQuestionImpl.setCompanyId(pollsQuestion.getCompanyId());
467 pollsQuestionImpl.setUserId(pollsQuestion.getUserId());
468 pollsQuestionImpl.setUserName(pollsQuestion.getUserName());
469 pollsQuestionImpl.setCreateDate(pollsQuestion.getCreateDate());
470 pollsQuestionImpl.setModifiedDate(pollsQuestion.getModifiedDate());
471 pollsQuestionImpl.setTitle(pollsQuestion.getTitle());
472 pollsQuestionImpl.setDescription(pollsQuestion.getDescription());
473 pollsQuestionImpl.setExpirationDate(pollsQuestion.getExpirationDate());
474 pollsQuestionImpl.setLastVoteDate(pollsQuestion.getLastVoteDate());
475
476 return pollsQuestionImpl;
477 }
478
479
487 @Override
488 public PollsQuestion findByPrimaryKey(Serializable primaryKey)
489 throws NoSuchModelException, SystemException {
490 return findByPrimaryKey(((Long)primaryKey).longValue());
491 }
492
493
501 public PollsQuestion findByPrimaryKey(long questionId)
502 throws NoSuchQuestionException, SystemException {
503 PollsQuestion pollsQuestion = fetchByPrimaryKey(questionId);
504
505 if (pollsQuestion == null) {
506 if (_log.isWarnEnabled()) {
507 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + questionId);
508 }
509
510 throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
511 questionId);
512 }
513
514 return pollsQuestion;
515 }
516
517
524 @Override
525 public PollsQuestion fetchByPrimaryKey(Serializable primaryKey)
526 throws SystemException {
527 return fetchByPrimaryKey(((Long)primaryKey).longValue());
528 }
529
530
537 public PollsQuestion fetchByPrimaryKey(long questionId)
538 throws SystemException {
539 PollsQuestion pollsQuestion = (PollsQuestion)EntityCacheUtil.getResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
540 PollsQuestionImpl.class, questionId);
541
542 if (pollsQuestion == _nullPollsQuestion) {
543 return null;
544 }
545
546 if (pollsQuestion == null) {
547 Session session = null;
548
549 boolean hasException = false;
550
551 try {
552 session = openSession();
553
554 pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
555 Long.valueOf(questionId));
556 }
557 catch (Exception e) {
558 hasException = true;
559
560 throw processException(e);
561 }
562 finally {
563 if (pollsQuestion != null) {
564 cacheResult(pollsQuestion);
565 }
566 else if (!hasException) {
567 EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
568 PollsQuestionImpl.class, questionId, _nullPollsQuestion);
569 }
570
571 closeSession(session);
572 }
573 }
574
575 return pollsQuestion;
576 }
577
578
585 public List<PollsQuestion> findByUuid(String uuid)
586 throws SystemException {
587 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
588 }
589
590
603 public List<PollsQuestion> findByUuid(String uuid, int start, int end)
604 throws SystemException {
605 return findByUuid(uuid, start, end, null);
606 }
607
608
622 public List<PollsQuestion> findByUuid(String uuid, int start, int end,
623 OrderByComparator orderByComparator) throws SystemException {
624 FinderPath finderPath = null;
625 Object[] finderArgs = null;
626
627 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
628 (orderByComparator == null)) {
629 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
630 finderArgs = new Object[] { uuid };
631 }
632 else {
633 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
634 finderArgs = new Object[] { uuid, start, end, orderByComparator };
635 }
636
637 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
638 finderArgs, this);
639
640 if (list == null) {
641 StringBundler query = null;
642
643 if (orderByComparator != null) {
644 query = new StringBundler(3 +
645 (orderByComparator.getOrderByFields().length * 3));
646 }
647 else {
648 query = new StringBundler(3);
649 }
650
651 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
652
653 if (uuid == null) {
654 query.append(_FINDER_COLUMN_UUID_UUID_1);
655 }
656 else {
657 if (uuid.equals(StringPool.BLANK)) {
658 query.append(_FINDER_COLUMN_UUID_UUID_3);
659 }
660 else {
661 query.append(_FINDER_COLUMN_UUID_UUID_2);
662 }
663 }
664
665 if (orderByComparator != null) {
666 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
667 orderByComparator);
668 }
669
670 else {
671 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
672 }
673
674 String sql = query.toString();
675
676 Session session = null;
677
678 try {
679 session = openSession();
680
681 Query q = session.createQuery(sql);
682
683 QueryPos qPos = QueryPos.getInstance(q);
684
685 if (uuid != null) {
686 qPos.add(uuid);
687 }
688
689 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
690 start, end);
691 }
692 catch (Exception e) {
693 throw processException(e);
694 }
695 finally {
696 if (list == null) {
697 FinderCacheUtil.removeResult(finderPath, finderArgs);
698 }
699 else {
700 cacheResult(list);
701
702 FinderCacheUtil.putResult(finderPath, finderArgs, list);
703 }
704
705 closeSession(session);
706 }
707 }
708
709 return list;
710 }
711
712
725 public PollsQuestion findByUuid_First(String uuid,
726 OrderByComparator orderByComparator)
727 throws NoSuchQuestionException, SystemException {
728 List<PollsQuestion> list = findByUuid(uuid, 0, 1, orderByComparator);
729
730 if (list.isEmpty()) {
731 StringBundler msg = new StringBundler(4);
732
733 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
734
735 msg.append("uuid=");
736 msg.append(uuid);
737
738 msg.append(StringPool.CLOSE_CURLY_BRACE);
739
740 throw new NoSuchQuestionException(msg.toString());
741 }
742 else {
743 return list.get(0);
744 }
745 }
746
747
760 public PollsQuestion findByUuid_Last(String uuid,
761 OrderByComparator orderByComparator)
762 throws NoSuchQuestionException, SystemException {
763 int count = countByUuid(uuid);
764
765 List<PollsQuestion> list = findByUuid(uuid, count - 1, count,
766 orderByComparator);
767
768 if (list.isEmpty()) {
769 StringBundler msg = new StringBundler(4);
770
771 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
772
773 msg.append("uuid=");
774 msg.append(uuid);
775
776 msg.append(StringPool.CLOSE_CURLY_BRACE);
777
778 throw new NoSuchQuestionException(msg.toString());
779 }
780 else {
781 return list.get(0);
782 }
783 }
784
785
799 public PollsQuestion[] findByUuid_PrevAndNext(long questionId, String uuid,
800 OrderByComparator orderByComparator)
801 throws NoSuchQuestionException, SystemException {
802 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
803
804 Session session = null;
805
806 try {
807 session = openSession();
808
809 PollsQuestion[] array = new PollsQuestionImpl[3];
810
811 array[0] = getByUuid_PrevAndNext(session, pollsQuestion, uuid,
812 orderByComparator, true);
813
814 array[1] = pollsQuestion;
815
816 array[2] = getByUuid_PrevAndNext(session, pollsQuestion, uuid,
817 orderByComparator, false);
818
819 return array;
820 }
821 catch (Exception e) {
822 throw processException(e);
823 }
824 finally {
825 closeSession(session);
826 }
827 }
828
829 protected PollsQuestion getByUuid_PrevAndNext(Session session,
830 PollsQuestion pollsQuestion, String uuid,
831 OrderByComparator orderByComparator, boolean previous) {
832 StringBundler query = null;
833
834 if (orderByComparator != null) {
835 query = new StringBundler(6 +
836 (orderByComparator.getOrderByFields().length * 6));
837 }
838 else {
839 query = new StringBundler(3);
840 }
841
842 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
843
844 if (uuid == null) {
845 query.append(_FINDER_COLUMN_UUID_UUID_1);
846 }
847 else {
848 if (uuid.equals(StringPool.BLANK)) {
849 query.append(_FINDER_COLUMN_UUID_UUID_3);
850 }
851 else {
852 query.append(_FINDER_COLUMN_UUID_UUID_2);
853 }
854 }
855
856 if (orderByComparator != null) {
857 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
858
859 if (orderByConditionFields.length > 0) {
860 query.append(WHERE_AND);
861 }
862
863 for (int i = 0; i < orderByConditionFields.length; i++) {
864 query.append(_ORDER_BY_ENTITY_ALIAS);
865 query.append(orderByConditionFields[i]);
866
867 if ((i + 1) < orderByConditionFields.length) {
868 if (orderByComparator.isAscending() ^ previous) {
869 query.append(WHERE_GREATER_THAN_HAS_NEXT);
870 }
871 else {
872 query.append(WHERE_LESSER_THAN_HAS_NEXT);
873 }
874 }
875 else {
876 if (orderByComparator.isAscending() ^ previous) {
877 query.append(WHERE_GREATER_THAN);
878 }
879 else {
880 query.append(WHERE_LESSER_THAN);
881 }
882 }
883 }
884
885 query.append(ORDER_BY_CLAUSE);
886
887 String[] orderByFields = orderByComparator.getOrderByFields();
888
889 for (int i = 0; i < orderByFields.length; i++) {
890 query.append(_ORDER_BY_ENTITY_ALIAS);
891 query.append(orderByFields[i]);
892
893 if ((i + 1) < orderByFields.length) {
894 if (orderByComparator.isAscending() ^ previous) {
895 query.append(ORDER_BY_ASC_HAS_NEXT);
896 }
897 else {
898 query.append(ORDER_BY_DESC_HAS_NEXT);
899 }
900 }
901 else {
902 if (orderByComparator.isAscending() ^ previous) {
903 query.append(ORDER_BY_ASC);
904 }
905 else {
906 query.append(ORDER_BY_DESC);
907 }
908 }
909 }
910 }
911
912 else {
913 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
914 }
915
916 String sql = query.toString();
917
918 Query q = session.createQuery(sql);
919
920 q.setFirstResult(0);
921 q.setMaxResults(2);
922
923 QueryPos qPos = QueryPos.getInstance(q);
924
925 if (uuid != null) {
926 qPos.add(uuid);
927 }
928
929 if (orderByComparator != null) {
930 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
931
932 for (Object value : values) {
933 qPos.add(value);
934 }
935 }
936
937 List<PollsQuestion> list = q.list();
938
939 if (list.size() == 2) {
940 return list.get(1);
941 }
942 else {
943 return null;
944 }
945 }
946
947
956 public PollsQuestion findByUUID_G(String uuid, long groupId)
957 throws NoSuchQuestionException, SystemException {
958 PollsQuestion pollsQuestion = fetchByUUID_G(uuid, groupId);
959
960 if (pollsQuestion == null) {
961 StringBundler msg = new StringBundler(6);
962
963 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
964
965 msg.append("uuid=");
966 msg.append(uuid);
967
968 msg.append(", groupId=");
969 msg.append(groupId);
970
971 msg.append(StringPool.CLOSE_CURLY_BRACE);
972
973 if (_log.isWarnEnabled()) {
974 _log.warn(msg.toString());
975 }
976
977 throw new NoSuchQuestionException(msg.toString());
978 }
979
980 return pollsQuestion;
981 }
982
983
991 public PollsQuestion fetchByUUID_G(String uuid, long groupId)
992 throws SystemException {
993 return fetchByUUID_G(uuid, groupId, true);
994 }
995
996
1005 public PollsQuestion fetchByUUID_G(String uuid, long groupId,
1006 boolean retrieveFromCache) throws SystemException {
1007 Object[] finderArgs = new Object[] { uuid, groupId };
1008
1009 Object result = null;
1010
1011 if (retrieveFromCache) {
1012 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1013 finderArgs, this);
1014 }
1015
1016 if (result == null) {
1017 StringBundler query = new StringBundler(4);
1018
1019 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1020
1021 if (uuid == null) {
1022 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1023 }
1024 else {
1025 if (uuid.equals(StringPool.BLANK)) {
1026 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1027 }
1028 else {
1029 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1030 }
1031 }
1032
1033 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1034
1035 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
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 if (uuid != null) {
1049 qPos.add(uuid);
1050 }
1051
1052 qPos.add(groupId);
1053
1054 List<PollsQuestion> list = q.list();
1055
1056 result = list;
1057
1058 PollsQuestion pollsQuestion = null;
1059
1060 if (list.isEmpty()) {
1061 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1062 finderArgs, list);
1063 }
1064 else {
1065 pollsQuestion = list.get(0);
1066
1067 cacheResult(pollsQuestion);
1068
1069 if ((pollsQuestion.getUuid() == null) ||
1070 !pollsQuestion.getUuid().equals(uuid) ||
1071 (pollsQuestion.getGroupId() != groupId)) {
1072 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1073 finderArgs, pollsQuestion);
1074 }
1075 }
1076
1077 return pollsQuestion;
1078 }
1079 catch (Exception e) {
1080 throw processException(e);
1081 }
1082 finally {
1083 if (result == null) {
1084 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1085 finderArgs);
1086 }
1087
1088 closeSession(session);
1089 }
1090 }
1091 else {
1092 if (result instanceof List<?>) {
1093 return null;
1094 }
1095 else {
1096 return (PollsQuestion)result;
1097 }
1098 }
1099 }
1100
1101
1108 public List<PollsQuestion> findByGroupId(long groupId)
1109 throws SystemException {
1110 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1111 }
1112
1113
1126 public List<PollsQuestion> findByGroupId(long groupId, int start, int end)
1127 throws SystemException {
1128 return findByGroupId(groupId, start, end, null);
1129 }
1130
1131
1145 public List<PollsQuestion> findByGroupId(long groupId, int start, int end,
1146 OrderByComparator orderByComparator) throws SystemException {
1147 FinderPath finderPath = null;
1148 Object[] finderArgs = null;
1149
1150 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1151 (orderByComparator == null)) {
1152 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1153 finderArgs = new Object[] { groupId };
1154 }
1155 else {
1156 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1157 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1158 }
1159
1160 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
1161 finderArgs, this);
1162
1163 if (list == null) {
1164 StringBundler query = null;
1165
1166 if (orderByComparator != null) {
1167 query = new StringBundler(3 +
1168 (orderByComparator.getOrderByFields().length * 3));
1169 }
1170 else {
1171 query = new StringBundler(3);
1172 }
1173
1174 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1175
1176 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1177
1178 if (orderByComparator != null) {
1179 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1180 orderByComparator);
1181 }
1182
1183 else {
1184 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1185 }
1186
1187 String sql = query.toString();
1188
1189 Session session = null;
1190
1191 try {
1192 session = openSession();
1193
1194 Query q = session.createQuery(sql);
1195
1196 QueryPos qPos = QueryPos.getInstance(q);
1197
1198 qPos.add(groupId);
1199
1200 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1201 start, end);
1202 }
1203 catch (Exception e) {
1204 throw processException(e);
1205 }
1206 finally {
1207 if (list == null) {
1208 FinderCacheUtil.removeResult(finderPath, finderArgs);
1209 }
1210 else {
1211 cacheResult(list);
1212
1213 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1214 }
1215
1216 closeSession(session);
1217 }
1218 }
1219
1220 return list;
1221 }
1222
1223
1236 public PollsQuestion findByGroupId_First(long groupId,
1237 OrderByComparator orderByComparator)
1238 throws NoSuchQuestionException, SystemException {
1239 List<PollsQuestion> list = findByGroupId(groupId, 0, 1,
1240 orderByComparator);
1241
1242 if (list.isEmpty()) {
1243 StringBundler msg = new StringBundler(4);
1244
1245 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1246
1247 msg.append("groupId=");
1248 msg.append(groupId);
1249
1250 msg.append(StringPool.CLOSE_CURLY_BRACE);
1251
1252 throw new NoSuchQuestionException(msg.toString());
1253 }
1254 else {
1255 return list.get(0);
1256 }
1257 }
1258
1259
1272 public PollsQuestion findByGroupId_Last(long groupId,
1273 OrderByComparator orderByComparator)
1274 throws NoSuchQuestionException, SystemException {
1275 int count = countByGroupId(groupId);
1276
1277 List<PollsQuestion> list = findByGroupId(groupId, count - 1, count,
1278 orderByComparator);
1279
1280 if (list.isEmpty()) {
1281 StringBundler msg = new StringBundler(4);
1282
1283 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1284
1285 msg.append("groupId=");
1286 msg.append(groupId);
1287
1288 msg.append(StringPool.CLOSE_CURLY_BRACE);
1289
1290 throw new NoSuchQuestionException(msg.toString());
1291 }
1292 else {
1293 return list.get(0);
1294 }
1295 }
1296
1297
1311 public PollsQuestion[] findByGroupId_PrevAndNext(long questionId,
1312 long groupId, OrderByComparator orderByComparator)
1313 throws NoSuchQuestionException, SystemException {
1314 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
1315
1316 Session session = null;
1317
1318 try {
1319 session = openSession();
1320
1321 PollsQuestion[] array = new PollsQuestionImpl[3];
1322
1323 array[0] = getByGroupId_PrevAndNext(session, pollsQuestion,
1324 groupId, orderByComparator, true);
1325
1326 array[1] = pollsQuestion;
1327
1328 array[2] = getByGroupId_PrevAndNext(session, pollsQuestion,
1329 groupId, orderByComparator, false);
1330
1331 return array;
1332 }
1333 catch (Exception e) {
1334 throw processException(e);
1335 }
1336 finally {
1337 closeSession(session);
1338 }
1339 }
1340
1341 protected PollsQuestion getByGroupId_PrevAndNext(Session session,
1342 PollsQuestion pollsQuestion, long groupId,
1343 OrderByComparator orderByComparator, boolean previous) {
1344 StringBundler query = null;
1345
1346 if (orderByComparator != null) {
1347 query = new StringBundler(6 +
1348 (orderByComparator.getOrderByFields().length * 6));
1349 }
1350 else {
1351 query = new StringBundler(3);
1352 }
1353
1354 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1355
1356 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1357
1358 if (orderByComparator != null) {
1359 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1360
1361 if (orderByConditionFields.length > 0) {
1362 query.append(WHERE_AND);
1363 }
1364
1365 for (int i = 0; i < orderByConditionFields.length; i++) {
1366 query.append(_ORDER_BY_ENTITY_ALIAS);
1367 query.append(orderByConditionFields[i]);
1368
1369 if ((i + 1) < orderByConditionFields.length) {
1370 if (orderByComparator.isAscending() ^ previous) {
1371 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1372 }
1373 else {
1374 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1375 }
1376 }
1377 else {
1378 if (orderByComparator.isAscending() ^ previous) {
1379 query.append(WHERE_GREATER_THAN);
1380 }
1381 else {
1382 query.append(WHERE_LESSER_THAN);
1383 }
1384 }
1385 }
1386
1387 query.append(ORDER_BY_CLAUSE);
1388
1389 String[] orderByFields = orderByComparator.getOrderByFields();
1390
1391 for (int i = 0; i < orderByFields.length; i++) {
1392 query.append(_ORDER_BY_ENTITY_ALIAS);
1393 query.append(orderByFields[i]);
1394
1395 if ((i + 1) < orderByFields.length) {
1396 if (orderByComparator.isAscending() ^ previous) {
1397 query.append(ORDER_BY_ASC_HAS_NEXT);
1398 }
1399 else {
1400 query.append(ORDER_BY_DESC_HAS_NEXT);
1401 }
1402 }
1403 else {
1404 if (orderByComparator.isAscending() ^ previous) {
1405 query.append(ORDER_BY_ASC);
1406 }
1407 else {
1408 query.append(ORDER_BY_DESC);
1409 }
1410 }
1411 }
1412 }
1413
1414 else {
1415 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1416 }
1417
1418 String sql = query.toString();
1419
1420 Query q = session.createQuery(sql);
1421
1422 q.setFirstResult(0);
1423 q.setMaxResults(2);
1424
1425 QueryPos qPos = QueryPos.getInstance(q);
1426
1427 qPos.add(groupId);
1428
1429 if (orderByComparator != null) {
1430 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
1431
1432 for (Object value : values) {
1433 qPos.add(value);
1434 }
1435 }
1436
1437 List<PollsQuestion> list = q.list();
1438
1439 if (list.size() == 2) {
1440 return list.get(1);
1441 }
1442 else {
1443 return null;
1444 }
1445 }
1446
1447
1454 public List<PollsQuestion> filterFindByGroupId(long groupId)
1455 throws SystemException {
1456 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1457 QueryUtil.ALL_POS, null);
1458 }
1459
1460
1473 public List<PollsQuestion> filterFindByGroupId(long groupId, int start,
1474 int end) throws SystemException {
1475 return filterFindByGroupId(groupId, start, end, null);
1476 }
1477
1478
1492 public List<PollsQuestion> filterFindByGroupId(long groupId, int start,
1493 int end, OrderByComparator orderByComparator) throws SystemException {
1494 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1495 return findByGroupId(groupId, start, end, orderByComparator);
1496 }
1497
1498 StringBundler query = null;
1499
1500 if (orderByComparator != null) {
1501 query = new StringBundler(3 +
1502 (orderByComparator.getOrderByFields().length * 3));
1503 }
1504 else {
1505 query = new StringBundler(3);
1506 }
1507
1508 if (getDB().isSupportsInlineDistinct()) {
1509 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_WHERE);
1510 }
1511 else {
1512 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1);
1513 }
1514
1515 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1516
1517 if (!getDB().isSupportsInlineDistinct()) {
1518 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2);
1519 }
1520
1521 if (orderByComparator != null) {
1522 if (getDB().isSupportsInlineDistinct()) {
1523 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1524 orderByComparator);
1525 }
1526 else {
1527 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1528 orderByComparator);
1529 }
1530 }
1531
1532 else {
1533 if (getDB().isSupportsInlineDistinct()) {
1534 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1535 }
1536 else {
1537 query.append(PollsQuestionModelImpl.ORDER_BY_SQL);
1538 }
1539 }
1540
1541 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1542 PollsQuestion.class.getName(),
1543 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1544
1545 Session session = null;
1546
1547 try {
1548 session = openSession();
1549
1550 SQLQuery q = session.createSQLQuery(sql);
1551
1552 if (getDB().isSupportsInlineDistinct()) {
1553 q.addEntity(_FILTER_ENTITY_ALIAS, PollsQuestionImpl.class);
1554 }
1555 else {
1556 q.addEntity(_FILTER_ENTITY_TABLE, PollsQuestionImpl.class);
1557 }
1558
1559 QueryPos qPos = QueryPos.getInstance(q);
1560
1561 qPos.add(groupId);
1562
1563 return (List<PollsQuestion>)QueryUtil.list(q, getDialect(), start,
1564 end);
1565 }
1566 catch (Exception e) {
1567 throw processException(e);
1568 }
1569 finally {
1570 closeSession(session);
1571 }
1572 }
1573
1574
1584 public PollsQuestion[] filterFindByGroupId_PrevAndNext(long questionId,
1585 long groupId, OrderByComparator orderByComparator)
1586 throws NoSuchQuestionException, SystemException {
1587 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1588 return findByGroupId_PrevAndNext(questionId, groupId,
1589 orderByComparator);
1590 }
1591
1592 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
1593
1594 Session session = null;
1595
1596 try {
1597 session = openSession();
1598
1599 PollsQuestion[] array = new PollsQuestionImpl[3];
1600
1601 array[0] = filterGetByGroupId_PrevAndNext(session, pollsQuestion,
1602 groupId, orderByComparator, true);
1603
1604 array[1] = pollsQuestion;
1605
1606 array[2] = filterGetByGroupId_PrevAndNext(session, pollsQuestion,
1607 groupId, orderByComparator, false);
1608
1609 return array;
1610 }
1611 catch (Exception e) {
1612 throw processException(e);
1613 }
1614 finally {
1615 closeSession(session);
1616 }
1617 }
1618
1619 protected PollsQuestion filterGetByGroupId_PrevAndNext(Session session,
1620 PollsQuestion pollsQuestion, long groupId,
1621 OrderByComparator orderByComparator, boolean previous) {
1622 StringBundler query = null;
1623
1624 if (orderByComparator != null) {
1625 query = new StringBundler(6 +
1626 (orderByComparator.getOrderByFields().length * 6));
1627 }
1628 else {
1629 query = new StringBundler(3);
1630 }
1631
1632 if (getDB().isSupportsInlineDistinct()) {
1633 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_WHERE);
1634 }
1635 else {
1636 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1);
1637 }
1638
1639 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1640
1641 if (!getDB().isSupportsInlineDistinct()) {
1642 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2);
1643 }
1644
1645 if (orderByComparator != null) {
1646 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1647
1648 if (orderByConditionFields.length > 0) {
1649 query.append(WHERE_AND);
1650 }
1651
1652 for (int i = 0; i < orderByConditionFields.length; i++) {
1653 if (getDB().isSupportsInlineDistinct()) {
1654 query.append(_ORDER_BY_ENTITY_ALIAS);
1655 }
1656 else {
1657 query.append(_ORDER_BY_ENTITY_TABLE);
1658 }
1659
1660 query.append(orderByConditionFields[i]);
1661
1662 if ((i + 1) < orderByConditionFields.length) {
1663 if (orderByComparator.isAscending() ^ previous) {
1664 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1665 }
1666 else {
1667 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1668 }
1669 }
1670 else {
1671 if (orderByComparator.isAscending() ^ previous) {
1672 query.append(WHERE_GREATER_THAN);
1673 }
1674 else {
1675 query.append(WHERE_LESSER_THAN);
1676 }
1677 }
1678 }
1679
1680 query.append(ORDER_BY_CLAUSE);
1681
1682 String[] orderByFields = orderByComparator.getOrderByFields();
1683
1684 for (int i = 0; i < orderByFields.length; i++) {
1685 if (getDB().isSupportsInlineDistinct()) {
1686 query.append(_ORDER_BY_ENTITY_ALIAS);
1687 }
1688 else {
1689 query.append(_ORDER_BY_ENTITY_TABLE);
1690 }
1691
1692 query.append(orderByFields[i]);
1693
1694 if ((i + 1) < orderByFields.length) {
1695 if (orderByComparator.isAscending() ^ previous) {
1696 query.append(ORDER_BY_ASC_HAS_NEXT);
1697 }
1698 else {
1699 query.append(ORDER_BY_DESC_HAS_NEXT);
1700 }
1701 }
1702 else {
1703 if (orderByComparator.isAscending() ^ previous) {
1704 query.append(ORDER_BY_ASC);
1705 }
1706 else {
1707 query.append(ORDER_BY_DESC);
1708 }
1709 }
1710 }
1711 }
1712
1713 else {
1714 if (getDB().isSupportsInlineDistinct()) {
1715 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1716 }
1717 else {
1718 query.append(PollsQuestionModelImpl.ORDER_BY_SQL);
1719 }
1720 }
1721
1722 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1723 PollsQuestion.class.getName(),
1724 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1725
1726 SQLQuery q = session.createSQLQuery(sql);
1727
1728 q.setFirstResult(0);
1729 q.setMaxResults(2);
1730
1731 if (getDB().isSupportsInlineDistinct()) {
1732 q.addEntity(_FILTER_ENTITY_ALIAS, PollsQuestionImpl.class);
1733 }
1734 else {
1735 q.addEntity(_FILTER_ENTITY_TABLE, PollsQuestionImpl.class);
1736 }
1737
1738 QueryPos qPos = QueryPos.getInstance(q);
1739
1740 qPos.add(groupId);
1741
1742 if (orderByComparator != null) {
1743 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
1744
1745 for (Object value : values) {
1746 qPos.add(value);
1747 }
1748 }
1749
1750 List<PollsQuestion> list = q.list();
1751
1752 if (list.size() == 2) {
1753 return list.get(1);
1754 }
1755 else {
1756 return null;
1757 }
1758 }
1759
1760
1766 public List<PollsQuestion> findAll() throws SystemException {
1767 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1768 }
1769
1770
1782 public List<PollsQuestion> findAll(int start, int end)
1783 throws SystemException {
1784 return findAll(start, end, null);
1785 }
1786
1787
1800 public List<PollsQuestion> findAll(int start, int end,
1801 OrderByComparator orderByComparator) throws SystemException {
1802 FinderPath finderPath = null;
1803 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1804
1805 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1806 (orderByComparator == null)) {
1807 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1808 finderArgs = FINDER_ARGS_EMPTY;
1809 }
1810 else {
1811 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1812 finderArgs = new Object[] { start, end, orderByComparator };
1813 }
1814
1815 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
1816 finderArgs, this);
1817
1818 if (list == null) {
1819 StringBundler query = null;
1820 String sql = null;
1821
1822 if (orderByComparator != null) {
1823 query = new StringBundler(2 +
1824 (orderByComparator.getOrderByFields().length * 3));
1825
1826 query.append(_SQL_SELECT_POLLSQUESTION);
1827
1828 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1829 orderByComparator);
1830
1831 sql = query.toString();
1832 }
1833 else {
1834 sql = _SQL_SELECT_POLLSQUESTION.concat(PollsQuestionModelImpl.ORDER_BY_JPQL);
1835 }
1836
1837 Session session = null;
1838
1839 try {
1840 session = openSession();
1841
1842 Query q = session.createQuery(sql);
1843
1844 if (orderByComparator == null) {
1845 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1846 start, end, false);
1847
1848 Collections.sort(list);
1849 }
1850 else {
1851 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1852 start, end);
1853 }
1854 }
1855 catch (Exception e) {
1856 throw processException(e);
1857 }
1858 finally {
1859 if (list == null) {
1860 FinderCacheUtil.removeResult(finderPath, finderArgs);
1861 }
1862 else {
1863 cacheResult(list);
1864
1865 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1866 }
1867
1868 closeSession(session);
1869 }
1870 }
1871
1872 return list;
1873 }
1874
1875
1881 public void removeByUuid(String uuid) throws SystemException {
1882 for (PollsQuestion pollsQuestion : findByUuid(uuid)) {
1883 pollsQuestionPersistence.remove(pollsQuestion);
1884 }
1885 }
1886
1887
1894 public void removeByUUID_G(String uuid, long groupId)
1895 throws NoSuchQuestionException, SystemException {
1896 PollsQuestion pollsQuestion = findByUUID_G(uuid, groupId);
1897
1898 pollsQuestionPersistence.remove(pollsQuestion);
1899 }
1900
1901
1907 public void removeByGroupId(long groupId) throws SystemException {
1908 for (PollsQuestion pollsQuestion : findByGroupId(groupId)) {
1909 pollsQuestionPersistence.remove(pollsQuestion);
1910 }
1911 }
1912
1913
1918 public void removeAll() throws SystemException {
1919 for (PollsQuestion pollsQuestion : findAll()) {
1920 pollsQuestionPersistence.remove(pollsQuestion);
1921 }
1922 }
1923
1924
1931 public int countByUuid(String uuid) throws SystemException {
1932 Object[] finderArgs = new Object[] { uuid };
1933
1934 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1935 finderArgs, this);
1936
1937 if (count == null) {
1938 StringBundler query = new StringBundler(2);
1939
1940 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
1941
1942 if (uuid == null) {
1943 query.append(_FINDER_COLUMN_UUID_UUID_1);
1944 }
1945 else {
1946 if (uuid.equals(StringPool.BLANK)) {
1947 query.append(_FINDER_COLUMN_UUID_UUID_3);
1948 }
1949 else {
1950 query.append(_FINDER_COLUMN_UUID_UUID_2);
1951 }
1952 }
1953
1954 String sql = query.toString();
1955
1956 Session session = null;
1957
1958 try {
1959 session = openSession();
1960
1961 Query q = session.createQuery(sql);
1962
1963 QueryPos qPos = QueryPos.getInstance(q);
1964
1965 if (uuid != null) {
1966 qPos.add(uuid);
1967 }
1968
1969 count = (Long)q.uniqueResult();
1970 }
1971 catch (Exception e) {
1972 throw processException(e);
1973 }
1974 finally {
1975 if (count == null) {
1976 count = Long.valueOf(0);
1977 }
1978
1979 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1980 finderArgs, count);
1981
1982 closeSession(session);
1983 }
1984 }
1985
1986 return count.intValue();
1987 }
1988
1989
1997 public int countByUUID_G(String uuid, long groupId)
1998 throws SystemException {
1999 Object[] finderArgs = new Object[] { uuid, groupId };
2000
2001 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2002 finderArgs, this);
2003
2004 if (count == null) {
2005 StringBundler query = new StringBundler(3);
2006
2007 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
2008
2009 if (uuid == null) {
2010 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2011 }
2012 else {
2013 if (uuid.equals(StringPool.BLANK)) {
2014 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2015 }
2016 else {
2017 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2018 }
2019 }
2020
2021 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2022
2023 String sql = query.toString();
2024
2025 Session session = null;
2026
2027 try {
2028 session = openSession();
2029
2030 Query q = session.createQuery(sql);
2031
2032 QueryPos qPos = QueryPos.getInstance(q);
2033
2034 if (uuid != null) {
2035 qPos.add(uuid);
2036 }
2037
2038 qPos.add(groupId);
2039
2040 count = (Long)q.uniqueResult();
2041 }
2042 catch (Exception e) {
2043 throw processException(e);
2044 }
2045 finally {
2046 if (count == null) {
2047 count = Long.valueOf(0);
2048 }
2049
2050 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2051 finderArgs, count);
2052
2053 closeSession(session);
2054 }
2055 }
2056
2057 return count.intValue();
2058 }
2059
2060
2067 public int countByGroupId(long groupId) throws SystemException {
2068 Object[] finderArgs = new Object[] { groupId };
2069
2070 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2071 finderArgs, this);
2072
2073 if (count == null) {
2074 StringBundler query = new StringBundler(2);
2075
2076 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
2077
2078 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2079
2080 String sql = query.toString();
2081
2082 Session session = null;
2083
2084 try {
2085 session = openSession();
2086
2087 Query q = session.createQuery(sql);
2088
2089 QueryPos qPos = QueryPos.getInstance(q);
2090
2091 qPos.add(groupId);
2092
2093 count = (Long)q.uniqueResult();
2094 }
2095 catch (Exception e) {
2096 throw processException(e);
2097 }
2098 finally {
2099 if (count == null) {
2100 count = Long.valueOf(0);
2101 }
2102
2103 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2104 finderArgs, count);
2105
2106 closeSession(session);
2107 }
2108 }
2109
2110 return count.intValue();
2111 }
2112
2113
2120 public int filterCountByGroupId(long groupId) throws SystemException {
2121 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2122 return countByGroupId(groupId);
2123 }
2124
2125 StringBundler query = new StringBundler(2);
2126
2127 query.append(_FILTER_SQL_COUNT_POLLSQUESTION_WHERE);
2128
2129 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2130
2131 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2132 PollsQuestion.class.getName(),
2133 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2134
2135 Session session = null;
2136
2137 try {
2138 session = openSession();
2139
2140 SQLQuery q = session.createSQLQuery(sql);
2141
2142 q.addScalar(COUNT_COLUMN_NAME,
2143 com.liferay.portal.kernel.dao.orm.Type.LONG);
2144
2145 QueryPos qPos = QueryPos.getInstance(q);
2146
2147 qPos.add(groupId);
2148
2149 Long count = (Long)q.uniqueResult();
2150
2151 return count.intValue();
2152 }
2153 catch (Exception e) {
2154 throw processException(e);
2155 }
2156 finally {
2157 closeSession(session);
2158 }
2159 }
2160
2161
2167 public int countAll() throws SystemException {
2168 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2169 FINDER_ARGS_EMPTY, this);
2170
2171 if (count == null) {
2172 Session session = null;
2173
2174 try {
2175 session = openSession();
2176
2177 Query q = session.createQuery(_SQL_COUNT_POLLSQUESTION);
2178
2179 count = (Long)q.uniqueResult();
2180 }
2181 catch (Exception e) {
2182 throw processException(e);
2183 }
2184 finally {
2185 if (count == null) {
2186 count = Long.valueOf(0);
2187 }
2188
2189 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2190 FINDER_ARGS_EMPTY, count);
2191
2192 closeSession(session);
2193 }
2194 }
2195
2196 return count.intValue();
2197 }
2198
2199
2202 public void afterPropertiesSet() {
2203 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2204 com.liferay.portal.util.PropsUtil.get(
2205 "value.object.listener.com.liferay.portlet.polls.model.PollsQuestion")));
2206
2207 if (listenerClassNames.length > 0) {
2208 try {
2209 List<ModelListener<PollsQuestion>> listenersList = new ArrayList<ModelListener<PollsQuestion>>();
2210
2211 for (String listenerClassName : listenerClassNames) {
2212 listenersList.add((ModelListener<PollsQuestion>)InstanceFactory.newInstance(
2213 listenerClassName));
2214 }
2215
2216 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2217 }
2218 catch (Exception e) {
2219 _log.error(e);
2220 }
2221 }
2222 }
2223
2224 public void destroy() {
2225 EntityCacheUtil.removeCache(PollsQuestionImpl.class.getName());
2226 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2227 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2228 }
2229
2230 @BeanReference(type = PollsChoicePersistence.class)
2231 protected PollsChoicePersistence pollsChoicePersistence;
2232 @BeanReference(type = PollsQuestionPersistence.class)
2233 protected PollsQuestionPersistence pollsQuestionPersistence;
2234 @BeanReference(type = PollsVotePersistence.class)
2235 protected PollsVotePersistence pollsVotePersistence;
2236 @BeanReference(type = ResourcePersistence.class)
2237 protected ResourcePersistence resourcePersistence;
2238 @BeanReference(type = UserPersistence.class)
2239 protected UserPersistence userPersistence;
2240 private static final String _SQL_SELECT_POLLSQUESTION = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion";
2241 private static final String _SQL_SELECT_POLLSQUESTION_WHERE = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion WHERE ";
2242 private static final String _SQL_COUNT_POLLSQUESTION = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion";
2243 private static final String _SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion WHERE ";
2244 private static final String _FINDER_COLUMN_UUID_UUID_1 = "pollsQuestion.uuid IS NULL";
2245 private static final String _FINDER_COLUMN_UUID_UUID_2 = "pollsQuestion.uuid = ?";
2246 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?)";
2247 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "pollsQuestion.uuid IS NULL AND ";
2248 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "pollsQuestion.uuid = ? AND ";
2249 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?) AND ";
2250 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "pollsQuestion.groupId = ?";
2251 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "pollsQuestion.groupId = ?";
2252 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "pollsQuestion.questionId";
2253 private static final String _FILTER_SQL_SELECT_POLLSQUESTION_WHERE = "SELECT DISTINCT {pollsQuestion.*} FROM PollsQuestion pollsQuestion WHERE ";
2254 private static final String _FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1 =
2255 "SELECT {PollsQuestion.*} FROM (SELECT DISTINCT pollsQuestion.questionId FROM PollsQuestion pollsQuestion WHERE ";
2256 private static final String _FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2 =
2257 ") TEMP_TABLE INNER JOIN PollsQuestion ON TEMP_TABLE.questionId = PollsQuestion.questionId";
2258 private static final String _FILTER_SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(DISTINCT pollsQuestion.questionId) AS COUNT_VALUE FROM PollsQuestion pollsQuestion WHERE ";
2259 private static final String _FILTER_ENTITY_ALIAS = "pollsQuestion";
2260 private static final String _FILTER_ENTITY_TABLE = "PollsQuestion";
2261 private static final String _ORDER_BY_ENTITY_ALIAS = "pollsQuestion.";
2262 private static final String _ORDER_BY_ENTITY_TABLE = "PollsQuestion.";
2263 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsQuestion exists with the primary key ";
2264 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsQuestion exists with the key {";
2265 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2266 private static Log _log = LogFactoryUtil.getLog(PollsQuestionPersistenceImpl.class);
2267 private static PollsQuestion _nullPollsQuestion = new PollsQuestionImpl() {
2268 @Override
2269 public Object clone() {
2270 return this;
2271 }
2272
2273 @Override
2274 public CacheModel<PollsQuestion> toCacheModel() {
2275 return _nullPollsQuestionCacheModel;
2276 }
2277 };
2278
2279 private static CacheModel<PollsQuestion> _nullPollsQuestionCacheModel = new CacheModel<PollsQuestion>() {
2280 public PollsQuestion toEntityModel() {
2281 return _nullPollsQuestion;
2282 }
2283 };
2284 }