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.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041    import com.liferay.portal.service.persistence.BatchSessionUtil;
042    import com.liferay.portal.service.persistence.ResourcePersistence;
043    import com.liferay.portal.service.persistence.UserPersistence;
044    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045    
046    import com.liferay.portlet.polls.NoSuchQuestionException;
047    import com.liferay.portlet.polls.model.PollsQuestion;
048    import com.liferay.portlet.polls.model.impl.PollsQuestionImpl;
049    import com.liferay.portlet.polls.model.impl.PollsQuestionModelImpl;
050    
051    import java.io.Serializable;
052    
053    import java.util.ArrayList;
054    import java.util.Collections;
055    import java.util.List;
056    
057    /**
058     * @author    Brian Wing Shun Chan
059     * @see       PollsQuestionPersistence
060     * @see       PollsQuestionUtil
061     * @generated
062     */
063    public class PollsQuestionPersistenceImpl extends BasePersistenceImpl<PollsQuestion>
064            implements PollsQuestionPersistence {
065            public static final String FINDER_CLASS_NAME_ENTITY = PollsQuestionImpl.class.getName();
066            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
067                    ".List";
068            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
069                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
070                            FINDER_CLASS_NAME_LIST, "findByUuid",
071                            new String[] {
072                                    String.class.getName(),
073                                    
074                            "java.lang.Integer", "java.lang.Integer",
075                                    "com.liferay.portal.kernel.util.OrderByComparator"
076                            });
077            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
078                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
079                            FINDER_CLASS_NAME_LIST, "countByUuid",
080                            new String[] { String.class.getName() });
081            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
082                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
083                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
084                            new String[] { String.class.getName(), Long.class.getName() });
085            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
086                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
087                            FINDER_CLASS_NAME_LIST, "countByUUID_G",
088                            new String[] { String.class.getName(), Long.class.getName() });
089            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
090                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
091                            FINDER_CLASS_NAME_LIST, "findByGroupId",
092                            new String[] {
093                                    Long.class.getName(),
094                                    
095                            "java.lang.Integer", "java.lang.Integer",
096                                    "com.liferay.portal.kernel.util.OrderByComparator"
097                            });
098            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
099                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
100                            FINDER_CLASS_NAME_LIST, "countByGroupId",
101                            new String[] { Long.class.getName() });
102            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
103                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
104                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
105            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
106                            PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
107                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
108    
109            public void cacheResult(PollsQuestion pollsQuestion) {
110                    EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
111                            PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
112                            pollsQuestion);
113    
114                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
115                            new Object[] {
116                                    pollsQuestion.getUuid(), new Long(pollsQuestion.getGroupId())
117                            }, pollsQuestion);
118            }
119    
120            public void cacheResult(List<PollsQuestion> pollsQuestions) {
121                    for (PollsQuestion pollsQuestion : pollsQuestions) {
122                            if (EntityCacheUtil.getResult(
123                                                    PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
124                                                    PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
125                                                    this) == null) {
126                                    cacheResult(pollsQuestion);
127                            }
128                    }
129            }
130    
131            public void clearCache() {
132                    CacheRegistryUtil.clear(PollsQuestionImpl.class.getName());
133                    EntityCacheUtil.clearCache(PollsQuestionImpl.class.getName());
134                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
135                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
136            }
137    
138            public void clearCache(PollsQuestion pollsQuestion) {
139                    EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
140                            PollsQuestionImpl.class, pollsQuestion.getPrimaryKey());
141    
142                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
143                            new Object[] {
144                                    pollsQuestion.getUuid(), new Long(pollsQuestion.getGroupId())
145                            });
146            }
147    
148            public PollsQuestion create(long questionId) {
149                    PollsQuestion pollsQuestion = new PollsQuestionImpl();
150    
151                    pollsQuestion.setNew(true);
152                    pollsQuestion.setPrimaryKey(questionId);
153    
154                    String uuid = PortalUUIDUtil.generate();
155    
156                    pollsQuestion.setUuid(uuid);
157    
158                    return pollsQuestion;
159            }
160    
161            public PollsQuestion remove(Serializable primaryKey)
162                    throws NoSuchModelException, SystemException {
163                    return remove(((Long)primaryKey).longValue());
164            }
165    
166            public PollsQuestion remove(long questionId)
167                    throws NoSuchQuestionException, SystemException {
168                    Session session = null;
169    
170                    try {
171                            session = openSession();
172    
173                            PollsQuestion pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
174                                            new Long(questionId));
175    
176                            if (pollsQuestion == null) {
177                                    if (_log.isWarnEnabled()) {
178                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + questionId);
179                                    }
180    
181                                    throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
182                                            questionId);
183                            }
184    
185                            return remove(pollsQuestion);
186                    }
187                    catch (NoSuchQuestionException nsee) {
188                            throw nsee;
189                    }
190                    catch (Exception e) {
191                            throw processException(e);
192                    }
193                    finally {
194                            closeSession(session);
195                    }
196            }
197    
198            protected PollsQuestion removeImpl(PollsQuestion pollsQuestion)
199                    throws SystemException {
200                    pollsQuestion = toUnwrappedModel(pollsQuestion);
201    
202                    Session session = null;
203    
204                    try {
205                            session = openSession();
206    
207                            if (pollsQuestion.isCachedModel() || BatchSessionUtil.isEnabled()) {
208                                    Object staleObject = session.get(PollsQuestionImpl.class,
209                                                    pollsQuestion.getPrimaryKeyObj());
210    
211                                    if (staleObject != null) {
212                                            session.evict(staleObject);
213                                    }
214                            }
215    
216                            session.delete(pollsQuestion);
217    
218                            session.flush();
219                    }
220                    catch (Exception e) {
221                            throw processException(e);
222                    }
223                    finally {
224                            closeSession(session);
225                    }
226    
227                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
228    
229                    PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
230    
231                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
232                            new Object[] {
233                                    pollsQuestionModelImpl.getOriginalUuid(),
234                                    new Long(pollsQuestionModelImpl.getOriginalGroupId())
235                            });
236    
237                    EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
238                            PollsQuestionImpl.class, pollsQuestion.getPrimaryKey());
239    
240                    return pollsQuestion;
241            }
242    
243            public PollsQuestion updateImpl(
244                    com.liferay.portlet.polls.model.PollsQuestion pollsQuestion,
245                    boolean merge) throws SystemException {
246                    pollsQuestion = toUnwrappedModel(pollsQuestion);
247    
248                    boolean isNew = pollsQuestion.isNew();
249    
250                    PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
251    
252                    if (Validator.isNull(pollsQuestion.getUuid())) {
253                            String uuid = PortalUUIDUtil.generate();
254    
255                            pollsQuestion.setUuid(uuid);
256                    }
257    
258                    Session session = null;
259    
260                    try {
261                            session = openSession();
262    
263                            BatchSessionUtil.update(session, pollsQuestion, merge);
264    
265                            pollsQuestion.setNew(false);
266                    }
267                    catch (Exception e) {
268                            throw processException(e);
269                    }
270                    finally {
271                            closeSession(session);
272                    }
273    
274                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
275    
276                    EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
277                            PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
278                            pollsQuestion);
279    
280                    if (!isNew &&
281                                    (!Validator.equals(pollsQuestion.getUuid(),
282                                            pollsQuestionModelImpl.getOriginalUuid()) ||
283                                    (pollsQuestion.getGroupId() != pollsQuestionModelImpl.getOriginalGroupId()))) {
284                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
285                                    new Object[] {
286                                            pollsQuestionModelImpl.getOriginalUuid(),
287                                            new Long(pollsQuestionModelImpl.getOriginalGroupId())
288                                    });
289                    }
290    
291                    if (isNew ||
292                                    (!Validator.equals(pollsQuestion.getUuid(),
293                                            pollsQuestionModelImpl.getOriginalUuid()) ||
294                                    (pollsQuestion.getGroupId() != pollsQuestionModelImpl.getOriginalGroupId()))) {
295                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
296                                    new Object[] {
297                                            pollsQuestion.getUuid(),
298                                            new Long(pollsQuestion.getGroupId())
299                                    }, pollsQuestion);
300                    }
301    
302                    return pollsQuestion;
303            }
304    
305            protected PollsQuestion toUnwrappedModel(PollsQuestion pollsQuestion) {
306                    if (pollsQuestion instanceof PollsQuestionImpl) {
307                            return pollsQuestion;
308                    }
309    
310                    PollsQuestionImpl pollsQuestionImpl = new PollsQuestionImpl();
311    
312                    pollsQuestionImpl.setNew(pollsQuestion.isNew());
313                    pollsQuestionImpl.setPrimaryKey(pollsQuestion.getPrimaryKey());
314    
315                    pollsQuestionImpl.setUuid(pollsQuestion.getUuid());
316                    pollsQuestionImpl.setQuestionId(pollsQuestion.getQuestionId());
317                    pollsQuestionImpl.setGroupId(pollsQuestion.getGroupId());
318                    pollsQuestionImpl.setCompanyId(pollsQuestion.getCompanyId());
319                    pollsQuestionImpl.setUserId(pollsQuestion.getUserId());
320                    pollsQuestionImpl.setUserName(pollsQuestion.getUserName());
321                    pollsQuestionImpl.setCreateDate(pollsQuestion.getCreateDate());
322                    pollsQuestionImpl.setModifiedDate(pollsQuestion.getModifiedDate());
323                    pollsQuestionImpl.setTitle(pollsQuestion.getTitle());
324                    pollsQuestionImpl.setDescription(pollsQuestion.getDescription());
325                    pollsQuestionImpl.setExpirationDate(pollsQuestion.getExpirationDate());
326                    pollsQuestionImpl.setLastVoteDate(pollsQuestion.getLastVoteDate());
327    
328                    return pollsQuestionImpl;
329            }
330    
331            public PollsQuestion findByPrimaryKey(Serializable primaryKey)
332                    throws NoSuchModelException, SystemException {
333                    return findByPrimaryKey(((Long)primaryKey).longValue());
334            }
335    
336            public PollsQuestion findByPrimaryKey(long questionId)
337                    throws NoSuchQuestionException, SystemException {
338                    PollsQuestion pollsQuestion = fetchByPrimaryKey(questionId);
339    
340                    if (pollsQuestion == null) {
341                            if (_log.isWarnEnabled()) {
342                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + questionId);
343                            }
344    
345                            throw new NoSuchQuestionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
346                                    questionId);
347                    }
348    
349                    return pollsQuestion;
350            }
351    
352            public PollsQuestion fetchByPrimaryKey(Serializable primaryKey)
353                    throws SystemException {
354                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
355            }
356    
357            public PollsQuestion fetchByPrimaryKey(long questionId)
358                    throws SystemException {
359                    PollsQuestion pollsQuestion = (PollsQuestion)EntityCacheUtil.getResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
360                                    PollsQuestionImpl.class, questionId, this);
361    
362                    if (pollsQuestion == null) {
363                            Session session = null;
364    
365                            try {
366                                    session = openSession();
367    
368                                    pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
369                                                    new Long(questionId));
370                            }
371                            catch (Exception e) {
372                                    throw processException(e);
373                            }
374                            finally {
375                                    if (pollsQuestion != null) {
376                                            cacheResult(pollsQuestion);
377                                    }
378    
379                                    closeSession(session);
380                            }
381                    }
382    
383                    return pollsQuestion;
384            }
385    
386            public List<PollsQuestion> findByUuid(String uuid)
387                    throws SystemException {
388                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
389            }
390    
391            public List<PollsQuestion> findByUuid(String uuid, int start, int end)
392                    throws SystemException {
393                    return findByUuid(uuid, start, end, null);
394            }
395    
396            public List<PollsQuestion> findByUuid(String uuid, int start, int end,
397                    OrderByComparator orderByComparator) throws SystemException {
398                    Object[] finderArgs = new Object[] {
399                                    uuid,
400                                    
401                                    String.valueOf(start), String.valueOf(end),
402                                    String.valueOf(orderByComparator)
403                            };
404    
405                    List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
406                                    finderArgs, this);
407    
408                    if (list == null) {
409                            Session session = null;
410    
411                            try {
412                                    session = openSession();
413    
414                                    StringBundler query = null;
415    
416                                    if (orderByComparator != null) {
417                                            query = new StringBundler(3 +
418                                                            (orderByComparator.getOrderByFields().length * 3));
419                                    }
420                                    else {
421                                            query = new StringBundler(3);
422                                    }
423    
424                                    query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
425    
426                                    if (uuid == null) {
427                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
428                                    }
429                                    else {
430                                            if (uuid.equals(StringPool.BLANK)) {
431                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
432                                            }
433                                            else {
434                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
435                                            }
436                                    }
437    
438                                    if (orderByComparator != null) {
439                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
440                                                    orderByComparator);
441                                    }
442    
443                                    else {
444                                            query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
445                                    }
446    
447                                    String sql = query.toString();
448    
449                                    Query q = session.createQuery(sql);
450    
451                                    QueryPos qPos = QueryPos.getInstance(q);
452    
453                                    if (uuid != null) {
454                                            qPos.add(uuid);
455                                    }
456    
457                                    list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
458                                                    start, end);
459                            }
460                            catch (Exception e) {
461                                    throw processException(e);
462                            }
463                            finally {
464                                    if (list == null) {
465                                            list = new ArrayList<PollsQuestion>();
466                                    }
467    
468                                    cacheResult(list);
469    
470                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
471                                            list);
472    
473                                    closeSession(session);
474                            }
475                    }
476    
477                    return list;
478            }
479    
480            public PollsQuestion findByUuid_First(String uuid,
481                    OrderByComparator orderByComparator)
482                    throws NoSuchQuestionException, SystemException {
483                    List<PollsQuestion> list = findByUuid(uuid, 0, 1, orderByComparator);
484    
485                    if (list.isEmpty()) {
486                            StringBundler msg = new StringBundler(4);
487    
488                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
489    
490                            msg.append("uuid=");
491                            msg.append(uuid);
492    
493                            msg.append(StringPool.CLOSE_CURLY_BRACE);
494    
495                            throw new NoSuchQuestionException(msg.toString());
496                    }
497                    else {
498                            return list.get(0);
499                    }
500            }
501    
502            public PollsQuestion findByUuid_Last(String uuid,
503                    OrderByComparator orderByComparator)
504                    throws NoSuchQuestionException, SystemException {
505                    int count = countByUuid(uuid);
506    
507                    List<PollsQuestion> list = findByUuid(uuid, count - 1, count,
508                                    orderByComparator);
509    
510                    if (list.isEmpty()) {
511                            StringBundler msg = new StringBundler(4);
512    
513                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
514    
515                            msg.append("uuid=");
516                            msg.append(uuid);
517    
518                            msg.append(StringPool.CLOSE_CURLY_BRACE);
519    
520                            throw new NoSuchQuestionException(msg.toString());
521                    }
522                    else {
523                            return list.get(0);
524                    }
525            }
526    
527            public PollsQuestion[] findByUuid_PrevAndNext(long questionId, String uuid,
528                    OrderByComparator orderByComparator)
529                    throws NoSuchQuestionException, SystemException {
530                    PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
531    
532                    Session session = null;
533    
534                    try {
535                            session = openSession();
536    
537                            PollsQuestion[] array = new PollsQuestionImpl[3];
538    
539                            array[0] = getByUuid_PrevAndNext(session, pollsQuestion, uuid,
540                                            orderByComparator, true);
541    
542                            array[1] = pollsQuestion;
543    
544                            array[2] = getByUuid_PrevAndNext(session, pollsQuestion, uuid,
545                                            orderByComparator, false);
546    
547                            return array;
548                    }
549                    catch (Exception e) {
550                            throw processException(e);
551                    }
552                    finally {
553                            closeSession(session);
554                    }
555            }
556    
557            protected PollsQuestion getByUuid_PrevAndNext(Session session,
558                    PollsQuestion pollsQuestion, String uuid,
559                    OrderByComparator orderByComparator, boolean previous) {
560                    StringBundler query = null;
561    
562                    if (orderByComparator != null) {
563                            query = new StringBundler(6 +
564                                            (orderByComparator.getOrderByFields().length * 6));
565                    }
566                    else {
567                            query = new StringBundler(3);
568                    }
569    
570                    query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
571    
572                    if (uuid == null) {
573                            query.append(_FINDER_COLUMN_UUID_UUID_1);
574                    }
575                    else {
576                            if (uuid.equals(StringPool.BLANK)) {
577                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
578                            }
579                            else {
580                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
581                            }
582                    }
583    
584                    if (orderByComparator != null) {
585                            String[] orderByFields = orderByComparator.getOrderByFields();
586    
587                            if (orderByFields.length > 0) {
588                                    query.append(WHERE_AND);
589                            }
590    
591                            for (int i = 0; i < orderByFields.length; i++) {
592                                    query.append(_ORDER_BY_ENTITY_ALIAS);
593                                    query.append(orderByFields[i]);
594    
595                                    if ((i + 1) < orderByFields.length) {
596                                            if (orderByComparator.isAscending() ^ previous) {
597                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
598                                            }
599                                            else {
600                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
601                                            }
602                                    }
603                                    else {
604                                            if (orderByComparator.isAscending() ^ previous) {
605                                                    query.append(WHERE_GREATER_THAN);
606                                            }
607                                            else {
608                                                    query.append(WHERE_LESSER_THAN);
609                                            }
610                                    }
611                            }
612    
613                            query.append(ORDER_BY_CLAUSE);
614    
615                            for (int i = 0; i < orderByFields.length; i++) {
616                                    query.append(_ORDER_BY_ENTITY_ALIAS);
617                                    query.append(orderByFields[i]);
618    
619                                    if ((i + 1) < orderByFields.length) {
620                                            if (orderByComparator.isAscending() ^ previous) {
621                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
622                                            }
623                                            else {
624                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
625                                            }
626                                    }
627                                    else {
628                                            if (orderByComparator.isAscending() ^ previous) {
629                                                    query.append(ORDER_BY_ASC);
630                                            }
631                                            else {
632                                                    query.append(ORDER_BY_DESC);
633                                            }
634                                    }
635                            }
636                    }
637    
638                    else {
639                            query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
640                    }
641    
642                    String sql = query.toString();
643    
644                    Query q = session.createQuery(sql);
645    
646                    q.setFirstResult(0);
647                    q.setMaxResults(2);
648    
649                    QueryPos qPos = QueryPos.getInstance(q);
650    
651                    if (uuid != null) {
652                            qPos.add(uuid);
653                    }
654    
655                    if (orderByComparator != null) {
656                            Object[] values = orderByComparator.getOrderByValues(pollsQuestion);
657    
658                            for (Object value : values) {
659                                    qPos.add(value);
660                            }
661                    }
662    
663                    List<PollsQuestion> list = q.list();
664    
665                    if (list.size() == 2) {
666                            return list.get(1);
667                    }
668                    else {
669                            return null;
670                    }
671            }
672    
673            public PollsQuestion findByUUID_G(String uuid, long groupId)
674                    throws NoSuchQuestionException, SystemException {
675                    PollsQuestion pollsQuestion = fetchByUUID_G(uuid, groupId);
676    
677                    if (pollsQuestion == null) {
678                            StringBundler msg = new StringBundler(6);
679    
680                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
681    
682                            msg.append("uuid=");
683                            msg.append(uuid);
684    
685                            msg.append(", groupId=");
686                            msg.append(groupId);
687    
688                            msg.append(StringPool.CLOSE_CURLY_BRACE);
689    
690                            if (_log.isWarnEnabled()) {
691                                    _log.warn(msg.toString());
692                            }
693    
694                            throw new NoSuchQuestionException(msg.toString());
695                    }
696    
697                    return pollsQuestion;
698            }
699    
700            public PollsQuestion fetchByUUID_G(String uuid, long groupId)
701                    throws SystemException {
702                    return fetchByUUID_G(uuid, groupId, true);
703            }
704    
705            public PollsQuestion fetchByUUID_G(String uuid, long groupId,
706                    boolean retrieveFromCache) throws SystemException {
707                    Object[] finderArgs = new Object[] { uuid, groupId };
708    
709                    Object result = null;
710    
711                    if (retrieveFromCache) {
712                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
713                                            finderArgs, this);
714                    }
715    
716                    if (result == null) {
717                            Session session = null;
718    
719                            try {
720                                    session = openSession();
721    
722                                    StringBundler query = new StringBundler(4);
723    
724                                    query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
725    
726                                    if (uuid == null) {
727                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
728                                    }
729                                    else {
730                                            if (uuid.equals(StringPool.BLANK)) {
731                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
732                                            }
733                                            else {
734                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
735                                            }
736                                    }
737    
738                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
739    
740                                    query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
741    
742                                    String sql = query.toString();
743    
744                                    Query q = session.createQuery(sql);
745    
746                                    QueryPos qPos = QueryPos.getInstance(q);
747    
748                                    if (uuid != null) {
749                                            qPos.add(uuid);
750                                    }
751    
752                                    qPos.add(groupId);
753    
754                                    List<PollsQuestion> list = q.list();
755    
756                                    result = list;
757    
758                                    PollsQuestion pollsQuestion = null;
759    
760                                    if (list.isEmpty()) {
761                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
762                                                    finderArgs, list);
763                                    }
764                                    else {
765                                            pollsQuestion = list.get(0);
766    
767                                            cacheResult(pollsQuestion);
768    
769                                            if ((pollsQuestion.getUuid() == null) ||
770                                                            !pollsQuestion.getUuid().equals(uuid) ||
771                                                            (pollsQuestion.getGroupId() != groupId)) {
772                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
773                                                            finderArgs, pollsQuestion);
774                                            }
775                                    }
776    
777                                    return pollsQuestion;
778                            }
779                            catch (Exception e) {
780                                    throw processException(e);
781                            }
782                            finally {
783                                    if (result == null) {
784                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
785                                                    finderArgs, new ArrayList<PollsQuestion>());
786                                    }
787    
788                                    closeSession(session);
789                            }
790                    }
791                    else {
792                            if (result instanceof List<?>) {
793                                    return null;
794                            }
795                            else {
796                                    return (PollsQuestion)result;
797                            }
798                    }
799            }
800    
801            public List<PollsQuestion> findByGroupId(long groupId)
802                    throws SystemException {
803                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
804            }
805    
806            public List<PollsQuestion> findByGroupId(long groupId, int start, int end)
807                    throws SystemException {
808                    return findByGroupId(groupId, start, end, null);
809            }
810    
811            public List<PollsQuestion> findByGroupId(long groupId, int start, int end,
812                    OrderByComparator orderByComparator) throws SystemException {
813                    Object[] finderArgs = new Object[] {
814                                    groupId,
815                                    
816                                    String.valueOf(start), String.valueOf(end),
817                                    String.valueOf(orderByComparator)
818                            };
819    
820                    List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
821                                    finderArgs, this);
822    
823                    if (list == null) {
824                            Session session = null;
825    
826                            try {
827                                    session = openSession();
828    
829                                    StringBundler query = null;
830    
831                                    if (orderByComparator != null) {
832                                            query = new StringBundler(3 +
833                                                            (orderByComparator.getOrderByFields().length * 3));
834                                    }
835                                    else {
836                                            query = new StringBundler(3);
837                                    }
838    
839                                    query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
840    
841                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
842    
843                                    if (orderByComparator != null) {
844                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
845                                                    orderByComparator);
846                                    }
847    
848                                    else {
849                                            query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
850                                    }
851    
852                                    String sql = query.toString();
853    
854                                    Query q = session.createQuery(sql);
855    
856                                    QueryPos qPos = QueryPos.getInstance(q);
857    
858                                    qPos.add(groupId);
859    
860                                    list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
861                                                    start, end);
862                            }
863                            catch (Exception e) {
864                                    throw processException(e);
865                            }
866                            finally {
867                                    if (list == null) {
868                                            list = new ArrayList<PollsQuestion>();
869                                    }
870    
871                                    cacheResult(list);
872    
873                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
874                                            finderArgs, list);
875    
876                                    closeSession(session);
877                            }
878                    }
879    
880                    return list;
881            }
882    
883            public PollsQuestion findByGroupId_First(long groupId,
884                    OrderByComparator orderByComparator)
885                    throws NoSuchQuestionException, SystemException {
886                    List<PollsQuestion> list = findByGroupId(groupId, 0, 1,
887                                    orderByComparator);
888    
889                    if (list.isEmpty()) {
890                            StringBundler msg = new StringBundler(4);
891    
892                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
893    
894                            msg.append("groupId=");
895                            msg.append(groupId);
896    
897                            msg.append(StringPool.CLOSE_CURLY_BRACE);
898    
899                            throw new NoSuchQuestionException(msg.toString());
900                    }
901                    else {
902                            return list.get(0);
903                    }
904            }
905    
906            public PollsQuestion findByGroupId_Last(long groupId,
907                    OrderByComparator orderByComparator)
908                    throws NoSuchQuestionException, SystemException {
909                    int count = countByGroupId(groupId);
910    
911                    List<PollsQuestion> list = findByGroupId(groupId, count - 1, count,
912                                    orderByComparator);
913    
914                    if (list.isEmpty()) {
915                            StringBundler msg = new StringBundler(4);
916    
917                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
918    
919                            msg.append("groupId=");
920                            msg.append(groupId);
921    
922                            msg.append(StringPool.CLOSE_CURLY_BRACE);
923    
924                            throw new NoSuchQuestionException(msg.toString());
925                    }
926                    else {
927                            return list.get(0);
928                    }
929            }
930    
931            public PollsQuestion[] findByGroupId_PrevAndNext(long questionId,
932                    long groupId, OrderByComparator orderByComparator)
933                    throws NoSuchQuestionException, SystemException {
934                    PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
935    
936                    Session session = null;
937    
938                    try {
939                            session = openSession();
940    
941                            PollsQuestion[] array = new PollsQuestionImpl[3];
942    
943                            array[0] = getByGroupId_PrevAndNext(session, pollsQuestion,
944                                            groupId, orderByComparator, true);
945    
946                            array[1] = pollsQuestion;
947    
948                            array[2] = getByGroupId_PrevAndNext(session, pollsQuestion,
949                                            groupId, orderByComparator, false);
950    
951                            return array;
952                    }
953                    catch (Exception e) {
954                            throw processException(e);
955                    }
956                    finally {
957                            closeSession(session);
958                    }
959            }
960    
961            protected PollsQuestion getByGroupId_PrevAndNext(Session session,
962                    PollsQuestion pollsQuestion, long groupId,
963                    OrderByComparator orderByComparator, boolean previous) {
964                    StringBundler query = null;
965    
966                    if (orderByComparator != null) {
967                            query = new StringBundler(6 +
968                                            (orderByComparator.getOrderByFields().length * 6));
969                    }
970                    else {
971                            query = new StringBundler(3);
972                    }
973    
974                    query.append(_SQL_SELECT_POLLSQUESTION_WHERE);
975    
976                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
977    
978                    if (orderByComparator != null) {
979                            String[] orderByFields = orderByComparator.getOrderByFields();
980    
981                            if (orderByFields.length > 0) {
982                                    query.append(WHERE_AND);
983                            }
984    
985                            for (int i = 0; i < orderByFields.length; i++) {
986                                    query.append(_ORDER_BY_ENTITY_ALIAS);
987                                    query.append(orderByFields[i]);
988    
989                                    if ((i + 1) < orderByFields.length) {
990                                            if (orderByComparator.isAscending() ^ previous) {
991                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
992                                            }
993                                            else {
994                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
995                                            }
996                                    }
997                                    else {
998                                            if (orderByComparator.isAscending() ^ previous) {
999                                                    query.append(WHERE_GREATER_THAN);
1000                                            }
1001                                            else {
1002                                                    query.append(WHERE_LESSER_THAN);
1003                                            }
1004                                    }
1005                            }
1006    
1007                            query.append(ORDER_BY_CLAUSE);
1008    
1009                            for (int i = 0; i < orderByFields.length; i++) {
1010                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1011                                    query.append(orderByFields[i]);
1012    
1013                                    if ((i + 1) < orderByFields.length) {
1014                                            if (orderByComparator.isAscending() ^ previous) {
1015                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1016                                            }
1017                                            else {
1018                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1019                                            }
1020                                    }
1021                                    else {
1022                                            if (orderByComparator.isAscending() ^ previous) {
1023                                                    query.append(ORDER_BY_ASC);
1024                                            }
1025                                            else {
1026                                                    query.append(ORDER_BY_DESC);
1027                                            }
1028                                    }
1029                            }
1030                    }
1031    
1032                    else {
1033                            query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1034                    }
1035    
1036                    String sql = query.toString();
1037    
1038                    Query q = session.createQuery(sql);
1039    
1040                    q.setFirstResult(0);
1041                    q.setMaxResults(2);
1042    
1043                    QueryPos qPos = QueryPos.getInstance(q);
1044    
1045                    qPos.add(groupId);
1046    
1047                    if (orderByComparator != null) {
1048                            Object[] values = orderByComparator.getOrderByValues(pollsQuestion);
1049    
1050                            for (Object value : values) {
1051                                    qPos.add(value);
1052                            }
1053                    }
1054    
1055                    List<PollsQuestion> list = q.list();
1056    
1057                    if (list.size() == 2) {
1058                            return list.get(1);
1059                    }
1060                    else {
1061                            return null;
1062                    }
1063            }
1064    
1065            public List<PollsQuestion> filterFindByGroupId(long groupId)
1066                    throws SystemException {
1067                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1068                            QueryUtil.ALL_POS, null);
1069            }
1070    
1071            public List<PollsQuestion> filterFindByGroupId(long groupId, int start,
1072                    int end) throws SystemException {
1073                    return filterFindByGroupId(groupId, start, end, null);
1074            }
1075    
1076            public List<PollsQuestion> filterFindByGroupId(long groupId, int start,
1077                    int end, OrderByComparator orderByComparator) throws SystemException {
1078                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1079                            return findByGroupId(groupId, start, end, orderByComparator);
1080                    }
1081    
1082                    Session session = null;
1083    
1084                    try {
1085                            session = openSession();
1086    
1087                            StringBundler query = null;
1088    
1089                            if (orderByComparator != null) {
1090                                    query = new StringBundler(3 +
1091                                                    (orderByComparator.getOrderByFields().length * 3));
1092                            }
1093                            else {
1094                                    query = new StringBundler(3);
1095                            }
1096    
1097                            query.append(_FILTER_SQL_SELECT_POLLSQUESTION_WHERE);
1098    
1099                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1100    
1101                            if (orderByComparator != null) {
1102                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1103                                            orderByComparator);
1104                            }
1105    
1106                            else {
1107                                    query.append(PollsQuestionModelImpl.ORDER_BY_JPQL);
1108                            }
1109    
1110                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1111                                            PollsQuestion.class.getName(), _FILTER_COLUMN_PK,
1112                                            _FILTER_COLUMN_USERID, groupId);
1113    
1114                            SQLQuery q = session.createSQLQuery(sql);
1115    
1116                            q.addEntity(_FILTER_ENTITY_ALIAS, PollsQuestionImpl.class);
1117    
1118                            QueryPos qPos = QueryPos.getInstance(q);
1119    
1120                            qPos.add(groupId);
1121    
1122                            return (List<PollsQuestion>)QueryUtil.list(q, getDialect(), start,
1123                                    end);
1124                    }
1125                    catch (Exception e) {
1126                            throw processException(e);
1127                    }
1128                    finally {
1129                            closeSession(session);
1130                    }
1131            }
1132    
1133            public List<PollsQuestion> findAll() throws SystemException {
1134                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1135            }
1136    
1137            public List<PollsQuestion> findAll(int start, int end)
1138                    throws SystemException {
1139                    return findAll(start, end, null);
1140            }
1141    
1142            public List<PollsQuestion> findAll(int start, int end,
1143                    OrderByComparator orderByComparator) throws SystemException {
1144                    Object[] finderArgs = new Object[] {
1145                                    String.valueOf(start), String.valueOf(end),
1146                                    String.valueOf(orderByComparator)
1147                            };
1148    
1149                    List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1150                                    finderArgs, this);
1151    
1152                    if (list == null) {
1153                            Session session = null;
1154    
1155                            try {
1156                                    session = openSession();
1157    
1158                                    StringBundler query = null;
1159                                    String sql = null;
1160    
1161                                    if (orderByComparator != null) {
1162                                            query = new StringBundler(2 +
1163                                                            (orderByComparator.getOrderByFields().length * 3));
1164    
1165                                            query.append(_SQL_SELECT_POLLSQUESTION);
1166    
1167                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1168                                                    orderByComparator);
1169    
1170                                            sql = query.toString();
1171                                    }
1172                                    else {
1173                                            sql = _SQL_SELECT_POLLSQUESTION.concat(PollsQuestionModelImpl.ORDER_BY_JPQL);
1174                                    }
1175    
1176                                    Query q = session.createQuery(sql);
1177    
1178                                    if (orderByComparator == null) {
1179                                            list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1180                                                            start, end, false);
1181    
1182                                            Collections.sort(list);
1183                                    }
1184                                    else {
1185                                            list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1186                                                            start, end);
1187                                    }
1188                            }
1189                            catch (Exception e) {
1190                                    throw processException(e);
1191                            }
1192                            finally {
1193                                    if (list == null) {
1194                                            list = new ArrayList<PollsQuestion>();
1195                                    }
1196    
1197                                    cacheResult(list);
1198    
1199                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1200    
1201                                    closeSession(session);
1202                            }
1203                    }
1204    
1205                    return list;
1206            }
1207    
1208            public void removeByUuid(String uuid) throws SystemException {
1209                    for (PollsQuestion pollsQuestion : findByUuid(uuid)) {
1210                            remove(pollsQuestion);
1211                    }
1212            }
1213    
1214            public void removeByUUID_G(String uuid, long groupId)
1215                    throws NoSuchQuestionException, SystemException {
1216                    PollsQuestion pollsQuestion = findByUUID_G(uuid, groupId);
1217    
1218                    remove(pollsQuestion);
1219            }
1220    
1221            public void removeByGroupId(long groupId) throws SystemException {
1222                    for (PollsQuestion pollsQuestion : findByGroupId(groupId)) {
1223                            remove(pollsQuestion);
1224                    }
1225            }
1226    
1227            public void removeAll() throws SystemException {
1228                    for (PollsQuestion pollsQuestion : findAll()) {
1229                            remove(pollsQuestion);
1230                    }
1231            }
1232    
1233            public int countByUuid(String uuid) throws SystemException {
1234                    Object[] finderArgs = new Object[] { uuid };
1235    
1236                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1237                                    finderArgs, this);
1238    
1239                    if (count == null) {
1240                            Session session = null;
1241    
1242                            try {
1243                                    session = openSession();
1244    
1245                                    StringBundler query = new StringBundler(2);
1246    
1247                                    query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
1248    
1249                                    if (uuid == null) {
1250                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1251                                    }
1252                                    else {
1253                                            if (uuid.equals(StringPool.BLANK)) {
1254                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1255                                            }
1256                                            else {
1257                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1258                                            }
1259                                    }
1260    
1261                                    String sql = query.toString();
1262    
1263                                    Query q = session.createQuery(sql);
1264    
1265                                    QueryPos qPos = QueryPos.getInstance(q);
1266    
1267                                    if (uuid != null) {
1268                                            qPos.add(uuid);
1269                                    }
1270    
1271                                    count = (Long)q.uniqueResult();
1272                            }
1273                            catch (Exception e) {
1274                                    throw processException(e);
1275                            }
1276                            finally {
1277                                    if (count == null) {
1278                                            count = Long.valueOf(0);
1279                                    }
1280    
1281                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1282                                            finderArgs, count);
1283    
1284                                    closeSession(session);
1285                            }
1286                    }
1287    
1288                    return count.intValue();
1289            }
1290    
1291            public int countByUUID_G(String uuid, long groupId)
1292                    throws SystemException {
1293                    Object[] finderArgs = new Object[] { uuid, groupId };
1294    
1295                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1296                                    finderArgs, this);
1297    
1298                    if (count == null) {
1299                            Session session = null;
1300    
1301                            try {
1302                                    session = openSession();
1303    
1304                                    StringBundler query = new StringBundler(3);
1305    
1306                                    query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
1307    
1308                                    if (uuid == null) {
1309                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1310                                    }
1311                                    else {
1312                                            if (uuid.equals(StringPool.BLANK)) {
1313                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1314                                            }
1315                                            else {
1316                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1317                                            }
1318                                    }
1319    
1320                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1321    
1322                                    String sql = query.toString();
1323    
1324                                    Query q = session.createQuery(sql);
1325    
1326                                    QueryPos qPos = QueryPos.getInstance(q);
1327    
1328                                    if (uuid != null) {
1329                                            qPos.add(uuid);
1330                                    }
1331    
1332                                    qPos.add(groupId);
1333    
1334                                    count = (Long)q.uniqueResult();
1335                            }
1336                            catch (Exception e) {
1337                                    throw processException(e);
1338                            }
1339                            finally {
1340                                    if (count == null) {
1341                                            count = Long.valueOf(0);
1342                                    }
1343    
1344                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1345                                            finderArgs, count);
1346    
1347                                    closeSession(session);
1348                            }
1349                    }
1350    
1351                    return count.intValue();
1352            }
1353    
1354            public int countByGroupId(long groupId) throws SystemException {
1355                    Object[] finderArgs = new Object[] { groupId };
1356    
1357                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1358                                    finderArgs, this);
1359    
1360                    if (count == null) {
1361                            Session session = null;
1362    
1363                            try {
1364                                    session = openSession();
1365    
1366                                    StringBundler query = new StringBundler(2);
1367    
1368                                    query.append(_SQL_COUNT_POLLSQUESTION_WHERE);
1369    
1370                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1371    
1372                                    String sql = query.toString();
1373    
1374                                    Query q = session.createQuery(sql);
1375    
1376                                    QueryPos qPos = QueryPos.getInstance(q);
1377    
1378                                    qPos.add(groupId);
1379    
1380                                    count = (Long)q.uniqueResult();
1381                            }
1382                            catch (Exception e) {
1383                                    throw processException(e);
1384                            }
1385                            finally {
1386                                    if (count == null) {
1387                                            count = Long.valueOf(0);
1388                                    }
1389    
1390                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1391                                            finderArgs, count);
1392    
1393                                    closeSession(session);
1394                            }
1395                    }
1396    
1397                    return count.intValue();
1398            }
1399    
1400            public int filterCountByGroupId(long groupId) throws SystemException {
1401                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1402                            return countByGroupId(groupId);
1403                    }
1404    
1405                    Session session = null;
1406    
1407                    try {
1408                            session = openSession();
1409    
1410                            StringBundler query = new StringBundler(2);
1411    
1412                            query.append(_FILTER_SQL_COUNT_POLLSQUESTION_WHERE);
1413    
1414                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1415    
1416                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1417                                            PollsQuestion.class.getName(), _FILTER_COLUMN_PK,
1418                                            _FILTER_COLUMN_USERID, groupId);
1419    
1420                            SQLQuery q = session.createSQLQuery(sql);
1421    
1422                            q.addScalar(COUNT_COLUMN_NAME,
1423                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1424    
1425                            QueryPos qPos = QueryPos.getInstance(q);
1426    
1427                            qPos.add(groupId);
1428    
1429                            Long count = (Long)q.uniqueResult();
1430    
1431                            return count.intValue();
1432                    }
1433                    catch (Exception e) {
1434                            throw processException(e);
1435                    }
1436                    finally {
1437                            closeSession(session);
1438                    }
1439            }
1440    
1441            public int countAll() throws SystemException {
1442                    Object[] finderArgs = new Object[0];
1443    
1444                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1445                                    finderArgs, this);
1446    
1447                    if (count == null) {
1448                            Session session = null;
1449    
1450                            try {
1451                                    session = openSession();
1452    
1453                                    Query q = session.createQuery(_SQL_COUNT_POLLSQUESTION);
1454    
1455                                    count = (Long)q.uniqueResult();
1456                            }
1457                            catch (Exception e) {
1458                                    throw processException(e);
1459                            }
1460                            finally {
1461                                    if (count == null) {
1462                                            count = Long.valueOf(0);
1463                                    }
1464    
1465                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1466                                            count);
1467    
1468                                    closeSession(session);
1469                            }
1470                    }
1471    
1472                    return count.intValue();
1473            }
1474    
1475            public void afterPropertiesSet() {
1476                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1477                                            com.liferay.portal.util.PropsUtil.get(
1478                                                    "value.object.listener.com.liferay.portlet.polls.model.PollsQuestion")));
1479    
1480                    if (listenerClassNames.length > 0) {
1481                            try {
1482                                    List<ModelListener<PollsQuestion>> listenersList = new ArrayList<ModelListener<PollsQuestion>>();
1483    
1484                                    for (String listenerClassName : listenerClassNames) {
1485                                            listenersList.add((ModelListener<PollsQuestion>)InstanceFactory.newInstance(
1486                                                            listenerClassName));
1487                                    }
1488    
1489                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1490                            }
1491                            catch (Exception e) {
1492                                    _log.error(e);
1493                            }
1494                    }
1495            }
1496    
1497            @BeanReference(type = PollsChoicePersistence.class)
1498            protected PollsChoicePersistence pollsChoicePersistence;
1499            @BeanReference(type = PollsQuestionPersistence.class)
1500            protected PollsQuestionPersistence pollsQuestionPersistence;
1501            @BeanReference(type = PollsVotePersistence.class)
1502            protected PollsVotePersistence pollsVotePersistence;
1503            @BeanReference(type = ResourcePersistence.class)
1504            protected ResourcePersistence resourcePersistence;
1505            @BeanReference(type = UserPersistence.class)
1506            protected UserPersistence userPersistence;
1507            private static final String _SQL_SELECT_POLLSQUESTION = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion";
1508            private static final String _SQL_SELECT_POLLSQUESTION_WHERE = "SELECT pollsQuestion FROM PollsQuestion pollsQuestion WHERE ";
1509            private static final String _SQL_COUNT_POLLSQUESTION = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion";
1510            private static final String _SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion WHERE ";
1511            private static final String _FINDER_COLUMN_UUID_UUID_1 = "pollsQuestion.uuid IS NULL";
1512            private static final String _FINDER_COLUMN_UUID_UUID_2 = "pollsQuestion.uuid = ?";
1513            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?)";
1514            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "pollsQuestion.uuid IS NULL AND ";
1515            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "pollsQuestion.uuid = ? AND ";
1516            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(pollsQuestion.uuid IS NULL OR pollsQuestion.uuid = ?) AND ";
1517            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "pollsQuestion.groupId = ?";
1518            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "pollsQuestion.groupId = ?";
1519            private static final String _FILTER_SQL_SELECT_POLLSQUESTION_WHERE = "SELECT DISTINCT {pollsQuestion.*} FROM PollsQuestion pollsQuestion WHERE ";
1520            private static final String _FILTER_SQL_COUNT_POLLSQUESTION_WHERE = "SELECT COUNT(DISTINCT pollsQuestion.questionId) AS COUNT_VALUE FROM PollsQuestion pollsQuestion WHERE ";
1521            private static final String _FILTER_COLUMN_PK = "pollsQuestion.questionId";
1522            private static final String _FILTER_COLUMN_USERID = "pollsQuestion.userId";
1523            private static final String _FILTER_ENTITY_ALIAS = "pollsQuestion";
1524            private static final String _ORDER_BY_ENTITY_ALIAS = "pollsQuestion.";
1525            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PollsQuestion exists with the primary key ";
1526            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PollsQuestion exists with the key {";
1527            private static Log _log = LogFactoryUtil.getLog(PollsQuestionPersistenceImpl.class);
1528    }