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_WITH_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_WITHOUT_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
433 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
434
435 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
436 new Object[] {
437 pollsQuestion.getUuid(),
438 Long.valueOf(pollsQuestion.getGroupId())
439 }, pollsQuestion);
440 }
441 }
442
443 return pollsQuestion;
444 }
445
446 protected PollsQuestion toUnwrappedModel(PollsQuestion pollsQuestion) {
447 if (pollsQuestion instanceof PollsQuestionImpl) {
448 return pollsQuestion;
449 }
450
451 PollsQuestionImpl pollsQuestionImpl = new PollsQuestionImpl();
452
453 pollsQuestionImpl.setNew(pollsQuestion.isNew());
454 pollsQuestionImpl.setPrimaryKey(pollsQuestion.getPrimaryKey());
455
456 pollsQuestionImpl.setUuid(pollsQuestion.getUuid());
457 pollsQuestionImpl.setQuestionId(pollsQuestion.getQuestionId());
458 pollsQuestionImpl.setGroupId(pollsQuestion.getGroupId());
459 pollsQuestionImpl.setCompanyId(pollsQuestion.getCompanyId());
460 pollsQuestionImpl.setUserId(pollsQuestion.getUserId());
461 pollsQuestionImpl.setUserName(pollsQuestion.getUserName());
462 pollsQuestionImpl.setCreateDate(pollsQuestion.getCreateDate());
463 pollsQuestionImpl.setModifiedDate(pollsQuestion.getModifiedDate());
464 pollsQuestionImpl.setTitle(pollsQuestion.getTitle());
465 pollsQuestionImpl.setDescription(pollsQuestion.getDescription());
466 pollsQuestionImpl.setExpirationDate(pollsQuestion.getExpirationDate());
467 pollsQuestionImpl.setLastVoteDate(pollsQuestion.getLastVoteDate());
468
469 return pollsQuestionImpl;
470 }
471
472
480 @Override
481 public PollsQuestion findByPrimaryKey(Serializable primaryKey)
482 throws NoSuchModelException, SystemException {
483 return findByPrimaryKey(((Long)primaryKey).longValue());
484 }
485
486
494 public PollsQuestion findByPrimaryKey(long questionId)
495 throws NoSuchQuestionException, SystemException {
496 PollsQuestion pollsQuestion = fetchByPrimaryKey(questionId);
497
498 if (pollsQuestion == null) {
499 if (_log.isWarnEnabled()) {
500 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + questionId);
501 }
502
503 throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
504 questionId);
505 }
506
507 return pollsQuestion;
508 }
509
510
517 @Override
518 public PollsQuestion fetchByPrimaryKey(Serializable primaryKey)
519 throws SystemException {
520 return fetchByPrimaryKey(((Long)primaryKey).longValue());
521 }
522
523
530 public PollsQuestion fetchByPrimaryKey(long questionId)
531 throws SystemException {
532 PollsQuestion pollsQuestion = (PollsQuestion)EntityCacheUtil.getResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
533 PollsQuestionImpl.class, questionId);
534
535 if (pollsQuestion == _nullPollsQuestion) {
536 return null;
537 }
538
539 if (pollsQuestion == null) {
540 Session session = null;
541
542 boolean hasException = false;
543
544 try {
545 session = openSession();
546
547 pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
548 Long.valueOf(questionId));
549 }
550 catch (Exception e) {
551 hasException = true;
552
553 throw processException(e);
554 }
555 finally {
556 if (pollsQuestion != null) {
557 cacheResult(pollsQuestion);
558 }
559 else if (!hasException) {
560 EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
561 PollsQuestionImpl.class, questionId, _nullPollsQuestion);
562 }
563
564 closeSession(session);
565 }
566 }
567
568 return pollsQuestion;
569 }
570
571
578 public List<PollsQuestion> findByUuid(String uuid)
579 throws SystemException {
580 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
581 }
582
583
596 public List<PollsQuestion> findByUuid(String uuid, int start, int end)
597 throws SystemException {
598 return findByUuid(uuid, start, end, null);
599 }
600
601
615 public List<PollsQuestion> findByUuid(String uuid, int start, int end,
616 OrderByComparator orderByComparator) throws SystemException {
617 FinderPath finderPath = null;
618 Object[] finderArgs = null;
619
620 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
621 (orderByComparator == null)) {
622 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
623 finderArgs = new Object[] { uuid };
624 }
625 else {
626 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
627 finderArgs = new Object[] { uuid, start, end, orderByComparator };
628 }
629
630 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
631 finderArgs, this);
632
633 if ((list != null) && !list.isEmpty()) {
634 for (PollsQuestion pollsQuestion : list) {
635 if (!Validator.equals(uuid, pollsQuestion.getUuid())) {
636 list = null;
637
638 break;
639 }
640 }
641 }
642
643 if (list == null) {
644 StringBundler query = null;
645
646 if (orderByComparator != null) {
647 query = new StringBundler(3 +
648 (orderByComparator.getOrderByFields().length * 3));
649 }
650 else {
651 query = new StringBundler(3);
652 }
653
654 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
655
656 if (uuid == null) {
657 query.append(_FINDER_COLUMN_UUID_UUID_1);
658 }
659 else {
660 if (uuid.equals(StringPool.BLANK)) {
661 query.append(_FINDER_COLUMN_UUID_UUID_3);
662 }
663 else {
664 query.append(_FINDER_COLUMN_UUID_UUID_2);
665 }
666 }
667
668 if (orderByComparator != null) {
669 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
670 orderByComparator);
671 }
672
673 else {
674 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
675 }
676
677 String sql = query.toString();
678
679 Session session = null;
680
681 try {
682 session = openSession();
683
684 Query q = session.createQuery(sql);
685
686 QueryPos qPos = QueryPos.getInstance(q);
687
688 if (uuid != null) {
689 qPos.add(uuid);
690 }
691
692 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
693 start, end);
694 }
695 catch (Exception e) {
696 throw processException(e);
697 }
698 finally {
699 if (list == null) {
700 FinderCacheUtil.removeResult(finderPath, finderArgs);
701 }
702 else {
703 cacheResult(list);
704
705 FinderCacheUtil.putResult(finderPath, finderArgs, list);
706 }
707
708 closeSession(session);
709 }
710 }
711
712 return list;
713 }
714
715
724 public PollsQuestion findByUuid_First(String uuid,
725 OrderByComparator orderByComparator)
726 throws NoSuchQuestionException, SystemException {
727 PollsQuestion pollsQuestion = fetchByUuid_First(uuid, orderByComparator);
728
729 if (pollsQuestion != null) {
730 return pollsQuestion;
731 }
732
733 StringBundler msg = new StringBundler(4);
734
735 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
736
737 msg.append("uuid=");
738 msg.append(uuid);
739
740 msg.append(StringPool.CLOSE_CURLY_BRACE);
741
742 throw new NoSuchQuestionException(msg.toString());
743 }
744
745
753 public PollsQuestion fetchByUuid_First(String uuid,
754 OrderByComparator orderByComparator) throws SystemException {
755 List<PollsQuestion> list = findByUuid(uuid, 0, 1, orderByComparator);
756
757 if (!list.isEmpty()) {
758 return list.get(0);
759 }
760
761 return null;
762 }
763
764
773 public PollsQuestion findByUuid_Last(String uuid,
774 OrderByComparator orderByComparator)
775 throws NoSuchQuestionException, SystemException {
776 PollsQuestion pollsQuestion = fetchByUuid_Last(uuid, orderByComparator);
777
778 if (pollsQuestion != null) {
779 return pollsQuestion;
780 }
781
782 StringBundler msg = new StringBundler(4);
783
784 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
785
786 msg.append("uuid=");
787 msg.append(uuid);
788
789 msg.append(StringPool.CLOSE_CURLY_BRACE);
790
791 throw new NoSuchQuestionException(msg.toString());
792 }
793
794
802 public PollsQuestion fetchByUuid_Last(String uuid,
803 OrderByComparator orderByComparator) throws SystemException {
804 int count = countByUuid(uuid);
805
806 List<PollsQuestion> list = findByUuid(uuid, count - 1, count,
807 orderByComparator);
808
809 if (!list.isEmpty()) {
810 return list.get(0);
811 }
812
813 return null;
814 }
815
816
826 public PollsQuestion[] findByUuid_PrevAndNext(long questionId, String uuid,
827 OrderByComparator orderByComparator)
828 throws NoSuchQuestionException, SystemException {
829 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
830
831 Session session = null;
832
833 try {
834 session = openSession();
835
836 PollsQuestion[] array = new PollsQuestionImpl[3];
837
838 array[0] = getByUuid_PrevAndNext(session, pollsQuestion, uuid,
839 orderByComparator, true);
840
841 array[1] = pollsQuestion;
842
843 array[2] = getByUuid_PrevAndNext(session, pollsQuestion, uuid,
844 orderByComparator, false);
845
846 return array;
847 }
848 catch (Exception e) {
849 throw processException(e);
850 }
851 finally {
852 closeSession(session);
853 }
854 }
855
856 protected PollsQuestion getByUuid_PrevAndNext(Session session,
857 PollsQuestion pollsQuestion, String uuid,
858 OrderByComparator orderByComparator, boolean previous) {
859 StringBundler query = null;
860
861 if (orderByComparator != null) {
862 query = new StringBundler(6 +
863 (orderByComparator.getOrderByFields().length * 6));
864 }
865 else {
866 query = new StringBundler(3);
867 }
868
869 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
870
871 if (uuid == null) {
872 query.append(_FINDER_COLUMN_UUID_UUID_1);
873 }
874 else {
875 if (uuid.equals(StringPool.BLANK)) {
876 query.append(_FINDER_COLUMN_UUID_UUID_3);
877 }
878 else {
879 query.append(_FINDER_COLUMN_UUID_UUID_2);
880 }
881 }
882
883 if (orderByComparator != null) {
884 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
885
886 if (orderByConditionFields.length > 0) {
887 query.append(WHERE_AND);
888 }
889
890 for (int i = 0; i < orderByConditionFields.length; i++) {
891 query.append(_ORDER_BY_ENTITY_ALIAS);
892 query.append(orderByConditionFields[i]);
893
894 if ((i + 1) < orderByConditionFields.length) {
895 if (orderByComparator.isAscending() ^ previous) {
896 query.append(WHERE_GREATER_THAN_HAS_NEXT);
897 }
898 else {
899 query.append(WHERE_LESSER_THAN_HAS_NEXT);
900 }
901 }
902 else {
903 if (orderByComparator.isAscending() ^ previous) {
904 query.append(WHERE_GREATER_THAN);
905 }
906 else {
907 query.append(WHERE_LESSER_THAN);
908 }
909 }
910 }
911
912 query.append(ORDER_BY_CLAUSE);
913
914 String[] orderByFields = orderByComparator.getOrderByFields();
915
916 for (int i = 0; i < orderByFields.length; i++) {
917 query.append(_ORDER_BY_ENTITY_ALIAS);
918 query.append(orderByFields[i]);
919
920 if ((i + 1) < orderByFields.length) {
921 if (orderByComparator.isAscending() ^ previous) {
922 query.append(ORDER_BY_ASC_HAS_NEXT);
923 }
924 else {
925 query.append(ORDER_BY_DESC_HAS_NEXT);
926 }
927 }
928 else {
929 if (orderByComparator.isAscending() ^ previous) {
930 query.append(ORDER_BY_ASC);
931 }
932 else {
933 query.append(ORDER_BY_DESC);
934 }
935 }
936 }
937 }
938
939 else {
940 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
941 }
942
943 String sql = query.toString();
944
945 Query q = session.createQuery(sql);
946
947 q.setFirstResult(0);
948 q.setMaxResults(2);
949
950 QueryPos qPos = QueryPos.getInstance(q);
951
952 if (uuid != null) {
953 qPos.add(uuid);
954 }
955
956 if (orderByComparator != null) {
957 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
958
959 for (Object value : values) {
960 qPos.add(value);
961 }
962 }
963
964 List<PollsQuestion> list = q.list();
965
966 if (list.size() == 2) {
967 return list.get(1);
968 }
969 else {
970 return null;
971 }
972 }
973
974
983 public PollsQuestion findByUUID_G(String uuid, long groupId)
984 throws NoSuchQuestionException, SystemException {
985 PollsQuestion pollsQuestion = fetchByUUID_G(uuid, groupId);
986
987 if (pollsQuestion == null) {
988 StringBundler msg = new StringBundler(6);
989
990 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
991
992 msg.append("uuid=");
993 msg.append(uuid);
994
995 msg.append(", groupId=");
996 msg.append(groupId);
997
998 msg.append(StringPool.CLOSE_CURLY_BRACE);
999
1000 if (_log.isWarnEnabled()) {
1001 _log.warn(msg.toString());
1002 }
1003
1004 throw new NoSuchQuestionException(msg.toString());
1005 }
1006
1007 return pollsQuestion;
1008 }
1009
1010
1018 public PollsQuestion fetchByUUID_G(String uuid, long groupId)
1019 throws SystemException {
1020 return fetchByUUID_G(uuid, groupId, true);
1021 }
1022
1023
1032 public PollsQuestion fetchByUUID_G(String uuid, long groupId,
1033 boolean retrieveFromCache) throws SystemException {
1034 Object[] finderArgs = new Object[] { uuid, groupId };
1035
1036 Object result = null;
1037
1038 if (retrieveFromCache) {
1039 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1040 finderArgs, this);
1041 }
1042
1043 if (result instanceof PollsQuestion) {
1044 PollsQuestion pollsQuestion = (PollsQuestion)result;
1045
1046 if (!Validator.equals(uuid, pollsQuestion.getUuid()) ||
1047 (groupId != pollsQuestion.getGroupId())) {
1048 result = null;
1049 }
1050 }
1051
1052 if (result == null) {
1053 StringBundler query = new StringBundler(4);
1054
1055 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1056
1057 if (uuid == null) {
1058 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1059 }
1060 else {
1061 if (uuid.equals(StringPool.BLANK)) {
1062 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1063 }
1064 else {
1065 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1066 }
1067 }
1068
1069 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1070
1071 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1072
1073 String sql = query.toString();
1074
1075 Session session = null;
1076
1077 try {
1078 session = openSession();
1079
1080 Query q = session.createQuery(sql);
1081
1082 QueryPos qPos = QueryPos.getInstance(q);
1083
1084 if (uuid != null) {
1085 qPos.add(uuid);
1086 }
1087
1088 qPos.add(groupId);
1089
1090 List<PollsQuestion> list = q.list();
1091
1092 result = list;
1093
1094 PollsQuestion pollsQuestion = null;
1095
1096 if (list.isEmpty()) {
1097 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1098 finderArgs, list);
1099 }
1100 else {
1101 pollsQuestion = list.get(0);
1102
1103 cacheResult(pollsQuestion);
1104
1105 if ((pollsQuestion.getUuid() == null) ||
1106 !pollsQuestion.getUuid().equals(uuid) ||
1107 (pollsQuestion.getGroupId() != groupId)) {
1108 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1109 finderArgs, pollsQuestion);
1110 }
1111 }
1112
1113 return pollsQuestion;
1114 }
1115 catch (Exception e) {
1116 throw processException(e);
1117 }
1118 finally {
1119 if (result == null) {
1120 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1121 finderArgs);
1122 }
1123
1124 closeSession(session);
1125 }
1126 }
1127 else {
1128 if (result instanceof List<?>) {
1129 return null;
1130 }
1131 else {
1132 return (PollsQuestion)result;
1133 }
1134 }
1135 }
1136
1137
1144 public List<PollsQuestion> findByGroupId(long groupId)
1145 throws SystemException {
1146 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1147 }
1148
1149
1162 public List<PollsQuestion> findByGroupId(long groupId, int start, int end)
1163 throws SystemException {
1164 return findByGroupId(groupId, start, end, null);
1165 }
1166
1167
1181 public List<PollsQuestion> findByGroupId(long groupId, int start, int end,
1182 OrderByComparator orderByComparator) throws SystemException {
1183 FinderPath finderPath = null;
1184 Object[] finderArgs = null;
1185
1186 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1187 (orderByComparator == null)) {
1188 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1189 finderArgs = new Object[] { groupId };
1190 }
1191 else {
1192 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1193 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1194 }
1195
1196 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
1197 finderArgs, this);
1198
1199 if ((list != null) && !list.isEmpty()) {
1200 for (PollsQuestion pollsQuestion : list) {
1201 if ((groupId != pollsQuestion.getGroupId())) {
1202 list = null;
1203
1204 break;
1205 }
1206 }
1207 }
1208
1209 if (list == null) {
1210 StringBundler query = null;
1211
1212 if (orderByComparator != null) {
1213 query = new StringBundler(3 +
1214 (orderByComparator.getOrderByFields().length * 3));
1215 }
1216 else {
1217 query = new StringBundler(3);
1218 }
1219
1220 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1221
1222 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1223
1224 if (orderByComparator != null) {
1225 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1226 orderByComparator);
1227 }
1228
1229 else {
1230 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1231 }
1232
1233 String sql = query.toString();
1234
1235 Session session = null;
1236
1237 try {
1238 session = openSession();
1239
1240 Query q = session.createQuery(sql);
1241
1242 QueryPos qPos = QueryPos.getInstance(q);
1243
1244 qPos.add(groupId);
1245
1246 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1247 start, end);
1248 }
1249 catch (Exception e) {
1250 throw processException(e);
1251 }
1252 finally {
1253 if (list == null) {
1254 FinderCacheUtil.removeResult(finderPath, finderArgs);
1255 }
1256 else {
1257 cacheResult(list);
1258
1259 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1260 }
1261
1262 closeSession(session);
1263 }
1264 }
1265
1266 return list;
1267 }
1268
1269
1278 public PollsQuestion findByGroupId_First(long groupId,
1279 OrderByComparator orderByComparator)
1280 throws NoSuchQuestionException, SystemException {
1281 PollsQuestion pollsQuestion = fetchByGroupId_First(groupId,
1282 orderByComparator);
1283
1284 if (pollsQuestion != null) {
1285 return pollsQuestion;
1286 }
1287
1288 StringBundler msg = new StringBundler(4);
1289
1290 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1291
1292 msg.append("groupId=");
1293 msg.append(groupId);
1294
1295 msg.append(StringPool.CLOSE_CURLY_BRACE);
1296
1297 throw new NoSuchQuestionException(msg.toString());
1298 }
1299
1300
1308 public PollsQuestion fetchByGroupId_First(long groupId,
1309 OrderByComparator orderByComparator) throws SystemException {
1310 List<PollsQuestion> list = findByGroupId(groupId, 0, 1,
1311 orderByComparator);
1312
1313 if (!list.isEmpty()) {
1314 return list.get(0);
1315 }
1316
1317 return null;
1318 }
1319
1320
1329 public PollsQuestion findByGroupId_Last(long groupId,
1330 OrderByComparator orderByComparator)
1331 throws NoSuchQuestionException, SystemException {
1332 PollsQuestion pollsQuestion = fetchByGroupId_Last(groupId,
1333 orderByComparator);
1334
1335 if (pollsQuestion != null) {
1336 return pollsQuestion;
1337 }
1338
1339 StringBundler msg = new StringBundler(4);
1340
1341 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1342
1343 msg.append("groupId=");
1344 msg.append(groupId);
1345
1346 msg.append(StringPool.CLOSE_CURLY_BRACE);
1347
1348 throw new NoSuchQuestionException(msg.toString());
1349 }
1350
1351
1359 public PollsQuestion fetchByGroupId_Last(long groupId,
1360 OrderByComparator orderByComparator) throws SystemException {
1361 int count = countByGroupId(groupId);
1362
1363 List<PollsQuestion> list = findByGroupId(groupId, count - 1, count,
1364 orderByComparator);
1365
1366 if (!list.isEmpty()) {
1367 return list.get(0);
1368 }
1369
1370 return null;
1371 }
1372
1373
1383 public PollsQuestion[] findByGroupId_PrevAndNext(long questionId,
1384 long groupId, OrderByComparator orderByComparator)
1385 throws NoSuchQuestionException, SystemException {
1386 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
1387
1388 Session session = null;
1389
1390 try {
1391 session = openSession();
1392
1393 PollsQuestion[] array = new PollsQuestionImpl[3];
1394
1395 array[0] = getByGroupId_PrevAndNext(session, pollsQuestion,
1396 groupId, orderByComparator, true);
1397
1398 array[1] = pollsQuestion;
1399
1400 array[2] = getByGroupId_PrevAndNext(session, pollsQuestion,
1401 groupId, orderByComparator, false);
1402
1403 return array;
1404 }
1405 catch (Exception e) {
1406 throw processException(e);
1407 }
1408 finally {
1409 closeSession(session);
1410 }
1411 }
1412
1413 protected PollsQuestion getByGroupId_PrevAndNext(Session session,
1414 PollsQuestion pollsQuestion, long groupId,
1415 OrderByComparator orderByComparator, boolean previous) {
1416 StringBundler query = null;
1417
1418 if (orderByComparator != null) {
1419 query = new StringBundler(6 +
1420 (orderByComparator.getOrderByFields().length * 6));
1421 }
1422 else {
1423 query = new StringBundler(3);
1424 }
1425
1426 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1427
1428 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1429
1430 if (orderByComparator != null) {
1431 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1432
1433 if (orderByConditionFields.length > 0) {
1434 query.append(WHERE_AND);
1435 }
1436
1437 for (int i = 0; i < orderByConditionFields.length; i++) {
1438 query.append(_ORDER_BY_ENTITY_ALIAS);
1439 query.append(orderByConditionFields[i]);
1440
1441 if ((i + 1) < orderByConditionFields.length) {
1442 if (orderByComparator.isAscending() ^ previous) {
1443 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1444 }
1445 else {
1446 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1447 }
1448 }
1449 else {
1450 if (orderByComparator.isAscending() ^ previous) {
1451 query.append(WHERE_GREATER_THAN);
1452 }
1453 else {
1454 query.append(WHERE_LESSER_THAN);
1455 }
1456 }
1457 }
1458
1459 query.append(ORDER_BY_CLAUSE);
1460
1461 String[] orderByFields = orderByComparator.getOrderByFields();
1462
1463 for (int i = 0; i < orderByFields.length; i++) {
1464 query.append(_ORDER_BY_ENTITY_ALIAS);
1465 query.append(orderByFields[i]);
1466
1467 if ((i + 1) < orderByFields.length) {
1468 if (orderByComparator.isAscending() ^ previous) {
1469 query.append(ORDER_BY_ASC_HAS_NEXT);
1470 }
1471 else {
1472 query.append(ORDER_BY_DESC_HAS_NEXT);
1473 }
1474 }
1475 else {
1476 if (orderByComparator.isAscending() ^ previous) {
1477 query.append(ORDER_BY_ASC);
1478 }
1479 else {
1480 query.append(ORDER_BY_DESC);
1481 }
1482 }
1483 }
1484 }
1485
1486 else {
1487 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1488 }
1489
1490 String sql = query.toString();
1491
1492 Query q = session.createQuery(sql);
1493
1494 q.setFirstResult(0);
1495 q.setMaxResults(2);
1496
1497 QueryPos qPos = QueryPos.getInstance(q);
1498
1499 qPos.add(groupId);
1500
1501 if (orderByComparator != null) {
1502 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
1503
1504 for (Object value : values) {
1505 qPos.add(value);
1506 }
1507 }
1508
1509 List<PollsQuestion> list = q.list();
1510
1511 if (list.size() == 2) {
1512 return list.get(1);
1513 }
1514 else {
1515 return null;
1516 }
1517 }
1518
1519
1526 public List<PollsQuestion> filterFindByGroupId(long groupId)
1527 throws SystemException {
1528 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1529 QueryUtil.ALL_POS, null);
1530 }
1531
1532
1545 public List<PollsQuestion> filterFindByGroupId(long groupId, int start,
1546 int end) throws SystemException {
1547 return filterFindByGroupId(groupId, start, end, null);
1548 }
1549
1550
1564 public List<PollsQuestion> filterFindByGroupId(long groupId, int start,
1565 int end, OrderByComparator orderByComparator) throws SystemException {
1566 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1567 return findByGroupId(groupId, start, end, orderByComparator);
1568 }
1569
1570 StringBundler query = null;
1571
1572 if (orderByComparator != null) {
1573 query = new StringBundler(3 +
1574 (orderByComparator.getOrderByFields().length * 3));
1575 }
1576 else {
1577 query = new StringBundler(3);
1578 }
1579
1580 if (getDB().isSupportsInlineDistinct()) {
1581 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_WHERE);
1582 }
1583 else {
1584 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1);
1585 }
1586
1587 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1588
1589 if (!getDB().isSupportsInlineDistinct()) {
1590 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2);
1591 }
1592
1593 if (orderByComparator != null) {
1594 if (getDB().isSupportsInlineDistinct()) {
1595 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1596 orderByComparator);
1597 }
1598 else {
1599 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1600 orderByComparator);
1601 }
1602 }
1603
1604 else {
1605 if (getDB().isSupportsInlineDistinct()) {
1606 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1607 }
1608 else {
1609 query.append(PollsQuestionModelImpl.ORDER_BY_SQL);
1610 }
1611 }
1612
1613 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1614 PollsQuestion.class.getName(),
1615 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1616
1617 Session session = null;
1618
1619 try {
1620 session = openSession();
1621
1622 SQLQuery q = session.createSQLQuery(sql);
1623
1624 if (getDB().isSupportsInlineDistinct()) {
1625 q.addEntity(_FILTER_ENTITY_ALIAS, PollsQuestionImpl.class);
1626 }
1627 else {
1628 q.addEntity(_FILTER_ENTITY_TABLE, PollsQuestionImpl.class);
1629 }
1630
1631 QueryPos qPos = QueryPos.getInstance(q);
1632
1633 qPos.add(groupId);
1634
1635 return (List<PollsQuestion>)QueryUtil.list(q, getDialect(), start,
1636 end);
1637 }
1638 catch (Exception e) {
1639 throw processException(e);
1640 }
1641 finally {
1642 closeSession(session);
1643 }
1644 }
1645
1646
1656 public PollsQuestion[] filterFindByGroupId_PrevAndNext(long questionId,
1657 long groupId, OrderByComparator orderByComparator)
1658 throws NoSuchQuestionException, SystemException {
1659 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1660 return findByGroupId_PrevAndNext(questionId, groupId,
1661 orderByComparator);
1662 }
1663
1664 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
1665
1666 Session session = null;
1667
1668 try {
1669 session = openSession();
1670
1671 PollsQuestion[] array = new PollsQuestionImpl[3];
1672
1673 array[0] = filterGetByGroupId_PrevAndNext(session, pollsQuestion,
1674 groupId, orderByComparator, true);
1675
1676 array[1] = pollsQuestion;
1677
1678 array[2] = filterGetByGroupId_PrevAndNext(session, pollsQuestion,
1679 groupId, orderByComparator, false);
1680
1681 return array;
1682 }
1683 catch (Exception e) {
1684 throw processException(e);
1685 }
1686 finally {
1687 closeSession(session);
1688 }
1689 }
1690
1691 protected PollsQuestion filterGetByGroupId_PrevAndNext(Session session,
1692 PollsQuestion pollsQuestion, long groupId,
1693 OrderByComparator orderByComparator, boolean previous) {
1694 StringBundler query = null;
1695
1696 if (orderByComparator != null) {
1697 query = new StringBundler(6 +
1698 (orderByComparator.getOrderByFields().length * 6));
1699 }
1700 else {
1701 query = new StringBundler(3);
1702 }
1703
1704 if (getDB().isSupportsInlineDistinct()) {
1705 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_WHERE);
1706 }
1707 else {
1708 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1);
1709 }
1710
1711 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1712
1713 if (!getDB().isSupportsInlineDistinct()) {
1714 query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2);
1715 }
1716
1717 if (orderByComparator != null) {
1718 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1719
1720 if (orderByConditionFields.length > 0) {
1721 query.append(WHERE_AND);
1722 }
1723
1724 for (int i = 0; i < orderByConditionFields.length; i++) {
1725 if (getDB().isSupportsInlineDistinct()) {
1726 query.append(_ORDER_BY_ENTITY_ALIAS);
1727 }
1728 else {
1729 query.append(_ORDER_BY_ENTITY_TABLE);
1730 }
1731
1732 query.append(orderByConditionFields[i]);
1733
1734 if ((i + 1) < orderByConditionFields.length) {
1735 if (orderByComparator.isAscending() ^ previous) {
1736 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1737 }
1738 else {
1739 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1740 }
1741 }
1742 else {
1743 if (orderByComparator.isAscending() ^ previous) {
1744 query.append(WHERE_GREATER_THAN);
1745 }
1746 else {
1747 query.append(WHERE_LESSER_THAN);
1748 }
1749 }
1750 }
1751
1752 query.append(ORDER_BY_CLAUSE);
1753
1754 String[] orderByFields = orderByComparator.getOrderByFields();
1755
1756 for (int i = 0; i < orderByFields.length; i++) {
1757 if (getDB().isSupportsInlineDistinct()) {
1758 query.append(_ORDER_BY_ENTITY_ALIAS);
1759 }
1760 else {
1761 query.append(_ORDER_BY_ENTITY_TABLE);
1762 }
1763
1764 query.append(orderByFields[i]);
1765
1766 if ((i + 1) < orderByFields.length) {
1767 if (orderByComparator.isAscending() ^ previous) {
1768 query.append(ORDER_BY_ASC_HAS_NEXT);
1769 }
1770 else {
1771 query.append(ORDER_BY_DESC_HAS_NEXT);
1772 }
1773 }
1774 else {
1775 if (orderByComparator.isAscending() ^ previous) {
1776 query.append(ORDER_BY_ASC);
1777 }
1778 else {
1779 query.append(ORDER_BY_DESC);
1780 }
1781 }
1782 }
1783 }
1784
1785 else {
1786 if (getDB().isSupportsInlineDistinct()) {
1787 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1788 }
1789 else {
1790 query.append(PollsQuestionModelImpl.ORDER_BY_SQL);
1791 }
1792 }
1793
1794 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1795 PollsQuestion.class.getName(),
1796 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1797
1798 SQLQuery q = session.createSQLQuery(sql);
1799
1800 q.setFirstResult(0);
1801 q.setMaxResults(2);
1802
1803 if (getDB().isSupportsInlineDistinct()) {
1804 q.addEntity(_FILTER_ENTITY_ALIAS, PollsQuestionImpl.class);
1805 }
1806 else {
1807 q.addEntity(_FILTER_ENTITY_TABLE, PollsQuestionImpl.class);
1808 }
1809
1810 QueryPos qPos = QueryPos.getInstance(q);
1811
1812 qPos.add(groupId);
1813
1814 if (orderByComparator != null) {
1815 Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
1816
1817 for (Object value : values) {
1818 qPos.add(value);
1819 }
1820 }
1821
1822 List<PollsQuestion> list = q.list();
1823
1824 if (list.size() == 2) {
1825 return list.get(1);
1826 }
1827 else {
1828 return null;
1829 }
1830 }
1831
1832
1838 public List<PollsQuestion> findAll() throws SystemException {
1839 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1840 }
1841
1842
1854 public List<PollsQuestion> findAll(int start, int end)
1855 throws SystemException {
1856 return findAll(start, end, null);
1857 }
1858
1859
1872 public List<PollsQuestion> findAll(int start, int end,
1873 OrderByComparator orderByComparator) throws SystemException {
1874 FinderPath finderPath = null;
1875 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1876
1877 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1878 (orderByComparator == null)) {
1879 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1880 finderArgs = FINDER_ARGS_EMPTY;
1881 }
1882 else {
1883 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1884 finderArgs = new Object[] { start, end, orderByComparator };
1885 }
1886
1887 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
1888 finderArgs, this);
1889
1890 if (list == null) {
1891 StringBundler query = null;
1892 String sql = null;
1893
1894 if (orderByComparator != null) {
1895 query = new StringBundler(2 +
1896 (orderByComparator.getOrderByFields().length * 3));
1897
1898 query.append(_SQL_SELECT_POLLSQUESTION);
1899
1900 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1901 orderByComparator);
1902
1903 sql = query.toString();
1904 }
1905 else {
1906 sql = _SQL_SELECT_POLLSQUESTION.concat(PollsQuestionModelImpl.ORDER_BY_JPQL);
1907 }
1908
1909 Session session = null;
1910
1911 try {
1912 session = openSession();
1913
1914 Query q = session.createQuery(sql);
1915
1916 if (orderByComparator == null) {
1917 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1918 start, end, false);
1919
1920 Collections.sort(list);
1921 }
1922 else {
1923 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1924 start, end);
1925 }
1926 }
1927 catch (Exception e) {
1928 throw processException(e);
1929 }
1930 finally {
1931 if (list == null) {
1932 FinderCacheUtil.removeResult(finderPath, finderArgs);
1933 }
1934 else {
1935 cacheResult(list);
1936
1937 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1938 }
1939
1940 closeSession(session);
1941 }
1942 }
1943
1944 return list;
1945 }
1946
1947
1953 public void removeByUuid(String uuid) throws SystemException {
1954 for (PollsQuestion pollsQuestion : findByUuid(uuid)) {
1955 remove(pollsQuestion);
1956 }
1957 }
1958
1959
1967 public PollsQuestion removeByUUID_G(String uuid, long groupId)
1968 throws NoSuchQuestionException, SystemException {
1969 PollsQuestion pollsQuestion = findByUUID_G(uuid, groupId);
1970
1971 return remove(pollsQuestion);
1972 }
1973
1974
1980 public void removeByGroupId(long groupId) throws SystemException {
1981 for (PollsQuestion pollsQuestion : findByGroupId(groupId)) {
1982 remove(pollsQuestion);
1983 }
1984 }
1985
1986
1991 public void removeAll() throws SystemException {
1992 for (PollsQuestion pollsQuestion : findAll()) {
1993 remove(pollsQuestion);
1994 }
1995 }
1996
1997
2004 public int countByUuid(String uuid) throws SystemException {
2005 Object[] finderArgs = new Object[] { uuid };
2006
2007 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2008 finderArgs, this);
2009
2010 if (count == null) {
2011 StringBundler query = new StringBundler(2);
2012
2013 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
2014
2015 if (uuid == null) {
2016 query.append(_FINDER_COLUMN_UUID_UUID_1);
2017 }
2018 else {
2019 if (uuid.equals(StringPool.BLANK)) {
2020 query.append(_FINDER_COLUMN_UUID_UUID_3);
2021 }
2022 else {
2023 query.append(_FINDER_COLUMN_UUID_UUID_2);
2024 }
2025 }
2026
2027 String sql = query.toString();
2028
2029 Session session = null;
2030
2031 try {
2032 session = openSession();
2033
2034 Query q = session.createQuery(sql);
2035
2036 QueryPos qPos = QueryPos.getInstance(q);
2037
2038 if (uuid != null) {
2039 qPos.add(uuid);
2040 }
2041
2042 count = (Long)q.uniqueResult();
2043 }
2044 catch (Exception e) {
2045 throw processException(e);
2046 }
2047 finally {
2048 if (count == null) {
2049 count = Long.valueOf(0);
2050 }
2051
2052 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2053 finderArgs, count);
2054
2055 closeSession(session);
2056 }
2057 }
2058
2059 return count.intValue();
2060 }
2061
2062
2070 public int countByUUID_G(String uuid, long groupId)
2071 throws SystemException {
2072 Object[] finderArgs = new Object[] { uuid, groupId };
2073
2074 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2075 finderArgs, this);
2076
2077 if (count == null) {
2078 StringBundler query = new StringBundler(3);
2079
2080 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
2081
2082 if (uuid == null) {
2083 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2084 }
2085 else {
2086 if (uuid.equals(StringPool.BLANK)) {
2087 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2088 }
2089 else {
2090 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2091 }
2092 }
2093
2094 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2095
2096 String sql = query.toString();
2097
2098 Session session = null;
2099
2100 try {
2101 session = openSession();
2102
2103 Query q = session.createQuery(sql);
2104
2105 QueryPos qPos = QueryPos.getInstance(q);
2106
2107 if (uuid != null) {
2108 qPos.add(uuid);
2109 }
2110
2111 qPos.add(groupId);
2112
2113 count = (Long)q.uniqueResult();
2114 }
2115 catch (Exception e) {
2116 throw processException(e);
2117 }
2118 finally {
2119 if (count == null) {
2120 count = Long.valueOf(0);
2121 }
2122
2123 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2124 finderArgs, count);
2125
2126 closeSession(session);
2127 }
2128 }
2129
2130 return count.intValue();
2131 }
2132
2133
2140 public int countByGroupId(long groupId) throws SystemException {
2141 Object[] finderArgs = new Object[] { groupId };
2142
2143 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2144 finderArgs, this);
2145
2146 if (count == null) {
2147 StringBundler query = new StringBundler(2);
2148
2149 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
2150
2151 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2152
2153 String sql = query.toString();
2154
2155 Session session = null;
2156
2157 try {
2158 session = openSession();
2159
2160 Query q = session.createQuery(sql);
2161
2162 QueryPos qPos = QueryPos.getInstance(q);
2163
2164 qPos.add(groupId);
2165
2166 count = (Long)q.uniqueResult();
2167 }
2168 catch (Exception e) {
2169 throw processException(e);
2170 }
2171 finally {
2172 if (count == null) {
2173 count = Long.valueOf(0);
2174 }
2175
2176 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2177 finderArgs, count);
2178
2179 closeSession(session);
2180 }
2181 }
2182
2183 return count.intValue();
2184 }
2185
2186
2193 public int filterCountByGroupId(long groupId) throws SystemException {
2194 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2195 return countByGroupId(groupId);
2196 }
2197
2198 StringBundler query = new StringBundler(2);
2199
2200 query.append(_FILTER_SQL_COUNT_POLLSQUESTION_WHERE);
2201
2202 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2203
2204 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2205 PollsQuestion.class.getName(),
2206 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2207
2208 Session session = null;
2209
2210 try {
2211 session = openSession();
2212
2213 SQLQuery q = session.createSQLQuery(sql);
2214
2215 q.addScalar(COUNT_COLUMN_NAME,
2216 com.liferay.portal.kernel.dao.orm.Type.LONG);
2217
2218 QueryPos qPos = QueryPos.getInstance(q);
2219
2220 qPos.add(groupId);
2221
2222 Long count = (Long)q.uniqueResult();
2223
2224 return count.intValue();
2225 }
2226 catch (Exception e) {
2227 throw processException(e);
2228 }
2229 finally {
2230 closeSession(session);
2231 }
2232 }
2233
2234
2240 public int countAll() throws SystemException {
2241 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2242 FINDER_ARGS_EMPTY, this);
2243
2244 if (count == null) {
2245 Session session = null;
2246
2247 try {
2248 session = openSession();
2249
2250 Query q = session.createQuery(_SQL_COUNT_POLLSQUESTION);
2251
2252 count = (Long)q.uniqueResult();
2253 }
2254 catch (Exception e) {
2255 throw processException(e);
2256 }
2257 finally {
2258 if (count == null) {
2259 count = Long.valueOf(0);
2260 }
2261
2262 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2263 FINDER_ARGS_EMPTY, count);
2264
2265 closeSession(session);
2266 }
2267 }
2268
2269 return count.intValue();
2270 }
2271
2272
2275 public void afterPropertiesSet() {
2276 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2277 com.liferay.portal.util.PropsUtil.get(
2278 "value.object.listener.com.liferay.portlet.polls.model.PollsQuestion")));
2279
2280 if (listenerClassNames.length > 0) {
2281 try {
2282 List<ModelListener<PollsQuestion>> listenersList = new ArrayList<ModelListener<PollsQuestion>>();
2283
2284 for (String listenerClassName : listenerClassNames) {
2285 listenersList.add((ModelListener<PollsQuestion>)InstanceFactory.newInstance(
2286 listenerClassName));
2287 }
2288
2289 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2290 }
2291 catch (Exception e) {
2292 _log.error(e);
2293 }
2294 }
2295 }
2296
2297 public void destroy() {
2298 EntityCacheUtil.removeCache(PollsQuestionImpl.class.getName());
2299 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2300 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2301 }
2302
2303 @BeanReference(type = PollsChoicePersistence.class)
2304 protected PollsChoicePersistence pollsChoicePersistence;
2305 @BeanReference(type = PollsQuestionPersistence.class)
2306 protected PollsQuestionPersistence pollsQuestionPersistence;
2307 @BeanReference(type = PollsVotePersistence.class)
2308 protected PollsVotePersistence pollsVotePersistence;
2309 @BeanReference(type = ResourcePersistence.class)
2310 protected ResourcePersistence resourcePersistence;
2311 @BeanReference(type = UserPersistence.class)
2312 protected UserPersistence userPersistence;
2313 private static final String _SQL_SELECT_POLLSQUESTION = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion";
2314 private static final String _SQL_SELECT_POLLSQUESTION_WHERE = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion WHERE ";
2315 private static final String _SQL_COUNT_POLLSQUESTION = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion";
2316 private static final String _SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion WHERE ";
2317 private static final String _FINDER_COLUMN_UUID_UUID_1 = "pollsQuestion.uuid IS NULL";
2318 private static final String _FINDER_COLUMN_UUID_UUID_2 = "pollsQuestion.uuid = ?";
2319 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?)";
2320 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "pollsQuestion.uuid IS NULL AND ";
2321 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "pollsQuestion.uuid = ? AND ";
2322 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?) AND ";
2323 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "pollsQuestion.groupId = ?";
2324 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "pollsQuestion.groupId = ?";
2325 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "pollsQuestion.questionId";
2326 private static final String _FILTER_SQL_SELECT_POLLSQUESTION_WHERE = "SELECT DISTINCT {pollsQuestion.*} FROM PollsQuestion pollsQuestion WHERE ";
2327 private static final String _FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1 =
2328 "SELECT {PollsQuestion.*} FROM (SELECT DISTINCT pollsQuestion.questionId FROM PollsQuestion pollsQuestion WHERE ";
2329 private static final String _FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2 =
2330 ") TEMP_TABLE INNER JOIN PollsQuestion ON TEMP_TABLE.questionId = PollsQuestion.questionId";
2331 private static final String _FILTER_SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(DISTINCT pollsQuestion.questionId) AS COUNT_VALUE FROM PollsQuestion pollsQuestion WHERE ";
2332 private static final String _FILTER_ENTITY_ALIAS = "pollsQuestion";
2333 private static final String _FILTER_ENTITY_TABLE = "PollsQuestion";
2334 private static final String _ORDER_BY_ENTITY_ALIAS = "pollsQuestion.";
2335 private static final String _ORDER_BY_ENTITY_TABLE = "PollsQuestion.";
2336 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsQuestion exists with the primary key ";
2337 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsQuestion exists with the key {";
2338 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2339 private static Log _log = LogFactoryUtil.getLog(PollsQuestionPersistenceImpl.class);
2340 private static PollsQuestion _nullPollsQuestion = new PollsQuestionImpl() {
2341 @Override
2342 public Object clone() {
2343 return this;
2344 }
2345
2346 @Override
2347 public CacheModel<PollsQuestion> toCacheModel() {
2348 return _nullPollsQuestionCacheModel;
2349 }
2350 };
2351
2352 private static CacheModel<PollsQuestion> _nullPollsQuestionCacheModel = new CacheModel<PollsQuestion>() {
2353 public PollsQuestion toEntityModel() {
2354 return _nullPollsQuestion;
2355 }
2356 };
2357 }