1
14
15 package com.liferay.portlet.polls.service.persistence;
16
17 import com.liferay.portal.NoSuchModelException;
18 import com.liferay.portal.SystemException;
19 import com.liferay.portal.kernel.annotation.BeanReference;
20 import com.liferay.portal.kernel.cache.CacheRegistry;
21 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23 import com.liferay.portal.kernel.dao.orm.FinderPath;
24 import com.liferay.portal.kernel.dao.orm.Query;
25 import com.liferay.portal.kernel.dao.orm.QueryPos;
26 import com.liferay.portal.kernel.dao.orm.QueryUtil;
27 import com.liferay.portal.kernel.dao.orm.Session;
28 import com.liferay.portal.kernel.log.Log;
29 import com.liferay.portal.kernel.log.LogFactoryUtil;
30 import com.liferay.portal.kernel.util.GetterUtil;
31 import com.liferay.portal.kernel.util.OrderByComparator;
32 import com.liferay.portal.kernel.util.StringBundler;
33 import com.liferay.portal.kernel.util.StringPool;
34 import com.liferay.portal.kernel.util.StringUtil;
35 import com.liferay.portal.kernel.util.Validator;
36 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
37 import com.liferay.portal.model.ModelListener;
38 import com.liferay.portal.service.persistence.BatchSessionUtil;
39 import com.liferay.portal.service.persistence.ResourcePersistence;
40 import com.liferay.portal.service.persistence.UserPersistence;
41 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
42
43 import com.liferay.portlet.polls.NoSuchQuestionException;
44 import com.liferay.portlet.polls.model.PollsQuestion;
45 import com.liferay.portlet.polls.model.impl.PollsQuestionImpl;
46 import com.liferay.portlet.polls.model.impl.PollsQuestionModelImpl;
47
48 import java.io.Serializable;
49
50 import java.util.ArrayList;
51 import java.util.Collections;
52 import java.util.List;
53
54
67 public class PollsQuestionPersistenceImpl extends BasePersistenceImpl<PollsQuestion>
68 implements PollsQuestionPersistence {
69 public static final String FINDER_CLASS_NAME_ENTITY = PollsQuestionImpl.class.getName();
70 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
71 ".List";
72 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
73 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
74 FINDER_CLASS_NAME_LIST, "findByUuid",
75 new String[] { String.class.getName() });
76 public static final FinderPath FINDER_PATH_FIND_BY_OBC_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
77 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
78 FINDER_CLASS_NAME_LIST, "findByUuid",
79 new String[] {
80 String.class.getName(),
81
82 "java.lang.Integer", "java.lang.Integer",
83 "com.liferay.portal.kernel.util.OrderByComparator"
84 });
85 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
86 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
87 FINDER_CLASS_NAME_LIST, "countByUuid",
88 new String[] { String.class.getName() });
89 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
90 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
91 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
92 new String[] { String.class.getName(), Long.class.getName() });
93 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
94 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
95 FINDER_CLASS_NAME_LIST, "countByUUID_G",
96 new String[] { String.class.getName(), Long.class.getName() });
97 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
98 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
99 FINDER_CLASS_NAME_LIST, "findByGroupId",
100 new String[] { Long.class.getName() });
101 public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
102 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
103 FINDER_CLASS_NAME_LIST, "findByGroupId",
104 new String[] {
105 Long.class.getName(),
106
107 "java.lang.Integer", "java.lang.Integer",
108 "com.liferay.portal.kernel.util.OrderByComparator"
109 });
110 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
111 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
112 FINDER_CLASS_NAME_LIST, "countByGroupId",
113 new String[] { Long.class.getName() });
114 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
115 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
116 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
117 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
118 PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
119 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
120
121 public void cacheResult(PollsQuestion pollsQuestion) {
122 EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
123 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
124 pollsQuestion);
125
126 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
127 new Object[] {
128 pollsQuestion.getUuid(), new Long(pollsQuestion.getGroupId())
129 }, pollsQuestion);
130 }
131
132 public void cacheResult(List<PollsQuestion> pollsQuestions) {
133 for (PollsQuestion pollsQuestion : pollsQuestions) {
134 if (EntityCacheUtil.getResult(
135 PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
136 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
137 this) == null) {
138 cacheResult(pollsQuestion);
139 }
140 }
141 }
142
143 public void clearCache() {
144 CacheRegistry.clear(PollsQuestionImpl.class.getName());
145 EntityCacheUtil.clearCache(PollsQuestionImpl.class.getName());
146 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
147 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
148 }
149
150 public PollsQuestion create(long questionId) {
151 PollsQuestion pollsQuestion = new PollsQuestionImpl();
152
153 pollsQuestion.setNew(true);
154 pollsQuestion.setPrimaryKey(questionId);
155
156 String uuid = PortalUUIDUtil.generate();
157
158 pollsQuestion.setUuid(uuid);
159
160 return pollsQuestion;
161 }
162
163 public PollsQuestion remove(Serializable primaryKey)
164 throws NoSuchModelException, SystemException {
165 return remove(((Long)primaryKey).longValue());
166 }
167
168 public PollsQuestion remove(long questionId)
169 throws NoSuchQuestionException, SystemException {
170 Session session = null;
171
172 try {
173 session = openSession();
174
175 PollsQuestion pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
176 new Long(questionId));
177
178 if (pollsQuestion == null) {
179 if (_log.isWarnEnabled()) {
180 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + questionId);
181 }
182
183 throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
184 questionId);
185 }
186
187 return remove(pollsQuestion);
188 }
189 catch (NoSuchQuestionException nsee) {
190 throw nsee;
191 }
192 catch (Exception e) {
193 throw processException(e);
194 }
195 finally {
196 closeSession(session);
197 }
198 }
199
200 public PollsQuestion remove(PollsQuestion pollsQuestion)
201 throws SystemException {
202 for (ModelListener<PollsQuestion> listener : listeners) {
203 listener.onBeforeRemove(pollsQuestion);
204 }
205
206 pollsQuestion = removeImpl(pollsQuestion);
207
208 for (ModelListener<PollsQuestion> listener : listeners) {
209 listener.onAfterRemove(pollsQuestion);
210 }
211
212 return pollsQuestion;
213 }
214
215 protected PollsQuestion removeImpl(PollsQuestion pollsQuestion)
216 throws SystemException {
217 pollsQuestion = toUnwrappedModel(pollsQuestion);
218
219 Session session = null;
220
221 try {
222 session = openSession();
223
224 if (pollsQuestion.isCachedModel() || BatchSessionUtil.isEnabled()) {
225 Object staleObject = session.get(PollsQuestionImpl.class,
226 pollsQuestion.getPrimaryKeyObj());
227
228 if (staleObject != null) {
229 session.evict(staleObject);
230 }
231 }
232
233 session.delete(pollsQuestion);
234
235 session.flush();
236 }
237 catch (Exception e) {
238 throw processException(e);
239 }
240 finally {
241 closeSession(session);
242 }
243
244 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
245
246 PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
247
248 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
249 new Object[] {
250 pollsQuestionModelImpl.getOriginalUuid(),
251 new Long(pollsQuestionModelImpl.getOriginalGroupId())
252 });
253
254 EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
255 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey());
256
257 return pollsQuestion;
258 }
259
260
263 public PollsQuestion update(PollsQuestion pollsQuestion)
264 throws SystemException {
265 if (_log.isWarnEnabled()) {
266 _log.warn(
267 "Using the deprecated update(PollsQuestion pollsQuestion) method. Use update(PollsQuestion pollsQuestion, boolean merge) instead.");
268 }
269
270 return update(pollsQuestion, false);
271 }
272
273 public PollsQuestion updateImpl(
274 com.liferay.portlet.polls.model.PollsQuestion pollsQuestion,
275 boolean merge) throws SystemException {
276 pollsQuestion = toUnwrappedModel(pollsQuestion);
277
278 boolean isNew = pollsQuestion.isNew();
279
280 PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
281
282 if (Validator.isNull(pollsQuestion.getUuid())) {
283 String uuid = PortalUUIDUtil.generate();
284
285 pollsQuestion.setUuid(uuid);
286 }
287
288 Session session = null;
289
290 try {
291 session = openSession();
292
293 BatchSessionUtil.update(session, pollsQuestion, merge);
294
295 pollsQuestion.setNew(false);
296 }
297 catch (Exception e) {
298 throw processException(e);
299 }
300 finally {
301 closeSession(session);
302 }
303
304 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
305
306 EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
307 PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
308 pollsQuestion);
309
310 if (!isNew &&
311 (!Validator.equals(pollsQuestion.getUuid(),
312 pollsQuestionModelImpl.getOriginalUuid()) ||
313 (pollsQuestion.getGroupId() != pollsQuestionModelImpl.getOriginalGroupId()))) {
314 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
315 new Object[] {
316 pollsQuestionModelImpl.getOriginalUuid(),
317 new Long(pollsQuestionModelImpl.getOriginalGroupId())
318 });
319 }
320
321 if (isNew ||
322 (!Validator.equals(pollsQuestion.getUuid(),
323 pollsQuestionModelImpl.getOriginalUuid()) ||
324 (pollsQuestion.getGroupId() != pollsQuestionModelImpl.getOriginalGroupId()))) {
325 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
326 new Object[] {
327 pollsQuestion.getUuid(),
328 new Long(pollsQuestion.getGroupId())
329 }, pollsQuestion);
330 }
331
332 return pollsQuestion;
333 }
334
335 protected PollsQuestion toUnwrappedModel(PollsQuestion pollsQuestion) {
336 if (pollsQuestion instanceof PollsQuestionImpl) {
337 return pollsQuestion;
338 }
339
340 PollsQuestionImpl pollsQuestionImpl = new PollsQuestionImpl();
341
342 pollsQuestionImpl.setNew(pollsQuestion.isNew());
343 pollsQuestionImpl.setPrimaryKey(pollsQuestion.getPrimaryKey());
344
345 pollsQuestionImpl.setUuid(pollsQuestion.getUuid());
346 pollsQuestionImpl.setQuestionId(pollsQuestion.getQuestionId());
347 pollsQuestionImpl.setGroupId(pollsQuestion.getGroupId());
348 pollsQuestionImpl.setCompanyId(pollsQuestion.getCompanyId());
349 pollsQuestionImpl.setUserId(pollsQuestion.getUserId());
350 pollsQuestionImpl.setUserName(pollsQuestion.getUserName());
351 pollsQuestionImpl.setCreateDate(pollsQuestion.getCreateDate());
352 pollsQuestionImpl.setModifiedDate(pollsQuestion.getModifiedDate());
353 pollsQuestionImpl.setTitle(pollsQuestion.getTitle());
354 pollsQuestionImpl.setDescription(pollsQuestion.getDescription());
355 pollsQuestionImpl.setExpirationDate(pollsQuestion.getExpirationDate());
356 pollsQuestionImpl.setLastVoteDate(pollsQuestion.getLastVoteDate());
357
358 return pollsQuestionImpl;
359 }
360
361 public PollsQuestion findByPrimaryKey(Serializable primaryKey)
362 throws NoSuchModelException, SystemException {
363 return findByPrimaryKey(((Long)primaryKey).longValue());
364 }
365
366 public PollsQuestion findByPrimaryKey(long questionId)
367 throws NoSuchQuestionException, SystemException {
368 PollsQuestion pollsQuestion = fetchByPrimaryKey(questionId);
369
370 if (pollsQuestion == null) {
371 if (_log.isWarnEnabled()) {
372 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + questionId);
373 }
374
375 throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
376 questionId);
377 }
378
379 return pollsQuestion;
380 }
381
382 public PollsQuestion fetchByPrimaryKey(Serializable primaryKey)
383 throws SystemException {
384 return fetchByPrimaryKey(((Long)primaryKey).longValue());
385 }
386
387 public PollsQuestion fetchByPrimaryKey(long questionId)
388 throws SystemException {
389 PollsQuestion pollsQuestion = (PollsQuestion)EntityCacheUtil.getResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
390 PollsQuestionImpl.class, questionId, this);
391
392 if (pollsQuestion == null) {
393 Session session = null;
394
395 try {
396 session = openSession();
397
398 pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
399 new Long(questionId));
400 }
401 catch (Exception e) {
402 throw processException(e);
403 }
404 finally {
405 if (pollsQuestion != null) {
406 cacheResult(pollsQuestion);
407 }
408
409 closeSession(session);
410 }
411 }
412
413 return pollsQuestion;
414 }
415
416 public List<PollsQuestion> findByUuid(String uuid)
417 throws SystemException {
418 Object[] finderArgs = new Object[] { uuid };
419
420 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
421 finderArgs, this);
422
423 if (list == null) {
424 Session session = null;
425
426 try {
427 session = openSession();
428
429 StringBundler query = new StringBundler(3);
430
431 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
432
433 if (uuid == null) {
434 query.append(_FINDER_COLUMN_UUID_UUID_1);
435 }
436 else {
437 if (uuid.equals(StringPool.BLANK)) {
438 query.append(_FINDER_COLUMN_UUID_UUID_3);
439 }
440 else {
441 query.append(_FINDER_COLUMN_UUID_UUID_2);
442 }
443 }
444
445 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
446
447 String sql = query.toString();
448
449 Query q = session.createQuery(sql);
450
451 QueryPos qPos = QueryPos.getInstance(q);
452
453 if (uuid != null) {
454 qPos.add(uuid);
455 }
456
457 list = q.list();
458 }
459 catch (Exception e) {
460 throw processException(e);
461 }
462 finally {
463 if (list == null) {
464 list = new ArrayList<PollsQuestion>();
465 }
466
467 cacheResult(list);
468
469 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
470 list);
471
472 closeSession(session);
473 }
474 }
475
476 return list;
477 }
478
479 public List<PollsQuestion> findByUuid(String uuid, int start, int end)
480 throws SystemException {
481 return findByUuid(uuid, start, end, null);
482 }
483
484 public List<PollsQuestion> findByUuid(String uuid, int start, int end,
485 OrderByComparator orderByComparator) throws SystemException {
486 Object[] finderArgs = new Object[] {
487 uuid,
488
489 String.valueOf(start), String.valueOf(end),
490 String.valueOf(orderByComparator)
491 };
492
493 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_UUID,
494 finderArgs, this);
495
496 if (list == null) {
497 Session session = null;
498
499 try {
500 session = openSession();
501
502 StringBundler query = null;
503
504 if (orderByComparator != null) {
505 query = new StringBundler(3 +
506 (orderByComparator.getOrderByFields().length * 3));
507 }
508 else {
509 query = new StringBundler(3);
510 }
511
512 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
513
514 if (uuid == null) {
515 query.append(_FINDER_COLUMN_UUID_UUID_1);
516 }
517 else {
518 if (uuid.equals(StringPool.BLANK)) {
519 query.append(_FINDER_COLUMN_UUID_UUID_3);
520 }
521 else {
522 query.append(_FINDER_COLUMN_UUID_UUID_2);
523 }
524 }
525
526 if (orderByComparator != null) {
527 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
528 orderByComparator);
529 }
530
531 else {
532 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
533 }
534
535 String sql = query.toString();
536
537 Query q = session.createQuery(sql);
538
539 QueryPos qPos = QueryPos.getInstance(q);
540
541 if (uuid != null) {
542 qPos.add(uuid);
543 }
544
545 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
546 start, end);
547 }
548 catch (Exception e) {
549 throw processException(e);
550 }
551 finally {
552 if (list == null) {
553 list = new ArrayList<PollsQuestion>();
554 }
555
556 cacheResult(list);
557
558 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
559 finderArgs, list);
560
561 closeSession(session);
562 }
563 }
564
565 return list;
566 }
567
568 public PollsQuestion findByUuid_First(String uuid,
569 OrderByComparator orderByComparator)
570 throws NoSuchQuestionException, SystemException {
571 List<PollsQuestion> list = findByUuid(uuid, 0, 1, orderByComparator);
572
573 if (list.isEmpty()) {
574 StringBundler msg = new StringBundler(4);
575
576 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
577
578 msg.append("uuid=");
579 msg.append(uuid);
580
581 msg.append(StringPool.CLOSE_CURLY_BRACE);
582
583 throw new NoSuchQuestionException(msg.toString());
584 }
585 else {
586 return list.get(0);
587 }
588 }
589
590 public PollsQuestion findByUuid_Last(String uuid,
591 OrderByComparator orderByComparator)
592 throws NoSuchQuestionException, SystemException {
593 int count = countByUuid(uuid);
594
595 List<PollsQuestion> list = findByUuid(uuid, count - 1, count,
596 orderByComparator);
597
598 if (list.isEmpty()) {
599 StringBundler msg = new StringBundler(4);
600
601 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
602
603 msg.append("uuid=");
604 msg.append(uuid);
605
606 msg.append(StringPool.CLOSE_CURLY_BRACE);
607
608 throw new NoSuchQuestionException(msg.toString());
609 }
610 else {
611 return list.get(0);
612 }
613 }
614
615 public PollsQuestion[] findByUuid_PrevAndNext(long questionId, String uuid,
616 OrderByComparator orderByComparator)
617 throws NoSuchQuestionException, SystemException {
618 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
619
620 int count = countByUuid(uuid);
621
622 Session session = null;
623
624 try {
625 session = openSession();
626
627 StringBundler query = null;
628
629 if (orderByComparator != null) {
630 query = new StringBundler(3 +
631 (orderByComparator.getOrderByFields().length * 3));
632 }
633 else {
634 query = new StringBundler(3);
635 }
636
637 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
638
639 if (uuid == null) {
640 query.append(_FINDER_COLUMN_UUID_UUID_1);
641 }
642 else {
643 if (uuid.equals(StringPool.BLANK)) {
644 query.append(_FINDER_COLUMN_UUID_UUID_3);
645 }
646 else {
647 query.append(_FINDER_COLUMN_UUID_UUID_2);
648 }
649 }
650
651 if (orderByComparator != null) {
652 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
653 orderByComparator);
654 }
655
656 else {
657 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
658 }
659
660 String sql = query.toString();
661
662 Query q = session.createQuery(sql);
663
664 QueryPos qPos = QueryPos.getInstance(q);
665
666 if (uuid != null) {
667 qPos.add(uuid);
668 }
669
670 Object[] objArray = QueryUtil.getPrevAndNext(q, count,
671 orderByComparator, pollsQuestion);
672
673 PollsQuestion[] array = new PollsQuestionImpl[3];
674
675 array[0] = (PollsQuestion)objArray[0];
676 array[1] = (PollsQuestion)objArray[1];
677 array[2] = (PollsQuestion)objArray[2];
678
679 return array;
680 }
681 catch (Exception e) {
682 throw processException(e);
683 }
684 finally {
685 closeSession(session);
686 }
687 }
688
689 public PollsQuestion findByUUID_G(String uuid, long groupId)
690 throws NoSuchQuestionException, SystemException {
691 PollsQuestion pollsQuestion = fetchByUUID_G(uuid, groupId);
692
693 if (pollsQuestion == null) {
694 StringBundler msg = new StringBundler(6);
695
696 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
697
698 msg.append("uuid=");
699 msg.append(uuid);
700
701 msg.append(", groupId=");
702 msg.append(groupId);
703
704 msg.append(StringPool.CLOSE_CURLY_BRACE);
705
706 if (_log.isWarnEnabled()) {
707 _log.warn(msg.toString());
708 }
709
710 throw new NoSuchQuestionException(msg.toString());
711 }
712
713 return pollsQuestion;
714 }
715
716 public PollsQuestion fetchByUUID_G(String uuid, long groupId)
717 throws SystemException {
718 return fetchByUUID_G(uuid, groupId, true);
719 }
720
721 public PollsQuestion fetchByUUID_G(String uuid, long groupId,
722 boolean retrieveFromCache) throws SystemException {
723 Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
724
725 Object result = null;
726
727 if (retrieveFromCache) {
728 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
729 finderArgs, this);
730 }
731
732 if (result == null) {
733 Session session = null;
734
735 try {
736 session = openSession();
737
738 StringBundler query = new StringBundler(4);
739
740 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
741
742 if (uuid == null) {
743 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
744 }
745 else {
746 if (uuid.equals(StringPool.BLANK)) {
747 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
748 }
749 else {
750 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
751 }
752 }
753
754 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
755
756 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
757
758 String sql = query.toString();
759
760 Query q = session.createQuery(sql);
761
762 QueryPos qPos = QueryPos.getInstance(q);
763
764 if (uuid != null) {
765 qPos.add(uuid);
766 }
767
768 qPos.add(groupId);
769
770 List<PollsQuestion> list = q.list();
771
772 result = list;
773
774 PollsQuestion pollsQuestion = null;
775
776 if (list.isEmpty()) {
777 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
778 finderArgs, list);
779 }
780 else {
781 pollsQuestion = list.get(0);
782
783 cacheResult(pollsQuestion);
784
785 if ((pollsQuestion.getUuid() == null) ||
786 !pollsQuestion.getUuid().equals(uuid) ||
787 (pollsQuestion.getGroupId() != groupId)) {
788 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
789 finderArgs, pollsQuestion);
790 }
791 }
792
793 return pollsQuestion;
794 }
795 catch (Exception e) {
796 throw processException(e);
797 }
798 finally {
799 if (result == null) {
800 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
801 finderArgs, new ArrayList<PollsQuestion>());
802 }
803
804 closeSession(session);
805 }
806 }
807 else {
808 if (result instanceof List<?>) {
809 return null;
810 }
811 else {
812 return (PollsQuestion)result;
813 }
814 }
815 }
816
817 public List<PollsQuestion> findByGroupId(long groupId)
818 throws SystemException {
819 Object[] finderArgs = new Object[] { new Long(groupId) };
820
821 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
822 finderArgs, this);
823
824 if (list == null) {
825 Session session = null;
826
827 try {
828 session = openSession();
829
830 StringBundler query = new StringBundler(3);
831
832 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
833
834 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
835
836 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
837
838 String sql = query.toString();
839
840 Query q = session.createQuery(sql);
841
842 QueryPos qPos = QueryPos.getInstance(q);
843
844 qPos.add(groupId);
845
846 list = q.list();
847 }
848 catch (Exception e) {
849 throw processException(e);
850 }
851 finally {
852 if (list == null) {
853 list = new ArrayList<PollsQuestion>();
854 }
855
856 cacheResult(list);
857
858 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
859 finderArgs, list);
860
861 closeSession(session);
862 }
863 }
864
865 return list;
866 }
867
868 public List<PollsQuestion> findByGroupId(long groupId, int start, int end)
869 throws SystemException {
870 return findByGroupId(groupId, start, end, null);
871 }
872
873 public List<PollsQuestion> findByGroupId(long groupId, int start, int end,
874 OrderByComparator orderByComparator) throws SystemException {
875 Object[] finderArgs = new Object[] {
876 new Long(groupId),
877
878 String.valueOf(start), String.valueOf(end),
879 String.valueOf(orderByComparator)
880 };
881
882 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
883 finderArgs, this);
884
885 if (list == null) {
886 Session session = null;
887
888 try {
889 session = openSession();
890
891 StringBundler query = null;
892
893 if (orderByComparator != null) {
894 query = new StringBundler(3 +
895 (orderByComparator.getOrderByFields().length * 3));
896 }
897 else {
898 query = new StringBundler(3);
899 }
900
901 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
902
903 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
904
905 if (orderByComparator != null) {
906 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
907 orderByComparator);
908 }
909
910 else {
911 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
912 }
913
914 String sql = query.toString();
915
916 Query q = session.createQuery(sql);
917
918 QueryPos qPos = QueryPos.getInstance(q);
919
920 qPos.add(groupId);
921
922 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
923 start, end);
924 }
925 catch (Exception e) {
926 throw processException(e);
927 }
928 finally {
929 if (list == null) {
930 list = new ArrayList<PollsQuestion>();
931 }
932
933 cacheResult(list);
934
935 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
936 finderArgs, list);
937
938 closeSession(session);
939 }
940 }
941
942 return list;
943 }
944
945 public PollsQuestion findByGroupId_First(long groupId,
946 OrderByComparator orderByComparator)
947 throws NoSuchQuestionException, SystemException {
948 List<PollsQuestion> list = findByGroupId(groupId, 0, 1,
949 orderByComparator);
950
951 if (list.isEmpty()) {
952 StringBundler msg = new StringBundler(4);
953
954 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
955
956 msg.append("groupId=");
957 msg.append(groupId);
958
959 msg.append(StringPool.CLOSE_CURLY_BRACE);
960
961 throw new NoSuchQuestionException(msg.toString());
962 }
963 else {
964 return list.get(0);
965 }
966 }
967
968 public PollsQuestion findByGroupId_Last(long groupId,
969 OrderByComparator orderByComparator)
970 throws NoSuchQuestionException, SystemException {
971 int count = countByGroupId(groupId);
972
973 List<PollsQuestion> list = findByGroupId(groupId, count - 1, count,
974 orderByComparator);
975
976 if (list.isEmpty()) {
977 StringBundler msg = new StringBundler(4);
978
979 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
980
981 msg.append("groupId=");
982 msg.append(groupId);
983
984 msg.append(StringPool.CLOSE_CURLY_BRACE);
985
986 throw new NoSuchQuestionException(msg.toString());
987 }
988 else {
989 return list.get(0);
990 }
991 }
992
993 public PollsQuestion[] findByGroupId_PrevAndNext(long questionId,
994 long groupId, OrderByComparator orderByComparator)
995 throws NoSuchQuestionException, SystemException {
996 PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
997
998 int count = countByGroupId(groupId);
999
1000 Session session = null;
1001
1002 try {
1003 session = openSession();
1004
1005 StringBundler query = null;
1006
1007 if (orderByComparator != null) {
1008 query = new StringBundler(3 +
1009 (orderByComparator.getOrderByFields().length * 3));
1010 }
1011 else {
1012 query = new StringBundler(3);
1013 }
1014
1015 query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1016
1017 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1018
1019 if (orderByComparator != null) {
1020 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1021 orderByComparator);
1022 }
1023
1024 else {
1025 query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1026 }
1027
1028 String sql = query.toString();
1029
1030 Query q = session.createQuery(sql);
1031
1032 QueryPos qPos = QueryPos.getInstance(q);
1033
1034 qPos.add(groupId);
1035
1036 Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1037 orderByComparator, pollsQuestion);
1038
1039 PollsQuestion[] array = new PollsQuestionImpl[3];
1040
1041 array[0] = (PollsQuestion)objArray[0];
1042 array[1] = (PollsQuestion)objArray[1];
1043 array[2] = (PollsQuestion)objArray[2];
1044
1045 return array;
1046 }
1047 catch (Exception e) {
1048 throw processException(e);
1049 }
1050 finally {
1051 closeSession(session);
1052 }
1053 }
1054
1055 public List<PollsQuestion> findAll() throws SystemException {
1056 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1057 }
1058
1059 public List<PollsQuestion> findAll(int start, int end)
1060 throws SystemException {
1061 return findAll(start, end, null);
1062 }
1063
1064 public List<PollsQuestion> findAll(int start, int end,
1065 OrderByComparator orderByComparator) throws SystemException {
1066 Object[] finderArgs = new Object[] {
1067 String.valueOf(start), String.valueOf(end),
1068 String.valueOf(orderByComparator)
1069 };
1070
1071 List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1072 finderArgs, this);
1073
1074 if (list == null) {
1075 Session session = null;
1076
1077 try {
1078 session = openSession();
1079
1080 StringBundler query = null;
1081 String sql = null;
1082
1083 if (orderByComparator != null) {
1084 query = new StringBundler(2 +
1085 (orderByComparator.getOrderByFields().length * 3));
1086
1087 query.append(_SQL_SELECT_POLLSQUESTION);
1088
1089 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1090 orderByComparator);
1091
1092 sql = query.toString();
1093 }
1094
1095 else {
1096 sql = _SQL_SELECT_POLLSQUESTION.concat(PollsQuestionModelImpl.ORDER_BY_JPQL);
1097 }
1098
1099 Query q = session.createQuery(sql);
1100
1101 if (orderByComparator == null) {
1102 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1103 start, end, false);
1104
1105 Collections.sort(list);
1106 }
1107 else {
1108 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1109 start, end);
1110 }
1111 }
1112 catch (Exception e) {
1113 throw processException(e);
1114 }
1115 finally {
1116 if (list == null) {
1117 list = new ArrayList<PollsQuestion>();
1118 }
1119
1120 cacheResult(list);
1121
1122 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1123
1124 closeSession(session);
1125 }
1126 }
1127
1128 return list;
1129 }
1130
1131 public void removeByUuid(String uuid) throws SystemException {
1132 for (PollsQuestion pollsQuestion : findByUuid(uuid)) {
1133 remove(pollsQuestion);
1134 }
1135 }
1136
1137 public void removeByUUID_G(String uuid, long groupId)
1138 throws NoSuchQuestionException, SystemException {
1139 PollsQuestion pollsQuestion = findByUUID_G(uuid, groupId);
1140
1141 remove(pollsQuestion);
1142 }
1143
1144 public void removeByGroupId(long groupId) throws SystemException {
1145 for (PollsQuestion pollsQuestion : findByGroupId(groupId)) {
1146 remove(pollsQuestion);
1147 }
1148 }
1149
1150 public void removeAll() throws SystemException {
1151 for (PollsQuestion pollsQuestion : findAll()) {
1152 remove(pollsQuestion);
1153 }
1154 }
1155
1156 public int countByUuid(String uuid) throws SystemException {
1157 Object[] finderArgs = new Object[] { uuid };
1158
1159 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1160 finderArgs, this);
1161
1162 if (count == null) {
1163 Session session = null;
1164
1165 try {
1166 session = openSession();
1167
1168 StringBundler query = new StringBundler(2);
1169
1170 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
1171
1172 if (uuid == null) {
1173 query.append(_FINDER_COLUMN_UUID_UUID_1);
1174 }
1175 else {
1176 if (uuid.equals(StringPool.BLANK)) {
1177 query.append(_FINDER_COLUMN_UUID_UUID_3);
1178 }
1179 else {
1180 query.append(_FINDER_COLUMN_UUID_UUID_2);
1181 }
1182 }
1183
1184 String sql = query.toString();
1185
1186 Query q = session.createQuery(sql);
1187
1188 QueryPos qPos = QueryPos.getInstance(q);
1189
1190 if (uuid != null) {
1191 qPos.add(uuid);
1192 }
1193
1194 count = (Long)q.uniqueResult();
1195 }
1196 catch (Exception e) {
1197 throw processException(e);
1198 }
1199 finally {
1200 if (count == null) {
1201 count = Long.valueOf(0);
1202 }
1203
1204 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1205 finderArgs, count);
1206
1207 closeSession(session);
1208 }
1209 }
1210
1211 return count.intValue();
1212 }
1213
1214 public int countByUUID_G(String uuid, long groupId)
1215 throws SystemException {
1216 Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1217
1218 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1219 finderArgs, this);
1220
1221 if (count == null) {
1222 Session session = null;
1223
1224 try {
1225 session = openSession();
1226
1227 StringBundler query = new StringBundler(3);
1228
1229 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
1230
1231 if (uuid == null) {
1232 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1233 }
1234 else {
1235 if (uuid.equals(StringPool.BLANK)) {
1236 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1237 }
1238 else {
1239 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1240 }
1241 }
1242
1243 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1244
1245 String sql = query.toString();
1246
1247 Query q = session.createQuery(sql);
1248
1249 QueryPos qPos = QueryPos.getInstance(q);
1250
1251 if (uuid != null) {
1252 qPos.add(uuid);
1253 }
1254
1255 qPos.add(groupId);
1256
1257 count = (Long)q.uniqueResult();
1258 }
1259 catch (Exception e) {
1260 throw processException(e);
1261 }
1262 finally {
1263 if (count == null) {
1264 count = Long.valueOf(0);
1265 }
1266
1267 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1268 finderArgs, count);
1269
1270 closeSession(session);
1271 }
1272 }
1273
1274 return count.intValue();
1275 }
1276
1277 public int countByGroupId(long groupId) throws SystemException {
1278 Object[] finderArgs = new Object[] { new Long(groupId) };
1279
1280 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1281 finderArgs, this);
1282
1283 if (count == null) {
1284 Session session = null;
1285
1286 try {
1287 session = openSession();
1288
1289 StringBundler query = new StringBundler(2);
1290
1291 query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
1292
1293 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1294
1295 String sql = query.toString();
1296
1297 Query q = session.createQuery(sql);
1298
1299 QueryPos qPos = QueryPos.getInstance(q);
1300
1301 qPos.add(groupId);
1302
1303 count = (Long)q.uniqueResult();
1304 }
1305 catch (Exception e) {
1306 throw processException(e);
1307 }
1308 finally {
1309 if (count == null) {
1310 count = Long.valueOf(0);
1311 }
1312
1313 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1314 finderArgs, count);
1315
1316 closeSession(session);
1317 }
1318 }
1319
1320 return count.intValue();
1321 }
1322
1323 public int countAll() throws SystemException {
1324 Object[] finderArgs = new Object[0];
1325
1326 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1327 finderArgs, this);
1328
1329 if (count == null) {
1330 Session session = null;
1331
1332 try {
1333 session = openSession();
1334
1335 Query q = session.createQuery(_SQL_COUNT_POLLSQUESTION);
1336
1337 count = (Long)q.uniqueResult();
1338 }
1339 catch (Exception e) {
1340 throw processException(e);
1341 }
1342 finally {
1343 if (count == null) {
1344 count = Long.valueOf(0);
1345 }
1346
1347 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1348 count);
1349
1350 closeSession(session);
1351 }
1352 }
1353
1354 return count.intValue();
1355 }
1356
1357 public void afterPropertiesSet() {
1358 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1359 com.liferay.portal.util.PropsUtil.get(
1360 "value.object.listener.com.liferay.portlet.polls.model.PollsQuestion")));
1361
1362 if (listenerClassNames.length > 0) {
1363 try {
1364 List<ModelListener<PollsQuestion>> listenersList = new ArrayList<ModelListener<PollsQuestion>>();
1365
1366 for (String listenerClassName : listenerClassNames) {
1367 listenersList.add((ModelListener<PollsQuestion>)Class.forName(
1368 listenerClassName).newInstance());
1369 }
1370
1371 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1372 }
1373 catch (Exception e) {
1374 _log.error(e);
1375 }
1376 }
1377 }
1378
1379 @BeanReference(type = PollsChoicePersistence.class)
1380 protected PollsChoicePersistence pollsChoicePersistence;
1381 @BeanReference(type = PollsQuestionPersistence.class)
1382 protected PollsQuestionPersistence pollsQuestionPersistence;
1383 @BeanReference(type = PollsVotePersistence.class)
1384 protected PollsVotePersistence pollsVotePersistence;
1385 @BeanReference(type = ResourcePersistence.class)
1386 protected ResourcePersistence resourcePersistence;
1387 @BeanReference(type = UserPersistence.class)
1388 protected UserPersistence userPersistence;
1389 private static final String _SQL_SELECT_POLLSQUESTION = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion";
1390 private static final String _SQL_SELECT_POLLSQUESTION_WHERE = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion WHERE ";
1391 private static final String _SQL_COUNT_POLLSQUESTION = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion";
1392 private static final String _SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion WHERE ";
1393 private static final String _FINDER_COLUMN_UUID_UUID_1 = "pollsQuestion.uuid IS NULL";
1394 private static final String _FINDER_COLUMN_UUID_UUID_2 = "pollsQuestion.uuid = ?";
1395 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?)";
1396 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "pollsQuestion.uuid IS NULL AND ";
1397 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "pollsQuestion.uuid = ? AND ";
1398 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?) AND ";
1399 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "pollsQuestion.groupId = ?";
1400 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "pollsQuestion.groupId = ?";
1401 private static final String _ORDER_BY_ENTITY_ALIAS = "pollsQuestion.";
1402 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsQuestion exists with the primary key ";
1403 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsQuestion exists with the key {";
1404 private static Log _log = LogFactoryUtil.getLog(PollsQuestionPersistenceImpl.class);
1405}