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