001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.polls.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042    import com.liferay.portal.service.persistence.UserPersistence;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.polls.NoSuchQuestionException;
046    import com.liferay.portlet.polls.model.PollsQuestion;
047    import com.liferay.portlet.polls.model.impl.PollsQuestionImpl;
048    import com.liferay.portlet.polls.model.impl.PollsQuestionModelImpl;
049    
050    import java.io.Serializable;
051    
052    import java.util.ArrayList;
053    import java.util.Collections;
054    import java.util.List;
055    
056    /**
057     * The persistence implementation for the polls question service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see PollsQuestionPersistence
065     * @see PollsQuestionUtil
066     * @generated
067     */
068    public class PollsQuestionPersistenceImpl extends BasePersistenceImpl<PollsQuestion>
069            implements PollsQuestionPersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * 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.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = PollsQuestionImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
081                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
082                            PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
083                            "findByUuid",
084                            new String[] {
085                                    String.class.getName(),
086                                    
087                            "java.lang.Integer", "java.lang.Integer",
088                                    "com.liferay.portal.kernel.util.OrderByComparator"
089                            });
090            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
091                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
092                            PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
093                            "findByUuid", new String[] { String.class.getName() },
094                            PollsQuestionModelImpl.UUID_COLUMN_BITMASK);
095            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
096                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
098                            new String[] { String.class.getName() });
099            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
100                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
101                            PollsQuestionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
102                            new String[] { String.class.getName(), Long.class.getName() },
103                            PollsQuestionModelImpl.UUID_COLUMN_BITMASK |
104                            PollsQuestionModelImpl.GROUPID_COLUMN_BITMASK);
105            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
106                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
108                            new String[] { String.class.getName(), Long.class.getName() });
109            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
110                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
111                            PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
112                            "findByUuid_C",
113                            new String[] {
114                                    String.class.getName(), Long.class.getName(),
115                                    
116                            "java.lang.Integer", "java.lang.Integer",
117                                    "com.liferay.portal.kernel.util.OrderByComparator"
118                            });
119            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
120                    new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
121                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
122                            PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
123                            "findByUuid_C",
124                            new String[] { String.class.getName(), Long.class.getName() },
125                            PollsQuestionModelImpl.UUID_COLUMN_BITMASK |
126                            PollsQuestionModelImpl.COMPANYID_COLUMN_BITMASK);
127            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
128                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
129                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
130                            new String[] { String.class.getName(), Long.class.getName() });
131            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
132                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
133                            PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
134                            "findByGroupId",
135                            new String[] {
136                                    Long.class.getName(),
137                                    
138                            "java.lang.Integer", "java.lang.Integer",
139                                    "com.liferay.portal.kernel.util.OrderByComparator"
140                            });
141            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
142                    new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
143                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
144                            PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
145                            "findByGroupId", new String[] { Long.class.getName() },
146                            PollsQuestionModelImpl.GROUPID_COLUMN_BITMASK);
147            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
148                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
149                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
150                            new String[] { Long.class.getName() });
151            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
152                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
153                            PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
154                            "findAll", new String[0]);
155            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
156                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
157                            PollsQuestionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
158                            "findAll", new String[0]);
159            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
160                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED, Long.class,
161                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
162    
163            /**
164             * Caches the polls question in the entity cache if it is enabled.
165             *
166             * @param pollsQuestion the polls question
167             */
168            public void cacheResult(PollsQuestion pollsQuestion) {
169                    EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
170                            PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
171                            pollsQuestion);
172    
173                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
174                            new Object[] {
175                                    pollsQuestion.getUuid(),
176                                    Long.valueOf(pollsQuestion.getGroupId())
177                            }, pollsQuestion);
178    
179                    pollsQuestion.resetOriginalValues();
180            }
181    
182            /**
183             * Caches the polls questions in the entity cache if it is enabled.
184             *
185             * @param pollsQuestions the polls questions
186             */
187            public void cacheResult(List<PollsQuestion> pollsQuestions) {
188                    for (PollsQuestion pollsQuestion : pollsQuestions) {
189                            if (EntityCacheUtil.getResult(
190                                                    PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
191                                                    PollsQuestionImpl.class, pollsQuestion.getPrimaryKey()) == null) {
192                                    cacheResult(pollsQuestion);
193                            }
194                            else {
195                                    pollsQuestion.resetOriginalValues();
196                            }
197                    }
198            }
199    
200            /**
201             * Clears the cache for all polls questions.
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() {
209                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
210                            CacheRegistryUtil.clear(PollsQuestionImpl.class.getName());
211                    }
212    
213                    EntityCacheUtil.clearCache(PollsQuestionImpl.class.getName());
214    
215                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
216                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
217                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
218            }
219    
220            /**
221             * Clears the cache for the polls question.
222             *
223             * <p>
224             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
225             * </p>
226             */
227            @Override
228            public void clearCache(PollsQuestion pollsQuestion) {
229                    EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
230                            PollsQuestionImpl.class, pollsQuestion.getPrimaryKey());
231    
232                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
233                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
234    
235                    clearUniqueFindersCache(pollsQuestion);
236            }
237    
238            @Override
239            public void clearCache(List<PollsQuestion> pollsQuestions) {
240                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
241                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
242    
243                    for (PollsQuestion pollsQuestion : pollsQuestions) {
244                            EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
245                                    PollsQuestionImpl.class, pollsQuestion.getPrimaryKey());
246    
247                            clearUniqueFindersCache(pollsQuestion);
248                    }
249            }
250    
251            protected void clearUniqueFindersCache(PollsQuestion pollsQuestion) {
252                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
253                            new Object[] {
254                                    pollsQuestion.getUuid(),
255                                    Long.valueOf(pollsQuestion.getGroupId())
256                            });
257            }
258    
259            /**
260             * Creates a new polls question with the primary key. Does not add the polls question to the database.
261             *
262             * @param questionId the primary key for the new polls question
263             * @return the new polls question
264             */
265            public PollsQuestion create(long questionId) {
266                    PollsQuestion pollsQuestion = new PollsQuestionImpl();
267    
268                    pollsQuestion.setNew(true);
269                    pollsQuestion.setPrimaryKey(questionId);
270    
271                    String uuid = PortalUUIDUtil.generate();
272    
273                    pollsQuestion.setUuid(uuid);
274    
275                    return pollsQuestion;
276            }
277    
278            /**
279             * Removes the polls question with the primary key from the database. Also notifies the appropriate model listeners.
280             *
281             * @param questionId the primary key of the polls question
282             * @return the polls question that was removed
283             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a polls question with the primary key could not be found
284             * @throws SystemException if a system exception occurred
285             */
286            public PollsQuestion remove(long questionId)
287                    throws NoSuchQuestionException, SystemException {
288                    return remove(Long.valueOf(questionId));
289            }
290    
291            /**
292             * Removes the polls question with the primary key from the database. Also notifies the appropriate model listeners.
293             *
294             * @param primaryKey the primary key of the polls question
295             * @return the polls question that was removed
296             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a polls question with the primary key could not be found
297             * @throws SystemException if a system exception occurred
298             */
299            @Override
300            public PollsQuestion remove(Serializable primaryKey)
301                    throws NoSuchQuestionException, SystemException {
302                    Session session = null;
303    
304                    try {
305                            session = openSession();
306    
307                            PollsQuestion pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
308                                            primaryKey);
309    
310                            if (pollsQuestion == null) {
311                                    if (_log.isWarnEnabled()) {
312                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
313                                    }
314    
315                                    throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
316                                            primaryKey);
317                            }
318    
319                            return remove(pollsQuestion);
320                    }
321                    catch (NoSuchQuestionException nsee) {
322                            throw nsee;
323                    }
324                    catch (Exception e) {
325                            throw processException(e);
326                    }
327                    finally {
328                            closeSession(session);
329                    }
330            }
331    
332            @Override
333            protected PollsQuestion removeImpl(PollsQuestion pollsQuestion)
334                    throws SystemException {
335                    pollsQuestion = toUnwrappedModel(pollsQuestion);
336    
337                    Session session = null;
338    
339                    try {
340                            session = openSession();
341    
342                            if (pollsQuestion.isCachedModel()) {
343                                    pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
344                                                    pollsQuestion.getPrimaryKeyObj());
345                            }
346    
347                            session.delete(pollsQuestion);
348                    }
349                    catch (Exception e) {
350                            throw processException(e);
351                    }
352                    finally {
353                            closeSession(session);
354                    }
355    
356                    clearCache(pollsQuestion);
357    
358                    return pollsQuestion;
359            }
360    
361            @Override
362            public PollsQuestion updateImpl(
363                    com.liferay.portlet.polls.model.PollsQuestion pollsQuestion)
364                    throws SystemException {
365                    pollsQuestion = toUnwrappedModel(pollsQuestion);
366    
367                    boolean isNew = pollsQuestion.isNew();
368    
369                    PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
370    
371                    if (Validator.isNull(pollsQuestion.getUuid())) {
372                            String uuid = PortalUUIDUtil.generate();
373    
374                            pollsQuestion.setUuid(uuid);
375                    }
376    
377                    Session session = null;
378    
379                    try {
380                            session = openSession();
381    
382                            if (pollsQuestion.isNew()) {
383                                    session.save(pollsQuestion);
384    
385                                    pollsQuestion.setNew(false);
386                            }
387                            else {
388                                    session.merge(pollsQuestion);
389                            }
390                    }
391                    catch (Exception e) {
392                            throw processException(e);
393                    }
394                    finally {
395                            closeSession(session);
396                    }
397    
398                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
399    
400                    if (isNew || !PollsQuestionModelImpl.COLUMN_BITMASK_ENABLED) {
401                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
402                    }
403    
404                    else {
405                            if ((pollsQuestionModelImpl.getColumnBitmask() &
406                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
407                                    Object[] args = new Object[] {
408                                                    pollsQuestionModelImpl.getOriginalUuid()
409                                            };
410    
411                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
412                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
413                                            args);
414    
415                                    args = new Object[] { pollsQuestionModelImpl.getUuid() };
416    
417                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
418                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
419                                            args);
420                            }
421    
422                            if ((pollsQuestionModelImpl.getColumnBitmask() &
423                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
424                                    Object[] args = new Object[] {
425                                                    pollsQuestionModelImpl.getOriginalUuid(),
426                                                    Long.valueOf(pollsQuestionModelImpl.getOriginalCompanyId())
427                                            };
428    
429                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
430                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
431                                            args);
432    
433                                    args = new Object[] {
434                                                    pollsQuestionModelImpl.getUuid(),
435                                                    Long.valueOf(pollsQuestionModelImpl.getCompanyId())
436                                            };
437    
438                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
439                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
440                                            args);
441                            }
442    
443                            if ((pollsQuestionModelImpl.getColumnBitmask() &
444                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
445                                    Object[] args = new Object[] {
446                                                    Long.valueOf(pollsQuestionModelImpl.getOriginalGroupId())
447                                            };
448    
449                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
450                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
451                                            args);
452    
453                                    args = new Object[] {
454                                                    Long.valueOf(pollsQuestionModelImpl.getGroupId())
455                                            };
456    
457                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
458                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
459                                            args);
460                            }
461                    }
462    
463                    EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
464                            PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
465                            pollsQuestion);
466    
467                    if (isNew) {
468                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
469                                    new Object[] {
470                                            pollsQuestion.getUuid(),
471                                            Long.valueOf(pollsQuestion.getGroupId())
472                                    }, pollsQuestion);
473                    }
474                    else {
475                            if ((pollsQuestionModelImpl.getColumnBitmask() &
476                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
477                                    Object[] args = new Object[] {
478                                                    pollsQuestionModelImpl.getOriginalUuid(),
479                                                    Long.valueOf(pollsQuestionModelImpl.getOriginalGroupId())
480                                            };
481    
482                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
483    
484                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
485    
486                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
487                                            new Object[] {
488                                                    pollsQuestion.getUuid(),
489                                                    Long.valueOf(pollsQuestion.getGroupId())
490                                            }, pollsQuestion);
491                            }
492                    }
493    
494                    return pollsQuestion;
495            }
496    
497            protected PollsQuestion toUnwrappedModel(PollsQuestion pollsQuestion) {
498                    if (pollsQuestion instanceof PollsQuestionImpl) {
499                            return pollsQuestion;
500                    }
501    
502                    PollsQuestionImpl pollsQuestionImpl = new PollsQuestionImpl();
503    
504                    pollsQuestionImpl.setNew(pollsQuestion.isNew());
505                    pollsQuestionImpl.setPrimaryKey(pollsQuestion.getPrimaryKey());
506    
507                    pollsQuestionImpl.setUuid(pollsQuestion.getUuid());
508                    pollsQuestionImpl.setQuestionId(pollsQuestion.getQuestionId());
509                    pollsQuestionImpl.setGroupId(pollsQuestion.getGroupId());
510                    pollsQuestionImpl.setCompanyId(pollsQuestion.getCompanyId());
511                    pollsQuestionImpl.setUserId(pollsQuestion.getUserId());
512                    pollsQuestionImpl.setUserName(pollsQuestion.getUserName());
513                    pollsQuestionImpl.setCreateDate(pollsQuestion.getCreateDate());
514                    pollsQuestionImpl.setModifiedDate(pollsQuestion.getModifiedDate());
515                    pollsQuestionImpl.setTitle(pollsQuestion.getTitle());
516                    pollsQuestionImpl.setDescription(pollsQuestion.getDescription());
517                    pollsQuestionImpl.setExpirationDate(pollsQuestion.getExpirationDate());
518                    pollsQuestionImpl.setLastVoteDate(pollsQuestion.getLastVoteDate());
519    
520                    return pollsQuestionImpl;
521            }
522    
523            /**
524             * Returns the polls question with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
525             *
526             * @param primaryKey the primary key of the polls question
527             * @return the polls question
528             * @throws com.liferay.portal.NoSuchModelException if a polls question with the primary key could not be found
529             * @throws SystemException if a system exception occurred
530             */
531            @Override
532            public PollsQuestion findByPrimaryKey(Serializable primaryKey)
533                    throws NoSuchModelException, SystemException {
534                    return findByPrimaryKey(((Long)primaryKey).longValue());
535            }
536    
537            /**
538             * Returns the polls question with the primary key or throws a {@link com.liferay.portlet.polls.NoSuchQuestionException} if it could not be found.
539             *
540             * @param questionId the primary key of the polls question
541             * @return the polls question
542             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a polls question with the primary key could not be found
543             * @throws SystemException if a system exception occurred
544             */
545            public PollsQuestion findByPrimaryKey(long questionId)
546                    throws NoSuchQuestionException, SystemException {
547                    PollsQuestion pollsQuestion = fetchByPrimaryKey(questionId);
548    
549                    if (pollsQuestion == null) {
550                            if (_log.isWarnEnabled()) {
551                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + questionId);
552                            }
553    
554                            throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
555                                    questionId);
556                    }
557    
558                    return pollsQuestion;
559            }
560    
561            /**
562             * Returns the polls question with the primary key or returns <code>null</code> if it could not be found.
563             *
564             * @param primaryKey the primary key of the polls question
565             * @return the polls question, or <code>null</code> if a polls question with the primary key could not be found
566             * @throws SystemException if a system exception occurred
567             */
568            @Override
569            public PollsQuestion fetchByPrimaryKey(Serializable primaryKey)
570                    throws SystemException {
571                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
572            }
573    
574            /**
575             * Returns the polls question with the primary key or returns <code>null</code> if it could not be found.
576             *
577             * @param questionId the primary key of the polls question
578             * @return the polls question, or <code>null</code> if a polls question with the primary key could not be found
579             * @throws SystemException if a system exception occurred
580             */
581            public PollsQuestion fetchByPrimaryKey(long questionId)
582                    throws SystemException {
583                    PollsQuestion pollsQuestion = (PollsQuestion)EntityCacheUtil.getResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
584                                    PollsQuestionImpl.class, questionId);
585    
586                    if (pollsQuestion == _nullPollsQuestion) {
587                            return null;
588                    }
589    
590                    if (pollsQuestion == null) {
591                            Session session = null;
592    
593                            boolean hasException = false;
594    
595                            try {
596                                    session = openSession();
597    
598                                    pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
599                                                    Long.valueOf(questionId));
600                            }
601                            catch (Exception e) {
602                                    hasException = true;
603    
604                                    throw processException(e);
605                            }
606                            finally {
607                                    if (pollsQuestion != null) {
608                                            cacheResult(pollsQuestion);
609                                    }
610                                    else if (!hasException) {
611                                            EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
612                                                    PollsQuestionImpl.class, questionId, _nullPollsQuestion);
613                                    }
614    
615                                    closeSession(session);
616                            }
617                    }
618    
619                    return pollsQuestion;
620            }
621    
622            /**
623             * Returns all the polls questions where uuid = &#63;.
624             *
625             * @param uuid the uuid
626             * @return the matching polls questions
627             * @throws SystemException if a system exception occurred
628             */
629            public List<PollsQuestion> findByUuid(String uuid)
630                    throws SystemException {
631                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
632            }
633    
634            /**
635             * Returns a range of all the polls questions where uuid = &#63;.
636             *
637             * <p>
638             * 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.
639             * </p>
640             *
641             * @param uuid the uuid
642             * @param start the lower bound of the range of polls questions
643             * @param end the upper bound of the range of polls questions (not inclusive)
644             * @return the range of matching polls questions
645             * @throws SystemException if a system exception occurred
646             */
647            public List<PollsQuestion> findByUuid(String uuid, int start, int end)
648                    throws SystemException {
649                    return findByUuid(uuid, start, end, null);
650            }
651    
652            /**
653             * Returns an ordered range of all the polls questions where uuid = &#63;.
654             *
655             * <p>
656             * 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.
657             * </p>
658             *
659             * @param uuid the uuid
660             * @param start the lower bound of the range of polls questions
661             * @param end the upper bound of the range of polls questions (not inclusive)
662             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
663             * @return the ordered range of matching polls questions
664             * @throws SystemException if a system exception occurred
665             */
666            public List<PollsQuestion> findByUuid(String uuid, int start, int end,
667                    OrderByComparator orderByComparator) throws SystemException {
668                    FinderPath finderPath = null;
669                    Object[] finderArgs = null;
670    
671                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
672                                    (orderByComparator == null)) {
673                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
674                            finderArgs = new Object[] { uuid };
675                    }
676                    else {
677                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
678                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
679                    }
680    
681                    List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
682                                    finderArgs, this);
683    
684                    if ((list != null) && !list.isEmpty()) {
685                            for (PollsQuestion pollsQuestion : list) {
686                                    if (!Validator.equals(uuid, pollsQuestion.getUuid())) {
687                                            list = null;
688    
689                                            break;
690                                    }
691                            }
692                    }
693    
694                    if (list == null) {
695                            StringBundler query = null;
696    
697                            if (orderByComparator != null) {
698                                    query = new StringBundler(3 +
699                                                    (orderByComparator.getOrderByFields().length * 3));
700                            }
701                            else {
702                                    query = new StringBundler(3);
703                            }
704    
705                            query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
706    
707                            if (uuid == null) {
708                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
709                            }
710                            else {
711                                    if (uuid.equals(StringPool.BLANK)) {
712                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
713                                    }
714                                    else {
715                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
716                                    }
717                            }
718    
719                            if (orderByComparator != null) {
720                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
721                                            orderByComparator);
722                            }
723    
724                            else {
725                                    query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
726                            }
727    
728                            String sql = query.toString();
729    
730                            Session session = null;
731    
732                            try {
733                                    session = openSession();
734    
735                                    Query q = session.createQuery(sql);
736    
737                                    QueryPos qPos = QueryPos.getInstance(q);
738    
739                                    if (uuid != null) {
740                                            qPos.add(uuid);
741                                    }
742    
743                                    list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
744                                                    start, end);
745                            }
746                            catch (Exception e) {
747                                    throw processException(e);
748                            }
749                            finally {
750                                    if (list == null) {
751                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
752                                    }
753                                    else {
754                                            cacheResult(list);
755    
756                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
757                                    }
758    
759                                    closeSession(session);
760                            }
761                    }
762    
763                    return list;
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
772             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a matching polls question could not be found
773             * @throws SystemException if a system exception occurred
774             */
775            public PollsQuestion findByUuid_First(String uuid,
776                    OrderByComparator orderByComparator)
777                    throws NoSuchQuestionException, SystemException {
778                    PollsQuestion pollsQuestion = fetchByUuid_First(uuid, orderByComparator);
779    
780                    if (pollsQuestion != null) {
781                            return pollsQuestion;
782                    }
783    
784                    StringBundler msg = new StringBundler(4);
785    
786                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
787    
788                    msg.append("uuid=");
789                    msg.append(uuid);
790    
791                    msg.append(StringPool.CLOSE_CURLY_BRACE);
792    
793                    throw new NoSuchQuestionException(msg.toString());
794            }
795    
796            /**
797             * Returns the first polls question in the ordered set where uuid = &#63;.
798             *
799             * @param uuid the uuid
800             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
801             * @return the first matching polls question, or <code>null</code> if a matching polls question could not be found
802             * @throws SystemException if a system exception occurred
803             */
804            public PollsQuestion fetchByUuid_First(String uuid,
805                    OrderByComparator orderByComparator) throws SystemException {
806                    List<PollsQuestion> list = findByUuid(uuid, 0, 1, orderByComparator);
807    
808                    if (!list.isEmpty()) {
809                            return list.get(0);
810                    }
811    
812                    return null;
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
821             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a matching polls question could not be found
822             * @throws SystemException if a system exception occurred
823             */
824            public PollsQuestion findByUuid_Last(String uuid,
825                    OrderByComparator orderByComparator)
826                    throws NoSuchQuestionException, SystemException {
827                    PollsQuestion pollsQuestion = fetchByUuid_Last(uuid, orderByComparator);
828    
829                    if (pollsQuestion != null) {
830                            return pollsQuestion;
831                    }
832    
833                    StringBundler msg = new StringBundler(4);
834    
835                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
836    
837                    msg.append("uuid=");
838                    msg.append(uuid);
839    
840                    msg.append(StringPool.CLOSE_CURLY_BRACE);
841    
842                    throw new NoSuchQuestionException(msg.toString());
843            }
844    
845            /**
846             * Returns the last polls question in the ordered set where uuid = &#63;.
847             *
848             * @param uuid the uuid
849             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
850             * @return the last matching polls question, or <code>null</code> if a matching polls question could not be found
851             * @throws SystemException if a system exception occurred
852             */
853            public PollsQuestion fetchByUuid_Last(String uuid,
854                    OrderByComparator orderByComparator) throws SystemException {
855                    int count = countByUuid(uuid);
856    
857                    List<PollsQuestion> list = findByUuid(uuid, count - 1, count,
858                                    orderByComparator);
859    
860                    if (!list.isEmpty()) {
861                            return list.get(0);
862                    }
863    
864                    return null;
865            }
866    
867            /**
868             * Returns the polls questions before and after the current polls question in the ordered set where uuid = &#63;.
869             *
870             * @param questionId the primary key of the current polls question
871             * @param uuid the uuid
872             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
873             * @return the previous, current, and next polls question
874             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a polls question with the primary key could not be found
875             * @throws SystemException if a system exception occurred
876             */
877            public PollsQuestion[] findByUuid_PrevAndNext(long questionId, String uuid,
878                    OrderByComparator orderByComparator)
879                    throws NoSuchQuestionException, SystemException {
880                    PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
881    
882                    Session session = null;
883    
884                    try {
885                            session = openSession();
886    
887                            PollsQuestion[] array = new PollsQuestionImpl[3];
888    
889                            array[0] = getByUuid_PrevAndNext(session, pollsQuestion, uuid,
890                                            orderByComparator, true);
891    
892                            array[1] = pollsQuestion;
893    
894                            array[2] = getByUuid_PrevAndNext(session, pollsQuestion, uuid,
895                                            orderByComparator, false);
896    
897                            return array;
898                    }
899                    catch (Exception e) {
900                            throw processException(e);
901                    }
902                    finally {
903                            closeSession(session);
904                    }
905            }
906    
907            protected PollsQuestion getByUuid_PrevAndNext(Session session,
908                    PollsQuestion pollsQuestion, String uuid,
909                    OrderByComparator orderByComparator, boolean previous) {
910                    StringBundler query = null;
911    
912                    if (orderByComparator != null) {
913                            query = new StringBundler(6 +
914                                            (orderByComparator.getOrderByFields().length * 6));
915                    }
916                    else {
917                            query = new StringBundler(3);
918                    }
919    
920                    query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
921    
922                    if (uuid == null) {
923                            query.append(_FINDER_COLUMN_UUID_UUID_1);
924                    }
925                    else {
926                            if (uuid.equals(StringPool.BLANK)) {
927                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
928                            }
929                            else {
930                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
931                            }
932                    }
933    
934                    if (orderByComparator != null) {
935                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
936    
937                            if (orderByConditionFields.length > 0) {
938                                    query.append(WHERE_AND);
939                            }
940    
941                            for (int i = 0; i < orderByConditionFields.length; i++) {
942                                    query.append(_ORDER_BY_ENTITY_ALIAS);
943                                    query.append(orderByConditionFields[i]);
944    
945                                    if ((i + 1) < orderByConditionFields.length) {
946                                            if (orderByComparator.isAscending() ^ previous) {
947                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
948                                            }
949                                            else {
950                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
951                                            }
952                                    }
953                                    else {
954                                            if (orderByComparator.isAscending() ^ previous) {
955                                                    query.append(WHERE_GREATER_THAN);
956                                            }
957                                            else {
958                                                    query.append(WHERE_LESSER_THAN);
959                                            }
960                                    }
961                            }
962    
963                            query.append(ORDER_BY_CLAUSE);
964    
965                            String[] orderByFields = orderByComparator.getOrderByFields();
966    
967                            for (int i = 0; i < orderByFields.length; i++) {
968                                    query.append(_ORDER_BY_ENTITY_ALIAS);
969                                    query.append(orderByFields[i]);
970    
971                                    if ((i + 1) < orderByFields.length) {
972                                            if (orderByComparator.isAscending() ^ previous) {
973                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
974                                            }
975                                            else {
976                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
977                                            }
978                                    }
979                                    else {
980                                            if (orderByComparator.isAscending() ^ previous) {
981                                                    query.append(ORDER_BY_ASC);
982                                            }
983                                            else {
984                                                    query.append(ORDER_BY_DESC);
985                                            }
986                                    }
987                            }
988                    }
989    
990                    else {
991                            query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
992                    }
993    
994                    String sql = query.toString();
995    
996                    Query q = session.createQuery(sql);
997    
998                    q.setFirstResult(0);
999                    q.setMaxResults(2);
1000    
1001                    QueryPos qPos = QueryPos.getInstance(q);
1002    
1003                    if (uuid != null) {
1004                            qPos.add(uuid);
1005                    }
1006    
1007                    if (orderByComparator != null) {
1008                            Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
1009    
1010                            for (Object value : values) {
1011                                    qPos.add(value);
1012                            }
1013                    }
1014    
1015                    List<PollsQuestion> list = q.list();
1016    
1017                    if (list.size() == 2) {
1018                            return list.get(1);
1019                    }
1020                    else {
1021                            return null;
1022                    }
1023            }
1024    
1025            /**
1026             * 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.
1027             *
1028             * @param uuid the uuid
1029             * @param groupId the group ID
1030             * @return the matching polls question
1031             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a matching polls question could not be found
1032             * @throws SystemException if a system exception occurred
1033             */
1034            public PollsQuestion findByUUID_G(String uuid, long groupId)
1035                    throws NoSuchQuestionException, SystemException {
1036                    PollsQuestion pollsQuestion = fetchByUUID_G(uuid, groupId);
1037    
1038                    if (pollsQuestion == null) {
1039                            StringBundler msg = new StringBundler(6);
1040    
1041                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1042    
1043                            msg.append("uuid=");
1044                            msg.append(uuid);
1045    
1046                            msg.append(", groupId=");
1047                            msg.append(groupId);
1048    
1049                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1050    
1051                            if (_log.isWarnEnabled()) {
1052                                    _log.warn(msg.toString());
1053                            }
1054    
1055                            throw new NoSuchQuestionException(msg.toString());
1056                    }
1057    
1058                    return pollsQuestion;
1059            }
1060    
1061            /**
1062             * 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.
1063             *
1064             * @param uuid the uuid
1065             * @param groupId the group ID
1066             * @return the matching polls question, or <code>null</code> if a matching polls question could not be found
1067             * @throws SystemException if a system exception occurred
1068             */
1069            public PollsQuestion fetchByUUID_G(String uuid, long groupId)
1070                    throws SystemException {
1071                    return fetchByUUID_G(uuid, groupId, true);
1072            }
1073    
1074            /**
1075             * 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.
1076             *
1077             * @param uuid the uuid
1078             * @param groupId the group ID
1079             * @param retrieveFromCache whether to use the finder cache
1080             * @return the matching polls question, or <code>null</code> if a matching polls question could not be found
1081             * @throws SystemException if a system exception occurred
1082             */
1083            public PollsQuestion fetchByUUID_G(String uuid, long groupId,
1084                    boolean retrieveFromCache) throws SystemException {
1085                    Object[] finderArgs = new Object[] { uuid, groupId };
1086    
1087                    Object result = null;
1088    
1089                    if (retrieveFromCache) {
1090                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1091                                            finderArgs, this);
1092                    }
1093    
1094                    if (result instanceof PollsQuestion) {
1095                            PollsQuestion pollsQuestion = (PollsQuestion)result;
1096    
1097                            if (!Validator.equals(uuid, pollsQuestion.getUuid()) ||
1098                                            (groupId != pollsQuestion.getGroupId())) {
1099                                    result = null;
1100                            }
1101                    }
1102    
1103                    if (result == null) {
1104                            StringBundler query = new StringBundler(4);
1105    
1106                            query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1107    
1108                            if (uuid == null) {
1109                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1110                            }
1111                            else {
1112                                    if (uuid.equals(StringPool.BLANK)) {
1113                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1114                                    }
1115                                    else {
1116                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1117                                    }
1118                            }
1119    
1120                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1121    
1122                            query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1123    
1124                            String sql = query.toString();
1125    
1126                            Session session = null;
1127    
1128                            try {
1129                                    session = openSession();
1130    
1131                                    Query q = session.createQuery(sql);
1132    
1133                                    QueryPos qPos = QueryPos.getInstance(q);
1134    
1135                                    if (uuid != null) {
1136                                            qPos.add(uuid);
1137                                    }
1138    
1139                                    qPos.add(groupId);
1140    
1141                                    List<PollsQuestion> list = q.list();
1142    
1143                                    result = list;
1144    
1145                                    PollsQuestion pollsQuestion = null;
1146    
1147                                    if (list.isEmpty()) {
1148                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1149                                                    finderArgs, list);
1150                                    }
1151                                    else {
1152                                            pollsQuestion = list.get(0);
1153    
1154                                            cacheResult(pollsQuestion);
1155    
1156                                            if ((pollsQuestion.getUuid() == null) ||
1157                                                            !pollsQuestion.getUuid().equals(uuid) ||
1158                                                            (pollsQuestion.getGroupId() != groupId)) {
1159                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1160                                                            finderArgs, pollsQuestion);
1161                                            }
1162                                    }
1163    
1164                                    return pollsQuestion;
1165                            }
1166                            catch (Exception e) {
1167                                    throw processException(e);
1168                            }
1169                            finally {
1170                                    if (result == null) {
1171                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1172                                                    finderArgs);
1173                                    }
1174    
1175                                    closeSession(session);
1176                            }
1177                    }
1178                    else {
1179                            if (result instanceof List<?>) {
1180                                    return null;
1181                            }
1182                            else {
1183                                    return (PollsQuestion)result;
1184                            }
1185                    }
1186            }
1187    
1188            /**
1189             * Returns all the polls questions where uuid = &#63; and companyId = &#63;.
1190             *
1191             * @param uuid the uuid
1192             * @param companyId the company ID
1193             * @return the matching polls questions
1194             * @throws SystemException if a system exception occurred
1195             */
1196            public List<PollsQuestion> findByUuid_C(String uuid, long companyId)
1197                    throws SystemException {
1198                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1199                            QueryUtil.ALL_POS, null);
1200            }
1201    
1202            /**
1203             * Returns a range of all the polls questions where uuid = &#63; and companyId = &#63;.
1204             *
1205             * <p>
1206             * 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.
1207             * </p>
1208             *
1209             * @param uuid the uuid
1210             * @param companyId the company ID
1211             * @param start the lower bound of the range of polls questions
1212             * @param end the upper bound of the range of polls questions (not inclusive)
1213             * @return the range of matching polls questions
1214             * @throws SystemException if a system exception occurred
1215             */
1216            public List<PollsQuestion> findByUuid_C(String uuid, long companyId,
1217                    int start, int end) throws SystemException {
1218                    return findByUuid_C(uuid, companyId, start, end, null);
1219            }
1220    
1221            /**
1222             * Returns an ordered range of all the polls questions where uuid = &#63; and companyId = &#63;.
1223             *
1224             * <p>
1225             * 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.
1226             * </p>
1227             *
1228             * @param uuid the uuid
1229             * @param companyId the company ID
1230             * @param start the lower bound of the range of polls questions
1231             * @param end the upper bound of the range of polls questions (not inclusive)
1232             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1233             * @return the ordered range of matching polls questions
1234             * @throws SystemException if a system exception occurred
1235             */
1236            public List<PollsQuestion> findByUuid_C(String uuid, long companyId,
1237                    int start, int end, OrderByComparator orderByComparator)
1238                    throws SystemException {
1239                    FinderPath finderPath = null;
1240                    Object[] finderArgs = null;
1241    
1242                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1243                                    (orderByComparator == null)) {
1244                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1245                            finderArgs = new Object[] { uuid, companyId };
1246                    }
1247                    else {
1248                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1249                            finderArgs = new Object[] {
1250                                            uuid, companyId,
1251                                            
1252                                            start, end, orderByComparator
1253                                    };
1254                    }
1255    
1256                    List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
1257                                    finderArgs, this);
1258    
1259                    if ((list != null) && !list.isEmpty()) {
1260                            for (PollsQuestion pollsQuestion : list) {
1261                                    if (!Validator.equals(uuid, pollsQuestion.getUuid()) ||
1262                                                    (companyId != pollsQuestion.getCompanyId())) {
1263                                            list = null;
1264    
1265                                            break;
1266                                    }
1267                            }
1268                    }
1269    
1270                    if (list == null) {
1271                            StringBundler query = null;
1272    
1273                            if (orderByComparator != null) {
1274                                    query = new StringBundler(4 +
1275                                                    (orderByComparator.getOrderByFields().length * 3));
1276                            }
1277                            else {
1278                                    query = new StringBundler(4);
1279                            }
1280    
1281                            query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1282    
1283                            if (uuid == null) {
1284                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1285                            }
1286                            else {
1287                                    if (uuid.equals(StringPool.BLANK)) {
1288                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1289                                    }
1290                                    else {
1291                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1292                                    }
1293                            }
1294    
1295                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1296    
1297                            if (orderByComparator != null) {
1298                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1299                                            orderByComparator);
1300                            }
1301    
1302                            else {
1303                                    query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1304                            }
1305    
1306                            String sql = query.toString();
1307    
1308                            Session session = null;
1309    
1310                            try {
1311                                    session = openSession();
1312    
1313                                    Query q = session.createQuery(sql);
1314    
1315                                    QueryPos qPos = QueryPos.getInstance(q);
1316    
1317                                    if (uuid != null) {
1318                                            qPos.add(uuid);
1319                                    }
1320    
1321                                    qPos.add(companyId);
1322    
1323                                    list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1324                                                    start, end);
1325                            }
1326                            catch (Exception e) {
1327                                    throw processException(e);
1328                            }
1329                            finally {
1330                                    if (list == null) {
1331                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1332                                    }
1333                                    else {
1334                                            cacheResult(list);
1335    
1336                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1337                                    }
1338    
1339                                    closeSession(session);
1340                            }
1341                    }
1342    
1343                    return list;
1344            }
1345    
1346            /**
1347             * Returns the first polls question in the ordered set where uuid = &#63; and companyId = &#63;.
1348             *
1349             * @param uuid the uuid
1350             * @param companyId the company ID
1351             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1352             * @return the first matching polls question
1353             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a matching polls question could not be found
1354             * @throws SystemException if a system exception occurred
1355             */
1356            public PollsQuestion findByUuid_C_First(String uuid, long companyId,
1357                    OrderByComparator orderByComparator)
1358                    throws NoSuchQuestionException, SystemException {
1359                    PollsQuestion pollsQuestion = fetchByUuid_C_First(uuid, companyId,
1360                                    orderByComparator);
1361    
1362                    if (pollsQuestion != null) {
1363                            return pollsQuestion;
1364                    }
1365    
1366                    StringBundler msg = new StringBundler(6);
1367    
1368                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1369    
1370                    msg.append("uuid=");
1371                    msg.append(uuid);
1372    
1373                    msg.append(", companyId=");
1374                    msg.append(companyId);
1375    
1376                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1377    
1378                    throw new NoSuchQuestionException(msg.toString());
1379            }
1380    
1381            /**
1382             * Returns the first polls question in the ordered set where uuid = &#63; and companyId = &#63;.
1383             *
1384             * @param uuid the uuid
1385             * @param companyId the company ID
1386             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1387             * @return the first matching polls question, or <code>null</code> if a matching polls question could not be found
1388             * @throws SystemException if a system exception occurred
1389             */
1390            public PollsQuestion fetchByUuid_C_First(String uuid, long companyId,
1391                    OrderByComparator orderByComparator) throws SystemException {
1392                    List<PollsQuestion> list = findByUuid_C(uuid, companyId, 0, 1,
1393                                    orderByComparator);
1394    
1395                    if (!list.isEmpty()) {
1396                            return list.get(0);
1397                    }
1398    
1399                    return null;
1400            }
1401    
1402            /**
1403             * Returns the last polls question in the ordered set where uuid = &#63; and companyId = &#63;.
1404             *
1405             * @param uuid the uuid
1406             * @param companyId the company ID
1407             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1408             * @return the last matching polls question
1409             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a matching polls question could not be found
1410             * @throws SystemException if a system exception occurred
1411             */
1412            public PollsQuestion findByUuid_C_Last(String uuid, long companyId,
1413                    OrderByComparator orderByComparator)
1414                    throws NoSuchQuestionException, SystemException {
1415                    PollsQuestion pollsQuestion = fetchByUuid_C_Last(uuid, companyId,
1416                                    orderByComparator);
1417    
1418                    if (pollsQuestion != null) {
1419                            return pollsQuestion;
1420                    }
1421    
1422                    StringBundler msg = new StringBundler(6);
1423    
1424                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1425    
1426                    msg.append("uuid=");
1427                    msg.append(uuid);
1428    
1429                    msg.append(", companyId=");
1430                    msg.append(companyId);
1431    
1432                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1433    
1434                    throw new NoSuchQuestionException(msg.toString());
1435            }
1436    
1437            /**
1438             * Returns the last polls question in the ordered set where uuid = &#63; and companyId = &#63;.
1439             *
1440             * @param uuid the uuid
1441             * @param companyId the company ID
1442             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1443             * @return the last matching polls question, or <code>null</code> if a matching polls question could not be found
1444             * @throws SystemException if a system exception occurred
1445             */
1446            public PollsQuestion fetchByUuid_C_Last(String uuid, long companyId,
1447                    OrderByComparator orderByComparator) throws SystemException {
1448                    int count = countByUuid_C(uuid, companyId);
1449    
1450                    List<PollsQuestion> list = findByUuid_C(uuid, companyId, count - 1,
1451                                    count, orderByComparator);
1452    
1453                    if (!list.isEmpty()) {
1454                            return list.get(0);
1455                    }
1456    
1457                    return null;
1458            }
1459    
1460            /**
1461             * Returns the polls questions before and after the current polls question in the ordered set where uuid = &#63; and companyId = &#63;.
1462             *
1463             * @param questionId the primary key of the current polls question
1464             * @param uuid the uuid
1465             * @param companyId the company ID
1466             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1467             * @return the previous, current, and next polls question
1468             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a polls question with the primary key could not be found
1469             * @throws SystemException if a system exception occurred
1470             */
1471            public PollsQuestion[] findByUuid_C_PrevAndNext(long questionId,
1472                    String uuid, long companyId, OrderByComparator orderByComparator)
1473                    throws NoSuchQuestionException, SystemException {
1474                    PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
1475    
1476                    Session session = null;
1477    
1478                    try {
1479                            session = openSession();
1480    
1481                            PollsQuestion[] array = new PollsQuestionImpl[3];
1482    
1483                            array[0] = getByUuid_C_PrevAndNext(session, pollsQuestion, uuid,
1484                                            companyId, orderByComparator, true);
1485    
1486                            array[1] = pollsQuestion;
1487    
1488                            array[2] = getByUuid_C_PrevAndNext(session, pollsQuestion, uuid,
1489                                            companyId, orderByComparator, false);
1490    
1491                            return array;
1492                    }
1493                    catch (Exception e) {
1494                            throw processException(e);
1495                    }
1496                    finally {
1497                            closeSession(session);
1498                    }
1499            }
1500    
1501            protected PollsQuestion getByUuid_C_PrevAndNext(Session session,
1502                    PollsQuestion pollsQuestion, String uuid, long companyId,
1503                    OrderByComparator orderByComparator, boolean previous) {
1504                    StringBundler query = null;
1505    
1506                    if (orderByComparator != null) {
1507                            query = new StringBundler(6 +
1508                                            (orderByComparator.getOrderByFields().length * 6));
1509                    }
1510                    else {
1511                            query = new StringBundler(3);
1512                    }
1513    
1514                    query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1515    
1516                    if (uuid == null) {
1517                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1518                    }
1519                    else {
1520                            if (uuid.equals(StringPool.BLANK)) {
1521                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1522                            }
1523                            else {
1524                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1525                            }
1526                    }
1527    
1528                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1529    
1530                    if (orderByComparator != null) {
1531                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1532    
1533                            if (orderByConditionFields.length > 0) {
1534                                    query.append(WHERE_AND);
1535                            }
1536    
1537                            for (int i = 0; i < orderByConditionFields.length; i++) {
1538                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1539                                    query.append(orderByConditionFields[i]);
1540    
1541                                    if ((i + 1) < orderByConditionFields.length) {
1542                                            if (orderByComparator.isAscending() ^ previous) {
1543                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1544                                            }
1545                                            else {
1546                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1547                                            }
1548                                    }
1549                                    else {
1550                                            if (orderByComparator.isAscending() ^ previous) {
1551                                                    query.append(WHERE_GREATER_THAN);
1552                                            }
1553                                            else {
1554                                                    query.append(WHERE_LESSER_THAN);
1555                                            }
1556                                    }
1557                            }
1558    
1559                            query.append(ORDER_BY_CLAUSE);
1560    
1561                            String[] orderByFields = orderByComparator.getOrderByFields();
1562    
1563                            for (int i = 0; i < orderByFields.length; i++) {
1564                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1565                                    query.append(orderByFields[i]);
1566    
1567                                    if ((i + 1) < orderByFields.length) {
1568                                            if (orderByComparator.isAscending() ^ previous) {
1569                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1570                                            }
1571                                            else {
1572                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1573                                            }
1574                                    }
1575                                    else {
1576                                            if (orderByComparator.isAscending() ^ previous) {
1577                                                    query.append(ORDER_BY_ASC);
1578                                            }
1579                                            else {
1580                                                    query.append(ORDER_BY_DESC);
1581                                            }
1582                                    }
1583                            }
1584                    }
1585    
1586                    else {
1587                            query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1588                    }
1589    
1590                    String sql = query.toString();
1591    
1592                    Query q = session.createQuery(sql);
1593    
1594                    q.setFirstResult(0);
1595                    q.setMaxResults(2);
1596    
1597                    QueryPos qPos = QueryPos.getInstance(q);
1598    
1599                    if (uuid != null) {
1600                            qPos.add(uuid);
1601                    }
1602    
1603                    qPos.add(companyId);
1604    
1605                    if (orderByComparator != null) {
1606                            Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
1607    
1608                            for (Object value : values) {
1609                                    qPos.add(value);
1610                            }
1611                    }
1612    
1613                    List<PollsQuestion> list = q.list();
1614    
1615                    if (list.size() == 2) {
1616                            return list.get(1);
1617                    }
1618                    else {
1619                            return null;
1620                    }
1621            }
1622    
1623            /**
1624             * Returns all the polls questions where groupId = &#63;.
1625             *
1626             * @param groupId the group ID
1627             * @return the matching polls questions
1628             * @throws SystemException if a system exception occurred
1629             */
1630            public List<PollsQuestion> findByGroupId(long groupId)
1631                    throws SystemException {
1632                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1633            }
1634    
1635            /**
1636             * Returns a range of all the polls questions where groupId = &#63;.
1637             *
1638             * <p>
1639             * 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.
1640             * </p>
1641             *
1642             * @param groupId the group ID
1643             * @param start the lower bound of the range of polls questions
1644             * @param end the upper bound of the range of polls questions (not inclusive)
1645             * @return the range of matching polls questions
1646             * @throws SystemException if a system exception occurred
1647             */
1648            public List<PollsQuestion> findByGroupId(long groupId, int start, int end)
1649                    throws SystemException {
1650                    return findByGroupId(groupId, start, end, null);
1651            }
1652    
1653            /**
1654             * Returns an ordered range of all the polls questions where groupId = &#63;.
1655             *
1656             * <p>
1657             * 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.
1658             * </p>
1659             *
1660             * @param groupId the group ID
1661             * @param start the lower bound of the range of polls questions
1662             * @param end the upper bound of the range of polls questions (not inclusive)
1663             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1664             * @return the ordered range of matching polls questions
1665             * @throws SystemException if a system exception occurred
1666             */
1667            public List<PollsQuestion> findByGroupId(long groupId, int start, int end,
1668                    OrderByComparator orderByComparator) throws SystemException {
1669                    FinderPath finderPath = null;
1670                    Object[] finderArgs = null;
1671    
1672                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1673                                    (orderByComparator == null)) {
1674                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1675                            finderArgs = new Object[] { groupId };
1676                    }
1677                    else {
1678                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1679                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1680                    }
1681    
1682                    List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
1683                                    finderArgs, this);
1684    
1685                    if ((list != null) && !list.isEmpty()) {
1686                            for (PollsQuestion pollsQuestion : list) {
1687                                    if ((groupId != pollsQuestion.getGroupId())) {
1688                                            list = null;
1689    
1690                                            break;
1691                                    }
1692                            }
1693                    }
1694    
1695                    if (list == null) {
1696                            StringBundler query = null;
1697    
1698                            if (orderByComparator != null) {
1699                                    query = new StringBundler(3 +
1700                                                    (orderByComparator.getOrderByFields().length * 3));
1701                            }
1702                            else {
1703                                    query = new StringBundler(3);
1704                            }
1705    
1706                            query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1707    
1708                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1709    
1710                            if (orderByComparator != null) {
1711                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1712                                            orderByComparator);
1713                            }
1714    
1715                            else {
1716                                    query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1717                            }
1718    
1719                            String sql = query.toString();
1720    
1721                            Session session = null;
1722    
1723                            try {
1724                                    session = openSession();
1725    
1726                                    Query q = session.createQuery(sql);
1727    
1728                                    QueryPos qPos = QueryPos.getInstance(q);
1729    
1730                                    qPos.add(groupId);
1731    
1732                                    list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1733                                                    start, end);
1734                            }
1735                            catch (Exception e) {
1736                                    throw processException(e);
1737                            }
1738                            finally {
1739                                    if (list == null) {
1740                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1741                                    }
1742                                    else {
1743                                            cacheResult(list);
1744    
1745                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1746                                    }
1747    
1748                                    closeSession(session);
1749                            }
1750                    }
1751    
1752                    return list;
1753            }
1754    
1755            /**
1756             * Returns the first polls question in the ordered set where groupId = &#63;.
1757             *
1758             * @param groupId the group ID
1759             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1760             * @return the first matching polls question
1761             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a matching polls question could not be found
1762             * @throws SystemException if a system exception occurred
1763             */
1764            public PollsQuestion findByGroupId_First(long groupId,
1765                    OrderByComparator orderByComparator)
1766                    throws NoSuchQuestionException, SystemException {
1767                    PollsQuestion pollsQuestion = fetchByGroupId_First(groupId,
1768                                    orderByComparator);
1769    
1770                    if (pollsQuestion != null) {
1771                            return pollsQuestion;
1772                    }
1773    
1774                    StringBundler msg = new StringBundler(4);
1775    
1776                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1777    
1778                    msg.append("groupId=");
1779                    msg.append(groupId);
1780    
1781                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1782    
1783                    throw new NoSuchQuestionException(msg.toString());
1784            }
1785    
1786            /**
1787             * Returns the first polls question in the ordered set where groupId = &#63;.
1788             *
1789             * @param groupId the group ID
1790             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1791             * @return the first matching polls question, or <code>null</code> if a matching polls question could not be found
1792             * @throws SystemException if a system exception occurred
1793             */
1794            public PollsQuestion fetchByGroupId_First(long groupId,
1795                    OrderByComparator orderByComparator) throws SystemException {
1796                    List<PollsQuestion> list = findByGroupId(groupId, 0, 1,
1797                                    orderByComparator);
1798    
1799                    if (!list.isEmpty()) {
1800                            return list.get(0);
1801                    }
1802    
1803                    return null;
1804            }
1805    
1806            /**
1807             * Returns the last polls question in the ordered set where groupId = &#63;.
1808             *
1809             * @param groupId the group ID
1810             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1811             * @return the last matching polls question
1812             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a matching polls question could not be found
1813             * @throws SystemException if a system exception occurred
1814             */
1815            public PollsQuestion findByGroupId_Last(long groupId,
1816                    OrderByComparator orderByComparator)
1817                    throws NoSuchQuestionException, SystemException {
1818                    PollsQuestion pollsQuestion = fetchByGroupId_Last(groupId,
1819                                    orderByComparator);
1820    
1821                    if (pollsQuestion != null) {
1822                            return pollsQuestion;
1823                    }
1824    
1825                    StringBundler msg = new StringBundler(4);
1826    
1827                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1828    
1829                    msg.append("groupId=");
1830                    msg.append(groupId);
1831    
1832                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1833    
1834                    throw new NoSuchQuestionException(msg.toString());
1835            }
1836    
1837            /**
1838             * Returns the last polls question in the ordered set where groupId = &#63;.
1839             *
1840             * @param groupId the group ID
1841             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1842             * @return the last matching polls question, or <code>null</code> if a matching polls question could not be found
1843             * @throws SystemException if a system exception occurred
1844             */
1845            public PollsQuestion fetchByGroupId_Last(long groupId,
1846                    OrderByComparator orderByComparator) throws SystemException {
1847                    int count = countByGroupId(groupId);
1848    
1849                    List<PollsQuestion> list = findByGroupId(groupId, count - 1, count,
1850                                    orderByComparator);
1851    
1852                    if (!list.isEmpty()) {
1853                            return list.get(0);
1854                    }
1855    
1856                    return null;
1857            }
1858    
1859            /**
1860             * Returns the polls questions before and after the current polls question in the ordered set where groupId = &#63;.
1861             *
1862             * @param questionId the primary key of the current polls question
1863             * @param groupId the group ID
1864             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1865             * @return the previous, current, and next polls question
1866             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a polls question with the primary key could not be found
1867             * @throws SystemException if a system exception occurred
1868             */
1869            public PollsQuestion[] findByGroupId_PrevAndNext(long questionId,
1870                    long groupId, OrderByComparator orderByComparator)
1871                    throws NoSuchQuestionException, SystemException {
1872                    PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
1873    
1874                    Session session = null;
1875    
1876                    try {
1877                            session = openSession();
1878    
1879                            PollsQuestion[] array = new PollsQuestionImpl[3];
1880    
1881                            array[0] = getByGroupId_PrevAndNext(session, pollsQuestion,
1882                                            groupId, orderByComparator, true);
1883    
1884                            array[1] = pollsQuestion;
1885    
1886                            array[2] = getByGroupId_PrevAndNext(session, pollsQuestion,
1887                                            groupId, orderByComparator, false);
1888    
1889                            return array;
1890                    }
1891                    catch (Exception e) {
1892                            throw processException(e);
1893                    }
1894                    finally {
1895                            closeSession(session);
1896                    }
1897            }
1898    
1899            protected PollsQuestion getByGroupId_PrevAndNext(Session session,
1900                    PollsQuestion pollsQuestion, long groupId,
1901                    OrderByComparator orderByComparator, boolean previous) {
1902                    StringBundler query = null;
1903    
1904                    if (orderByComparator != null) {
1905                            query = new StringBundler(6 +
1906                                            (orderByComparator.getOrderByFields().length * 6));
1907                    }
1908                    else {
1909                            query = new StringBundler(3);
1910                    }
1911    
1912                    query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
1913    
1914                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1915    
1916                    if (orderByComparator != null) {
1917                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1918    
1919                            if (orderByConditionFields.length > 0) {
1920                                    query.append(WHERE_AND);
1921                            }
1922    
1923                            for (int i = 0; i < orderByConditionFields.length; i++) {
1924                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1925                                    query.append(orderByConditionFields[i]);
1926    
1927                                    if ((i + 1) < orderByConditionFields.length) {
1928                                            if (orderByComparator.isAscending() ^ previous) {
1929                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1930                                            }
1931                                            else {
1932                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1933                                            }
1934                                    }
1935                                    else {
1936                                            if (orderByComparator.isAscending() ^ previous) {
1937                                                    query.append(WHERE_GREATER_THAN);
1938                                            }
1939                                            else {
1940                                                    query.append(WHERE_LESSER_THAN);
1941                                            }
1942                                    }
1943                            }
1944    
1945                            query.append(ORDER_BY_CLAUSE);
1946    
1947                            String[] orderByFields = orderByComparator.getOrderByFields();
1948    
1949                            for (int i = 0; i < orderByFields.length; i++) {
1950                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1951                                    query.append(orderByFields[i]);
1952    
1953                                    if ((i + 1) < orderByFields.length) {
1954                                            if (orderByComparator.isAscending() ^ previous) {
1955                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1956                                            }
1957                                            else {
1958                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1959                                            }
1960                                    }
1961                                    else {
1962                                            if (orderByComparator.isAscending() ^ previous) {
1963                                                    query.append(ORDER_BY_ASC);
1964                                            }
1965                                            else {
1966                                                    query.append(ORDER_BY_DESC);
1967                                            }
1968                                    }
1969                            }
1970                    }
1971    
1972                    else {
1973                            query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1974                    }
1975    
1976                    String sql = query.toString();
1977    
1978                    Query q = session.createQuery(sql);
1979    
1980                    q.setFirstResult(0);
1981                    q.setMaxResults(2);
1982    
1983                    QueryPos qPos = QueryPos.getInstance(q);
1984    
1985                    qPos.add(groupId);
1986    
1987                    if (orderByComparator != null) {
1988                            Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
1989    
1990                            for (Object value : values) {
1991                                    qPos.add(value);
1992                            }
1993                    }
1994    
1995                    List<PollsQuestion> list = q.list();
1996    
1997                    if (list.size() == 2) {
1998                            return list.get(1);
1999                    }
2000                    else {
2001                            return null;
2002                    }
2003            }
2004    
2005            /**
2006             * Returns all the polls questions that the user has permission to view where groupId = &#63;.
2007             *
2008             * @param groupId the group ID
2009             * @return the matching polls questions that the user has permission to view
2010             * @throws SystemException if a system exception occurred
2011             */
2012            public List<PollsQuestion> filterFindByGroupId(long groupId)
2013                    throws SystemException {
2014                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
2015                            QueryUtil.ALL_POS, null);
2016            }
2017    
2018            /**
2019             * Returns a range of all the polls questions that the user has permission to view where groupId = &#63;.
2020             *
2021             * <p>
2022             * 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.
2023             * </p>
2024             *
2025             * @param groupId the group ID
2026             * @param start the lower bound of the range of polls questions
2027             * @param end the upper bound of the range of polls questions (not inclusive)
2028             * @return the range of matching polls questions that the user has permission to view
2029             * @throws SystemException if a system exception occurred
2030             */
2031            public List<PollsQuestion> filterFindByGroupId(long groupId, int start,
2032                    int end) throws SystemException {
2033                    return filterFindByGroupId(groupId, start, end, null);
2034            }
2035    
2036            /**
2037             * Returns an ordered range of all the polls questions that the user has permissions to view where groupId = &#63;.
2038             *
2039             * <p>
2040             * 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.
2041             * </p>
2042             *
2043             * @param groupId the group ID
2044             * @param start the lower bound of the range of polls questions
2045             * @param end the upper bound of the range of polls questions (not inclusive)
2046             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2047             * @return the ordered range of matching polls questions that the user has permission to view
2048             * @throws SystemException if a system exception occurred
2049             */
2050            public List<PollsQuestion> filterFindByGroupId(long groupId, int start,
2051                    int end, OrderByComparator orderByComparator) throws SystemException {
2052                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2053                            return findByGroupId(groupId, start, end, orderByComparator);
2054                    }
2055    
2056                    StringBundler query = null;
2057    
2058                    if (orderByComparator != null) {
2059                            query = new StringBundler(3 +
2060                                            (orderByComparator.getOrderByFields().length * 3));
2061                    }
2062                    else {
2063                            query = new StringBundler(3);
2064                    }
2065    
2066                    if (getDB().isSupportsInlineDistinct()) {
2067                            query.append(_FILTER_SQL_SELECT_POLLSQUESTION_WHERE);
2068                    }
2069                    else {
2070                            query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1);
2071                    }
2072    
2073                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2074    
2075                    if (!getDB().isSupportsInlineDistinct()) {
2076                            query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2);
2077                    }
2078    
2079                    if (orderByComparator != null) {
2080                            if (getDB().isSupportsInlineDistinct()) {
2081                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2082                                            orderByComparator);
2083                            }
2084                            else {
2085                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2086                                            orderByComparator);
2087                            }
2088                    }
2089    
2090                    else {
2091                            if (getDB().isSupportsInlineDistinct()) {
2092                                    query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
2093                            }
2094                            else {
2095                                    query.append(PollsQuestionModelImpl.ORDER_BY_SQL);
2096                            }
2097                    }
2098    
2099                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2100                                    PollsQuestion.class.getName(),
2101                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2102    
2103                    Session session = null;
2104    
2105                    try {
2106                            session = openSession();
2107    
2108                            SQLQuery q = session.createSQLQuery(sql);
2109    
2110                            if (getDB().isSupportsInlineDistinct()) {
2111                                    q.addEntity(_FILTER_ENTITY_ALIAS, PollsQuestionImpl.class);
2112                            }
2113                            else {
2114                                    q.addEntity(_FILTER_ENTITY_TABLE, PollsQuestionImpl.class);
2115                            }
2116    
2117                            QueryPos qPos = QueryPos.getInstance(q);
2118    
2119                            qPos.add(groupId);
2120    
2121                            return (List<PollsQuestion>)QueryUtil.list(q, getDialect(), start,
2122                                    end);
2123                    }
2124                    catch (Exception e) {
2125                            throw processException(e);
2126                    }
2127                    finally {
2128                            closeSession(session);
2129                    }
2130            }
2131    
2132            /**
2133             * 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;.
2134             *
2135             * @param questionId the primary key of the current polls question
2136             * @param groupId the group ID
2137             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2138             * @return the previous, current, and next polls question
2139             * @throws com.liferay.portlet.polls.NoSuchQuestionException if a polls question with the primary key could not be found
2140             * @throws SystemException if a system exception occurred
2141             */
2142            public PollsQuestion[] filterFindByGroupId_PrevAndNext(long questionId,
2143                    long groupId, OrderByComparator orderByComparator)
2144                    throws NoSuchQuestionException, SystemException {
2145                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2146                            return findByGroupId_PrevAndNext(questionId, groupId,
2147                                    orderByComparator);
2148                    }
2149    
2150                    PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
2151    
2152                    Session session = null;
2153    
2154                    try {
2155                            session = openSession();
2156    
2157                            PollsQuestion[] array = new PollsQuestionImpl[3];
2158    
2159                            array[0] = filterGetByGroupId_PrevAndNext(session, pollsQuestion,
2160                                            groupId, orderByComparator, true);
2161    
2162                            array[1] = pollsQuestion;
2163    
2164                            array[2] = filterGetByGroupId_PrevAndNext(session, pollsQuestion,
2165                                            groupId, orderByComparator, false);
2166    
2167                            return array;
2168                    }
2169                    catch (Exception e) {
2170                            throw processException(e);
2171                    }
2172                    finally {
2173                            closeSession(session);
2174                    }
2175            }
2176    
2177            protected PollsQuestion filterGetByGroupId_PrevAndNext(Session session,
2178                    PollsQuestion pollsQuestion, long groupId,
2179                    OrderByComparator orderByComparator, boolean previous) {
2180                    StringBundler query = null;
2181    
2182                    if (orderByComparator != null) {
2183                            query = new StringBundler(6 +
2184                                            (orderByComparator.getOrderByFields().length * 6));
2185                    }
2186                    else {
2187                            query = new StringBundler(3);
2188                    }
2189    
2190                    if (getDB().isSupportsInlineDistinct()) {
2191                            query.append(_FILTER_SQL_SELECT_POLLSQUESTION_WHERE);
2192                    }
2193                    else {
2194                            query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1);
2195                    }
2196    
2197                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2198    
2199                    if (!getDB().isSupportsInlineDistinct()) {
2200                            query.append(_FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2);
2201                    }
2202    
2203                    if (orderByComparator != null) {
2204                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2205    
2206                            if (orderByConditionFields.length > 0) {
2207                                    query.append(WHERE_AND);
2208                            }
2209    
2210                            for (int i = 0; i < orderByConditionFields.length; i++) {
2211                                    if (getDB().isSupportsInlineDistinct()) {
2212                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2213                                    }
2214                                    else {
2215                                            query.append(_ORDER_BY_ENTITY_TABLE);
2216                                    }
2217    
2218                                    query.append(orderByConditionFields[i]);
2219    
2220                                    if ((i + 1) < orderByConditionFields.length) {
2221                                            if (orderByComparator.isAscending() ^ previous) {
2222                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2223                                            }
2224                                            else {
2225                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2226                                            }
2227                                    }
2228                                    else {
2229                                            if (orderByComparator.isAscending() ^ previous) {
2230                                                    query.append(WHERE_GREATER_THAN);
2231                                            }
2232                                            else {
2233                                                    query.append(WHERE_LESSER_THAN);
2234                                            }
2235                                    }
2236                            }
2237    
2238                            query.append(ORDER_BY_CLAUSE);
2239    
2240                            String[] orderByFields = orderByComparator.getOrderByFields();
2241    
2242                            for (int i = 0; i < orderByFields.length; i++) {
2243                                    if (getDB().isSupportsInlineDistinct()) {
2244                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2245                                    }
2246                                    else {
2247                                            query.append(_ORDER_BY_ENTITY_TABLE);
2248                                    }
2249    
2250                                    query.append(orderByFields[i]);
2251    
2252                                    if ((i + 1) < orderByFields.length) {
2253                                            if (orderByComparator.isAscending() ^ previous) {
2254                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2255                                            }
2256                                            else {
2257                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2258                                            }
2259                                    }
2260                                    else {
2261                                            if (orderByComparator.isAscending() ^ previous) {
2262                                                    query.append(ORDER_BY_ASC);
2263                                            }
2264                                            else {
2265                                                    query.append(ORDER_BY_DESC);
2266                                            }
2267                                    }
2268                            }
2269                    }
2270    
2271                    else {
2272                            if (getDB().isSupportsInlineDistinct()) {
2273                                    query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
2274                            }
2275                            else {
2276                                    query.append(PollsQuestionModelImpl.ORDER_BY_SQL);
2277                            }
2278                    }
2279    
2280                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2281                                    PollsQuestion.class.getName(),
2282                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2283    
2284                    SQLQuery q = session.createSQLQuery(sql);
2285    
2286                    q.setFirstResult(0);
2287                    q.setMaxResults(2);
2288    
2289                    if (getDB().isSupportsInlineDistinct()) {
2290                            q.addEntity(_FILTER_ENTITY_ALIAS, PollsQuestionImpl.class);
2291                    }
2292                    else {
2293                            q.addEntity(_FILTER_ENTITY_TABLE, PollsQuestionImpl.class);
2294                    }
2295    
2296                    QueryPos qPos = QueryPos.getInstance(q);
2297    
2298                    qPos.add(groupId);
2299    
2300                    if (orderByComparator != null) {
2301                            Object[] values = orderByComparator.getOrderByConditionValues(pollsQuestion);
2302    
2303                            for (Object value : values) {
2304                                    qPos.add(value);
2305                            }
2306                    }
2307    
2308                    List<PollsQuestion> list = q.list();
2309    
2310                    if (list.size() == 2) {
2311                            return list.get(1);
2312                    }
2313                    else {
2314                            return null;
2315                    }
2316            }
2317    
2318            /**
2319             * Returns all the polls questions.
2320             *
2321             * @return the polls questions
2322             * @throws SystemException if a system exception occurred
2323             */
2324            public List<PollsQuestion> findAll() throws SystemException {
2325                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2326            }
2327    
2328            /**
2329             * Returns a range of all the polls questions.
2330             *
2331             * <p>
2332             * 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.
2333             * </p>
2334             *
2335             * @param start the lower bound of the range of polls questions
2336             * @param end the upper bound of the range of polls questions (not inclusive)
2337             * @return the range of polls questions
2338             * @throws SystemException if a system exception occurred
2339             */
2340            public List<PollsQuestion> findAll(int start, int end)
2341                    throws SystemException {
2342                    return findAll(start, end, null);
2343            }
2344    
2345            /**
2346             * Returns an ordered range of all the polls questions.
2347             *
2348             * <p>
2349             * 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.
2350             * </p>
2351             *
2352             * @param start the lower bound of the range of polls questions
2353             * @param end the upper bound of the range of polls questions (not inclusive)
2354             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2355             * @return the ordered range of polls questions
2356             * @throws SystemException if a system exception occurred
2357             */
2358            public List<PollsQuestion> findAll(int start, int end,
2359                    OrderByComparator orderByComparator) throws SystemException {
2360                    FinderPath finderPath = null;
2361                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
2362    
2363                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2364                                    (orderByComparator == null)) {
2365                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2366                            finderArgs = FINDER_ARGS_EMPTY;
2367                    }
2368                    else {
2369                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2370                            finderArgs = new Object[] { start, end, orderByComparator };
2371                    }
2372    
2373                    List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(finderPath,
2374                                    finderArgs, this);
2375    
2376                    if (list == null) {
2377                            StringBundler query = null;
2378                            String sql = null;
2379    
2380                            if (orderByComparator != null) {
2381                                    query = new StringBundler(2 +
2382                                                    (orderByComparator.getOrderByFields().length * 3));
2383    
2384                                    query.append(_SQL_SELECT_POLLSQUESTION);
2385    
2386                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2387                                            orderByComparator);
2388    
2389                                    sql = query.toString();
2390                            }
2391                            else {
2392                                    sql = _SQL_SELECT_POLLSQUESTION.concat(PollsQuestionModelImpl.ORDER_BY_JPQL);
2393                            }
2394    
2395                            Session session = null;
2396    
2397                            try {
2398                                    session = openSession();
2399    
2400                                    Query q = session.createQuery(sql);
2401    
2402                                    if (orderByComparator == null) {
2403                                            list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
2404                                                            start, end, false);
2405    
2406                                            Collections.sort(list);
2407                                    }
2408                                    else {
2409                                            list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
2410                                                            start, end);
2411                                    }
2412                            }
2413                            catch (Exception e) {
2414                                    throw processException(e);
2415                            }
2416                            finally {
2417                                    if (list == null) {
2418                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2419                                    }
2420                                    else {
2421                                            cacheResult(list);
2422    
2423                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2424                                    }
2425    
2426                                    closeSession(session);
2427                            }
2428                    }
2429    
2430                    return list;
2431            }
2432    
2433            /**
2434             * Removes all the polls questions where uuid = &#63; from the database.
2435             *
2436             * @param uuid the uuid
2437             * @throws SystemException if a system exception occurred
2438             */
2439            public void removeByUuid(String uuid) throws SystemException {
2440                    for (PollsQuestion pollsQuestion : findByUuid(uuid)) {
2441                            remove(pollsQuestion);
2442                    }
2443            }
2444    
2445            /**
2446             * Removes the polls question where uuid = &#63; and groupId = &#63; from the database.
2447             *
2448             * @param uuid the uuid
2449             * @param groupId the group ID
2450             * @return the polls question that was removed
2451             * @throws SystemException if a system exception occurred
2452             */
2453            public PollsQuestion removeByUUID_G(String uuid, long groupId)
2454                    throws NoSuchQuestionException, SystemException {
2455                    PollsQuestion pollsQuestion = findByUUID_G(uuid, groupId);
2456    
2457                    return remove(pollsQuestion);
2458            }
2459    
2460            /**
2461             * Removes all the polls questions where uuid = &#63; and companyId = &#63; from the database.
2462             *
2463             * @param uuid the uuid
2464             * @param companyId the company ID
2465             * @throws SystemException if a system exception occurred
2466             */
2467            public void removeByUuid_C(String uuid, long companyId)
2468                    throws SystemException {
2469                    for (PollsQuestion pollsQuestion : findByUuid_C(uuid, companyId)) {
2470                            remove(pollsQuestion);
2471                    }
2472            }
2473    
2474            /**
2475             * Removes all the polls questions where groupId = &#63; from the database.
2476             *
2477             * @param groupId the group ID
2478             * @throws SystemException if a system exception occurred
2479             */
2480            public void removeByGroupId(long groupId) throws SystemException {
2481                    for (PollsQuestion pollsQuestion : findByGroupId(groupId)) {
2482                            remove(pollsQuestion);
2483                    }
2484            }
2485    
2486            /**
2487             * Removes all the polls questions from the database.
2488             *
2489             * @throws SystemException if a system exception occurred
2490             */
2491            public void removeAll() throws SystemException {
2492                    for (PollsQuestion pollsQuestion : findAll()) {
2493                            remove(pollsQuestion);
2494                    }
2495            }
2496    
2497            /**
2498             * Returns the number of polls questions where uuid = &#63;.
2499             *
2500             * @param uuid the uuid
2501             * @return the number of matching polls questions
2502             * @throws SystemException if a system exception occurred
2503             */
2504            public int countByUuid(String uuid) throws SystemException {
2505                    Object[] finderArgs = new Object[] { uuid };
2506    
2507                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2508                                    finderArgs, this);
2509    
2510                    if (count == null) {
2511                            StringBundler query = new StringBundler(2);
2512    
2513                            query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
2514    
2515                            if (uuid == null) {
2516                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
2517                            }
2518                            else {
2519                                    if (uuid.equals(StringPool.BLANK)) {
2520                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
2521                                    }
2522                                    else {
2523                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
2524                                    }
2525                            }
2526    
2527                            String sql = query.toString();
2528    
2529                            Session session = null;
2530    
2531                            try {
2532                                    session = openSession();
2533    
2534                                    Query q = session.createQuery(sql);
2535    
2536                                    QueryPos qPos = QueryPos.getInstance(q);
2537    
2538                                    if (uuid != null) {
2539                                            qPos.add(uuid);
2540                                    }
2541    
2542                                    count = (Long)q.uniqueResult();
2543                            }
2544                            catch (Exception e) {
2545                                    throw processException(e);
2546                            }
2547                            finally {
2548                                    if (count == null) {
2549                                            count = Long.valueOf(0);
2550                                    }
2551    
2552                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2553                                            finderArgs, count);
2554    
2555                                    closeSession(session);
2556                            }
2557                    }
2558    
2559                    return count.intValue();
2560            }
2561    
2562            /**
2563             * Returns the number of polls questions where uuid = &#63; and groupId = &#63;.
2564             *
2565             * @param uuid the uuid
2566             * @param groupId the group ID
2567             * @return the number of matching polls questions
2568             * @throws SystemException if a system exception occurred
2569             */
2570            public int countByUUID_G(String uuid, long groupId)
2571                    throws SystemException {
2572                    Object[] finderArgs = new Object[] { uuid, groupId };
2573    
2574                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2575                                    finderArgs, this);
2576    
2577                    if (count == null) {
2578                            StringBundler query = new StringBundler(3);
2579    
2580                            query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
2581    
2582                            if (uuid == null) {
2583                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2584                            }
2585                            else {
2586                                    if (uuid.equals(StringPool.BLANK)) {
2587                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2588                                    }
2589                                    else {
2590                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2591                                    }
2592                            }
2593    
2594                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2595    
2596                            String sql = query.toString();
2597    
2598                            Session session = null;
2599    
2600                            try {
2601                                    session = openSession();
2602    
2603                                    Query q = session.createQuery(sql);
2604    
2605                                    QueryPos qPos = QueryPos.getInstance(q);
2606    
2607                                    if (uuid != null) {
2608                                            qPos.add(uuid);
2609                                    }
2610    
2611                                    qPos.add(groupId);
2612    
2613                                    count = (Long)q.uniqueResult();
2614                            }
2615                            catch (Exception e) {
2616                                    throw processException(e);
2617                            }
2618                            finally {
2619                                    if (count == null) {
2620                                            count = Long.valueOf(0);
2621                                    }
2622    
2623                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2624                                            finderArgs, count);
2625    
2626                                    closeSession(session);
2627                            }
2628                    }
2629    
2630                    return count.intValue();
2631            }
2632    
2633            /**
2634             * Returns the number of polls questions where uuid = &#63; and companyId = &#63;.
2635             *
2636             * @param uuid the uuid
2637             * @param companyId the company ID
2638             * @return the number of matching polls questions
2639             * @throws SystemException if a system exception occurred
2640             */
2641            public int countByUuid_C(String uuid, long companyId)
2642                    throws SystemException {
2643                    Object[] finderArgs = new Object[] { uuid, companyId };
2644    
2645                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_C,
2646                                    finderArgs, this);
2647    
2648                    if (count == null) {
2649                            StringBundler query = new StringBundler(3);
2650    
2651                            query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
2652    
2653                            if (uuid == null) {
2654                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
2655                            }
2656                            else {
2657                                    if (uuid.equals(StringPool.BLANK)) {
2658                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
2659                                    }
2660                                    else {
2661                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
2662                                    }
2663                            }
2664    
2665                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
2666    
2667                            String sql = query.toString();
2668    
2669                            Session session = null;
2670    
2671                            try {
2672                                    session = openSession();
2673    
2674                                    Query q = session.createQuery(sql);
2675    
2676                                    QueryPos qPos = QueryPos.getInstance(q);
2677    
2678                                    if (uuid != null) {
2679                                            qPos.add(uuid);
2680                                    }
2681    
2682                                    qPos.add(companyId);
2683    
2684                                    count = (Long)q.uniqueResult();
2685                            }
2686                            catch (Exception e) {
2687                                    throw processException(e);
2688                            }
2689                            finally {
2690                                    if (count == null) {
2691                                            count = Long.valueOf(0);
2692                                    }
2693    
2694                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_C,
2695                                            finderArgs, count);
2696    
2697                                    closeSession(session);
2698                            }
2699                    }
2700    
2701                    return count.intValue();
2702            }
2703    
2704            /**
2705             * Returns the number of polls questions where groupId = &#63;.
2706             *
2707             * @param groupId the group ID
2708             * @return the number of matching polls questions
2709             * @throws SystemException if a system exception occurred
2710             */
2711            public int countByGroupId(long groupId) throws SystemException {
2712                    Object[] finderArgs = new Object[] { groupId };
2713    
2714                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2715                                    finderArgs, this);
2716    
2717                    if (count == null) {
2718                            StringBundler query = new StringBundler(2);
2719    
2720                            query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
2721    
2722                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2723    
2724                            String sql = query.toString();
2725    
2726                            Session session = null;
2727    
2728                            try {
2729                                    session = openSession();
2730    
2731                                    Query q = session.createQuery(sql);
2732    
2733                                    QueryPos qPos = QueryPos.getInstance(q);
2734    
2735                                    qPos.add(groupId);
2736    
2737                                    count = (Long)q.uniqueResult();
2738                            }
2739                            catch (Exception e) {
2740                                    throw processException(e);
2741                            }
2742                            finally {
2743                                    if (count == null) {
2744                                            count = Long.valueOf(0);
2745                                    }
2746    
2747                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2748                                            finderArgs, count);
2749    
2750                                    closeSession(session);
2751                            }
2752                    }
2753    
2754                    return count.intValue();
2755            }
2756    
2757            /**
2758             * Returns the number of polls questions that the user has permission to view where groupId = &#63;.
2759             *
2760             * @param groupId the group ID
2761             * @return the number of matching polls questions that the user has permission to view
2762             * @throws SystemException if a system exception occurred
2763             */
2764            public int filterCountByGroupId(long groupId) throws SystemException {
2765                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2766                            return countByGroupId(groupId);
2767                    }
2768    
2769                    StringBundler query = new StringBundler(2);
2770    
2771                    query.append(_FILTER_SQL_COUNT_POLLSQUESTION_WHERE);
2772    
2773                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2774    
2775                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2776                                    PollsQuestion.class.getName(),
2777                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2778    
2779                    Session session = null;
2780    
2781                    try {
2782                            session = openSession();
2783    
2784                            SQLQuery q = session.createSQLQuery(sql);
2785    
2786                            q.addScalar(COUNT_COLUMN_NAME,
2787                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2788    
2789                            QueryPos qPos = QueryPos.getInstance(q);
2790    
2791                            qPos.add(groupId);
2792    
2793                            Long count = (Long)q.uniqueResult();
2794    
2795                            return count.intValue();
2796                    }
2797                    catch (Exception e) {
2798                            throw processException(e);
2799                    }
2800                    finally {
2801                            closeSession(session);
2802                    }
2803            }
2804    
2805            /**
2806             * Returns the number of polls questions.
2807             *
2808             * @return the number of polls questions
2809             * @throws SystemException if a system exception occurred
2810             */
2811            public int countAll() throws SystemException {
2812                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2813                                    FINDER_ARGS_EMPTY, this);
2814    
2815                    if (count == null) {
2816                            Session session = null;
2817    
2818                            try {
2819                                    session = openSession();
2820    
2821                                    Query q = session.createQuery(_SQL_COUNT_POLLSQUESTION);
2822    
2823                                    count = (Long)q.uniqueResult();
2824                            }
2825                            catch (Exception e) {
2826                                    throw processException(e);
2827                            }
2828                            finally {
2829                                    if (count == null) {
2830                                            count = Long.valueOf(0);
2831                                    }
2832    
2833                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2834                                            FINDER_ARGS_EMPTY, count);
2835    
2836                                    closeSession(session);
2837                            }
2838                    }
2839    
2840                    return count.intValue();
2841            }
2842    
2843            /**
2844             * Initializes the polls question persistence.
2845             */
2846            public void afterPropertiesSet() {
2847                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2848                                            com.liferay.portal.util.PropsUtil.get(
2849                                                    "value.object.listener.com.liferay.portlet.polls.model.PollsQuestion")));
2850    
2851                    if (listenerClassNames.length > 0) {
2852                            try {
2853                                    List<ModelListener<PollsQuestion>> listenersList = new ArrayList<ModelListener<PollsQuestion>>();
2854    
2855                                    for (String listenerClassName : listenerClassNames) {
2856                                            listenersList.add((ModelListener<PollsQuestion>)InstanceFactory.newInstance(
2857                                                            listenerClassName));
2858                                    }
2859    
2860                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2861                            }
2862                            catch (Exception e) {
2863                                    _log.error(e);
2864                            }
2865                    }
2866            }
2867    
2868            public void destroy() {
2869                    EntityCacheUtil.removeCache(PollsQuestionImpl.class.getName());
2870                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2871                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2872            }
2873    
2874            @BeanReference(type = PollsChoicePersistence.class)
2875            protected PollsChoicePersistence pollsChoicePersistence;
2876            @BeanReference(type = PollsQuestionPersistence.class)
2877            protected PollsQuestionPersistence pollsQuestionPersistence;
2878            @BeanReference(type = PollsVotePersistence.class)
2879            protected PollsVotePersistence pollsVotePersistence;
2880            @BeanReference(type = UserPersistence.class)
2881            protected UserPersistence userPersistence;
2882            private static final String _SQL_SELECT_POLLSQUESTION = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion";
2883            private static final String _SQL_SELECT_POLLSQUESTION_WHERE = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion WHERE ";
2884            private static final String _SQL_COUNT_POLLSQUESTION = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion";
2885            private static final String _SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion WHERE ";
2886            private static final String _FINDER_COLUMN_UUID_UUID_1 = "pollsQuestion.uuid IS NULL";
2887            private static final String _FINDER_COLUMN_UUID_UUID_2 = "pollsQuestion.uuid = ?";
2888            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?)";
2889            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "pollsQuestion.uuid IS NULL AND ";
2890            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "pollsQuestion.uuid = ? AND ";
2891            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?) AND ";
2892            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "pollsQuestion.groupId = ?";
2893            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "pollsQuestion.uuid IS NULL AND ";
2894            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "pollsQuestion.uuid = ? AND ";
2895            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?) AND ";
2896            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "pollsQuestion.companyId = ?";
2897            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "pollsQuestion.groupId = ?";
2898            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "pollsQuestion.questionId";
2899            private static final String _FILTER_SQL_SELECT_POLLSQUESTION_WHERE = "SELECT DISTINCT {pollsQuestion.*} FROM PollsQuestion pollsQuestion WHERE ";
2900            private static final String _FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_1 =
2901                    "SELECT {PollsQuestion.*} FROM (SELECT DISTINCT pollsQuestion.questionId FROM PollsQuestion pollsQuestion WHERE ";
2902            private static final String _FILTER_SQL_SELECT_POLLSQUESTION_NO_INLINE_DISTINCT_WHERE_2 =
2903                    ") TEMP_TABLE INNER JOIN PollsQuestion ON TEMP_TABLE.questionId = PollsQuestion.questionId";
2904            private static final String _FILTER_SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(DISTINCT pollsQuestion.questionId) AS COUNT_VALUE FROM PollsQuestion pollsQuestion WHERE ";
2905            private static final String _FILTER_ENTITY_ALIAS = "pollsQuestion";
2906            private static final String _FILTER_ENTITY_TABLE = "PollsQuestion";
2907            private static final String _ORDER_BY_ENTITY_ALIAS = "pollsQuestion.";
2908            private static final String _ORDER_BY_ENTITY_TABLE = "PollsQuestion.";
2909            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsQuestion exists with the primary key ";
2910            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsQuestion exists with the key {";
2911            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2912            private static Log _log = LogFactoryUtil.getLog(PollsQuestionPersistenceImpl.class);
2913            private static PollsQuestion _nullPollsQuestion = new PollsQuestionImpl() {
2914                            @Override
2915                            public Object clone() {
2916                                    return this;
2917                            }
2918    
2919                            @Override
2920                            public CacheModel<PollsQuestion> toCacheModel() {
2921                                    return _nullPollsQuestionCacheModel;
2922                            }
2923                    };
2924    
2925            private static CacheModel<PollsQuestion> _nullPollsQuestionCacheModel = new CacheModel<PollsQuestion>() {
2926                            public PollsQuestion toEntityModel() {
2927                                    return _nullPollsQuestion;
2928                            }
2929                    };
2930    }