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