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