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