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