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 clearUniqueFindersCache(pollsQuestion);
216 }
217
218 @Override
219 public void clearCache(List<PollsQuestion> pollsQuestions) {
220 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
221 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
222
223 for (PollsQuestion pollsQuestion : pollsQuestions) {
224 EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
225 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey());
226
227 clearUniqueFindersCache(pollsQuestion);
228 }
229 }
230
231 protected void clearUniqueFindersCache(PollsQuestion pollsQuestion) {
232 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
233 new Object[] {
234 pollsQuestion.getUuid(),
235 Long.valueOf(pollsQuestion.getGroupId())
236 });
237 }
238
239
245 public PollsQuestion create(long questionId) {
246 PollsQuestion pollsQuestion = new PollsQuestionImpl();
247
248 pollsQuestion.setNew(true);
249 pollsQuestion.setPrimaryKey(questionId);
250
251 String uuid = PortalUUIDUtil.generate();
252
253 pollsQuestion.setUuid(uuid);
254
255 return pollsQuestion;
256 }
257
258
266 public PollsQuestion remove(long questionId)
267 throws NoSuchQuestionException, SystemException {
268 return remove(Long.valueOf(questionId));
269 }
270
271
279 @Override
280 public PollsQuestion remove(Serializable primaryKey)
281 throws NoSuchQuestionException, SystemException {
282 Session session = null;
283
284 try {
285 session = openSession();
286
287 PollsQuestion pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
288 primaryKey);
289
290 if (pollsQuestion == null) {
291 if (_log.isWarnEnabled()) {
292 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
293 }
294
295 throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
296 primaryKey);
297 }
298
299 return remove(pollsQuestion);
300 }
301 catch (NoSuchQuestionException nsee) {
302 throw nsee;
303 }
304 catch (Exception e) {
305 throw processException(e);
306 }
307 finally {
308 closeSession(session);
309 }
310 }
311
312 @Override
313 protected PollsQuestion removeImpl(PollsQuestion pollsQuestion)
314 throws SystemException {
315 pollsQuestion = toUnwrappedModel(pollsQuestion);
316
317 Session session = null;
318
319 try {
320 session = openSession();
321
322 BatchSessionUtil.delete(session, pollsQuestion);
323 }
324 catch (Exception e) {
325 throw processException(e);
326 }
327 finally {
328 closeSession(session);
329 }
330
331 clearCache(pollsQuestion);
332
333 return pollsQuestion;
334 }
335
336 @Override
337 public PollsQuestion updateImpl(
338 com.liferay.portlet.polls.model.PollsQuestion pollsQuestion,
339 boolean merge) throws SystemException {
340 pollsQuestion = toUnwrappedModel(pollsQuestion);
341
342 boolean isNew = pollsQuestion.isNew();
343
344 PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
345
346 if (Validator.isNull(pollsQuestion.getUuid())) {
347 String uuid = PortalUUIDUtil.generate();
348
349 pollsQuestion.setUuid(uuid);
350 }
351
352 Session session = null;
353
354 try {
355 session = openSession();
356
357 BatchSessionUtil.update(session, pollsQuestion, merge);
358
359 pollsQuestion.setNew(false);
360 }
361 catch (Exception e) {
362 throw processException(e);
363 }
364 finally {
365 closeSession(session);
366 }
367
368 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
369
370 if (isNew || !PollsQuestionModelImpl.COLUMN_BITMASK_ENABLED) {
371 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
372 }
373
374 else {
375 if ((pollsQuestionModelImpl.getColumnBitmask() &
376 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
377 Object[] args = new Object[] {
378 pollsQuestionModelImpl.getOriginalUuid()
379 };
380
381 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
382 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
383 args);
384
385 args = new Object[] { pollsQuestionModelImpl.getUuid() };
386
387 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
388 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
389 args);
390 }
391
392 if ((pollsQuestionModelImpl.getColumnBitmask() &
393 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
394 Object[] args = new Object[] {
395 Long.valueOf(pollsQuestionModelImpl.getOriginalGroupId())
396 };
397
398 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
399 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
400 args);
401
402 args = new Object[] {
403 Long.valueOf(pollsQuestionModelImpl.getGroupId())
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 }
411
412 EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
413 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
414 pollsQuestion);
415
416 if (isNew) {
417 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
418 new Object[] {
419 pollsQuestion.getUuid(),
420 Long.valueOf(pollsQuestion.getGroupId())
421 }, pollsQuestion);
422 }
423 else {
424 if ((pollsQuestionModelImpl.getColumnBitmask() &
425 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
426 Object[] args = new Object[] {
427 pollsQuestionModelImpl.getOriginalUuid(),
428 Long.valueOf(pollsQuestionModelImpl.getOriginalGroupId())
429 };
430
431 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
432 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
433
434 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
435 new Object[] {
436 pollsQuestion.getUuid(),
437 Long.valueOf(pollsQuestion.getGroupId())
438 }, pollsQuestion);
439 }
440 }
441
442 return pollsQuestion;
443 }
444
445 protected PollsQuestion toUnwrappedModel(PollsQuestion pollsQuestion) {
446 if (pollsQuestion instanceof PollsQuestionImpl) {
447 return pollsQuestion;
448 }
449
450 PollsQuestionImpl pollsQuestionImpl = new PollsQuestionImpl();
451
452 pollsQuestionImpl.setNew(pollsQuestion.isNew());
453 pollsQuestionImpl.setPrimaryKey(pollsQuestion.getPrimaryKey());
454
455 pollsQuestionImpl.setUuid(pollsQuestion.getUuid());
456 pollsQuestionImpl.setQuestionId(pollsQuestion.getQuestionId());
457 pollsQuestionImpl.setGroupId(pollsQuestion.getGroupId());
458 pollsQuestionImpl.setCompanyId(pollsQuestion.getCompanyId());
459 pollsQuestionImpl.setUserId(pollsQuestion.getUserId());
460 pollsQuestionImpl.setUserName(pollsQuestion.getUserName());
461 pollsQuestionImpl.setCreateDate(pollsQuestion.getCreateDate());
462 pollsQuestionImpl.setModifiedDate(pollsQuestion.getModifiedDate());
463 pollsQuestionImpl.setTitle(pollsQuestion.getTitle());
464 pollsQuestionImpl.setDescription(pollsQuestion.getDescription());
465 pollsQuestionImpl.setExpirationDate(pollsQuestion.getExpirationDate());
466 pollsQuestionImpl.setLastVoteDate(pollsQuestion.getLastVoteDate());
467
468 return pollsQuestionImpl;
469 }
470
471
479 @Override
480 public PollsQuestion findByPrimaryKey(Serializable primaryKey)
481 throws NoSuchModelException, SystemException {
482 return findByPrimaryKey(((Long)primaryKey).longValue());
483 }
484
485
493 public PollsQuestion findByPrimaryKey(long questionId)
494 throws NoSuchQuestionException, SystemException {
495 PollsQuestion pollsQuestion = fetchByPrimaryKey(questionId);
496
497 if (pollsQuestion == null) {
498 if (_log.isWarnEnabled()) {
499 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + questionId);
500 }
501
502 throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
503 questionId);
504 }
505
506 return pollsQuestion;
507 }
508
509
516 @Override
517 public PollsQuestion fetchByPrimaryKey(Serializable primaryKey)
518 throws SystemException {
519 return fetchByPrimaryKey(((Long)primaryKey).longValue());
520 }
521
522
529 public PollsQuestion fetchByPrimaryKey(long questionId)
530 throws SystemException {
531 PollsQuestion pollsQuestion = (PollsQuestion)EntityCacheUtil.getResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
532 PollsQuestionImpl.class, questionId);
533
534 if (pollsQuestion == _nullPollsQuestion) {
535 return null;
536 }
537
538 if (pollsQuestion == null) {
539 Session session = null;
540
541 boolean hasException = false;
542
543 try {
544 session = openSession();
545
546 pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
547 Long.valueOf(questionId));
548 }
549 catch (Exception e) {
550 hasException = true;
551
552 throw processException(e);
553 }
554 finally {
555 if (pollsQuestion != null) {
556 cacheResult(pollsQuestion);
557 }
558 else if (!hasException) {
559 EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
560 PollsQuestionImpl.class, questionId, _nullPollsQuestion);
561 }
562
563 closeSession(session);
564 }
565 }
566
567 return pollsQuestion;
568 }
569
570
577 public List<PollsQuestion> findByUuid(String uuid)
578 throws SystemException {
579 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
580 }
581
582
595 public List<PollsQuestion> findByUuid(String uuid, int start, int end)
596 throws SystemException {
597 return findByUuid(uuid, start, end, null);
598 }
599
600
614 public List<PollsQuestion> findByUuid(String uuid, int start, int end,
615 OrderByComparator orderByComparator) throws SystemException {
616 FinderPath finderPath = null;
617 Object[] finderArgs = null;
618
619 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
620 (orderByComparator == null)) {
621 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
622 finderArgs = new Object[] { uuid };
623 }
624 else {
625 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
626 finderArgs = new Object[] { uuid, start, end, orderByComparator };
627 }
628
629 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
630 finderArgs, this);
631
632 if (list == null) {
633 StringBundler query = null;
634
635 if (orderByComparator != null) {
636 query = new StringBundler(3 +
637 (orderByComparator.getOrderByFields().length * 3));
638 }
639 else {
640 query = new StringBundler(3);
641 }
642
643 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
644
645 if (uuid == null) {
646 query.append(_FINDER_COLUMN_UUID_UUID_1);
647 }
648 else {
649 if (uuid.equals(StringPool.BLANK)) {
650 query.append(_FINDER_COLUMN_UUID_UUID_3);
651 }
652 else {
653 query.append(_FINDER_COLUMN_UUID_UUID_2);
654 }
655 }
656
657 if (orderByComparator != null) {
658 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
659 orderByComparator);
660 }
661
662 else {
663 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
664 }
665
666 String sql = query.toString();
667
668 Session session = null;
669
670 try {
671 session = openSession();
672
673 Query q = session.createQuery(sql);
674
675 QueryPos qPos = QueryPos.getInstance(q);
676
677 if (uuid != null) {
678 qPos.add(uuid);
679 }
680
681 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
682 start, end);
683 }
684 catch (Exception e) {
685 throw processException(e);
686 }
687 finally {
688 if (list == null) {
689 FinderCacheUtil.removeResult(finderPath, finderArgs);
690 }
691 else {
692 cacheResult(list);
693
694 FinderCacheUtil.putResult(finderPath, finderArgs, list);
695 }
696
697 closeSession(session);
698 }
699 }
700
701 return list;
702 }
703
704
717 public PollsQuestion findByUuid_First(String uuid,
718 OrderByComparator orderByComparator)
719 throws NoSuchQuestionException, SystemException {
720 List<PollsQuestion> list = findByUuid(uuid, 0, 1, orderByComparator);
721
722 if (list.isEmpty()) {
723 StringBundler msg = new StringBundler(4);
724
725 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
726
727 msg.append("uuid=");
728 msg.append(uuid);
729
730 msg.append(StringPool.CLOSE_CURLY_BRACE);
731
732 throw new NoSuchQuestionException(msg.toString());
733 }
734 else {
735 return list.get(0);
736 }
737 }
738
739
752 public PollsQuestion findByUuid_Last(String uuid,
753 OrderByComparator orderByComparator)
754 throws NoSuchQuestionException, SystemException {
755 int count = countByUuid(uuid);
756
757 List<PollsQuestion> list = findByUuid(uuid, count - 1, count,
758 orderByComparator);
759
760 if (list.isEmpty()) {
761 StringBundler msg = new StringBundler(4);
762
763 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
764
765 msg.append("uuid=");
766 msg.append(uuid);
767
768 msg.append(StringPool.CLOSE_CURLY_BRACE);
769
770 throw new NoSuchQuestionException(msg.toString());
771 }
772 else {
773 return list.get(0);
774 }
775 }
776
777
791 public PollsQuestion[] findByUuid_PrevAndNext(long questionId, String uuid,
792 OrderByComparator orderByComparator)
793 throws NoSuchQuestionException, SystemException {
794 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
795
796 Session session = null;
797
798 try {
799 session = openSession();
800
801 PollsQuestion[] array = new PollsQuestionImpl[3];
802
803 array[0] = getByUuid_PrevAndNext(session, pollsQuestion, uuid,
804 orderByComparator, true);
805
806 array[1] = pollsQuestion;
807
808 array[2] = getByUuid_PrevAndNext(session, pollsQuestion, uuid,
809 orderByComparator, false);
810
811 return array;
812 }
813 catch (Exception e) {
814 throw processException(e);
815 }
816 finally {
817 closeSession(session);
818 }
819 }
820
821 protected PollsQuestion getByUuid_PrevAndNext(Session session,
822 PollsQuestion pollsQuestion, String uuid,
823 OrderByComparator orderByComparator, boolean previous) {
824 StringBundler query = null;
825
826 if (orderByComparator != null) {
827 query = new StringBundler(6 +
828 (orderByComparator.getOrderByFields().length * 6));
829 }
830 else {
831 query = new StringBundler(3);
832 }
833
834 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
835
836 if (uuid == null) {
837 query.append(_FINDER_COLUMN_UUID_UUID_1);
838 }
839 else {
840 if (uuid.equals(StringPool.BLANK)) {
841 query.append(_FINDER_COLUMN_UUID_UUID_3);
842 }
843 else {
844 query.append(_FINDER_COLUMN_UUID_UUID_2);
845 }
846 }
847
848 if (orderByComparator != null) {
849 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
850
851 if (orderByConditionFields.length > 0) {
852 query.append(WHERE_AND);
853 }
854
855 for (int i = 0; i < orderByConditionFields.length; i++) {
856 query.append(_ORDER_BY_ENTITY_ALIAS);
857 query.append(orderByConditionFields[i]);
858
859 if ((i + 1) < orderByConditionFields.length) {
860 if (orderByComparator.isAscending() ^ previous) {
861 query.append(WHERE_GREATER_THAN_HAS_NEXT);
862 }
863 else {
864 query.append(WHERE_LESSER_THAN_HAS_NEXT);
865 }
866 }
867 else {
868 if (orderByComparator.isAscending() ^ previous) {
869 query.append(WHERE_GREATER_THAN);
870 }
871 else {
872 query.append(WHERE_LESSER_THAN);
873 }
874 }
875 }
876
877 query.append(ORDER_BY_CLAUSE);
878
879 String[] orderByFields = orderByComparator.getOrderByFields();
880
881 for (int i = 0; i < orderByFields.length; i++) {
882 query.append(_ORDER_BY_ENTITY_ALIAS);
883 query.append(orderByFields[i]);
884
885 if ((i + 1) < orderByFields.length) {
886 if (orderByComparator.isAscending() ^ previous) {
887 query.append(ORDER_BY_ASC_HAS_NEXT);
888 }
889 else {
890 query.append(ORDER_BY_DESC_HAS_NEXT);
891 }
892 }
893 else {
894 if (orderByComparator.isAscending() ^ previous) {
895 query.append(ORDER_BY_ASC);
896 }
897 else {
898 query.append(ORDER_BY_DESC);
899 }
900 }
901 }
902 }
903
904 else {
905 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
906 }
907
908 String sql = query.toString();
909
910 Query q = session.createQuery(sql);
911
912 q.setFirstResult(0);
913 q.setMaxResults(2);
914
915 QueryPos qPos = QueryPos.getInstance(q);
916
917 if (uuid != null) {
918 qPos.add(uuid);
919 }
920
921 if (orderByComparator != null) {
922 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
923
924 for (Object value : values) {
925 qPos.add(value);
926 }
927 }
928
929 List<PollsQuestion> list = q.list();
930
931 if (list.size() == 2) {
932 return list.get(1);
933 }
934 else {
935 return null;
936 }
937 }
938
939
948 public PollsQuestion findByUUID_G(String uuid, long groupId)
949 throws NoSuchQuestionException, SystemException {
950 PollsQuestion pollsQuestion = fetchByUUID_G(uuid, groupId);
951
952 if (pollsQuestion == null) {
953 StringBundler msg = new StringBundler(6);
954
955 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
956
957 msg.append("uuid=");
958 msg.append(uuid);
959
960 msg.append(", groupId=");
961 msg.append(groupId);
962
963 msg.append(StringPool.CLOSE_CURLY_BRACE);
964
965 if (_log.isWarnEnabled()) {
966 _log.warn(msg.toString());
967 }
968
969 throw new NoSuchQuestionException(msg.toString());
970 }
971
972 return pollsQuestion;
973 }
974
975
983 public PollsQuestion fetchByUUID_G(String uuid, long groupId)
984 throws SystemException {
985 return fetchByUUID_G(uuid, groupId, true);
986 }
987
988
997 public PollsQuestion fetchByUUID_G(String uuid, long groupId,
998 boolean retrieveFromCache) throws SystemException {
999 Object[] finderArgs = new Object[] { uuid, groupId };
1000
1001 Object result = null;
1002
1003 if (retrieveFromCache) {
1004 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1005 finderArgs, this);
1006 }
1007
1008 if (result == null) {
1009 StringBundler query = new StringBundler(4);
1010
1011 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1012
1013 if (uuid == null) {
1014 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1015 }
1016 else {
1017 if (uuid.equals(StringPool.BLANK)) {
1018 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1019 }
1020 else {
1021 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1022 }
1023 }
1024
1025 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1026
1027 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1028
1029 String sql = query.toString();
1030
1031 Session session = null;
1032
1033 try {
1034 session = openSession();
1035
1036 Query q = session.createQuery(sql);
1037
1038 QueryPos qPos = QueryPos.getInstance(q);
1039
1040 if (uuid != null) {
1041 qPos.add(uuid);
1042 }
1043
1044 qPos.add(groupId);
1045
1046 List<PollsQuestion> list = q.list();
1047
1048 result = list;
1049
1050 PollsQuestion pollsQuestion = null;
1051
1052 if (list.isEmpty()) {
1053 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1054 finderArgs, list);
1055 }
1056 else {
1057 pollsQuestion = list.get(0);
1058
1059 cacheResult(pollsQuestion);
1060
1061 if ((pollsQuestion.getUuid() == null) ||
1062 !pollsQuestion.getUuid().equals(uuid) ||
1063 (pollsQuestion.getGroupId() != groupId)) {
1064 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1065 finderArgs, pollsQuestion);
1066 }
1067 }
1068
1069 return pollsQuestion;
1070 }
1071 catch (Exception e) {
1072 throw processException(e);
1073 }
1074 finally {
1075 if (result == null) {
1076 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1077 finderArgs);
1078 }
1079
1080 closeSession(session);
1081 }
1082 }
1083 else {
1084 if (result instanceof List<?>) {
1085 return null;
1086 }
1087 else {
1088 return (PollsQuestion)result;
1089 }
1090 }
1091 }
1092
1093
1100 public List<PollsQuestion> findByGroupId(long groupId)
1101 throws SystemException {
1102 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1103 }
1104
1105
1118 public List<PollsQuestion> findByGroupId(long groupId, int start, int end)
1119 throws SystemException {
1120 return findByGroupId(groupId, start, end, null);
1121 }
1122
1123
1137 public List<PollsQuestion> findByGroupId(long groupId, int start, int end,
1138 OrderByComparator orderByComparator) throws SystemException {
1139 FinderPath finderPath = null;
1140 Object[] finderArgs = null;
1141
1142 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1143 (orderByComparator == null)) {
1144 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1145 finderArgs = new Object[] { groupId };
1146 }
1147 else {
1148 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1149 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1150 }
1151
1152 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
1153 finderArgs, this);
1154
1155 if (list == null) {
1156 StringBundler query = null;
1157
1158 if (orderByComparator != null) {
1159 query = new StringBundler(3 +
1160 (orderByComparator.getOrderByFields().length * 3));
1161 }
1162 else {
1163 query = new StringBundler(3);
1164 }
1165
1166 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1167
1168 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1169
1170 if (orderByComparator != null) {
1171 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1172 orderByComparator);
1173 }
1174
1175 else {
1176 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1177 }
1178
1179 String sql = query.toString();
1180
1181 Session session = null;
1182
1183 try {
1184 session = openSession();
1185
1186 Query q = session.createQuery(sql);
1187
1188 QueryPos qPos = QueryPos.getInstance(q);
1189
1190 qPos.add(groupId);
1191
1192 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1193 start, end);
1194 }
1195 catch (Exception e) {
1196 throw processException(e);
1197 }
1198 finally {
1199 if (list == null) {
1200 FinderCacheUtil.removeResult(finderPath, finderArgs);
1201 }
1202 else {
1203 cacheResult(list);
1204
1205 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1206 }
1207
1208 closeSession(session);
1209 }
1210 }
1211
1212 return list;
1213 }
1214
1215
1228 public PollsQuestion findByGroupId_First(long groupId,
1229 OrderByComparator orderByComparator)
1230 throws NoSuchQuestionException, SystemException {
1231 List<PollsQuestion> list = findByGroupId(groupId, 0, 1,
1232 orderByComparator);
1233
1234 if (list.isEmpty()) {
1235 StringBundler msg = new StringBundler(4);
1236
1237 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1238
1239 msg.append("groupId=");
1240 msg.append(groupId);
1241
1242 msg.append(StringPool.CLOSE_CURLY_BRACE);
1243
1244 throw new NoSuchQuestionException(msg.toString());
1245 }
1246 else {
1247 return list.get(0);
1248 }
1249 }
1250
1251
1264 public PollsQuestion findByGroupId_Last(long groupId,
1265 OrderByComparator orderByComparator)
1266 throws NoSuchQuestionException, SystemException {
1267 int count = countByGroupId(groupId);
1268
1269 List<PollsQuestion> list = findByGroupId(groupId, count - 1, count,
1270 orderByComparator);
1271
1272 if (list.isEmpty()) {
1273 StringBundler msg = new StringBundler(4);
1274
1275 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1276
1277 msg.append("groupId=");
1278 msg.append(groupId);
1279
1280 msg.append(StringPool.CLOSE_CURLY_BRACE);
1281
1282 throw new NoSuchQuestionException(msg.toString());
1283 }
1284 else {
1285 return list.get(0);
1286 }
1287 }
1288
1289
1303 public PollsQuestion[] findByGroupId_PrevAndNext(long questionId,
1304 long groupId, OrderByComparator orderByComparator)
1305 throws NoSuchQuestionException, SystemException {
1306 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
1307
1308 Session session = null;
1309
1310 try {
1311 session = openSession();
1312
1313 PollsQuestion[] array = new PollsQuestionImpl[3];
1314
1315 array[0] = getByGroupId_PrevAndNext(session, pollsQuestion,
1316 groupId, orderByComparator, true);
1317
1318 array[1] = pollsQuestion;
1319
1320 array[2] = getByGroupId_PrevAndNext(session, pollsQuestion,
1321 groupId, orderByComparator, false);
1322
1323 return array;
1324 }
1325 catch (Exception e) {
1326 throw processException(e);
1327 }
1328 finally {
1329 closeSession(session);
1330 }
1331 }
1332
1333 protected PollsQuestion getByGroupId_PrevAndNext(Session session,
1334 PollsQuestion pollsQuestion, long groupId,
1335 OrderByComparator orderByComparator, boolean previous) {
1336 StringBundler query = null;
1337
1338 if (orderByComparator != null) {
1339 query = new StringBundler(6 +
1340 (orderByComparator.getOrderByFields().length * 6));
1341 }
1342 else {
1343 query = new StringBundler(3);
1344 }
1345
1346 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1347
1348 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1349
1350 if (orderByComparator != null) {
1351 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1352
1353 if (orderByConditionFields.length > 0) {
1354 query.append(WHERE_AND);
1355 }
1356
1357 for (int i = 0; i < orderByConditionFields.length; i++) {
1358 query.append(_ORDER_BY_ENTITY_ALIAS);
1359 query.append(orderByConditionFields[i]);
1360
1361 if ((i + 1) < orderByConditionFields.length) {
1362 if (orderByComparator.isAscending() ^ previous) {
1363 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1364 }
1365 else {
1366 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1367 }
1368 }
1369 else {
1370 if (orderByComparator.isAscending() ^ previous) {
1371 query.append(WHERE_GREATER_THAN);
1372 }
1373 else {
1374 query.append(WHERE_LESSER_THAN);
1375 }
1376 }
1377 }
1378
1379 query.append(ORDER_BY_CLAUSE);
1380
1381 String[] orderByFields = orderByComparator.getOrderByFields();
1382
1383 for (int i = 0; i < orderByFields.length; i++) {
1384 query.append(_ORDER_BY_ENTITY_ALIAS);
1385 query.append(orderByFields[i]);
1386
1387 if ((i + 1) < orderByFields.length) {
1388 if (orderByComparator.isAscending() ^ previous) {
1389 query.append(ORDER_BY_ASC_HAS_NEXT);
1390 }
1391 else {
1392 query.append(ORDER_BY_DESC_HAS_NEXT);
1393 }
1394 }
1395 else {
1396 if (orderByComparator.isAscending() ^ previous) {
1397 query.append(ORDER_BY_ASC);
1398 }
1399 else {
1400 query.append(ORDER_BY_DESC);
1401 }
1402 }
1403 }
1404 }
1405
1406 else {
1407 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1408 }
1409
1410 String sql = query.toString();
1411
1412 Query q = session.createQuery(sql);
1413
1414 q.setFirstResult(0);
1415 q.setMaxResults(2);
1416
1417 QueryPos qPos = QueryPos.getInstance(q);
1418
1419 qPos.add(groupId);
1420
1421 if (orderByComparator != null) {
1422 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
1423
1424 for (Object value : values) {
1425 qPos.add(value);
1426 }
1427 }
1428
1429 List<PollsQuestion> list = q.list();
1430
1431 if (list.size() == 2) {
1432 return list.get(1);
1433 }
1434 else {
1435 return null;
1436 }
1437 }
1438
1439
1446 public List<PollsQuestion> filterFindByGroupId(long groupId)
1447 throws SystemException {
1448 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1449 QueryUtil.ALL_POS, null);
1450 }
1451
1452
1465 public List<PollsQuestion> filterFindByGroupId(long groupId, int start,
1466 int end) throws SystemException {
1467 return filterFindByGroupId(groupId, start, end, null);
1468 }
1469
1470
1484 public List<PollsQuestion> filterFindByGroupId(long groupId, int start,
1485 int end, OrderByComparator orderByComparator) throws SystemException {
1486 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1487 return findByGroupId(groupId, start, end, orderByComparator);
1488 }
1489
1490 StringBundler query = null;
1491
1492 if (orderByComparator != null) {
1493 query = new StringBundler(3 +
1494 (orderByComparator.getOrderByFields().length * 3));
1495 }
1496 else {
1497 query = new StringBundler(3);
1498 }
1499
1500 if (getDB().isSupportsInlineDistinct()) {
1501 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_WHERE);
1502 }
1503 else {
1504 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1);
1505 }
1506
1507 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1508
1509 if (!getDB().isSupportsInlineDistinct()) {
1510 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2);
1511 }
1512
1513 if (orderByComparator != null) {
1514 if (getDB().isSupportsInlineDistinct()) {
1515 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1516 orderByComparator);
1517 }
1518 else {
1519 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1520 orderByComparator);
1521 }
1522 }
1523
1524 else {
1525 if (getDB().isSupportsInlineDistinct()) {
1526 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1527 }
1528 else {
1529 query.append(PollsQuestionModelImpl.ORDER_BY_SQL);
1530 }
1531 }
1532
1533 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1534 PollsQuestion.class.getName(),
1535 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1536
1537 Session session = null;
1538
1539 try {
1540 session = openSession();
1541
1542 SQLQuery q = session.createSQLQuery(sql);
1543
1544 if (getDB().isSupportsInlineDistinct()) {
1545 q.addEntity(_FILTER_ENTITY_ALIAS, PollsQuestionImpl.class);
1546 }
1547 else {
1548 q.addEntity(_FILTER_ENTITY_TABLE, PollsQuestionImpl.class);
1549 }
1550
1551 QueryPos qPos = QueryPos.getInstance(q);
1552
1553 qPos.add(groupId);
1554
1555 return (List<PollsQuestion>)QueryUtil.list(q, getDialect(), start,
1556 end);
1557 }
1558 catch (Exception e) {
1559 throw processException(e);
1560 }
1561 finally {
1562 closeSession(session);
1563 }
1564 }
1565
1566
1576 public PollsQuestion[] filterFindByGroupId_PrevAndNext(long questionId,
1577 long groupId, OrderByComparator orderByComparator)
1578 throws NoSuchQuestionException, SystemException {
1579 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1580 return findByGroupId_PrevAndNext(questionId, groupId,
1581 orderByComparator);
1582 }
1583
1584 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
1585
1586 Session session = null;
1587
1588 try {
1589 session = openSession();
1590
1591 PollsQuestion[] array = new PollsQuestionImpl[3];
1592
1593 array[0] = filterGetByGroupId_PrevAndNext(session, pollsQuestion,
1594 groupId, orderByComparator, true);
1595
1596 array[1] = pollsQuestion;
1597
1598 array[2] = filterGetByGroupId_PrevAndNext(session, pollsQuestion,
1599 groupId, orderByComparator, false);
1600
1601 return array;
1602 }
1603 catch (Exception e) {
1604 throw processException(e);
1605 }
1606 finally {
1607 closeSession(session);
1608 }
1609 }
1610
1611 protected PollsQuestion filterGetByGroupId_PrevAndNext(Session session,
1612 PollsQuestion pollsQuestion, long groupId,
1613 OrderByComparator orderByComparator, boolean previous) {
1614 StringBundler query = null;
1615
1616 if (orderByComparator != null) {
1617 query = new StringBundler(6 +
1618 (orderByComparator.getOrderByFields().length * 6));
1619 }
1620 else {
1621 query = new StringBundler(3);
1622 }
1623
1624 if (getDB().isSupportsInlineDistinct()) {
1625 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_WHERE);
1626 }
1627 else {
1628 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1);
1629 }
1630
1631 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1632
1633 if (!getDB().isSupportsInlineDistinct()) {
1634 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2);
1635 }
1636
1637 if (orderByComparator != null) {
1638 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1639
1640 if (orderByConditionFields.length > 0) {
1641 query.append(WHERE_AND);
1642 }
1643
1644 for (int i = 0; i < orderByConditionFields.length; i++) {
1645 if (getDB().isSupportsInlineDistinct()) {
1646 query.append(_ORDER_BY_ENTITY_ALIAS);
1647 }
1648 else {
1649 query.append(_ORDER_BY_ENTITY_TABLE);
1650 }
1651
1652 query.append(orderByConditionFields[i]);
1653
1654 if ((i + 1) < orderByConditionFields.length) {
1655 if (orderByComparator.isAscending() ^ previous) {
1656 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1657 }
1658 else {
1659 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1660 }
1661 }
1662 else {
1663 if (orderByComparator.isAscending() ^ previous) {
1664 query.append(WHERE_GREATER_THAN);
1665 }
1666 else {
1667 query.append(WHERE_LESSER_THAN);
1668 }
1669 }
1670 }
1671
1672 query.append(ORDER_BY_CLAUSE);
1673
1674 String[] orderByFields = orderByComparator.getOrderByFields();
1675
1676 for (int i = 0; i < orderByFields.length; i++) {
1677 if (getDB().isSupportsInlineDistinct()) {
1678 query.append(_ORDER_BY_ENTITY_ALIAS);
1679 }
1680 else {
1681 query.append(_ORDER_BY_ENTITY_TABLE);
1682 }
1683
1684 query.append(orderByFields[i]);
1685
1686 if ((i + 1) < orderByFields.length) {
1687 if (orderByComparator.isAscending() ^ previous) {
1688 query.append(ORDER_BY_ASC_HAS_NEXT);
1689 }
1690 else {
1691 query.append(ORDER_BY_DESC_HAS_NEXT);
1692 }
1693 }
1694 else {
1695 if (orderByComparator.isAscending() ^ previous) {
1696 query.append(ORDER_BY_ASC);
1697 }
1698 else {
1699 query.append(ORDER_BY_DESC);
1700 }
1701 }
1702 }
1703 }
1704
1705 else {
1706 if (getDB().isSupportsInlineDistinct()) {
1707 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1708 }
1709 else {
1710 query.append(PollsQuestionModelImpl.ORDER_BY_SQL);
1711 }
1712 }
1713
1714 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1715 PollsQuestion.class.getName(),
1716 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1717
1718 SQLQuery q = session.createSQLQuery(sql);
1719
1720 q.setFirstResult(0);
1721 q.setMaxResults(2);
1722
1723 if (getDB().isSupportsInlineDistinct()) {
1724 q.addEntity(_FILTER_ENTITY_ALIAS, PollsQuestionImpl.class);
1725 }
1726 else {
1727 q.addEntity(_FILTER_ENTITY_TABLE, PollsQuestionImpl.class);
1728 }
1729
1730 QueryPos qPos = QueryPos.getInstance(q);
1731
1732 qPos.add(groupId);
1733
1734 if (orderByComparator != null) {
1735 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
1736
1737 for (Object value : values) {
1738 qPos.add(value);
1739 }
1740 }
1741
1742 List<PollsQuestion> list = q.list();
1743
1744 if (list.size() == 2) {
1745 return list.get(1);
1746 }
1747 else {
1748 return null;
1749 }
1750 }
1751
1752
1758 public List<PollsQuestion> findAll() throws SystemException {
1759 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1760 }
1761
1762
1774 public List<PollsQuestion> findAll(int start, int end)
1775 throws SystemException {
1776 return findAll(start, end, null);
1777 }
1778
1779
1792 public List<PollsQuestion> findAll(int start, int end,
1793 OrderByComparator orderByComparator) throws SystemException {
1794 FinderPath finderPath = null;
1795 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1796
1797 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1798 (orderByComparator == null)) {
1799 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1800 finderArgs = FINDER_ARGS_EMPTY;
1801 }
1802 else {
1803 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1804 finderArgs = new Object[] { start, end, orderByComparator };
1805 }
1806
1807 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
1808 finderArgs, this);
1809
1810 if (list == null) {
1811 StringBundler query = null;
1812 String sql = null;
1813
1814 if (orderByComparator != null) {
1815 query = new StringBundler(2 +
1816 (orderByComparator.getOrderByFields().length * 3));
1817
1818 query.append(_SQL_SELECT_POLLSQUESTION);
1819
1820 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1821 orderByComparator);
1822
1823 sql = query.toString();
1824 }
1825 else {
1826 sql = _SQL_SELECT_POLLSQUESTION.concat(PollsQuestionModelImpl.ORDER_BY_JPQL);
1827 }
1828
1829 Session session = null;
1830
1831 try {
1832 session = openSession();
1833
1834 Query q = session.createQuery(sql);
1835
1836 if (orderByComparator == null) {
1837 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1838 start, end, false);
1839
1840 Collections.sort(list);
1841 }
1842 else {
1843 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1844 start, end);
1845 }
1846 }
1847 catch (Exception e) {
1848 throw processException(e);
1849 }
1850 finally {
1851 if (list == null) {
1852 FinderCacheUtil.removeResult(finderPath, finderArgs);
1853 }
1854 else {
1855 cacheResult(list);
1856
1857 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1858 }
1859
1860 closeSession(session);
1861 }
1862 }
1863
1864 return list;
1865 }
1866
1867
1873 public void removeByUuid(String uuid) throws SystemException {
1874 for (PollsQuestion pollsQuestion : findByUuid(uuid)) {
1875 remove(pollsQuestion);
1876 }
1877 }
1878
1879
1886 public void removeByUUID_G(String uuid, long groupId)
1887 throws NoSuchQuestionException, SystemException {
1888 PollsQuestion pollsQuestion = findByUUID_G(uuid, groupId);
1889
1890 remove(pollsQuestion);
1891 }
1892
1893
1899 public void removeByGroupId(long groupId) throws SystemException {
1900 for (PollsQuestion pollsQuestion : findByGroupId(groupId)) {
1901 remove(pollsQuestion);
1902 }
1903 }
1904
1905
1910 public void removeAll() throws SystemException {
1911 for (PollsQuestion pollsQuestion : findAll()) {
1912 remove(pollsQuestion);
1913 }
1914 }
1915
1916
1923 public int countByUuid(String uuid) throws SystemException {
1924 Object[] finderArgs = new Object[] { uuid };
1925
1926 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1927 finderArgs, this);
1928
1929 if (count == null) {
1930 StringBundler query = new StringBundler(2);
1931
1932 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
1933
1934 if (uuid == null) {
1935 query.append(_FINDER_COLUMN_UUID_UUID_1);
1936 }
1937 else {
1938 if (uuid.equals(StringPool.BLANK)) {
1939 query.append(_FINDER_COLUMN_UUID_UUID_3);
1940 }
1941 else {
1942 query.append(_FINDER_COLUMN_UUID_UUID_2);
1943 }
1944 }
1945
1946 String sql = query.toString();
1947
1948 Session session = null;
1949
1950 try {
1951 session = openSession();
1952
1953 Query q = session.createQuery(sql);
1954
1955 QueryPos qPos = QueryPos.getInstance(q);
1956
1957 if (uuid != null) {
1958 qPos.add(uuid);
1959 }
1960
1961 count = (Long)q.uniqueResult();
1962 }
1963 catch (Exception e) {
1964 throw processException(e);
1965 }
1966 finally {
1967 if (count == null) {
1968 count = Long.valueOf(0);
1969 }
1970
1971 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1972 finderArgs, count);
1973
1974 closeSession(session);
1975 }
1976 }
1977
1978 return count.intValue();
1979 }
1980
1981
1989 public int countByUUID_G(String uuid, long groupId)
1990 throws SystemException {
1991 Object[] finderArgs = new Object[] { uuid, groupId };
1992
1993 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1994 finderArgs, this);
1995
1996 if (count == null) {
1997 StringBundler query = new StringBundler(3);
1998
1999 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
2000
2001 if (uuid == null) {
2002 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2003 }
2004 else {
2005 if (uuid.equals(StringPool.BLANK)) {
2006 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2007 }
2008 else {
2009 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2010 }
2011 }
2012
2013 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2014
2015 String sql = query.toString();
2016
2017 Session session = null;
2018
2019 try {
2020 session = openSession();
2021
2022 Query q = session.createQuery(sql);
2023
2024 QueryPos qPos = QueryPos.getInstance(q);
2025
2026 if (uuid != null) {
2027 qPos.add(uuid);
2028 }
2029
2030 qPos.add(groupId);
2031
2032 count = (Long)q.uniqueResult();
2033 }
2034 catch (Exception e) {
2035 throw processException(e);
2036 }
2037 finally {
2038 if (count == null) {
2039 count = Long.valueOf(0);
2040 }
2041
2042 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2043 finderArgs, count);
2044
2045 closeSession(session);
2046 }
2047 }
2048
2049 return count.intValue();
2050 }
2051
2052
2059 public int countByGroupId(long groupId) throws SystemException {
2060 Object[] finderArgs = new Object[] { groupId };
2061
2062 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2063 finderArgs, this);
2064
2065 if (count == null) {
2066 StringBundler query = new StringBundler(2);
2067
2068 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
2069
2070 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2071
2072 String sql = query.toString();
2073
2074 Session session = null;
2075
2076 try {
2077 session = openSession();
2078
2079 Query q = session.createQuery(sql);
2080
2081 QueryPos qPos = QueryPos.getInstance(q);
2082
2083 qPos.add(groupId);
2084
2085 count = (Long)q.uniqueResult();
2086 }
2087 catch (Exception e) {
2088 throw processException(e);
2089 }
2090 finally {
2091 if (count == null) {
2092 count = Long.valueOf(0);
2093 }
2094
2095 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2096 finderArgs, count);
2097
2098 closeSession(session);
2099 }
2100 }
2101
2102 return count.intValue();
2103 }
2104
2105
2112 public int filterCountByGroupId(long groupId) throws SystemException {
2113 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2114 return countByGroupId(groupId);
2115 }
2116
2117 StringBundler query = new StringBundler(2);
2118
2119 query.append(_FILTER_SQL_COUNT_POLLSQUESTION_WHERE);
2120
2121 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2122
2123 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2124 PollsQuestion.class.getName(),
2125 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2126
2127 Session session = null;
2128
2129 try {
2130 session = openSession();
2131
2132 SQLQuery q = session.createSQLQuery(sql);
2133
2134 q.addScalar(COUNT_COLUMN_NAME,
2135 com.liferay.portal.kernel.dao.orm.Type.LONG);
2136
2137 QueryPos qPos = QueryPos.getInstance(q);
2138
2139 qPos.add(groupId);
2140
2141 Long count = (Long)q.uniqueResult();
2142
2143 return count.intValue();
2144 }
2145 catch (Exception e) {
2146 throw processException(e);
2147 }
2148 finally {
2149 closeSession(session);
2150 }
2151 }
2152
2153
2159 public int countAll() throws SystemException {
2160 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2161 FINDER_ARGS_EMPTY, this);
2162
2163 if (count == null) {
2164 Session session = null;
2165
2166 try {
2167 session = openSession();
2168
2169 Query q = session.createQuery(_SQL_COUNT_POLLSQUESTION);
2170
2171 count = (Long)q.uniqueResult();
2172 }
2173 catch (Exception e) {
2174 throw processException(e);
2175 }
2176 finally {
2177 if (count == null) {
2178 count = Long.valueOf(0);
2179 }
2180
2181 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2182 FINDER_ARGS_EMPTY, count);
2183
2184 closeSession(session);
2185 }
2186 }
2187
2188 return count.intValue();
2189 }
2190
2191
2194 public void afterPropertiesSet() {
2195 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2196 com.liferay.portal.util.PropsUtil.get(
2197 "value.object.listener.com.liferay.portlet.polls.model.PollsQuestion")));
2198
2199 if (listenerClassNames.length > 0) {
2200 try {
2201 List<ModelListener<PollsQuestion>> listenersList = new ArrayList<ModelListener<PollsQuestion>>();
2202
2203 for (String listenerClassName : listenerClassNames) {
2204 listenersList.add((ModelListener<PollsQuestion>)InstanceFactory.newInstance(
2205 listenerClassName));
2206 }
2207
2208 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2209 }
2210 catch (Exception e) {
2211 _log.error(e);
2212 }
2213 }
2214 }
2215
2216 public void destroy() {
2217 EntityCacheUtil.removeCache(PollsQuestionImpl.class.getName());
2218 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2219 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2220 }
2221
2222 @BeanReference(type = PollsChoicePersistence.class)
2223 protected PollsChoicePersistence pollsChoicePersistence;
2224 @BeanReference(type = PollsQuestionPersistence.class)
2225 protected PollsQuestionPersistence pollsQuestionPersistence;
2226 @BeanReference(type = PollsVotePersistence.class)
2227 protected PollsVotePersistence pollsVotePersistence;
2228 @BeanReference(type = ResourcePersistence.class)
2229 protected ResourcePersistence resourcePersistence;
2230 @BeanReference(type = UserPersistence.class)
2231 protected UserPersistence userPersistence;
2232 private static final String _SQL_SELECT_POLLSQUESTION = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion";
2233 private static final String _SQL_SELECT_POLLSQUESTION_WHERE = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion WHERE ";
2234 private static final String _SQL_COUNT_POLLSQUESTION = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion";
2235 private static final String _SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion WHERE ";
2236 private static final String _FINDER_COLUMN_UUID_UUID_1 = "pollsQuestion.uuid IS NULL";
2237 private static final String _FINDER_COLUMN_UUID_UUID_2 = "pollsQuestion.uuid = ?";
2238 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?)";
2239 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "pollsQuestion.uuid IS NULL AND ";
2240 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "pollsQuestion.uuid = ? AND ";
2241 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?) AND ";
2242 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "pollsQuestion.groupId = ?";
2243 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "pollsQuestion.groupId = ?";
2244 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "pollsQuestion.questionId";
2245 private static final String _FILTER_SQL_SELECT_POLLSQUESTION_WHERE = "SELECT DISTINCT {pollsQuestion.*} FROM PollsQuestion pollsQuestion WHERE ";
2246 private static final String _FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1 =
2247 "SELECT {PollsQuestion.*} FROM (SELECT DISTINCT pollsQuestion.questionId FROM PollsQuestion pollsQuestion WHERE ";
2248 private static final String _FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2 =
2249 ") TEMP_TABLE INNER JOIN PollsQuestion ON TEMP_TABLE.questionId = PollsQuestion.questionId";
2250 private static final String _FILTER_SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(DISTINCT pollsQuestion.questionId) AS COUNT_VALUE FROM PollsQuestion pollsQuestion WHERE ";
2251 private static final String _FILTER_ENTITY_ALIAS = "pollsQuestion";
2252 private static final String _FILTER_ENTITY_TABLE = "PollsQuestion";
2253 private static final String _ORDER_BY_ENTITY_ALIAS = "pollsQuestion.";
2254 private static final String _ORDER_BY_ENTITY_TABLE = "PollsQuestion.";
2255 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsQuestion exists with the primary key ";
2256 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsQuestion exists with the key {";
2257 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2258 private static Log _log = LogFactoryUtil.getLog(PollsQuestionPersistenceImpl.class);
2259 private static PollsQuestion _nullPollsQuestion = new PollsQuestionImpl() {
2260 @Override
2261 public Object clone() {
2262 return this;
2263 }
2264
2265 @Override
2266 public CacheModel<PollsQuestion> toCacheModel() {
2267 return _nullPollsQuestionCacheModel;
2268 }
2269 };
2270
2271 private static CacheModel<PollsQuestion> _nullPollsQuestionCacheModel = new CacheModel<PollsQuestion>() {
2272 public PollsQuestion toEntityModel() {
2273 return _nullPollsQuestion;
2274 }
2275 };
2276 }