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