001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.polls.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042    import com.liferay.portal.service.persistence.BatchSessionUtil;
043    import com.liferay.portal.service.persistence.ResourcePersistence;
044    import com.liferay.portal.service.persistence.UserPersistence;
045    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046    
047    import com.liferay.portlet.polls.NoSuchQuestionException;
048    import com.liferay.portlet.polls.model.PollsQuestion;
049    import com.liferay.portlet.polls.model.impl.PollsQuestionImpl;
050    import com.liferay.portlet.polls.model.impl.PollsQuestionModelImpl;
051    
052    import java.io.Serializable;
053    
054    import java.util.ArrayList;
055    import java.util.Collections;
056    import java.util.List;
057    
058    /**
059     * The persistence implementation for the polls question service.
060     *
061     * <p>
062     * Caching information and settings can be found in <code>portal.properties</code>
063     * </p>
064     *
065     * @author Brian Wing Shun Chan
066     * @see PollsQuestionPersistence
067     * @see PollsQuestionUtil
068     * @generated
069     */
070    public class PollsQuestionPersistenceImpl extends BasePersistenceImpl<PollsQuestion>
071            implements PollsQuestionPersistence {
072            /*
073             * NOTE FOR DEVELOPERS:
074             *
075             * Never modify or reference this class directly. Always use {@link PollsQuestionUtil} to access the polls question persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
076             */
077            public static final String FINDER_CLASS_NAME_ENTITY = PollsQuestionImpl.class.getName();
078            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List1";
080            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List2";
082            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
083                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
084                            PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
085                            "findByUuid",
086                            new String[] {
087                                    String.class.getName(),
088                                    
089                            "java.lang.Integer", "java.lang.Integer",
090                                    "com.liferay.portal.kernel.util.OrderByComparator"
091                            });
092            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
093                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
094                            PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
095                            "findByUuid", new String[] { String.class.getName() },
096                            PollsQuestionModelImpl.UUID_COLUMN_BITMASK);
097            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
098                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
100                            new String[] { String.class.getName() });
101            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
102                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
103                            PollsQuestionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
104                            new String[] { String.class.getName(), Long.class.getName() },
105                            PollsQuestionModelImpl.UUID_COLUMN_BITMASK |
106                            PollsQuestionModelImpl.GROUPID_COLUMN_BITMASK);
107            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
108                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
110                            new String[] { String.class.getName(), Long.class.getName() });
111            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
112                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
113                            PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
114                            "findByGroupId",
115                            new String[] {
116                                    Long.class.getName(),
117                                    
118                            "java.lang.Integer", "java.lang.Integer",
119                                    "com.liferay.portal.kernel.util.OrderByComparator"
120                            });
121            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
122                    new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
123                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
124                            PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
125                            "findByGroupId", new String[] { Long.class.getName() },
126                            PollsQuestionModelImpl.GROUPID_COLUMN_BITMASK);
127            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
128                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
129                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
130                            new String[] { Long.class.getName() });
131            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
132                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
133                            PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
134                            "findAll", new String[0]);
135            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
136                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
137                            PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
138                            "findAll", new String[0]);
139            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
140                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
141                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
142    
143            /**
144             * Caches the polls question in the entity cache if it is enabled.
145             *
146             * @param pollsQuestion the polls question
147             */
148            public void cacheResult(PollsQuestion pollsQuestion) {
149                    EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
150                            PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
151                            pollsQuestion);
152    
153                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
154                            new Object[] {
155                                    pollsQuestion.getUuid(),
156                                    Long.valueOf(pollsQuestion.getGroupId())
157                            }, pollsQuestion);
158    
159                    pollsQuestion.resetOriginalValues();
160            }
161    
162            /**
163             * Caches the polls questions in the entity cache if it is enabled.
164             *
165             * @param pollsQuestions the polls questions
166             */
167            public void cacheResult(List<PollsQuestion> pollsQuestions) {
168                    for (PollsQuestion pollsQuestion : pollsQuestions) {
169                            if (EntityCacheUtil.getResult(
170                                                    PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
171                                                    PollsQuestionImpl.class, pollsQuestion.getPrimaryKey()) == null) {
172                                    cacheResult(pollsQuestion);
173                            }
174                            else {
175                                    pollsQuestion.resetOriginalValues();
176                            }
177                    }
178            }
179    
180            /**
181             * Clears the cache for all polls questions.
182             *
183             * <p>
184             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
185             * </p>
186             */
187            @Override
188            public void clearCache() {
189                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
190                            CacheRegistryUtil.clear(PollsQuestionImpl.class.getName());
191                    }
192    
193                    EntityCacheUtil.clearCache(PollsQuestionImpl.class.getName());
194    
195                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
196                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
197                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
198            }
199    
200            /**
201             * Clears the cache for the polls question.
202             *
203             * <p>
204             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
205             * </p>
206             */
207            @Override
208            public void clearCache(PollsQuestion pollsQuestion) {
209                    EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
210                            PollsQuestionImpl.class, pollsQuestion.getPrimaryKey());
211    
212                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
213                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
214    
215                    clearUniqueFindersCache(pollsQuestion);
216            }
217    
218            @Override
219            public void clearCache(List<PollsQuestion> pollsQuestions) {
220                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
221                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
222    
223                    for (PollsQuestion pollsQuestion : pollsQuestions) {
224                            EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
225                                    PollsQuestionImpl.class, pollsQuestion.getPrimaryKey());
226    
227                            clearUniqueFindersCache(pollsQuestion);
228                    }
229            }
230    
231            protected void clearUniqueFindersCache(PollsQuestion pollsQuestion) {
232                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
233                            new Object[] {
234                                    pollsQuestion.getUuid(),
235                                    Long.valueOf(pollsQuestion.getGroupId())
236                            });
237            }
238    
239            /**
240             * Creates a new polls question with the primary key. Does not add the polls question to the database.
241             *
242             * @param questionId the primary key for the new polls question
243             * @return the new polls question
244             */
245            public PollsQuestion create(long questionId) {
246                    PollsQuestion pollsQuestion = new PollsQuestionImpl();
247    
248                    pollsQuestion.setNew(true);
249                    pollsQuestion.setPrimaryKey(questionId);
250    
251                    String uuid = PortalUUIDUtil.generate();
252    
253                    pollsQuestion.setUuid(uuid);
254    
255                    return pollsQuestion;
256            }
257    
258            /**
259             * Removes the polls question with the primary key from the database. Also notifies the appropriate model listeners.
260             *
261             * @param questionId the primary key of the polls question
262             * @return the polls question that was removed
263             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a polls question with the primary key could not be found
264             * @throws SystemException if a system exception occurred
265             */
266            public PollsQuestion remove(long questionId)
267                    throws NoSuchQuestionException, SystemException {
268                    return remove(Long.valueOf(questionId));
269            }
270    
271            /**
272             * Removes the polls question with the primary key from the database. Also notifies the appropriate model listeners.
273             *
274             * @param primaryKey the primary key of the polls question
275             * @return the polls question that was removed
276             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a polls question with the primary key could not be found
277             * @throws SystemException if a system exception occurred
278             */
279            @Override
280            public PollsQuestion remove(Serializable primaryKey)
281                    throws NoSuchQuestionException, SystemException {
282                    Session session = null;
283    
284                    try {
285                            session = openSession();
286    
287                            PollsQuestion pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
288                                            primaryKey);
289    
290                            if (pollsQuestion == null) {
291                                    if (_log.isWarnEnabled()) {
292                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
293                                    }
294    
295                                    throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
296                                            primaryKey);
297                            }
298    
299                            return remove(pollsQuestion);
300                    }
301                    catch (NoSuchQuestionException nsee) {
302                            throw nsee;
303                    }
304                    catch (Exception e) {
305                            throw processException(e);
306                    }
307                    finally {
308                            closeSession(session);
309                    }
310            }
311    
312            @Override
313            protected PollsQuestion removeImpl(PollsQuestion pollsQuestion)
314                    throws SystemException {
315                    pollsQuestion = toUnwrappedModel(pollsQuestion);
316    
317                    Session session = null;
318    
319                    try {
320                            session = openSession();
321    
322                            BatchSessionUtil.delete(session, pollsQuestion);
323                    }
324                    catch (Exception e) {
325                            throw processException(e);
326                    }
327                    finally {
328                            closeSession(session);
329                    }
330    
331                    clearCache(pollsQuestion);
332    
333                    return pollsQuestion;
334            }
335    
336            @Override
337            public PollsQuestion updateImpl(
338                    com.liferay.portlet.polls.model.PollsQuestion pollsQuestion,
339                    boolean merge) throws SystemException {
340                    pollsQuestion = toUnwrappedModel(pollsQuestion);
341    
342                    boolean isNew = pollsQuestion.isNew();
343    
344                    PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
345    
346                    if (Validator.isNull(pollsQuestion.getUuid())) {
347                            String uuid = PortalUUIDUtil.generate();
348    
349                            pollsQuestion.setUuid(uuid);
350                    }
351    
352                    Session session = null;
353    
354                    try {
355                            session = openSession();
356    
357                            BatchSessionUtil.update(session, pollsQuestion, merge);
358    
359                            pollsQuestion.setNew(false);
360                    }
361                    catch (Exception e) {
362                            throw processException(e);
363                    }
364                    finally {
365                            closeSession(session);
366                    }
367    
368                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
369    
370                    if (isNew || !PollsQuestionModelImpl.COLUMN_BITMASK_ENABLED) {
371                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
372                    }
373                    else {
374                            if ((pollsQuestionModelImpl.getColumnBitmask() &
375                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
376                                    Object[] args = new Object[] {
377                                                    pollsQuestionModelImpl.getOriginalUuid()
378                                            };
379    
380                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
381                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
382                                            args);
383    
384                                    args = new Object[] { pollsQuestionModelImpl.getUuid() };
385    
386                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
387                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
388                                            args);
389                            }
390    
391                            if ((pollsQuestionModelImpl.getColumnBitmask() &
392                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
393                                    Object[] args = new Object[] {
394                                                    Long.valueOf(pollsQuestionModelImpl.getOriginalGroupId())
395                                            };
396    
397                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
398                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
399                                            args);
400    
401                                    args = new Object[] {
402                                                    Long.valueOf(pollsQuestionModelImpl.getGroupId())
403                                            };
404    
405                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
406                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
407                                            args);
408                            }
409                    }
410    
411                    EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
412                            PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
413                            pollsQuestion);
414    
415                    if (isNew) {
416                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
417                                    new Object[] {
418                                            pollsQuestion.getUuid(),
419                                            Long.valueOf(pollsQuestion.getGroupId())
420                                    }, pollsQuestion);
421                    }
422                    else {
423                            if ((pollsQuestionModelImpl.getColumnBitmask() &
424                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
425                                    Object[] args = new Object[] {
426                                                    pollsQuestionModelImpl.getOriginalUuid(),
427                                                    Long.valueOf(pollsQuestionModelImpl.getOriginalGroupId())
428                                            };
429    
430                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
431                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
432    
433                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
434                                            new Object[] {
435                                                    pollsQuestion.getUuid(),
436                                                    Long.valueOf(pollsQuestion.getGroupId())
437                                            }, pollsQuestion);
438                            }
439                    }
440    
441                    return pollsQuestion;
442            }
443    
444            protected PollsQuestion toUnwrappedModel(PollsQuestion pollsQuestion) {
445                    if (pollsQuestion instanceof PollsQuestionImpl) {
446                            return pollsQuestion;
447                    }
448    
449                    PollsQuestionImpl pollsQuestionImpl = new PollsQuestionImpl();
450    
451                    pollsQuestionImpl.setNew(pollsQuestion.isNew());
452                    pollsQuestionImpl.setPrimaryKey(pollsQuestion.getPrimaryKey());
453    
454                    pollsQuestionImpl.setUuid(pollsQuestion.getUuid());
455                    pollsQuestionImpl.setQuestionId(pollsQuestion.getQuestionId());
456                    pollsQuestionImpl.setGroupId(pollsQuestion.getGroupId());
457                    pollsQuestionImpl.setCompanyId(pollsQuestion.getCompanyId());
458                    pollsQuestionImpl.setUserId(pollsQuestion.getUserId());
459                    pollsQuestionImpl.setUserName(pollsQuestion.getUserName());
460                    pollsQuestionImpl.setCreateDate(pollsQuestion.getCreateDate());
461                    pollsQuestionImpl.setModifiedDate(pollsQuestion.getModifiedDate());
462                    pollsQuestionImpl.setTitle(pollsQuestion.getTitle());
463                    pollsQuestionImpl.setDescription(pollsQuestion.getDescription());
464                    pollsQuestionImpl.setExpirationDate(pollsQuestion.getExpirationDate());
465                    pollsQuestionImpl.setLastVoteDate(pollsQuestion.getLastVoteDate());
466    
467                    return pollsQuestionImpl;
468            }
469    
470            /**
471             * Returns the polls question with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
472             *
473             * @param primaryKey the primary key of the polls question
474             * @return the polls question
475             * @throws com.liferay.portal.NoSuchModelException if a polls question with the primary key could not be found
476             * @throws SystemException if a system exception occurred
477             */
478            @Override
479            public PollsQuestion findByPrimaryKey(Serializable primaryKey)
480                    throws NoSuchModelException, SystemException {
481                    return findByPrimaryKey(((Long)primaryKey).longValue());
482            }
483    
484            /**
485             * Returns the polls question with the primary key or throws a {@link com.liferay.portlet.polls.NoSuchQuestionException} if it could not be found.
486             *
487             * @param questionId the primary key of the polls question
488             * @return the polls question
489             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a polls question with the primary key could not be found
490             * @throws SystemException if a system exception occurred
491             */
492            public PollsQuestion findByPrimaryKey(long questionId)
493                    throws NoSuchQuestionException, SystemException {
494                    PollsQuestion pollsQuestion = fetchByPrimaryKey(questionId);
495    
496                    if (pollsQuestion == null) {
497                            if (_log.isWarnEnabled()) {
498                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + questionId);
499                            }
500    
501                            throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
502                                    questionId);
503                    }
504    
505                    return pollsQuestion;
506            }
507    
508            /**
509             * Returns the polls question with the primary key or returns <code>null</code> if it could not be found.
510             *
511             * @param primaryKey the primary key of the polls question
512             * @return the polls question, or <code>null</code> if a polls question with the primary key could not be found
513             * @throws SystemException if a system exception occurred
514             */
515            @Override
516            public PollsQuestion fetchByPrimaryKey(Serializable primaryKey)
517                    throws SystemException {
518                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
519            }
520    
521            /**
522             * Returns the polls question with the primary key or returns <code>null</code> if it could not be found.
523             *
524             * @param questionId the primary key of the polls question
525             * @return the polls question, or <code>null</code> if a polls question with the primary key could not be found
526             * @throws SystemException if a system exception occurred
527             */
528            public PollsQuestion fetchByPrimaryKey(long questionId)
529                    throws SystemException {
530                    PollsQuestion pollsQuestion = (PollsQuestion)EntityCacheUtil.getResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
531                                    PollsQuestionImpl.class, questionId);
532    
533                    if (pollsQuestion == _nullPollsQuestion) {
534                            return null;
535                    }
536    
537                    if (pollsQuestion == null) {
538                            Session session = null;
539    
540                            boolean hasException = false;
541    
542                            try {
543                                    session = openSession();
544    
545                                    pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
546                                                    Long.valueOf(questionId));
547                            }
548                            catch (Exception e) {
549                                    hasException = true;
550    
551                                    throw processException(e);
552                            }
553                            finally {
554                                    if (pollsQuestion != null) {
555                                            cacheResult(pollsQuestion);
556                                    }
557                                    else if (!hasException) {
558                                            EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
559                                                    PollsQuestionImpl.class, questionId, _nullPollsQuestion);
560                                    }
561    
562                                    closeSession(session);
563                            }
564                    }
565    
566                    return pollsQuestion;
567            }
568    
569            /**
570             * Returns all the polls questions where uuid = &#63;.
571             *
572             * @param uuid the uuid
573             * @return the matching polls questions
574             * @throws SystemException if a system exception occurred
575             */
576            public List<PollsQuestion> findByUuid(String uuid)
577                    throws SystemException {
578                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
579            }
580    
581            /**
582             * Returns a range of all the polls questions where uuid = &#63;.
583             *
584             * <p>
585             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
586             * </p>
587             *
588             * @param uuid the uuid
589             * @param start the lower bound of the range of polls questions
590             * @param end the upper bound of the range of polls questions (not inclusive)
591             * @return the range of matching polls questions
592             * @throws SystemException if a system exception occurred
593             */
594            public List<PollsQuestion> findByUuid(String uuid, int start, int end)
595                    throws SystemException {
596                    return findByUuid(uuid, start, end, null);
597            }
598    
599            /**
600             * Returns an ordered range of all the polls questions where uuid = &#63;.
601             *
602             * <p>
603             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
604             * </p>
605             *
606             * @param uuid the uuid
607             * @param start the lower bound of the range of polls questions
608             * @param end the upper bound of the range of polls questions (not inclusive)
609             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
610             * @return the ordered range of matching polls questions
611             * @throws SystemException if a system exception occurred
612             */
613            public List<PollsQuestion> findByUuid(String uuid, int start, int end,
614                    OrderByComparator orderByComparator) throws SystemException {
615                    FinderPath finderPath = null;
616                    Object[] finderArgs = null;
617    
618                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
619                                    (orderByComparator == null)) {
620                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
621                            finderArgs = new Object[] { uuid };
622                    }
623                    else {
624                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
625                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
626                    }
627    
628                    List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
629                                    finderArgs, this);
630    
631                    if ((list != null) && !list.isEmpty()) {
632                            for (PollsQuestion pollsQuestion : list) {
633                                    if (!Validator.equals(uuid, pollsQuestion.getUuid())) {
634                                            list = null;
635    
636                                            break;
637                                    }
638                            }
639                    }
640    
641                    if (list == null) {
642                            StringBundler query = null;
643    
644                            if (orderByComparator != null) {
645                                    query = new StringBundler(3 +
646                                                    (orderByComparator.getOrderByFields().length * 3));
647                            }
648                            else {
649                                    query = new StringBundler(3);
650                            }
651    
652                            query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
653    
654                            if (uuid == null) {
655                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
656                            }
657                            else {
658                                    if (uuid.equals(StringPool.BLANK)) {
659                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
660                                    }
661                                    else {
662                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
663                                    }
664                            }
665    
666                            if (orderByComparator != null) {
667                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
668                                            orderByComparator);
669                            }
670    
671                            else {
672                                    query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
673                            }
674    
675                            String sql = query.toString();
676    
677                            Session session = null;
678    
679                            try {
680                                    session = openSession();
681    
682                                    Query q = session.createQuery(sql);
683    
684                                    QueryPos qPos = QueryPos.getInstance(q);
685    
686                                    if (uuid != null) {
687                                            qPos.add(uuid);
688                                    }
689    
690                                    list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
691                                                    start, end);
692                            }
693                            catch (Exception e) {
694                                    throw processException(e);
695                            }
696                            finally {
697                                    if (list == null) {
698                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
699                                    }
700                                    else {
701                                            cacheResult(list);
702    
703                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
704                                    }
705    
706                                    closeSession(session);
707                            }
708                    }
709    
710                    return list;
711            }
712    
713            /**
714             * Returns the first polls question in the ordered set where uuid = &#63;.
715             *
716             * <p>
717             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
718             * </p>
719             *
720             * @param uuid the uuid
721             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
722             * @return the first matching polls question
723             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a matching polls question could not be found
724             * @throws SystemException if a system exception occurred
725             */
726            public PollsQuestion findByUuid_First(String uuid,
727                    OrderByComparator orderByComparator)
728                    throws NoSuchQuestionException, SystemException {
729                    List<PollsQuestion> list = findByUuid(uuid, 0, 1, orderByComparator);
730    
731                    if (list.isEmpty()) {
732                            StringBundler msg = new StringBundler(4);
733    
734                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
735    
736                            msg.append("uuid=");
737                            msg.append(uuid);
738    
739                            msg.append(StringPool.CLOSE_CURLY_BRACE);
740    
741                            throw new NoSuchQuestionException(msg.toString());
742                    }
743                    else {
744                            return list.get(0);
745                    }
746            }
747    
748            /**
749             * Returns the last polls question in the ordered set where uuid = &#63;.
750             *
751             * <p>
752             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
753             * </p>
754             *
755             * @param uuid the uuid
756             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
757             * @return the last matching polls question
758             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a matching polls question could not be found
759             * @throws SystemException if a system exception occurred
760             */
761            public PollsQuestion findByUuid_Last(String uuid,
762                    OrderByComparator orderByComparator)
763                    throws NoSuchQuestionException, SystemException {
764                    int count = countByUuid(uuid);
765    
766                    List<PollsQuestion> list = findByUuid(uuid, count - 1, count,
767                                    orderByComparator);
768    
769                    if (list.isEmpty()) {
770                            StringBundler msg = new StringBundler(4);
771    
772                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
773    
774                            msg.append("uuid=");
775                            msg.append(uuid);
776    
777                            msg.append(StringPool.CLOSE_CURLY_BRACE);
778    
779                            throw new NoSuchQuestionException(msg.toString());
780                    }
781                    else {
782                            return list.get(0);
783                    }
784            }
785    
786            /**
787             * Returns the polls questions before and after the current polls question in the ordered set where uuid = &#63;.
788             *
789             * <p>
790             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
791             * </p>
792             *
793             * @param questionId the primary key of the current polls question
794             * @param uuid the uuid
795             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
796             * @return the previous, current, and next polls question
797             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a polls question with the primary key could not be found
798             * @throws SystemException if a system exception occurred
799             */
800            public PollsQuestion[] findByUuid_PrevAndNext(long questionId, String uuid,
801                    OrderByComparator orderByComparator)
802                    throws NoSuchQuestionException, SystemException {
803                    PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
804    
805                    Session session = null;
806    
807                    try {
808                            session = openSession();
809    
810                            PollsQuestion[] array = new PollsQuestionImpl[3];
811    
812                            array[0] = getByUuid_PrevAndNext(session, pollsQuestion, uuid,
813                                            orderByComparator, true);
814    
815                            array[1] = pollsQuestion;
816    
817                            array[2] = getByUuid_PrevAndNext(session, pollsQuestion, uuid,
818                                            orderByComparator, false);
819    
820                            return array;
821                    }
822                    catch (Exception e) {
823                            throw processException(e);
824                    }
825                    finally {
826                            closeSession(session);
827                    }
828            }
829    
830            protected PollsQuestion getByUuid_PrevAndNext(Session session,
831                    PollsQuestion pollsQuestion, String uuid,
832                    OrderByComparator orderByComparator, boolean previous) {
833                    StringBundler query = null;
834    
835                    if (orderByComparator != null) {
836                            query = new StringBundler(6 +
837                                            (orderByComparator.getOrderByFields().length * 6));
838                    }
839                    else {
840                            query = new StringBundler(3);
841                    }
842    
843                    query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
844    
845                    if (uuid == null) {
846                            query.append(_FINDER_COLUMN_UUID_UUID_1);
847                    }
848                    else {
849                            if (uuid.equals(StringPool.BLANK)) {
850                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
851                            }
852                            else {
853                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
854                            }
855                    }
856    
857                    if (orderByComparator != null) {
858                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
859    
860                            if (orderByConditionFields.length > 0) {
861                                    query.append(WHERE_AND);
862                            }
863    
864                            for (int i = 0; i < orderByConditionFields.length; i++) {
865                                    query.append(_ORDER_BY_ENTITY_ALIAS);
866                                    query.append(orderByConditionFields[i]);
867    
868                                    if ((i + 1) < orderByConditionFields.length) {
869                                            if (orderByComparator.isAscending() ^ previous) {
870                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
871                                            }
872                                            else {
873                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
874                                            }
875                                    }
876                                    else {
877                                            if (orderByComparator.isAscending() ^ previous) {
878                                                    query.append(WHERE_GREATER_THAN);
879                                            }
880                                            else {
881                                                    query.append(WHERE_LESSER_THAN);
882                                            }
883                                    }
884                            }
885    
886                            query.append(ORDER_BY_CLAUSE);
887    
888                            String[] orderByFields = orderByComparator.getOrderByFields();
889    
890                            for (int i = 0; i < orderByFields.length; i++) {
891                                    query.append(_ORDER_BY_ENTITY_ALIAS);
892                                    query.append(orderByFields[i]);
893    
894                                    if ((i + 1) < orderByFields.length) {
895                                            if (orderByComparator.isAscending() ^ previous) {
896                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
897                                            }
898                                            else {
899                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
900                                            }
901                                    }
902                                    else {
903                                            if (orderByComparator.isAscending() ^ previous) {
904                                                    query.append(ORDER_BY_ASC);
905                                            }
906                                            else {
907                                                    query.append(ORDER_BY_DESC);
908                                            }
909                                    }
910                            }
911                    }
912    
913                    else {
914                            query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
915                    }
916    
917                    String sql = query.toString();
918    
919                    Query q = session.createQuery(sql);
920    
921                    q.setFirstResult(0);
922                    q.setMaxResults(2);
923    
924                    QueryPos qPos = QueryPos.getInstance(q);
925    
926                    if (uuid != null) {
927                            qPos.add(uuid);
928                    }
929    
930                    if (orderByComparator != null) {
931                            Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
932    
933                            for (Object value : values) {
934                                    qPos.add(value);
935                            }
936                    }
937    
938                    List<PollsQuestion> list = q.list();
939    
940                    if (list.size() == 2) {
941                            return list.get(1);
942                    }
943                    else {
944                            return null;
945                    }
946            }
947    
948            /**
949             * Returns the polls question where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.polls.NoSuchQuestionException} if it could not be found.
950             *
951             * @param uuid the uuid
952             * @param groupId the group ID
953             * @return the matching polls question
954             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a matching polls question could not be found
955             * @throws SystemException if a system exception occurred
956             */
957            public PollsQuestion findByUUID_G(String uuid, long groupId)
958                    throws NoSuchQuestionException, SystemException {
959                    PollsQuestion pollsQuestion = fetchByUUID_G(uuid, groupId);
960    
961                    if (pollsQuestion == null) {
962                            StringBundler msg = new StringBundler(6);
963    
964                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
965    
966                            msg.append("uuid=");
967                            msg.append(uuid);
968    
969                            msg.append(", groupId=");
970                            msg.append(groupId);
971    
972                            msg.append(StringPool.CLOSE_CURLY_BRACE);
973    
974                            if (_log.isWarnEnabled()) {
975                                    _log.warn(msg.toString());
976                            }
977    
978                            throw new NoSuchQuestionException(msg.toString());
979                    }
980    
981                    return pollsQuestion;
982            }
983    
984            /**
985             * Returns the polls question where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
986             *
987             * @param uuid the uuid
988             * @param groupId the group ID
989             * @return the matching polls question, or <code>null</code> if a matching polls question could not be found
990             * @throws SystemException if a system exception occurred
991             */
992            public PollsQuestion fetchByUUID_G(String uuid, long groupId)
993                    throws SystemException {
994                    return fetchByUUID_G(uuid, groupId, true);
995            }
996    
997            /**
998             * Returns the polls question where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
999             *
1000             * @param uuid the uuid
1001             * @param groupId the group ID
1002             * @param retrieveFromCache whether to use the finder cache
1003             * @return the matching polls question, or <code>null</code> if a matching polls question could not be found
1004             * @throws SystemException if a system exception occurred
1005             */
1006            public PollsQuestion fetchByUUID_G(String uuid, long groupId,
1007                    boolean retrieveFromCache) throws SystemException {
1008                    Object[] finderArgs = new Object[] { uuid, groupId };
1009    
1010                    Object result = null;
1011    
1012                    if (retrieveFromCache) {
1013                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1014                                            finderArgs, this);
1015                    }
1016    
1017                    if (result instanceof PollsQuestion) {
1018                            PollsQuestion pollsQuestion = (PollsQuestion)result;
1019    
1020                            if (!Validator.equals(uuid, pollsQuestion.getUuid()) ||
1021                                            (groupId != pollsQuestion.getGroupId())) {
1022                                    result = null;
1023                            }
1024                    }
1025    
1026                    if (result == null) {
1027                            StringBundler query = new StringBundler(4);
1028    
1029                            query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1030    
1031                            if (uuid == null) {
1032                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1033                            }
1034                            else {
1035                                    if (uuid.equals(StringPool.BLANK)) {
1036                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1037                                    }
1038                                    else {
1039                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1040                                    }
1041                            }
1042    
1043                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1044    
1045                            query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1046    
1047                            String sql = query.toString();
1048    
1049                            Session session = null;
1050    
1051                            try {
1052                                    session = openSession();
1053    
1054                                    Query q = session.createQuery(sql);
1055    
1056                                    QueryPos qPos = QueryPos.getInstance(q);
1057    
1058                                    if (uuid != null) {
1059                                            qPos.add(uuid);
1060                                    }
1061    
1062                                    qPos.add(groupId);
1063    
1064                                    List<PollsQuestion> list = q.list();
1065    
1066                                    result = list;
1067    
1068                                    PollsQuestion pollsQuestion = null;
1069    
1070                                    if (list.isEmpty()) {
1071                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1072                                                    finderArgs, list);
1073                                    }
1074                                    else {
1075                                            pollsQuestion = list.get(0);
1076    
1077                                            cacheResult(pollsQuestion);
1078    
1079                                            if ((pollsQuestion.getUuid() == null) ||
1080                                                            !pollsQuestion.getUuid().equals(uuid) ||
1081                                                            (pollsQuestion.getGroupId() != groupId)) {
1082                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1083                                                            finderArgs, pollsQuestion);
1084                                            }
1085                                    }
1086    
1087                                    return pollsQuestion;
1088                            }
1089                            catch (Exception e) {
1090                                    throw processException(e);
1091                            }
1092                            finally {
1093                                    if (result == null) {
1094                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1095                                                    finderArgs);
1096                                    }
1097    
1098                                    closeSession(session);
1099                            }
1100                    }
1101                    else {
1102                            if (result instanceof List<?>) {
1103                                    return null;
1104                            }
1105                            else {
1106                                    return (PollsQuestion)result;
1107                            }
1108                    }
1109            }
1110    
1111            /**
1112             * Returns all the polls questions where groupId = &#63;.
1113             *
1114             * @param groupId the group ID
1115             * @return the matching polls questions
1116             * @throws SystemException if a system exception occurred
1117             */
1118            public List<PollsQuestion> findByGroupId(long groupId)
1119                    throws SystemException {
1120                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1121            }
1122    
1123            /**
1124             * Returns a range of all the polls questions where groupId = &#63;.
1125             *
1126             * <p>
1127             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1128             * </p>
1129             *
1130             * @param groupId the group ID
1131             * @param start the lower bound of the range of polls questions
1132             * @param end the upper bound of the range of polls questions (not inclusive)
1133             * @return the range of matching polls questions
1134             * @throws SystemException if a system exception occurred
1135             */
1136            public List<PollsQuestion> findByGroupId(long groupId, int start, int end)
1137                    throws SystemException {
1138                    return findByGroupId(groupId, start, end, null);
1139            }
1140    
1141            /**
1142             * Returns an ordered range of all the polls questions where groupId = &#63;.
1143             *
1144             * <p>
1145             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1146             * </p>
1147             *
1148             * @param groupId the group ID
1149             * @param start the lower bound of the range of polls questions
1150             * @param end the upper bound of the range of polls questions (not inclusive)
1151             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1152             * @return the ordered range of matching polls questions
1153             * @throws SystemException if a system exception occurred
1154             */
1155            public List<PollsQuestion> findByGroupId(long groupId, int start, int end,
1156                    OrderByComparator orderByComparator) throws SystemException {
1157                    FinderPath finderPath = null;
1158                    Object[] finderArgs = null;
1159    
1160                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1161                                    (orderByComparator == null)) {
1162                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1163                            finderArgs = new Object[] { groupId };
1164                    }
1165                    else {
1166                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1167                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1168                    }
1169    
1170                    List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
1171                                    finderArgs, this);
1172    
1173                    if ((list != null) && !list.isEmpty()) {
1174                            for (PollsQuestion pollsQuestion : list) {
1175                                    if ((groupId != pollsQuestion.getGroupId())) {
1176                                            list = null;
1177    
1178                                            break;
1179                                    }
1180                            }
1181                    }
1182    
1183                    if (list == null) {
1184                            StringBundler query = null;
1185    
1186                            if (orderByComparator != null) {
1187                                    query = new StringBundler(3 +
1188                                                    (orderByComparator.getOrderByFields().length * 3));
1189                            }
1190                            else {
1191                                    query = new StringBundler(3);
1192                            }
1193    
1194                            query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1195    
1196                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1197    
1198                            if (orderByComparator != null) {
1199                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1200                                            orderByComparator);
1201                            }
1202    
1203                            else {
1204                                    query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1205                            }
1206    
1207                            String sql = query.toString();
1208    
1209                            Session session = null;
1210    
1211                            try {
1212                                    session = openSession();
1213    
1214                                    Query q = session.createQuery(sql);
1215    
1216                                    QueryPos qPos = QueryPos.getInstance(q);
1217    
1218                                    qPos.add(groupId);
1219    
1220                                    list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1221                                                    start, end);
1222                            }
1223                            catch (Exception e) {
1224                                    throw processException(e);
1225                            }
1226                            finally {
1227                                    if (list == null) {
1228                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1229                                    }
1230                                    else {
1231                                            cacheResult(list);
1232    
1233                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1234                                    }
1235    
1236                                    closeSession(session);
1237                            }
1238                    }
1239    
1240                    return list;
1241            }
1242    
1243            /**
1244             * Returns the first polls question in the ordered set where groupId = &#63;.
1245             *
1246             * <p>
1247             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1248             * </p>
1249             *
1250             * @param groupId the group ID
1251             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1252             * @return the first matching polls question
1253             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a matching polls question could not be found
1254             * @throws SystemException if a system exception occurred
1255             */
1256            public PollsQuestion findByGroupId_First(long groupId,
1257                    OrderByComparator orderByComparator)
1258                    throws NoSuchQuestionException, SystemException {
1259                    List<PollsQuestion> list = findByGroupId(groupId, 0, 1,
1260                                    orderByComparator);
1261    
1262                    if (list.isEmpty()) {
1263                            StringBundler msg = new StringBundler(4);
1264    
1265                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1266    
1267                            msg.append("groupId=");
1268                            msg.append(groupId);
1269    
1270                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1271    
1272                            throw new NoSuchQuestionException(msg.toString());
1273                    }
1274                    else {
1275                            return list.get(0);
1276                    }
1277            }
1278    
1279            /**
1280             * Returns the last polls question in the ordered set where groupId = &#63;.
1281             *
1282             * <p>
1283             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1284             * </p>
1285             *
1286             * @param groupId the group ID
1287             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1288             * @return the last matching polls question
1289             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a matching polls question could not be found
1290             * @throws SystemException if a system exception occurred
1291             */
1292            public PollsQuestion findByGroupId_Last(long groupId,
1293                    OrderByComparator orderByComparator)
1294                    throws NoSuchQuestionException, SystemException {
1295                    int count = countByGroupId(groupId);
1296    
1297                    List<PollsQuestion> list = findByGroupId(groupId, count - 1, count,
1298                                    orderByComparator);
1299    
1300                    if (list.isEmpty()) {
1301                            StringBundler msg = new StringBundler(4);
1302    
1303                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1304    
1305                            msg.append("groupId=");
1306                            msg.append(groupId);
1307    
1308                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1309    
1310                            throw new NoSuchQuestionException(msg.toString());
1311                    }
1312                    else {
1313                            return list.get(0);
1314                    }
1315            }
1316    
1317            /**
1318             * Returns the polls questions before and after the current polls question in the ordered set where groupId = &#63;.
1319             *
1320             * <p>
1321             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1322             * </p>
1323             *
1324             * @param questionId the primary key of the current polls question
1325             * @param groupId the group ID
1326             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1327             * @return the previous, current, and next polls question
1328             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a polls question with the primary key could not be found
1329             * @throws SystemException if a system exception occurred
1330             */
1331            public PollsQuestion[] findByGroupId_PrevAndNext(long questionId,
1332                    long groupId, OrderByComparator orderByComparator)
1333                    throws NoSuchQuestionException, SystemException {
1334                    PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
1335    
1336                    Session session = null;
1337    
1338                    try {
1339                            session = openSession();
1340    
1341                            PollsQuestion[] array = new PollsQuestionImpl[3];
1342    
1343                            array[0] = getByGroupId_PrevAndNext(session, pollsQuestion,
1344                                            groupId, orderByComparator, true);
1345    
1346                            array[1] = pollsQuestion;
1347    
1348                            array[2] = getByGroupId_PrevAndNext(session, pollsQuestion,
1349                                            groupId, orderByComparator, false);
1350    
1351                            return array;
1352                    }
1353                    catch (Exception e) {
1354                            throw processException(e);
1355                    }
1356                    finally {
1357                            closeSession(session);
1358                    }
1359            }
1360    
1361            protected PollsQuestion getByGroupId_PrevAndNext(Session session,
1362                    PollsQuestion pollsQuestion, long groupId,
1363                    OrderByComparator orderByComparator, boolean previous) {
1364                    StringBundler query = null;
1365    
1366                    if (orderByComparator != null) {
1367                            query = new StringBundler(6 +
1368                                            (orderByComparator.getOrderByFields().length * 6));
1369                    }
1370                    else {
1371                            query = new StringBundler(3);
1372                    }
1373    
1374                    query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1375    
1376                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1377    
1378                    if (orderByComparator != null) {
1379                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1380    
1381                            if (orderByConditionFields.length > 0) {
1382                                    query.append(WHERE_AND);
1383                            }
1384    
1385                            for (int i = 0; i < orderByConditionFields.length; i++) {
1386                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1387                                    query.append(orderByConditionFields[i]);
1388    
1389                                    if ((i + 1) < orderByConditionFields.length) {
1390                                            if (orderByComparator.isAscending() ^ previous) {
1391                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1392                                            }
1393                                            else {
1394                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1395                                            }
1396                                    }
1397                                    else {
1398                                            if (orderByComparator.isAscending() ^ previous) {
1399                                                    query.append(WHERE_GREATER_THAN);
1400                                            }
1401                                            else {
1402                                                    query.append(WHERE_LESSER_THAN);
1403                                            }
1404                                    }
1405                            }
1406    
1407                            query.append(ORDER_BY_CLAUSE);
1408    
1409                            String[] orderByFields = orderByComparator.getOrderByFields();
1410    
1411                            for (int i = 0; i < orderByFields.length; i++) {
1412                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1413                                    query.append(orderByFields[i]);
1414    
1415                                    if ((i + 1) < orderByFields.length) {
1416                                            if (orderByComparator.isAscending() ^ previous) {
1417                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1418                                            }
1419                                            else {
1420                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1421                                            }
1422                                    }
1423                                    else {
1424                                            if (orderByComparator.isAscending() ^ previous) {
1425                                                    query.append(ORDER_BY_ASC);
1426                                            }
1427                                            else {
1428                                                    query.append(ORDER_BY_DESC);
1429                                            }
1430                                    }
1431                            }
1432                    }
1433    
1434                    else {
1435                            query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1436                    }
1437    
1438                    String sql = query.toString();
1439    
1440                    Query q = session.createQuery(sql);
1441    
1442                    q.setFirstResult(0);
1443                    q.setMaxResults(2);
1444    
1445                    QueryPos qPos = QueryPos.getInstance(q);
1446    
1447                    qPos.add(groupId);
1448    
1449                    if (orderByComparator != null) {
1450                            Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
1451    
1452                            for (Object value : values) {
1453                                    qPos.add(value);
1454                            }
1455                    }
1456    
1457                    List<PollsQuestion> list = q.list();
1458    
1459                    if (list.size() == 2) {
1460                            return list.get(1);
1461                    }
1462                    else {
1463                            return null;
1464                    }
1465            }
1466    
1467            /**
1468             * Returns all the polls questions that the user has permission to view where groupId = &#63;.
1469             *
1470             * @param groupId the group ID
1471             * @return the matching polls questions that the user has permission to view
1472             * @throws SystemException if a system exception occurred
1473             */
1474            public List<PollsQuestion> filterFindByGroupId(long groupId)
1475                    throws SystemException {
1476                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1477                            QueryUtil.ALL_POS, null);
1478            }
1479    
1480            /**
1481             * Returns a range of all the polls questions that the user has permission to view where groupId = &#63;.
1482             *
1483             * <p>
1484             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1485             * </p>
1486             *
1487             * @param groupId the group ID
1488             * @param start the lower bound of the range of polls questions
1489             * @param end the upper bound of the range of polls questions (not inclusive)
1490             * @return the range of matching polls questions that the user has permission to view
1491             * @throws SystemException if a system exception occurred
1492             */
1493            public List<PollsQuestion> filterFindByGroupId(long groupId, int start,
1494                    int end) throws SystemException {
1495                    return filterFindByGroupId(groupId, start, end, null);
1496            }
1497    
1498            /**
1499             * Returns an ordered range of all the polls questions that the user has permissions to view where groupId = &#63;.
1500             *
1501             * <p>
1502             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1503             * </p>
1504             *
1505             * @param groupId the group ID
1506             * @param start the lower bound of the range of polls questions
1507             * @param end the upper bound of the range of polls questions (not inclusive)
1508             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1509             * @return the ordered range of matching polls questions that the user has permission to view
1510             * @throws SystemException if a system exception occurred
1511             */
1512            public List<PollsQuestion> filterFindByGroupId(long groupId, int start,
1513                    int end, OrderByComparator orderByComparator) throws SystemException {
1514                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1515                            return findByGroupId(groupId, start, end, orderByComparator);
1516                    }
1517    
1518                    StringBundler query = null;
1519    
1520                    if (orderByComparator != null) {
1521                            query = new StringBundler(3 +
1522                                            (orderByComparator.getOrderByFields().length * 3));
1523                    }
1524                    else {
1525                            query = new StringBundler(3);
1526                    }
1527    
1528                    if (getDB().isSupportsInlineDistinct()) {
1529                            query.append(_FILTER_SQL_SELECT_POLLSQUESTION_WHERE);
1530                    }
1531                    else {
1532                            query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1);
1533                    }
1534    
1535                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1536    
1537                    if (!getDB().isSupportsInlineDistinct()) {
1538                            query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2);
1539                    }
1540    
1541                    if (orderByComparator != null) {
1542                            if (getDB().isSupportsInlineDistinct()) {
1543                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1544                                            orderByComparator);
1545                            }
1546                            else {
1547                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1548                                            orderByComparator);
1549                            }
1550                    }
1551    
1552                    else {
1553                            if (getDB().isSupportsInlineDistinct()) {
1554                                    query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1555                            }
1556                            else {
1557                                    query.append(PollsQuestionModelImpl.ORDER_BY_SQL);
1558                            }
1559                    }
1560    
1561                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1562                                    PollsQuestion.class.getName(),
1563                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1564    
1565                    Session session = null;
1566    
1567                    try {
1568                            session = openSession();
1569    
1570                            SQLQuery q = session.createSQLQuery(sql);
1571    
1572                            if (getDB().isSupportsInlineDistinct()) {
1573                                    q.addEntity(_FILTER_ENTITY_ALIAS, PollsQuestionImpl.class);
1574                            }
1575                            else {
1576                                    q.addEntity(_FILTER_ENTITY_TABLE, PollsQuestionImpl.class);
1577                            }
1578    
1579                            QueryPos qPos = QueryPos.getInstance(q);
1580    
1581                            qPos.add(groupId);
1582    
1583                            return (List<PollsQuestion>)QueryUtil.list(q, getDialect(), start,
1584                                    end);
1585                    }
1586                    catch (Exception e) {
1587                            throw processException(e);
1588                    }
1589                    finally {
1590                            closeSession(session);
1591                    }
1592            }
1593    
1594            /**
1595             * Returns the polls questions before and after the current polls question in the ordered set of polls questions that the user has permission to view where groupId = &#63;.
1596             *
1597             * @param questionId the primary key of the current polls question
1598             * @param groupId the group ID
1599             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1600             * @return the previous, current, and next polls question
1601             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a polls question with the primary key could not be found
1602             * @throws SystemException if a system exception occurred
1603             */
1604            public PollsQuestion[] filterFindByGroupId_PrevAndNext(long questionId,
1605                    long groupId, OrderByComparator orderByComparator)
1606                    throws NoSuchQuestionException, SystemException {
1607                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1608                            return findByGroupId_PrevAndNext(questionId, groupId,
1609                                    orderByComparator);
1610                    }
1611    
1612                    PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
1613    
1614                    Session session = null;
1615    
1616                    try {
1617                            session = openSession();
1618    
1619                            PollsQuestion[] array = new PollsQuestionImpl[3];
1620    
1621                            array[0] = filterGetByGroupId_PrevAndNext(session, pollsQuestion,
1622                                            groupId, orderByComparator, true);
1623    
1624                            array[1] = pollsQuestion;
1625    
1626                            array[2] = filterGetByGroupId_PrevAndNext(session, pollsQuestion,
1627                                            groupId, orderByComparator, false);
1628    
1629                            return array;
1630                    }
1631                    catch (Exception e) {
1632                            throw processException(e);
1633                    }
1634                    finally {
1635                            closeSession(session);
1636                    }
1637            }
1638    
1639            protected PollsQuestion filterGetByGroupId_PrevAndNext(Session session,
1640                    PollsQuestion pollsQuestion, long groupId,
1641                    OrderByComparator orderByComparator, boolean previous) {
1642                    StringBundler query = null;
1643    
1644                    if (orderByComparator != null) {
1645                            query = new StringBundler(6 +
1646                                            (orderByComparator.getOrderByFields().length * 6));
1647                    }
1648                    else {
1649                            query = new StringBundler(3);
1650                    }
1651    
1652                    if (getDB().isSupportsInlineDistinct()) {
1653                            query.append(_FILTER_SQL_SELECT_POLLSQUESTION_WHERE);
1654                    }
1655                    else {
1656                            query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1);
1657                    }
1658    
1659                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1660    
1661                    if (!getDB().isSupportsInlineDistinct()) {
1662                            query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2);
1663                    }
1664    
1665                    if (orderByComparator != null) {
1666                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1667    
1668                            if (orderByConditionFields.length > 0) {
1669                                    query.append(WHERE_AND);
1670                            }
1671    
1672                            for (int i = 0; i < orderByConditionFields.length; i++) {
1673                                    if (getDB().isSupportsInlineDistinct()) {
1674                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1675                                    }
1676                                    else {
1677                                            query.append(_ORDER_BY_ENTITY_TABLE);
1678                                    }
1679    
1680                                    query.append(orderByConditionFields[i]);
1681    
1682                                    if ((i + 1) < orderByConditionFields.length) {
1683                                            if (orderByComparator.isAscending() ^ previous) {
1684                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1685                                            }
1686                                            else {
1687                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1688                                            }
1689                                    }
1690                                    else {
1691                                            if (orderByComparator.isAscending() ^ previous) {
1692                                                    query.append(WHERE_GREATER_THAN);
1693                                            }
1694                                            else {
1695                                                    query.append(WHERE_LESSER_THAN);
1696                                            }
1697                                    }
1698                            }
1699    
1700                            query.append(ORDER_BY_CLAUSE);
1701    
1702                            String[] orderByFields = orderByComparator.getOrderByFields();
1703    
1704                            for (int i = 0; i < orderByFields.length; i++) {
1705                                    if (getDB().isSupportsInlineDistinct()) {
1706                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1707                                    }
1708                                    else {
1709                                            query.append(_ORDER_BY_ENTITY_TABLE);
1710                                    }
1711    
1712                                    query.append(orderByFields[i]);
1713    
1714                                    if ((i + 1) < orderByFields.length) {
1715                                            if (orderByComparator.isAscending() ^ previous) {
1716                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1717                                            }
1718                                            else {
1719                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1720                                            }
1721                                    }
1722                                    else {
1723                                            if (orderByComparator.isAscending() ^ previous) {
1724                                                    query.append(ORDER_BY_ASC);
1725                                            }
1726                                            else {
1727                                                    query.append(ORDER_BY_DESC);
1728                                            }
1729                                    }
1730                            }
1731                    }
1732    
1733                    else {
1734                            if (getDB().isSupportsInlineDistinct()) {
1735                                    query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1736                            }
1737                            else {
1738                                    query.append(PollsQuestionModelImpl.ORDER_BY_SQL);
1739                            }
1740                    }
1741    
1742                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1743                                    PollsQuestion.class.getName(),
1744                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1745    
1746                    SQLQuery q = session.createSQLQuery(sql);
1747    
1748                    q.setFirstResult(0);
1749                    q.setMaxResults(2);
1750    
1751                    if (getDB().isSupportsInlineDistinct()) {
1752                            q.addEntity(_FILTER_ENTITY_ALIAS, PollsQuestionImpl.class);
1753                    }
1754                    else {
1755                            q.addEntity(_FILTER_ENTITY_TABLE, PollsQuestionImpl.class);
1756                    }
1757    
1758                    QueryPos qPos = QueryPos.getInstance(q);
1759    
1760                    qPos.add(groupId);
1761    
1762                    if (orderByComparator != null) {
1763                            Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
1764    
1765                            for (Object value : values) {
1766                                    qPos.add(value);
1767                            }
1768                    }
1769    
1770                    List<PollsQuestion> list = q.list();
1771    
1772                    if (list.size() == 2) {
1773                            return list.get(1);
1774                    }
1775                    else {
1776                            return null;
1777                    }
1778            }
1779    
1780            /**
1781             * Returns all the polls questions.
1782             *
1783             * @return the polls questions
1784             * @throws SystemException if a system exception occurred
1785             */
1786            public List<PollsQuestion> findAll() throws SystemException {
1787                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1788            }
1789    
1790            /**
1791             * Returns a range of all the polls questions.
1792             *
1793             * <p>
1794             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1795             * </p>
1796             *
1797             * @param start the lower bound of the range of polls questions
1798             * @param end the upper bound of the range of polls questions (not inclusive)
1799             * @return the range of polls questions
1800             * @throws SystemException if a system exception occurred
1801             */
1802            public List<PollsQuestion> findAll(int start, int end)
1803                    throws SystemException {
1804                    return findAll(start, end, null);
1805            }
1806    
1807            /**
1808             * Returns an ordered range of all the polls questions.
1809             *
1810             * <p>
1811             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1812             * </p>
1813             *
1814             * @param start the lower bound of the range of polls questions
1815             * @param end the upper bound of the range of polls questions (not inclusive)
1816             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1817             * @return the ordered range of polls questions
1818             * @throws SystemException if a system exception occurred
1819             */
1820            public List<PollsQuestion> findAll(int start, int end,
1821                    OrderByComparator orderByComparator) throws SystemException {
1822                    FinderPath finderPath = null;
1823                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1824    
1825                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1826                                    (orderByComparator == null)) {
1827                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1828                            finderArgs = FINDER_ARGS_EMPTY;
1829                    }
1830                    else {
1831                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1832                            finderArgs = new Object[] { start, end, orderByComparator };
1833                    }
1834    
1835                    List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
1836                                    finderArgs, this);
1837    
1838                    if (list == null) {
1839                            StringBundler query = null;
1840                            String sql = null;
1841    
1842                            if (orderByComparator != null) {
1843                                    query = new StringBundler(2 +
1844                                                    (orderByComparator.getOrderByFields().length * 3));
1845    
1846                                    query.append(_SQL_SELECT_POLLSQUESTION);
1847    
1848                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1849                                            orderByComparator);
1850    
1851                                    sql = query.toString();
1852                            }
1853                            else {
1854                                    sql = _SQL_SELECT_POLLSQUESTION.concat(PollsQuestionModelImpl.ORDER_BY_JPQL);
1855                            }
1856    
1857                            Session session = null;
1858    
1859                            try {
1860                                    session = openSession();
1861    
1862                                    Query q = session.createQuery(sql);
1863    
1864                                    if (orderByComparator == null) {
1865                                            list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1866                                                            start, end, false);
1867    
1868                                            Collections.sort(list);
1869                                    }
1870                                    else {
1871                                            list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1872                                                            start, end);
1873                                    }
1874                            }
1875                            catch (Exception e) {
1876                                    throw processException(e);
1877                            }
1878                            finally {
1879                                    if (list == null) {
1880                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1881                                    }
1882                                    else {
1883                                            cacheResult(list);
1884    
1885                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1886                                    }
1887    
1888                                    closeSession(session);
1889                            }
1890                    }
1891    
1892                    return list;
1893            }
1894    
1895            /**
1896             * Removes all the polls questions where uuid = &#63; from the database.
1897             *
1898             * @param uuid the uuid
1899             * @throws SystemException if a system exception occurred
1900             */
1901            public void removeByUuid(String uuid) throws SystemException {
1902                    for (PollsQuestion pollsQuestion : findByUuid(uuid)) {
1903                            remove(pollsQuestion);
1904                    }
1905            }
1906    
1907            /**
1908             * Removes the polls question where uuid = &#63; and groupId = &#63; from the database.
1909             *
1910             * @param uuid the uuid
1911             * @param groupId the group ID
1912             * @throws SystemException if a system exception occurred
1913             */
1914            public void removeByUUID_G(String uuid, long groupId)
1915                    throws NoSuchQuestionException, SystemException {
1916                    PollsQuestion pollsQuestion = findByUUID_G(uuid, groupId);
1917    
1918                    remove(pollsQuestion);
1919            }
1920    
1921            /**
1922             * Removes all the polls questions where groupId = &#63; from the database.
1923             *
1924             * @param groupId the group ID
1925             * @throws SystemException if a system exception occurred
1926             */
1927            public void removeByGroupId(long groupId) throws SystemException {
1928                    for (PollsQuestion pollsQuestion : findByGroupId(groupId)) {
1929                            remove(pollsQuestion);
1930                    }
1931            }
1932    
1933            /**
1934             * Removes all the polls questions from the database.
1935             *
1936             * @throws SystemException if a system exception occurred
1937             */
1938            public void removeAll() throws SystemException {
1939                    for (PollsQuestion pollsQuestion : findAll()) {
1940                            remove(pollsQuestion);
1941                    }
1942            }
1943    
1944            /**
1945             * Returns the number of polls questions where uuid = &#63;.
1946             *
1947             * @param uuid the uuid
1948             * @return the number of matching polls questions
1949             * @throws SystemException if a system exception occurred
1950             */
1951            public int countByUuid(String uuid) throws SystemException {
1952                    Object[] finderArgs = new Object[] { uuid };
1953    
1954                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1955                                    finderArgs, this);
1956    
1957                    if (count == null) {
1958                            StringBundler query = new StringBundler(2);
1959    
1960                            query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
1961    
1962                            if (uuid == null) {
1963                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1964                            }
1965                            else {
1966                                    if (uuid.equals(StringPool.BLANK)) {
1967                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1968                                    }
1969                                    else {
1970                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1971                                    }
1972                            }
1973    
1974                            String sql = query.toString();
1975    
1976                            Session session = null;
1977    
1978                            try {
1979                                    session = openSession();
1980    
1981                                    Query q = session.createQuery(sql);
1982    
1983                                    QueryPos qPos = QueryPos.getInstance(q);
1984    
1985                                    if (uuid != null) {
1986                                            qPos.add(uuid);
1987                                    }
1988    
1989                                    count = (Long)q.uniqueResult();
1990                            }
1991                            catch (Exception e) {
1992                                    throw processException(e);
1993                            }
1994                            finally {
1995                                    if (count == null) {
1996                                            count = Long.valueOf(0);
1997                                    }
1998    
1999                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2000                                            finderArgs, count);
2001    
2002                                    closeSession(session);
2003                            }
2004                    }
2005    
2006                    return count.intValue();
2007            }
2008    
2009            /**
2010             * Returns the number of polls questions where uuid = &#63; and groupId = &#63;.
2011             *
2012             * @param uuid the uuid
2013             * @param groupId the group ID
2014             * @return the number of matching polls questions
2015             * @throws SystemException if a system exception occurred
2016             */
2017            public int countByUUID_G(String uuid, long groupId)
2018                    throws SystemException {
2019                    Object[] finderArgs = new Object[] { uuid, groupId };
2020    
2021                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2022                                    finderArgs, this);
2023    
2024                    if (count == null) {
2025                            StringBundler query = new StringBundler(3);
2026    
2027                            query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
2028    
2029                            if (uuid == null) {
2030                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2031                            }
2032                            else {
2033                                    if (uuid.equals(StringPool.BLANK)) {
2034                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2035                                    }
2036                                    else {
2037                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2038                                    }
2039                            }
2040    
2041                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2042    
2043                            String sql = query.toString();
2044    
2045                            Session session = null;
2046    
2047                            try {
2048                                    session = openSession();
2049    
2050                                    Query q = session.createQuery(sql);
2051    
2052                                    QueryPos qPos = QueryPos.getInstance(q);
2053    
2054                                    if (uuid != null) {
2055                                            qPos.add(uuid);
2056                                    }
2057    
2058                                    qPos.add(groupId);
2059    
2060                                    count = (Long)q.uniqueResult();
2061                            }
2062                            catch (Exception e) {
2063                                    throw processException(e);
2064                            }
2065                            finally {
2066                                    if (count == null) {
2067                                            count = Long.valueOf(0);
2068                                    }
2069    
2070                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2071                                            finderArgs, count);
2072    
2073                                    closeSession(session);
2074                            }
2075                    }
2076    
2077                    return count.intValue();
2078            }
2079    
2080            /**
2081             * Returns the number of polls questions where groupId = &#63;.
2082             *
2083             * @param groupId the group ID
2084             * @return the number of matching polls questions
2085             * @throws SystemException if a system exception occurred
2086             */
2087            public int countByGroupId(long groupId) throws SystemException {
2088                    Object[] finderArgs = new Object[] { groupId };
2089    
2090                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2091                                    finderArgs, this);
2092    
2093                    if (count == null) {
2094                            StringBundler query = new StringBundler(2);
2095    
2096                            query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
2097    
2098                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2099    
2100                            String sql = query.toString();
2101    
2102                            Session session = null;
2103    
2104                            try {
2105                                    session = openSession();
2106    
2107                                    Query q = session.createQuery(sql);
2108    
2109                                    QueryPos qPos = QueryPos.getInstance(q);
2110    
2111                                    qPos.add(groupId);
2112    
2113                                    count = (Long)q.uniqueResult();
2114                            }
2115                            catch (Exception e) {
2116                                    throw processException(e);
2117                            }
2118                            finally {
2119                                    if (count == null) {
2120                                            count = Long.valueOf(0);
2121                                    }
2122    
2123                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2124                                            finderArgs, count);
2125    
2126                                    closeSession(session);
2127                            }
2128                    }
2129    
2130                    return count.intValue();
2131            }
2132    
2133            /**
2134             * Returns the number of polls questions that the user has permission to view where groupId = &#63;.
2135             *
2136             * @param groupId the group ID
2137             * @return the number of matching polls questions that the user has permission to view
2138             * @throws SystemException if a system exception occurred
2139             */
2140            public int filterCountByGroupId(long groupId) throws SystemException {
2141                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2142                            return countByGroupId(groupId);
2143                    }
2144    
2145                    StringBundler query = new StringBundler(2);
2146    
2147                    query.append(_FILTER_SQL_COUNT_POLLSQUESTION_WHERE);
2148    
2149                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2150    
2151                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2152                                    PollsQuestion.class.getName(),
2153                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2154    
2155                    Session session = null;
2156    
2157                    try {
2158                            session = openSession();
2159    
2160                            SQLQuery q = session.createSQLQuery(sql);
2161    
2162                            q.addScalar(COUNT_COLUMN_NAME,
2163                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2164    
2165                            QueryPos qPos = QueryPos.getInstance(q);
2166    
2167                            qPos.add(groupId);
2168    
2169                            Long count = (Long)q.uniqueResult();
2170    
2171                            return count.intValue();
2172                    }
2173                    catch (Exception e) {
2174                            throw processException(e);
2175                    }
2176                    finally {
2177                            closeSession(session);
2178                    }
2179            }
2180    
2181            /**
2182             * Returns the number of polls questions.
2183             *
2184             * @return the number of polls questions
2185             * @throws SystemException if a system exception occurred
2186             */
2187            public int countAll() throws SystemException {
2188                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2189                                    FINDER_ARGS_EMPTY, this);
2190    
2191                    if (count == null) {
2192                            Session session = null;
2193    
2194                            try {
2195                                    session = openSession();
2196    
2197                                    Query q = session.createQuery(_SQL_COUNT_POLLSQUESTION);
2198    
2199                                    count = (Long)q.uniqueResult();
2200                            }
2201                            catch (Exception e) {
2202                                    throw processException(e);
2203                            }
2204                            finally {
2205                                    if (count == null) {
2206                                            count = Long.valueOf(0);
2207                                    }
2208    
2209                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2210                                            FINDER_ARGS_EMPTY, count);
2211    
2212                                    closeSession(session);
2213                            }
2214                    }
2215    
2216                    return count.intValue();
2217            }
2218    
2219            /**
2220             * Initializes the polls question persistence.
2221             */
2222            public void afterPropertiesSet() {
2223                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2224                                            com.liferay.portal.util.PropsUtil.get(
2225                                                    "value.object.listener.com.liferay.portlet.polls.model.PollsQuestion")));
2226    
2227                    if (listenerClassNames.length > 0) {
2228                            try {
2229                                    List<ModelListener<PollsQuestion>> listenersList = new ArrayList<ModelListener<PollsQuestion>>();
2230    
2231                                    for (String listenerClassName : listenerClassNames) {
2232                                            listenersList.add((ModelListener<PollsQuestion>)InstanceFactory.newInstance(
2233                                                            listenerClassName));
2234                                    }
2235    
2236                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2237                            }
2238                            catch (Exception e) {
2239                                    _log.error(e);
2240                            }
2241                    }
2242            }
2243    
2244            public void destroy() {
2245                    EntityCacheUtil.removeCache(PollsQuestionImpl.class.getName());
2246                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2247                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2248            }
2249    
2250            @BeanReference(type = PollsChoicePersistence.class)
2251            protected PollsChoicePersistence pollsChoicePersistence;
2252            @BeanReference(type = PollsQuestionPersistence.class)
2253            protected PollsQuestionPersistence pollsQuestionPersistence;
2254            @BeanReference(type = PollsVotePersistence.class)
2255            protected PollsVotePersistence pollsVotePersistence;
2256            @BeanReference(type = ResourcePersistence.class)
2257            protected ResourcePersistence resourcePersistence;
2258            @BeanReference(type = UserPersistence.class)
2259            protected UserPersistence userPersistence;
2260            private static final String _SQL_SELECT_POLLSQUESTION = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion";
2261            private static final String _SQL_SELECT_POLLSQUESTION_WHERE = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion WHERE ";
2262            private static final String _SQL_COUNT_POLLSQUESTION = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion";
2263            private static final String _SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion WHERE ";
2264            private static final String _FINDER_COLUMN_UUID_UUID_1 = "pollsQuestion.uuid IS NULL";
2265            private static final String _FINDER_COLUMN_UUID_UUID_2 = "pollsQuestion.uuid = ?";
2266            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?)";
2267            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "pollsQuestion.uuid IS NULL AND ";
2268            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "pollsQuestion.uuid = ? AND ";
2269            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?) AND ";
2270            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "pollsQuestion.groupId = ?";
2271            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "pollsQuestion.groupId = ?";
2272            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "pollsQuestion.questionId";
2273            private static final String _FILTER_SQL_SELECT_POLLSQUESTION_WHERE = "SELECT DISTINCT {pollsQuestion.*} FROM PollsQuestion pollsQuestion WHERE ";
2274            private static final String _FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1 =
2275                    "SELECT {PollsQuestion.*} FROM (SELECT DISTINCT pollsQuestion.questionId FROM PollsQuestion pollsQuestion WHERE ";
2276            private static final String _FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2 =
2277                    ") TEMP_TABLE INNER JOIN PollsQuestion ON TEMP_TABLE.questionId = PollsQuestion.questionId";
2278            private static final String _FILTER_SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(DISTINCT pollsQuestion.questionId) AS COUNT_VALUE FROM PollsQuestion pollsQuestion WHERE ";
2279            private static final String _FILTER_ENTITY_ALIAS = "pollsQuestion";
2280            private static final String _FILTER_ENTITY_TABLE = "PollsQuestion";
2281            private static final String _ORDER_BY_ENTITY_ALIAS = "pollsQuestion.";
2282            private static final String _ORDER_BY_ENTITY_TABLE = "PollsQuestion.";
2283            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsQuestion exists with the primary key ";
2284            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsQuestion exists with the key {";
2285            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2286            private static Log _log = LogFactoryUtil.getLog(PollsQuestionPersistenceImpl.class);
2287            private static PollsQuestion _nullPollsQuestion = new PollsQuestionImpl() {
2288                            @Override
2289                            public Object clone() {
2290                                    return this;
2291                            }
2292    
2293                            @Override
2294                            public CacheModel<PollsQuestion> toCacheModel() {
2295                                    return _nullPollsQuestionCacheModel;
2296                            }
2297                    };
2298    
2299            private static CacheModel<PollsQuestion> _nullPollsQuestionCacheModel = new CacheModel<PollsQuestion>() {
2300                            public PollsQuestion toEntityModel() {
2301                                    return _nullPollsQuestion;
2302                            }
2303                    };
2304    }