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