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