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