001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.polls.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.model.ModelListener;
037    import com.liferay.portal.service.persistence.BatchSessionUtil;
038    import com.liferay.portal.service.persistence.ResourcePersistence;
039    import com.liferay.portal.service.persistence.UserPersistence;
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    
053    /**
054     * The persistence implementation for the polls vote service.
055     *
056     * <p>
057     * 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.
058     * </p>
059     *
060     * <p>
061     * Caching information and settings can be found in <code>portal.properties</code>
062     * </p>
063     *
064     * @author Brian Wing Shun Chan
065     * @see PollsVotePersistence
066     * @see PollsVoteUtil
067     * @generated
068     */
069    public class PollsVotePersistenceImpl extends BasePersistenceImpl<PollsVote>
070            implements PollsVotePersistence {
071            public static final String FINDER_CLASS_NAME_ENTITY = PollsVoteImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
073                    ".List";
074            public static final FinderPath FINDER_PATH_FIND_BY_QUESTIONID = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
075                            PollsVoteModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
076                            "findByQuestionId",
077                            new String[] {
078                                    Long.class.getName(),
079                                    
080                            "java.lang.Integer", "java.lang.Integer",
081                                    "com.liferay.portal.kernel.util.OrderByComparator"
082                            });
083            public static final FinderPath FINDER_PATH_COUNT_BY_QUESTIONID = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
084                            PollsVoteModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
085                            "countByQuestionId", new String[] { Long.class.getName() });
086            public static final FinderPath FINDER_PATH_FIND_BY_CHOICEID = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
087                            PollsVoteModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
088                            "findByChoiceId",
089                            new String[] {
090                                    Long.class.getName(),
091                                    
092                            "java.lang.Integer", "java.lang.Integer",
093                                    "com.liferay.portal.kernel.util.OrderByComparator"
094                            });
095            public static final FinderPath FINDER_PATH_COUNT_BY_CHOICEID = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
096                            PollsVoteModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
097                            "countByChoiceId", new String[] { Long.class.getName() });
098            public static final FinderPath FINDER_PATH_FETCH_BY_Q_U = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
099                            PollsVoteModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
100                            "fetchByQ_U",
101                            new String[] { Long.class.getName(), Long.class.getName() });
102            public static final FinderPath FINDER_PATH_COUNT_BY_Q_U = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
103                            PollsVoteModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104                            "countByQ_U",
105                            new String[] { Long.class.getName(), Long.class.getName() });
106            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
107                            PollsVoteModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
108                            "findAll", new String[0]);
109            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
110                            PollsVoteModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
111                            "countAll", new String[0]);
112    
113            /**
114             * Caches the polls vote in the entity cache if it is enabled.
115             *
116             * @param pollsVote the polls vote to cache
117             */
118            public void cacheResult(PollsVote pollsVote) {
119                    EntityCacheUtil.putResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
120                            PollsVoteImpl.class, pollsVote.getPrimaryKey(), pollsVote);
121    
122                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
123                            new Object[] {
124                                    new Long(pollsVote.getQuestionId()),
125                                    new Long(pollsVote.getUserId())
126                            }, pollsVote);
127            }
128    
129            /**
130             * Caches the polls votes in the entity cache if it is enabled.
131             *
132             * @param pollsVotes the polls votes to cache
133             */
134            public void cacheResult(List<PollsVote> pollsVotes) {
135                    for (PollsVote pollsVote : pollsVotes) {
136                            if (EntityCacheUtil.getResult(
137                                                    PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
138                                                    PollsVoteImpl.class, pollsVote.getPrimaryKey(), this) == null) {
139                                    cacheResult(pollsVote);
140                            }
141                    }
142            }
143    
144            /**
145             * Clears the cache for all polls votes.
146             *
147             * <p>
148             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
149             * </p>
150             */
151            public void clearCache() {
152                    CacheRegistryUtil.clear(PollsVoteImpl.class.getName());
153                    EntityCacheUtil.clearCache(PollsVoteImpl.class.getName());
154                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
155                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
156            }
157    
158            /**
159             * Clears the cache for the polls vote.
160             *
161             * <p>
162             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
163             * </p>
164             */
165            public void clearCache(PollsVote pollsVote) {
166                    EntityCacheUtil.removeResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
167                            PollsVoteImpl.class, pollsVote.getPrimaryKey());
168    
169                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_U,
170                            new Object[] {
171                                    new Long(pollsVote.getQuestionId()),
172                                    new Long(pollsVote.getUserId())
173                            });
174            }
175    
176            /**
177             * Creates a new polls vote with the primary key. Does not add the polls vote to the database.
178             *
179             * @param voteId the primary key for the new polls vote
180             * @return the new polls vote
181             */
182            public PollsVote create(long voteId) {
183                    PollsVote pollsVote = new PollsVoteImpl();
184    
185                    pollsVote.setNew(true);
186                    pollsVote.setPrimaryKey(voteId);
187    
188                    return pollsVote;
189            }
190    
191            /**
192             * Removes the polls vote with the primary key from the database. Also notifies the appropriate model listeners.
193             *
194             * @param primaryKey the primary key of the polls vote to remove
195             * @return the polls vote that was removed
196             * @throws com.liferay.portal.NoSuchModelException if a polls vote with the primary key could not be found
197             * @throws SystemException if a system exception occurred
198             */
199            public PollsVote remove(Serializable primaryKey)
200                    throws NoSuchModelException, SystemException {
201                    return remove(((Long)primaryKey).longValue());
202            }
203    
204            /**
205             * Removes the polls vote with the primary key from the database. Also notifies the appropriate model listeners.
206             *
207             * @param voteId the primary key of the polls vote to remove
208             * @return the polls vote that was removed
209             * @throws com.liferay.portlet.polls.NoSuchVoteException if a polls vote with the primary key could not be found
210             * @throws SystemException if a system exception occurred
211             */
212            public PollsVote remove(long voteId)
213                    throws NoSuchVoteException, SystemException {
214                    Session session = null;
215    
216                    try {
217                            session = openSession();
218    
219                            PollsVote pollsVote = (PollsVote)session.get(PollsVoteImpl.class,
220                                            new Long(voteId));
221    
222                            if (pollsVote == null) {
223                                    if (_log.isWarnEnabled()) {
224                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + voteId);
225                                    }
226    
227                                    throw new NoSuchVoteException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
228                                            voteId);
229                            }
230    
231                            return remove(pollsVote);
232                    }
233                    catch (NoSuchVoteException nsee) {
234                            throw nsee;
235                    }
236                    catch (Exception e) {
237                            throw processException(e);
238                    }
239                    finally {
240                            closeSession(session);
241                    }
242            }
243    
244            protected PollsVote removeImpl(PollsVote pollsVote)
245                    throws SystemException {
246                    pollsVote = toUnwrappedModel(pollsVote);
247    
248                    Session session = null;
249    
250                    try {
251                            session = openSession();
252    
253                            if (pollsVote.isCachedModel() || BatchSessionUtil.isEnabled()) {
254                                    Object staleObject = session.get(PollsVoteImpl.class,
255                                                    pollsVote.getPrimaryKeyObj());
256    
257                                    if (staleObject != null) {
258                                            session.evict(staleObject);
259                                    }
260                            }
261    
262                            session.delete(pollsVote);
263    
264                            session.flush();
265                    }
266                    catch (Exception e) {
267                            throw processException(e);
268                    }
269                    finally {
270                            closeSession(session);
271                    }
272    
273                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
274    
275                    PollsVoteModelImpl pollsVoteModelImpl = (PollsVoteModelImpl)pollsVote;
276    
277                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_U,
278                            new Object[] {
279                                    new Long(pollsVoteModelImpl.getOriginalQuestionId()),
280                                    new Long(pollsVoteModelImpl.getOriginalUserId())
281                            });
282    
283                    EntityCacheUtil.removeResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
284                            PollsVoteImpl.class, pollsVote.getPrimaryKey());
285    
286                    return pollsVote;
287            }
288    
289            public PollsVote updateImpl(
290                    com.liferay.portlet.polls.model.PollsVote pollsVote, boolean merge)
291                    throws SystemException {
292                    pollsVote = toUnwrappedModel(pollsVote);
293    
294                    boolean isNew = pollsVote.isNew();
295    
296                    PollsVoteModelImpl pollsVoteModelImpl = (PollsVoteModelImpl)pollsVote;
297    
298                    Session session = null;
299    
300                    try {
301                            session = openSession();
302    
303                            BatchSessionUtil.update(session, pollsVote, merge);
304    
305                            pollsVote.setNew(false);
306                    }
307                    catch (Exception e) {
308                            throw processException(e);
309                    }
310                    finally {
311                            closeSession(session);
312                    }
313    
314                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
315    
316                    EntityCacheUtil.putResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
317                            PollsVoteImpl.class, pollsVote.getPrimaryKey(), pollsVote);
318    
319                    if (!isNew &&
320                                    ((pollsVote.getQuestionId() != pollsVoteModelImpl.getOriginalQuestionId()) ||
321                                    (pollsVote.getUserId() != pollsVoteModelImpl.getOriginalUserId()))) {
322                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_Q_U,
323                                    new Object[] {
324                                            new Long(pollsVoteModelImpl.getOriginalQuestionId()),
325                                            new Long(pollsVoteModelImpl.getOriginalUserId())
326                                    });
327                    }
328    
329                    if (isNew ||
330                                    ((pollsVote.getQuestionId() != pollsVoteModelImpl.getOriginalQuestionId()) ||
331                                    (pollsVote.getUserId() != pollsVoteModelImpl.getOriginalUserId()))) {
332                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
333                                    new Object[] {
334                                            new Long(pollsVote.getQuestionId()),
335                                            new Long(pollsVote.getUserId())
336                                    }, pollsVote);
337                    }
338    
339                    return pollsVote;
340            }
341    
342            protected PollsVote toUnwrappedModel(PollsVote pollsVote) {
343                    if (pollsVote instanceof PollsVoteImpl) {
344                            return pollsVote;
345                    }
346    
347                    PollsVoteImpl pollsVoteImpl = new PollsVoteImpl();
348    
349                    pollsVoteImpl.setNew(pollsVote.isNew());
350                    pollsVoteImpl.setPrimaryKey(pollsVote.getPrimaryKey());
351    
352                    pollsVoteImpl.setVoteId(pollsVote.getVoteId());
353                    pollsVoteImpl.setUserId(pollsVote.getUserId());
354                    pollsVoteImpl.setQuestionId(pollsVote.getQuestionId());
355                    pollsVoteImpl.setChoiceId(pollsVote.getChoiceId());
356                    pollsVoteImpl.setVoteDate(pollsVote.getVoteDate());
357    
358                    return pollsVoteImpl;
359            }
360    
361            /**
362             * Finds the polls vote with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
363             *
364             * @param primaryKey the primary key of the polls vote to find
365             * @return the polls vote
366             * @throws com.liferay.portal.NoSuchModelException if a polls vote with the primary key could not be found
367             * @throws SystemException if a system exception occurred
368             */
369            public PollsVote findByPrimaryKey(Serializable primaryKey)
370                    throws NoSuchModelException, SystemException {
371                    return findByPrimaryKey(((Long)primaryKey).longValue());
372            }
373    
374            /**
375             * Finds the polls vote with the primary key or throws a {@link com.liferay.portlet.polls.NoSuchVoteException} if it could not be found.
376             *
377             * @param voteId the primary key of the polls vote to find
378             * @return the polls vote
379             * @throws com.liferay.portlet.polls.NoSuchVoteException if a polls vote with the primary key could not be found
380             * @throws SystemException if a system exception occurred
381             */
382            public PollsVote findByPrimaryKey(long voteId)
383                    throws NoSuchVoteException, SystemException {
384                    PollsVote pollsVote = fetchByPrimaryKey(voteId);
385    
386                    if (pollsVote == null) {
387                            if (_log.isWarnEnabled()) {
388                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + voteId);
389                            }
390    
391                            throw new NoSuchVoteException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
392                                    voteId);
393                    }
394    
395                    return pollsVote;
396            }
397    
398            /**
399             * Finds the polls vote with the primary key or returns <code>null</code> if it could not be found.
400             *
401             * @param primaryKey the primary key of the polls vote to find
402             * @return the polls vote, or <code>null</code> if a polls vote with the primary key could not be found
403             * @throws SystemException if a system exception occurred
404             */
405            public PollsVote fetchByPrimaryKey(Serializable primaryKey)
406                    throws SystemException {
407                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
408            }
409    
410            /**
411             * Finds the polls vote with the primary key or returns <code>null</code> if it could not be found.
412             *
413             * @param voteId the primary key of the polls vote to find
414             * @return the polls vote, or <code>null</code> if a polls vote with the primary key could not be found
415             * @throws SystemException if a system exception occurred
416             */
417            public PollsVote fetchByPrimaryKey(long voteId) throws SystemException {
418                    PollsVote pollsVote = (PollsVote)EntityCacheUtil.getResult(PollsVoteModelImpl.ENTITY_CACHE_ENABLED,
419                                    PollsVoteImpl.class, voteId, this);
420    
421                    if (pollsVote == null) {
422                            Session session = null;
423    
424                            try {
425                                    session = openSession();
426    
427                                    pollsVote = (PollsVote)session.get(PollsVoteImpl.class,
428                                                    new Long(voteId));
429                            }
430                            catch (Exception e) {
431                                    throw processException(e);
432                            }
433                            finally {
434                                    if (pollsVote != null) {
435                                            cacheResult(pollsVote);
436                                    }
437    
438                                    closeSession(session);
439                            }
440                    }
441    
442                    return pollsVote;
443            }
444    
445            /**
446             * Finds all the polls votes where questionId = &#63;.
447             *
448             * @param questionId the question id to search with
449             * @return the matching polls votes
450             * @throws SystemException if a system exception occurred
451             */
452            public List<PollsVote> findByQuestionId(long questionId)
453                    throws SystemException {
454                    return findByQuestionId(questionId, QueryUtil.ALL_POS,
455                            QueryUtil.ALL_POS, null);
456            }
457    
458            /**
459             * Finds a range of all the polls votes where questionId = &#63;.
460             *
461             * <p>
462             * 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.
463             * </p>
464             *
465             * @param questionId the question id to search with
466             * @param start the lower bound of the range of polls votes to return
467             * @param end the upper bound of the range of polls votes to return (not inclusive)
468             * @return the range of matching polls votes
469             * @throws SystemException if a system exception occurred
470             */
471            public List<PollsVote> findByQuestionId(long questionId, int start, int end)
472                    throws SystemException {
473                    return findByQuestionId(questionId, start, end, null);
474            }
475    
476            /**
477             * Finds an ordered range of all the polls votes where questionId = &#63;.
478             *
479             * <p>
480             * 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.
481             * </p>
482             *
483             * @param questionId the question id to search with
484             * @param start the lower bound of the range of polls votes to return
485             * @param end the upper bound of the range of polls votes to return (not inclusive)
486             * @param orderByComparator the comparator to order the results by
487             * @return the ordered range of matching polls votes
488             * @throws SystemException if a system exception occurred
489             */
490            public List<PollsVote> findByQuestionId(long questionId, int start,
491                    int end, OrderByComparator orderByComparator) throws SystemException {
492                    Object[] finderArgs = new Object[] {
493                                    questionId,
494                                    
495                                    String.valueOf(start), String.valueOf(end),
496                                    String.valueOf(orderByComparator)
497                            };
498    
499                    List<PollsVote> list = (List<PollsVote>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_QUESTIONID,
500                                    finderArgs, this);
501    
502                    if (list == null) {
503                            Session session = null;
504    
505                            try {
506                                    session = openSession();
507    
508                                    StringBundler query = null;
509    
510                                    if (orderByComparator != null) {
511                                            query = new StringBundler(3 +
512                                                            (orderByComparator.getOrderByFields().length * 3));
513                                    }
514                                    else {
515                                            query = new StringBundler(2);
516                                    }
517    
518                                    query.append(_SQL_SELECT_POLLSVOTE_WHERE);
519    
520                                    query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
521    
522                                    if (orderByComparator != null) {
523                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
524                                                    orderByComparator);
525                                    }
526    
527                                    String sql = query.toString();
528    
529                                    Query q = session.createQuery(sql);
530    
531                                    QueryPos qPos = QueryPos.getInstance(q);
532    
533                                    qPos.add(questionId);
534    
535                                    list = (List<PollsVote>)QueryUtil.list(q, getDialect(), start,
536                                                    end);
537                            }
538                            catch (Exception e) {
539                                    throw processException(e);
540                            }
541                            finally {
542                                    if (list == null) {
543                                            list = new ArrayList<PollsVote>();
544                                    }
545    
546                                    cacheResult(list);
547    
548                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_QUESTIONID,
549                                            finderArgs, list);
550    
551                                    closeSession(session);
552                            }
553                    }
554    
555                    return list;
556            }
557    
558            /**
559             * Finds the first polls vote in the ordered set where questionId = &#63;.
560             *
561             * <p>
562             * 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.
563             * </p>
564             *
565             * @param questionId the question id to search with
566             * @param orderByComparator the comparator to order the set by
567             * @return the first matching polls vote
568             * @throws com.liferay.portlet.polls.NoSuchVoteException if a matching polls vote could not be found
569             * @throws SystemException if a system exception occurred
570             */
571            public PollsVote findByQuestionId_First(long questionId,
572                    OrderByComparator orderByComparator)
573                    throws NoSuchVoteException, SystemException {
574                    List<PollsVote> list = findByQuestionId(questionId, 0, 1,
575                                    orderByComparator);
576    
577                    if (list.isEmpty()) {
578                            StringBundler msg = new StringBundler(4);
579    
580                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
581    
582                            msg.append("questionId=");
583                            msg.append(questionId);
584    
585                            msg.append(StringPool.CLOSE_CURLY_BRACE);
586    
587                            throw new NoSuchVoteException(msg.toString());
588                    }
589                    else {
590                            return list.get(0);
591                    }
592            }
593    
594            /**
595             * Finds the last polls vote in the ordered set where questionId = &#63;.
596             *
597             * <p>
598             * 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.
599             * </p>
600             *
601             * @param questionId the question id to search with
602             * @param orderByComparator the comparator to order the set by
603             * @return the last matching polls vote
604             * @throws com.liferay.portlet.polls.NoSuchVoteException if a matching polls vote could not be found
605             * @throws SystemException if a system exception occurred
606             */
607            public PollsVote findByQuestionId_Last(long questionId,
608                    OrderByComparator orderByComparator)
609                    throws NoSuchVoteException, SystemException {
610                    int count = countByQuestionId(questionId);
611    
612                    List<PollsVote> list = findByQuestionId(questionId, count - 1, count,
613                                    orderByComparator);
614    
615                    if (list.isEmpty()) {
616                            StringBundler msg = new StringBundler(4);
617    
618                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
619    
620                            msg.append("questionId=");
621                            msg.append(questionId);
622    
623                            msg.append(StringPool.CLOSE_CURLY_BRACE);
624    
625                            throw new NoSuchVoteException(msg.toString());
626                    }
627                    else {
628                            return list.get(0);
629                    }
630            }
631    
632            /**
633             * Finds the polls votes before and after the current polls vote in the ordered set where questionId = &#63;.
634             *
635             * <p>
636             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
637             * </p>
638             *
639             * @param voteId the primary key of the current polls vote
640             * @param questionId the question id to search with
641             * @param orderByComparator the comparator to order the set by
642             * @return the previous, current, and next polls vote
643             * @throws com.liferay.portlet.polls.NoSuchVoteException if a polls vote with the primary key could not be found
644             * @throws SystemException if a system exception occurred
645             */
646            public PollsVote[] findByQuestionId_PrevAndNext(long voteId,
647                    long questionId, OrderByComparator orderByComparator)
648                    throws NoSuchVoteException, SystemException {
649                    PollsVote pollsVote = findByPrimaryKey(voteId);
650    
651                    Session session = null;
652    
653                    try {
654                            session = openSession();
655    
656                            PollsVote[] array = new PollsVoteImpl[3];
657    
658                            array[0] = getByQuestionId_PrevAndNext(session, pollsVote,
659                                            questionId, orderByComparator, true);
660    
661                            array[1] = pollsVote;
662    
663                            array[2] = getByQuestionId_PrevAndNext(session, pollsVote,
664                                            questionId, orderByComparator, false);
665    
666                            return array;
667                    }
668                    catch (Exception e) {
669                            throw processException(e);
670                    }
671                    finally {
672                            closeSession(session);
673                    }
674            }
675    
676            protected PollsVote getByQuestionId_PrevAndNext(Session session,
677                    PollsVote pollsVote, long questionId,
678                    OrderByComparator orderByComparator, boolean previous) {
679                    StringBundler query = null;
680    
681                    if (orderByComparator != null) {
682                            query = new StringBundler(6 +
683                                            (orderByComparator.getOrderByFields().length * 6));
684                    }
685                    else {
686                            query = new StringBundler(3);
687                    }
688    
689                    query.append(_SQL_SELECT_POLLSVOTE_WHERE);
690    
691                    query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
692    
693                    if (orderByComparator != null) {
694                            String[] orderByFields = orderByComparator.getOrderByFields();
695    
696                            if (orderByFields.length > 0) {
697                                    query.append(WHERE_AND);
698                            }
699    
700                            for (int i = 0; i < orderByFields.length; i++) {
701                                    query.append(_ORDER_BY_ENTITY_ALIAS);
702                                    query.append(orderByFields[i]);
703    
704                                    if ((i + 1) < orderByFields.length) {
705                                            if (orderByComparator.isAscending() ^ previous) {
706                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
707                                            }
708                                            else {
709                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
710                                            }
711                                    }
712                                    else {
713                                            if (orderByComparator.isAscending() ^ previous) {
714                                                    query.append(WHERE_GREATER_THAN);
715                                            }
716                                            else {
717                                                    query.append(WHERE_LESSER_THAN);
718                                            }
719                                    }
720                            }
721    
722                            query.append(ORDER_BY_CLAUSE);
723    
724                            for (int i = 0; i < orderByFields.length; i++) {
725                                    query.append(_ORDER_BY_ENTITY_ALIAS);
726                                    query.append(orderByFields[i]);
727    
728                                    if ((i + 1) < orderByFields.length) {
729                                            if (orderByComparator.isAscending() ^ previous) {
730                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
731                                            }
732                                            else {
733                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
734                                            }
735                                    }
736                                    else {
737                                            if (orderByComparator.isAscending() ^ previous) {
738                                                    query.append(ORDER_BY_ASC);
739                                            }
740                                            else {
741                                                    query.append(ORDER_BY_DESC);
742                                            }
743                                    }
744                            }
745                    }
746    
747                    String sql = query.toString();
748    
749                    Query q = session.createQuery(sql);
750    
751                    q.setFirstResult(0);
752                    q.setMaxResults(2);
753    
754                    QueryPos qPos = QueryPos.getInstance(q);
755    
756                    qPos.add(questionId);
757    
758                    if (orderByComparator != null) {
759                            Object[] values = orderByComparator.getOrderByValues(pollsVote);
760    
761                            for (Object value : values) {
762                                    qPos.add(value);
763                            }
764                    }
765    
766                    List<PollsVote> list = q.list();
767    
768                    if (list.size() == 2) {
769                            return list.get(1);
770                    }
771                    else {
772                            return null;
773                    }
774            }
775    
776            /**
777             * Finds all the polls votes where choiceId = &#63;.
778             *
779             * @param choiceId the choice id to search with
780             * @return the matching polls votes
781             * @throws SystemException if a system exception occurred
782             */
783            public List<PollsVote> findByChoiceId(long choiceId)
784                    throws SystemException {
785                    return findByChoiceId(choiceId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
786                            null);
787            }
788    
789            /**
790             * Finds a range of all the polls votes where choiceId = &#63;.
791             *
792             * <p>
793             * 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.
794             * </p>
795             *
796             * @param choiceId the choice id to search with
797             * @param start the lower bound of the range of polls votes to return
798             * @param end the upper bound of the range of polls votes to return (not inclusive)
799             * @return the range of matching polls votes
800             * @throws SystemException if a system exception occurred
801             */
802            public List<PollsVote> findByChoiceId(long choiceId, int start, int end)
803                    throws SystemException {
804                    return findByChoiceId(choiceId, start, end, null);
805            }
806    
807            /**
808             * Finds an ordered range of all the polls votes where choiceId = &#63;.
809             *
810             * <p>
811             * 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.
812             * </p>
813             *
814             * @param choiceId the choice id to search with
815             * @param start the lower bound of the range of polls votes to return
816             * @param end the upper bound of the range of polls votes to return (not inclusive)
817             * @param orderByComparator the comparator to order the results by
818             * @return the ordered range of matching polls votes
819             * @throws SystemException if a system exception occurred
820             */
821            public List<PollsVote> findByChoiceId(long choiceId, int start, int end,
822                    OrderByComparator orderByComparator) throws SystemException {
823                    Object[] finderArgs = new Object[] {
824                                    choiceId,
825                                    
826                                    String.valueOf(start), String.valueOf(end),
827                                    String.valueOf(orderByComparator)
828                            };
829    
830                    List<PollsVote> list = (List<PollsVote>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_CHOICEID,
831                                    finderArgs, this);
832    
833                    if (list == null) {
834                            Session session = null;
835    
836                            try {
837                                    session = openSession();
838    
839                                    StringBundler query = null;
840    
841                                    if (orderByComparator != null) {
842                                            query = new StringBundler(3 +
843                                                            (orderByComparator.getOrderByFields().length * 3));
844                                    }
845                                    else {
846                                            query = new StringBundler(2);
847                                    }
848    
849                                    query.append(_SQL_SELECT_POLLSVOTE_WHERE);
850    
851                                    query.append(_FINDER_COLUMN_CHOICEID_CHOICEID_2);
852    
853                                    if (orderByComparator != null) {
854                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
855                                                    orderByComparator);
856                                    }
857    
858                                    String sql = query.toString();
859    
860                                    Query q = session.createQuery(sql);
861    
862                                    QueryPos qPos = QueryPos.getInstance(q);
863    
864                                    qPos.add(choiceId);
865    
866                                    list = (List<PollsVote>)QueryUtil.list(q, getDialect(), start,
867                                                    end);
868                            }
869                            catch (Exception e) {
870                                    throw processException(e);
871                            }
872                            finally {
873                                    if (list == null) {
874                                            list = new ArrayList<PollsVote>();
875                                    }
876    
877                                    cacheResult(list);
878    
879                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_CHOICEID,
880                                            finderArgs, list);
881    
882                                    closeSession(session);
883                            }
884                    }
885    
886                    return list;
887            }
888    
889            /**
890             * Finds the first polls vote in the ordered set where choiceId = &#63;.
891             *
892             * <p>
893             * 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.
894             * </p>
895             *
896             * @param choiceId the choice id to search with
897             * @param orderByComparator the comparator to order the set by
898             * @return the first matching polls vote
899             * @throws com.liferay.portlet.polls.NoSuchVoteException if a matching polls vote could not be found
900             * @throws SystemException if a system exception occurred
901             */
902            public PollsVote findByChoiceId_First(long choiceId,
903                    OrderByComparator orderByComparator)
904                    throws NoSuchVoteException, SystemException {
905                    List<PollsVote> list = findByChoiceId(choiceId, 0, 1, orderByComparator);
906    
907                    if (list.isEmpty()) {
908                            StringBundler msg = new StringBundler(4);
909    
910                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
911    
912                            msg.append("choiceId=");
913                            msg.append(choiceId);
914    
915                            msg.append(StringPool.CLOSE_CURLY_BRACE);
916    
917                            throw new NoSuchVoteException(msg.toString());
918                    }
919                    else {
920                            return list.get(0);
921                    }
922            }
923    
924            /**
925             * Finds the last polls vote in the ordered set where choiceId = &#63;.
926             *
927             * <p>
928             * 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.
929             * </p>
930             *
931             * @param choiceId the choice id to search with
932             * @param orderByComparator the comparator to order the set by
933             * @return the last matching polls vote
934             * @throws com.liferay.portlet.polls.NoSuchVoteException if a matching polls vote could not be found
935             * @throws SystemException if a system exception occurred
936             */
937            public PollsVote findByChoiceId_Last(long choiceId,
938                    OrderByComparator orderByComparator)
939                    throws NoSuchVoteException, SystemException {
940                    int count = countByChoiceId(choiceId);
941    
942                    List<PollsVote> list = findByChoiceId(choiceId, count - 1, count,
943                                    orderByComparator);
944    
945                    if (list.isEmpty()) {
946                            StringBundler msg = new StringBundler(4);
947    
948                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
949    
950                            msg.append("choiceId=");
951                            msg.append(choiceId);
952    
953                            msg.append(StringPool.CLOSE_CURLY_BRACE);
954    
955                            throw new NoSuchVoteException(msg.toString());
956                    }
957                    else {
958                            return list.get(0);
959                    }
960            }
961    
962            /**
963             * Finds the polls votes before and after the current polls vote in the ordered set where choiceId = &#63;.
964             *
965             * <p>
966             * 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.
967             * </p>
968             *
969             * @param voteId the primary key of the current polls vote
970             * @param choiceId the choice id to search with
971             * @param orderByComparator the comparator to order the set by
972             * @return the previous, current, and next polls vote
973             * @throws com.liferay.portlet.polls.NoSuchVoteException if a polls vote with the primary key could not be found
974             * @throws SystemException if a system exception occurred
975             */
976            public PollsVote[] findByChoiceId_PrevAndNext(long voteId, long choiceId,
977                    OrderByComparator orderByComparator)
978                    throws NoSuchVoteException, SystemException {
979                    PollsVote pollsVote = findByPrimaryKey(voteId);
980    
981                    Session session = null;
982    
983                    try {
984                            session = openSession();
985    
986                            PollsVote[] array = new PollsVoteImpl[3];
987    
988                            array[0] = getByChoiceId_PrevAndNext(session, pollsVote, choiceId,
989                                            orderByComparator, true);
990    
991                            array[1] = pollsVote;
992    
993                            array[2] = getByChoiceId_PrevAndNext(session, pollsVote, choiceId,
994                                            orderByComparator, false);
995    
996                            return array;
997                    }
998                    catch (Exception e) {
999                            throw processException(e);
1000                    }
1001                    finally {
1002                            closeSession(session);
1003                    }
1004            }
1005    
1006            protected PollsVote getByChoiceId_PrevAndNext(Session session,
1007                    PollsVote pollsVote, long choiceId,
1008                    OrderByComparator orderByComparator, boolean previous) {
1009                    StringBundler query = null;
1010    
1011                    if (orderByComparator != null) {
1012                            query = new StringBundler(6 +
1013                                            (orderByComparator.getOrderByFields().length * 6));
1014                    }
1015                    else {
1016                            query = new StringBundler(3);
1017                    }
1018    
1019                    query.append(_SQL_SELECT_POLLSVOTE_WHERE);
1020    
1021                    query.append(_FINDER_COLUMN_CHOICEID_CHOICEID_2);
1022    
1023                    if (orderByComparator != null) {
1024                            String[] orderByFields = orderByComparator.getOrderByFields();
1025    
1026                            if (orderByFields.length > 0) {
1027                                    query.append(WHERE_AND);
1028                            }
1029    
1030                            for (int i = 0; i < orderByFields.length; i++) {
1031                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1032                                    query.append(orderByFields[i]);
1033    
1034                                    if ((i + 1) < orderByFields.length) {
1035                                            if (orderByComparator.isAscending() ^ previous) {
1036                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1037                                            }
1038                                            else {
1039                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1040                                            }
1041                                    }
1042                                    else {
1043                                            if (orderByComparator.isAscending() ^ previous) {
1044                                                    query.append(WHERE_GREATER_THAN);
1045                                            }
1046                                            else {
1047                                                    query.append(WHERE_LESSER_THAN);
1048                                            }
1049                                    }
1050                            }
1051    
1052                            query.append(ORDER_BY_CLAUSE);
1053    
1054                            for (int i = 0; i < orderByFields.length; i++) {
1055                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1056                                    query.append(orderByFields[i]);
1057    
1058                                    if ((i + 1) < orderByFields.length) {
1059                                            if (orderByComparator.isAscending() ^ previous) {
1060                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1061                                            }
1062                                            else {
1063                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1064                                            }
1065                                    }
1066                                    else {
1067                                            if (orderByComparator.isAscending() ^ previous) {
1068                                                    query.append(ORDER_BY_ASC);
1069                                            }
1070                                            else {
1071                                                    query.append(ORDER_BY_DESC);
1072                                            }
1073                                    }
1074                            }
1075                    }
1076    
1077                    String sql = query.toString();
1078    
1079                    Query q = session.createQuery(sql);
1080    
1081                    q.setFirstResult(0);
1082                    q.setMaxResults(2);
1083    
1084                    QueryPos qPos = QueryPos.getInstance(q);
1085    
1086                    qPos.add(choiceId);
1087    
1088                    if (orderByComparator != null) {
1089                            Object[] values = orderByComparator.getOrderByValues(pollsVote);
1090    
1091                            for (Object value : values) {
1092                                    qPos.add(value);
1093                            }
1094                    }
1095    
1096                    List<PollsVote> list = q.list();
1097    
1098                    if (list.size() == 2) {
1099                            return list.get(1);
1100                    }
1101                    else {
1102                            return null;
1103                    }
1104            }
1105    
1106            /**
1107             * Finds the polls vote where questionId = &#63; and userId = &#63; or throws a {@link com.liferay.portlet.polls.NoSuchVoteException} if it could not be found.
1108             *
1109             * @param questionId the question id to search with
1110             * @param userId the user id to search with
1111             * @return the 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 findByQ_U(long questionId, long userId)
1116                    throws NoSuchVoteException, SystemException {
1117                    PollsVote pollsVote = fetchByQ_U(questionId, userId);
1118    
1119                    if (pollsVote == null) {
1120                            StringBundler msg = new StringBundler(6);
1121    
1122                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1123    
1124                            msg.append("questionId=");
1125                            msg.append(questionId);
1126    
1127                            msg.append(", userId=");
1128                            msg.append(userId);
1129    
1130                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1131    
1132                            if (_log.isWarnEnabled()) {
1133                                    _log.warn(msg.toString());
1134                            }
1135    
1136                            throw new NoSuchVoteException(msg.toString());
1137                    }
1138    
1139                    return pollsVote;
1140            }
1141    
1142            /**
1143             * Finds the polls vote where questionId = &#63; and userId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1144             *
1145             * @param questionId the question id to search with
1146             * @param userId the user id to search with
1147             * @return the matching polls vote, or <code>null</code> if a matching polls vote could not be found
1148             * @throws SystemException if a system exception occurred
1149             */
1150            public PollsVote fetchByQ_U(long questionId, long userId)
1151                    throws SystemException {
1152                    return fetchByQ_U(questionId, userId, true);
1153            }
1154    
1155            /**
1156             * Finds 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.
1157             *
1158             * @param questionId the question id to search with
1159             * @param userId the user id to search with
1160             * @return the matching polls vote, or <code>null</code> if a matching polls vote could not be found
1161             * @throws SystemException if a system exception occurred
1162             */
1163            public PollsVote fetchByQ_U(long questionId, long userId,
1164                    boolean retrieveFromCache) throws SystemException {
1165                    Object[] finderArgs = new Object[] { questionId, userId };
1166    
1167                    Object result = null;
1168    
1169                    if (retrieveFromCache) {
1170                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_Q_U,
1171                                            finderArgs, this);
1172                    }
1173    
1174                    if (result == null) {
1175                            Session session = null;
1176    
1177                            try {
1178                                    session = openSession();
1179    
1180                                    StringBundler query = new StringBundler(3);
1181    
1182                                    query.append(_SQL_SELECT_POLLSVOTE_WHERE);
1183    
1184                                    query.append(_FINDER_COLUMN_Q_U_QUESTIONID_2);
1185    
1186                                    query.append(_FINDER_COLUMN_Q_U_USERID_2);
1187    
1188                                    String sql = query.toString();
1189    
1190                                    Query q = session.createQuery(sql);
1191    
1192                                    QueryPos qPos = QueryPos.getInstance(q);
1193    
1194                                    qPos.add(questionId);
1195    
1196                                    qPos.add(userId);
1197    
1198                                    List<PollsVote> list = q.list();
1199    
1200                                    result = list;
1201    
1202                                    PollsVote pollsVote = null;
1203    
1204                                    if (list.isEmpty()) {
1205                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
1206                                                    finderArgs, list);
1207                                    }
1208                                    else {
1209                                            pollsVote = list.get(0);
1210    
1211                                            cacheResult(pollsVote);
1212    
1213                                            if ((pollsVote.getQuestionId() != questionId) ||
1214                                                            (pollsVote.getUserId() != userId)) {
1215                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
1216                                                            finderArgs, pollsVote);
1217                                            }
1218                                    }
1219    
1220                                    return pollsVote;
1221                            }
1222                            catch (Exception e) {
1223                                    throw processException(e);
1224                            }
1225                            finally {
1226                                    if (result == null) {
1227                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_Q_U,
1228                                                    finderArgs, new ArrayList<PollsVote>());
1229                                    }
1230    
1231                                    closeSession(session);
1232                            }
1233                    }
1234                    else {
1235                            if (result instanceof List<?>) {
1236                                    return null;
1237                            }
1238                            else {
1239                                    return (PollsVote)result;
1240                            }
1241                    }
1242            }
1243    
1244            /**
1245             * Finds all the polls votes.
1246             *
1247             * @return the polls votes
1248             * @throws SystemException if a system exception occurred
1249             */
1250            public List<PollsVote> findAll() throws SystemException {
1251                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1252            }
1253    
1254            /**
1255             * Finds a range of all the polls votes.
1256             *
1257             * <p>
1258             * 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.
1259             * </p>
1260             *
1261             * @param start the lower bound of the range of polls votes to return
1262             * @param end the upper bound of the range of polls votes to return (not inclusive)
1263             * @return the range of polls votes
1264             * @throws SystemException if a system exception occurred
1265             */
1266            public List<PollsVote> findAll(int start, int end)
1267                    throws SystemException {
1268                    return findAll(start, end, null);
1269            }
1270    
1271            /**
1272             * Finds an ordered range of all the polls votes.
1273             *
1274             * <p>
1275             * 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.
1276             * </p>
1277             *
1278             * @param start the lower bound of the range of polls votes to return
1279             * @param end the upper bound of the range of polls votes to return (not inclusive)
1280             * @param orderByComparator the comparator to order the results by
1281             * @return the ordered range of polls votes
1282             * @throws SystemException if a system exception occurred
1283             */
1284            public List<PollsVote> findAll(int start, int end,
1285                    OrderByComparator orderByComparator) throws SystemException {
1286                    Object[] finderArgs = new Object[] {
1287                                    String.valueOf(start), String.valueOf(end),
1288                                    String.valueOf(orderByComparator)
1289                            };
1290    
1291                    List<PollsVote> list = (List<PollsVote>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1292                                    finderArgs, this);
1293    
1294                    if (list == null) {
1295                            Session session = null;
1296    
1297                            try {
1298                                    session = openSession();
1299    
1300                                    StringBundler query = null;
1301                                    String sql = null;
1302    
1303                                    if (orderByComparator != null) {
1304                                            query = new StringBundler(2 +
1305                                                            (orderByComparator.getOrderByFields().length * 3));
1306    
1307                                            query.append(_SQL_SELECT_POLLSVOTE);
1308    
1309                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1310                                                    orderByComparator);
1311    
1312                                            sql = query.toString();
1313                                    }
1314                                    else {
1315                                            sql = _SQL_SELECT_POLLSVOTE;
1316                                    }
1317    
1318                                    Query q = session.createQuery(sql);
1319    
1320                                    if (orderByComparator == null) {
1321                                            list = (List<PollsVote>)QueryUtil.list(q, getDialect(),
1322                                                            start, end, false);
1323    
1324                                            Collections.sort(list);
1325                                    }
1326                                    else {
1327                                            list = (List<PollsVote>)QueryUtil.list(q, getDialect(),
1328                                                            start, end);
1329                                    }
1330                            }
1331                            catch (Exception e) {
1332                                    throw processException(e);
1333                            }
1334                            finally {
1335                                    if (list == null) {
1336                                            list = new ArrayList<PollsVote>();
1337                                    }
1338    
1339                                    cacheResult(list);
1340    
1341                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1342    
1343                                    closeSession(session);
1344                            }
1345                    }
1346    
1347                    return list;
1348            }
1349    
1350            /**
1351             * Removes all the polls votes where questionId = &#63; from the database.
1352             *
1353             * @param questionId the question id to search with
1354             * @throws SystemException if a system exception occurred
1355             */
1356            public void removeByQuestionId(long questionId) throws SystemException {
1357                    for (PollsVote pollsVote : findByQuestionId(questionId)) {
1358                            remove(pollsVote);
1359                    }
1360            }
1361    
1362            /**
1363             * Removes all the polls votes where choiceId = &#63; from the database.
1364             *
1365             * @param choiceId the choice id to search with
1366             * @throws SystemException if a system exception occurred
1367             */
1368            public void removeByChoiceId(long choiceId) throws SystemException {
1369                    for (PollsVote pollsVote : findByChoiceId(choiceId)) {
1370                            remove(pollsVote);
1371                    }
1372            }
1373    
1374            /**
1375             * Removes the polls vote where questionId = &#63; and userId = &#63; from the database.
1376             *
1377             * @param questionId the question id to search with
1378             * @param userId the user id to search with
1379             * @throws SystemException if a system exception occurred
1380             */
1381            public void removeByQ_U(long questionId, long userId)
1382                    throws NoSuchVoteException, SystemException {
1383                    PollsVote pollsVote = findByQ_U(questionId, userId);
1384    
1385                    remove(pollsVote);
1386            }
1387    
1388            /**
1389             * Removes all the polls votes from the database.
1390             *
1391             * @throws SystemException if a system exception occurred
1392             */
1393            public void removeAll() throws SystemException {
1394                    for (PollsVote pollsVote : findAll()) {
1395                            remove(pollsVote);
1396                    }
1397            }
1398    
1399            /**
1400             * Counts all the polls votes where questionId = &#63;.
1401             *
1402             * @param questionId the question id to search with
1403             * @return the number of matching polls votes
1404             * @throws SystemException if a system exception occurred
1405             */
1406            public int countByQuestionId(long questionId) throws SystemException {
1407                    Object[] finderArgs = new Object[] { questionId };
1408    
1409                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1410                                    finderArgs, this);
1411    
1412                    if (count == null) {
1413                            Session session = null;
1414    
1415                            try {
1416                                    session = openSession();
1417    
1418                                    StringBundler query = new StringBundler(2);
1419    
1420                                    query.append(_SQL_COUNT_POLLSVOTE_WHERE);
1421    
1422                                    query.append(_FINDER_COLUMN_QUESTIONID_QUESTIONID_2);
1423    
1424                                    String sql = query.toString();
1425    
1426                                    Query q = session.createQuery(sql);
1427    
1428                                    QueryPos qPos = QueryPos.getInstance(q);
1429    
1430                                    qPos.add(questionId);
1431    
1432                                    count = (Long)q.uniqueResult();
1433                            }
1434                            catch (Exception e) {
1435                                    throw processException(e);
1436                            }
1437                            finally {
1438                                    if (count == null) {
1439                                            count = Long.valueOf(0);
1440                                    }
1441    
1442                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_QUESTIONID,
1443                                            finderArgs, count);
1444    
1445                                    closeSession(session);
1446                            }
1447                    }
1448    
1449                    return count.intValue();
1450            }
1451    
1452            /**
1453             * Counts all the polls votes where choiceId = &#63;.
1454             *
1455             * @param choiceId the choice id to search with
1456             * @return the number of matching polls votes
1457             * @throws SystemException if a system exception occurred
1458             */
1459            public int countByChoiceId(long choiceId) throws SystemException {
1460                    Object[] finderArgs = new Object[] { choiceId };
1461    
1462                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CHOICEID,
1463                                    finderArgs, this);
1464    
1465                    if (count == null) {
1466                            Session session = null;
1467    
1468                            try {
1469                                    session = openSession();
1470    
1471                                    StringBundler query = new StringBundler(2);
1472    
1473                                    query.append(_SQL_COUNT_POLLSVOTE_WHERE);
1474    
1475                                    query.append(_FINDER_COLUMN_CHOICEID_CHOICEID_2);
1476    
1477                                    String sql = query.toString();
1478    
1479                                    Query q = session.createQuery(sql);
1480    
1481                                    QueryPos qPos = QueryPos.getInstance(q);
1482    
1483                                    qPos.add(choiceId);
1484    
1485                                    count = (Long)q.uniqueResult();
1486                            }
1487                            catch (Exception e) {
1488                                    throw processException(e);
1489                            }
1490                            finally {
1491                                    if (count == null) {
1492                                            count = Long.valueOf(0);
1493                                    }
1494    
1495                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CHOICEID,
1496                                            finderArgs, count);
1497    
1498                                    closeSession(session);
1499                            }
1500                    }
1501    
1502                    return count.intValue();
1503            }
1504    
1505            /**
1506             * Counts all the polls votes where questionId = &#63; and userId = &#63;.
1507             *
1508             * @param questionId the question id to search with
1509             * @param userId the user id to search with
1510             * @return the number of matching polls votes
1511             * @throws SystemException if a system exception occurred
1512             */
1513            public int countByQ_U(long questionId, long userId)
1514                    throws SystemException {
1515                    Object[] finderArgs = new Object[] { questionId, userId };
1516    
1517                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_Q_U,
1518                                    finderArgs, this);
1519    
1520                    if (count == null) {
1521                            Session session = null;
1522    
1523                            try {
1524                                    session = openSession();
1525    
1526                                    StringBundler query = new StringBundler(3);
1527    
1528                                    query.append(_SQL_COUNT_POLLSVOTE_WHERE);
1529    
1530                                    query.append(_FINDER_COLUMN_Q_U_QUESTIONID_2);
1531    
1532                                    query.append(_FINDER_COLUMN_Q_U_USERID_2);
1533    
1534                                    String sql = query.toString();
1535    
1536                                    Query q = session.createQuery(sql);
1537    
1538                                    QueryPos qPos = QueryPos.getInstance(q);
1539    
1540                                    qPos.add(questionId);
1541    
1542                                    qPos.add(userId);
1543    
1544                                    count = (Long)q.uniqueResult();
1545                            }
1546                            catch (Exception e) {
1547                                    throw processException(e);
1548                            }
1549                            finally {
1550                                    if (count == null) {
1551                                            count = Long.valueOf(0);
1552                                    }
1553    
1554                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_Q_U, finderArgs,
1555                                            count);
1556    
1557                                    closeSession(session);
1558                            }
1559                    }
1560    
1561                    return count.intValue();
1562            }
1563    
1564            /**
1565             * Counts all the polls votes.
1566             *
1567             * @return the number of polls votes
1568             * @throws SystemException if a system exception occurred
1569             */
1570            public int countAll() throws SystemException {
1571                    Object[] finderArgs = new Object[0];
1572    
1573                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1574                                    finderArgs, this);
1575    
1576                    if (count == null) {
1577                            Session session = null;
1578    
1579                            try {
1580                                    session = openSession();
1581    
1582                                    Query q = session.createQuery(_SQL_COUNT_POLLSVOTE);
1583    
1584                                    count = (Long)q.uniqueResult();
1585                            }
1586                            catch (Exception e) {
1587                                    throw processException(e);
1588                            }
1589                            finally {
1590                                    if (count == null) {
1591                                            count = Long.valueOf(0);
1592                                    }
1593    
1594                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1595                                            count);
1596    
1597                                    closeSession(session);
1598                            }
1599                    }
1600    
1601                    return count.intValue();
1602            }
1603    
1604            /**
1605             * Initializes the polls vote persistence.
1606             */
1607            public void afterPropertiesSet() {
1608                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1609                                            com.liferay.portal.util.PropsUtil.get(
1610                                                    "value.object.listener.com.liferay.portlet.polls.model.PollsVote")));
1611    
1612                    if (listenerClassNames.length > 0) {
1613                            try {
1614                                    List<ModelListener<PollsVote>> listenersList = new ArrayList<ModelListener<PollsVote>>();
1615    
1616                                    for (String listenerClassName : listenerClassNames) {
1617                                            listenersList.add((ModelListener<PollsVote>)InstanceFactory.newInstance(
1618                                                            listenerClassName));
1619                                    }
1620    
1621                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1622                            }
1623                            catch (Exception e) {
1624                                    _log.error(e);
1625                            }
1626                    }
1627            }
1628    
1629            @BeanReference(type = PollsChoicePersistence.class)
1630            protected PollsChoicePersistence pollsChoicePersistence;
1631            @BeanReference(type = PollsQuestionPersistence.class)
1632            protected PollsQuestionPersistence pollsQuestionPersistence;
1633            @BeanReference(type = PollsVotePersistence.class)
1634            protected PollsVotePersistence pollsVotePersistence;
1635            @BeanReference(type = ResourcePersistence.class)
1636            protected ResourcePersistence resourcePersistence;
1637            @BeanReference(type = UserPersistence.class)
1638            protected UserPersistence userPersistence;
1639            private static final String _SQL_SELECT_POLLSVOTE = "SELECT pollsVote FROM PollsVote pollsVote";
1640            private static final String _SQL_SELECT_POLLSVOTE_WHERE = "SELECT pollsVote FROM PollsVote pollsVote WHERE ";
1641            private static final String _SQL_COUNT_POLLSVOTE = "SELECT COUNT(pollsVote) FROM PollsVote pollsVote";
1642            private static final String _SQL_COUNT_POLLSVOTE_WHERE = "SELECT COUNT(pollsVote) FROM PollsVote pollsVote WHERE ";
1643            private static final String _FINDER_COLUMN_QUESTIONID_QUESTIONID_2 = "pollsVote.questionId = ?";
1644            private static final String _FINDER_COLUMN_CHOICEID_CHOICEID_2 = "pollsVote.choiceId = ?";
1645            private static final String _FINDER_COLUMN_Q_U_QUESTIONID_2 = "pollsVote.questionId = ? AND ";
1646            private static final String _FINDER_COLUMN_Q_U_USERID_2 = "pollsVote.userId = ?";
1647            private static final String _ORDER_BY_ENTITY_ALIAS = "pollsVote.";
1648            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsVote exists with the primary key ";
1649            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsVote exists with the key {";
1650            private static Log _log = LogFactoryUtil.getLog(PollsVotePersistenceImpl.class);
1651    }