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