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