001    /**
002     * Copyright (c) 2000-present 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.messageboards.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
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.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.ArrayUtil;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.SetUtil;
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.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
040    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041    
042    import com.liferay.portlet.messageboards.NoSuchThreadException;
043    import com.liferay.portlet.messageboards.model.MBThread;
044    import com.liferay.portlet.messageboards.model.impl.MBThreadImpl;
045    import com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl;
046    import com.liferay.portlet.messageboards.service.persistence.MBThreadPersistence;
047    
048    import java.io.Serializable;
049    
050    import java.sql.Timestamp;
051    
052    import java.util.Collections;
053    import java.util.Date;
054    import java.util.HashMap;
055    import java.util.HashSet;
056    import java.util.Iterator;
057    import java.util.List;
058    import java.util.Map;
059    import java.util.Set;
060    
061    /**
062     * The persistence implementation for the message boards thread service.
063     *
064     * <p>
065     * Caching information and settings can be found in <code>portal.properties</code>
066     * </p>
067     *
068     * @author Brian Wing Shun Chan
069     * @see MBThreadPersistence
070     * @see MBThreadUtil
071     * @generated
072     */
073    @ProviderType
074    public class MBThreadPersistenceImpl extends BasePersistenceImpl<MBThread>
075            implements MBThreadPersistence {
076            /*
077             * NOTE FOR DEVELOPERS:
078             *
079             * Never modify or reference this class directly. Always use {@link MBThreadUtil} to access the message boards thread persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
080             */
081            public static final String FINDER_CLASS_NAME_ENTITY = MBThreadImpl.class.getName();
082            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List1";
084            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
085                    ".List2";
086            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
087                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
090                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
092            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
093                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
095            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
096                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
097                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
098                            new String[] {
099                                    String.class.getName(),
100                                    
101                            Integer.class.getName(), Integer.class.getName(),
102                                    OrderByComparator.class.getName()
103                            });
104            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
105                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
107                            new String[] { String.class.getName() },
108                            MBThreadModelImpl.UUID_COLUMN_BITMASK |
109                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
110                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
111            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
112                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
114                            new String[] { String.class.getName() });
115    
116            /**
117             * Returns all the message boards threads where uuid = &#63;.
118             *
119             * @param uuid the uuid
120             * @return the matching message boards threads
121             */
122            @Override
123            public List<MBThread> findByUuid(String uuid) {
124                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
125            }
126    
127            /**
128             * Returns a range of all the message boards threads where uuid = &#63;.
129             *
130             * <p>
131             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
132             * </p>
133             *
134             * @param uuid the uuid
135             * @param start the lower bound of the range of message boards threads
136             * @param end the upper bound of the range of message boards threads (not inclusive)
137             * @return the range of matching message boards threads
138             */
139            @Override
140            public List<MBThread> findByUuid(String uuid, int start, int end) {
141                    return findByUuid(uuid, start, end, null);
142            }
143    
144            /**
145             * Returns an ordered range of all the message boards threads where uuid = &#63;.
146             *
147             * <p>
148             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
149             * </p>
150             *
151             * @param uuid the uuid
152             * @param start the lower bound of the range of message boards threads
153             * @param end the upper bound of the range of message boards threads (not inclusive)
154             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
155             * @return the ordered range of matching message boards threads
156             */
157            @Override
158            public List<MBThread> findByUuid(String uuid, int start, int end,
159                    OrderByComparator<MBThread> orderByComparator) {
160                    boolean pagination = true;
161                    FinderPath finderPath = null;
162                    Object[] finderArgs = null;
163    
164                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
165                                    (orderByComparator == null)) {
166                            pagination = false;
167                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
168                            finderArgs = new Object[] { uuid };
169                    }
170                    else {
171                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
172                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
173                    }
174    
175                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
176                                    finderArgs, this);
177    
178                    if ((list != null) && !list.isEmpty()) {
179                            for (MBThread mbThread : list) {
180                                    if (!Validator.equals(uuid, mbThread.getUuid())) {
181                                            list = null;
182    
183                                            break;
184                                    }
185                            }
186                    }
187    
188                    if (list == null) {
189                            StringBundler query = null;
190    
191                            if (orderByComparator != null) {
192                                    query = new StringBundler(3 +
193                                                    (orderByComparator.getOrderByFields().length * 3));
194                            }
195                            else {
196                                    query = new StringBundler(3);
197                            }
198    
199                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
200    
201                            boolean bindUuid = false;
202    
203                            if (uuid == null) {
204                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
205                            }
206                            else if (uuid.equals(StringPool.BLANK)) {
207                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
208                            }
209                            else {
210                                    bindUuid = true;
211    
212                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
213                            }
214    
215                            if (orderByComparator != null) {
216                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
217                                            orderByComparator);
218                            }
219                            else
220                             if (pagination) {
221                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
222                            }
223    
224                            String sql = query.toString();
225    
226                            Session session = null;
227    
228                            try {
229                                    session = openSession();
230    
231                                    Query q = session.createQuery(sql);
232    
233                                    QueryPos qPos = QueryPos.getInstance(q);
234    
235                                    if (bindUuid) {
236                                            qPos.add(uuid);
237                                    }
238    
239                                    if (!pagination) {
240                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
241                                                            start, end, false);
242    
243                                            Collections.sort(list);
244    
245                                            list = Collections.unmodifiableList(list);
246                                    }
247                                    else {
248                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
249                                                            start, end);
250                                    }
251    
252                                    cacheResult(list);
253    
254                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
255                            }
256                            catch (Exception e) {
257                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
258    
259                                    throw processException(e);
260                            }
261                            finally {
262                                    closeSession(session);
263                            }
264                    }
265    
266                    return list;
267            }
268    
269            /**
270             * Returns the first message boards thread in the ordered set where uuid = &#63;.
271             *
272             * @param uuid the uuid
273             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
274             * @return the first matching message boards thread
275             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
276             */
277            @Override
278            public MBThread findByUuid_First(String uuid,
279                    OrderByComparator<MBThread> orderByComparator)
280                    throws NoSuchThreadException {
281                    MBThread mbThread = fetchByUuid_First(uuid, orderByComparator);
282    
283                    if (mbThread != null) {
284                            return mbThread;
285                    }
286    
287                    StringBundler msg = new StringBundler(4);
288    
289                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
290    
291                    msg.append("uuid=");
292                    msg.append(uuid);
293    
294                    msg.append(StringPool.CLOSE_CURLY_BRACE);
295    
296                    throw new NoSuchThreadException(msg.toString());
297            }
298    
299            /**
300             * Returns the first message boards thread in the ordered set where uuid = &#63;.
301             *
302             * @param uuid the uuid
303             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
304             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
305             */
306            @Override
307            public MBThread fetchByUuid_First(String uuid,
308                    OrderByComparator<MBThread> orderByComparator) {
309                    List<MBThread> list = findByUuid(uuid, 0, 1, orderByComparator);
310    
311                    if (!list.isEmpty()) {
312                            return list.get(0);
313                    }
314    
315                    return null;
316            }
317    
318            /**
319             * Returns the last message boards thread in the ordered set where uuid = &#63;.
320             *
321             * @param uuid the uuid
322             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
323             * @return the last matching message boards thread
324             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
325             */
326            @Override
327            public MBThread findByUuid_Last(String uuid,
328                    OrderByComparator<MBThread> orderByComparator)
329                    throws NoSuchThreadException {
330                    MBThread mbThread = fetchByUuid_Last(uuid, orderByComparator);
331    
332                    if (mbThread != null) {
333                            return mbThread;
334                    }
335    
336                    StringBundler msg = new StringBundler(4);
337    
338                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
339    
340                    msg.append("uuid=");
341                    msg.append(uuid);
342    
343                    msg.append(StringPool.CLOSE_CURLY_BRACE);
344    
345                    throw new NoSuchThreadException(msg.toString());
346            }
347    
348            /**
349             * Returns the last message boards thread in the ordered set where uuid = &#63;.
350             *
351             * @param uuid the uuid
352             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
353             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
354             */
355            @Override
356            public MBThread fetchByUuid_Last(String uuid,
357                    OrderByComparator<MBThread> orderByComparator) {
358                    int count = countByUuid(uuid);
359    
360                    if (count == 0) {
361                            return null;
362                    }
363    
364                    List<MBThread> list = findByUuid(uuid, count - 1, count,
365                                    orderByComparator);
366    
367                    if (!list.isEmpty()) {
368                            return list.get(0);
369                    }
370    
371                    return null;
372            }
373    
374            /**
375             * Returns the message boards threads before and after the current message boards thread in the ordered set where uuid = &#63;.
376             *
377             * @param threadId the primary key of the current message boards thread
378             * @param uuid the uuid
379             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
380             * @return the previous, current, and next message boards thread
381             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
382             */
383            @Override
384            public MBThread[] findByUuid_PrevAndNext(long threadId, String uuid,
385                    OrderByComparator<MBThread> orderByComparator)
386                    throws NoSuchThreadException {
387                    MBThread mbThread = findByPrimaryKey(threadId);
388    
389                    Session session = null;
390    
391                    try {
392                            session = openSession();
393    
394                            MBThread[] array = new MBThreadImpl[3];
395    
396                            array[0] = getByUuid_PrevAndNext(session, mbThread, uuid,
397                                            orderByComparator, true);
398    
399                            array[1] = mbThread;
400    
401                            array[2] = getByUuid_PrevAndNext(session, mbThread, uuid,
402                                            orderByComparator, false);
403    
404                            return array;
405                    }
406                    catch (Exception e) {
407                            throw processException(e);
408                    }
409                    finally {
410                            closeSession(session);
411                    }
412            }
413    
414            protected MBThread getByUuid_PrevAndNext(Session session,
415                    MBThread mbThread, String uuid,
416                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
417                    StringBundler query = null;
418    
419                    if (orderByComparator != null) {
420                            query = new StringBundler(6 +
421                                            (orderByComparator.getOrderByFields().length * 6));
422                    }
423                    else {
424                            query = new StringBundler(3);
425                    }
426    
427                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
428    
429                    boolean bindUuid = false;
430    
431                    if (uuid == null) {
432                            query.append(_FINDER_COLUMN_UUID_UUID_1);
433                    }
434                    else if (uuid.equals(StringPool.BLANK)) {
435                            query.append(_FINDER_COLUMN_UUID_UUID_3);
436                    }
437                    else {
438                            bindUuid = true;
439    
440                            query.append(_FINDER_COLUMN_UUID_UUID_2);
441                    }
442    
443                    if (orderByComparator != null) {
444                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
445    
446                            if (orderByConditionFields.length > 0) {
447                                    query.append(WHERE_AND);
448                            }
449    
450                            for (int i = 0; i < orderByConditionFields.length; i++) {
451                                    query.append(_ORDER_BY_ENTITY_ALIAS);
452                                    query.append(orderByConditionFields[i]);
453    
454                                    if ((i + 1) < orderByConditionFields.length) {
455                                            if (orderByComparator.isAscending() ^ previous) {
456                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
457                                            }
458                                            else {
459                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
460                                            }
461                                    }
462                                    else {
463                                            if (orderByComparator.isAscending() ^ previous) {
464                                                    query.append(WHERE_GREATER_THAN);
465                                            }
466                                            else {
467                                                    query.append(WHERE_LESSER_THAN);
468                                            }
469                                    }
470                            }
471    
472                            query.append(ORDER_BY_CLAUSE);
473    
474                            String[] orderByFields = orderByComparator.getOrderByFields();
475    
476                            for (int i = 0; i < orderByFields.length; i++) {
477                                    query.append(_ORDER_BY_ENTITY_ALIAS);
478                                    query.append(orderByFields[i]);
479    
480                                    if ((i + 1) < orderByFields.length) {
481                                            if (orderByComparator.isAscending() ^ previous) {
482                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
483                                            }
484                                            else {
485                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
486                                            }
487                                    }
488                                    else {
489                                            if (orderByComparator.isAscending() ^ previous) {
490                                                    query.append(ORDER_BY_ASC);
491                                            }
492                                            else {
493                                                    query.append(ORDER_BY_DESC);
494                                            }
495                                    }
496                            }
497                    }
498                    else {
499                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
500                    }
501    
502                    String sql = query.toString();
503    
504                    Query q = session.createQuery(sql);
505    
506                    q.setFirstResult(0);
507                    q.setMaxResults(2);
508    
509                    QueryPos qPos = QueryPos.getInstance(q);
510    
511                    if (bindUuid) {
512                            qPos.add(uuid);
513                    }
514    
515                    if (orderByComparator != null) {
516                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
517    
518                            for (Object value : values) {
519                                    qPos.add(value);
520                            }
521                    }
522    
523                    List<MBThread> list = q.list();
524    
525                    if (list.size() == 2) {
526                            return list.get(1);
527                    }
528                    else {
529                            return null;
530                    }
531            }
532    
533            /**
534             * Removes all the message boards threads where uuid = &#63; from the database.
535             *
536             * @param uuid the uuid
537             */
538            @Override
539            public void removeByUuid(String uuid) {
540                    for (MBThread mbThread : findByUuid(uuid, QueryUtil.ALL_POS,
541                                    QueryUtil.ALL_POS, null)) {
542                            remove(mbThread);
543                    }
544            }
545    
546            /**
547             * Returns the number of message boards threads where uuid = &#63;.
548             *
549             * @param uuid the uuid
550             * @return the number of matching message boards threads
551             */
552            @Override
553            public int countByUuid(String uuid) {
554                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
555    
556                    Object[] finderArgs = new Object[] { uuid };
557    
558                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
559                                    this);
560    
561                    if (count == null) {
562                            StringBundler query = new StringBundler(2);
563    
564                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
565    
566                            boolean bindUuid = false;
567    
568                            if (uuid == null) {
569                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
570                            }
571                            else if (uuid.equals(StringPool.BLANK)) {
572                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
573                            }
574                            else {
575                                    bindUuid = true;
576    
577                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
578                            }
579    
580                            String sql = query.toString();
581    
582                            Session session = null;
583    
584                            try {
585                                    session = openSession();
586    
587                                    Query q = session.createQuery(sql);
588    
589                                    QueryPos qPos = QueryPos.getInstance(q);
590    
591                                    if (bindUuid) {
592                                            qPos.add(uuid);
593                                    }
594    
595                                    count = (Long)q.uniqueResult();
596    
597                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
598                            }
599                            catch (Exception e) {
600                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
601    
602                                    throw processException(e);
603                            }
604                            finally {
605                                    closeSession(session);
606                            }
607                    }
608    
609                    return count.intValue();
610            }
611    
612            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbThread.uuid IS NULL";
613            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbThread.uuid = ?";
614            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbThread.uuid IS NULL OR mbThread.uuid = '')";
615            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
616                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
617                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
618                            new String[] { String.class.getName(), Long.class.getName() },
619                            MBThreadModelImpl.UUID_COLUMN_BITMASK |
620                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK);
621            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
622                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
623                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
624                            new String[] { String.class.getName(), Long.class.getName() });
625    
626            /**
627             * Returns the message boards thread where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.messageboards.NoSuchThreadException} if it could not be found.
628             *
629             * @param uuid the uuid
630             * @param groupId the group ID
631             * @return the matching message boards thread
632             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
633             */
634            @Override
635            public MBThread findByUUID_G(String uuid, long groupId)
636                    throws NoSuchThreadException {
637                    MBThread mbThread = fetchByUUID_G(uuid, groupId);
638    
639                    if (mbThread == null) {
640                            StringBundler msg = new StringBundler(6);
641    
642                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
643    
644                            msg.append("uuid=");
645                            msg.append(uuid);
646    
647                            msg.append(", groupId=");
648                            msg.append(groupId);
649    
650                            msg.append(StringPool.CLOSE_CURLY_BRACE);
651    
652                            if (_log.isWarnEnabled()) {
653                                    _log.warn(msg.toString());
654                            }
655    
656                            throw new NoSuchThreadException(msg.toString());
657                    }
658    
659                    return mbThread;
660            }
661    
662            /**
663             * Returns the message boards thread where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
664             *
665             * @param uuid the uuid
666             * @param groupId the group ID
667             * @return the matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
668             */
669            @Override
670            public MBThread fetchByUUID_G(String uuid, long groupId) {
671                    return fetchByUUID_G(uuid, groupId, true);
672            }
673    
674            /**
675             * Returns the message boards thread where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
676             *
677             * @param uuid the uuid
678             * @param groupId the group ID
679             * @param retrieveFromCache whether to use the finder cache
680             * @return the matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
681             */
682            @Override
683            public MBThread fetchByUUID_G(String uuid, long groupId,
684                    boolean retrieveFromCache) {
685                    Object[] finderArgs = new Object[] { uuid, groupId };
686    
687                    Object result = null;
688    
689                    if (retrieveFromCache) {
690                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
691                                            finderArgs, this);
692                    }
693    
694                    if (result instanceof MBThread) {
695                            MBThread mbThread = (MBThread)result;
696    
697                            if (!Validator.equals(uuid, mbThread.getUuid()) ||
698                                            (groupId != mbThread.getGroupId())) {
699                                    result = null;
700                            }
701                    }
702    
703                    if (result == null) {
704                            StringBundler query = new StringBundler(4);
705    
706                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
707    
708                            boolean bindUuid = false;
709    
710                            if (uuid == null) {
711                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
712                            }
713                            else if (uuid.equals(StringPool.BLANK)) {
714                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
715                            }
716                            else {
717                                    bindUuid = true;
718    
719                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
720                            }
721    
722                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
723    
724                            String sql = query.toString();
725    
726                            Session session = null;
727    
728                            try {
729                                    session = openSession();
730    
731                                    Query q = session.createQuery(sql);
732    
733                                    QueryPos qPos = QueryPos.getInstance(q);
734    
735                                    if (bindUuid) {
736                                            qPos.add(uuid);
737                                    }
738    
739                                    qPos.add(groupId);
740    
741                                    List<MBThread> list = q.list();
742    
743                                    if (list.isEmpty()) {
744                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
745                                                    finderArgs, list);
746                                    }
747                                    else {
748                                            MBThread mbThread = list.get(0);
749    
750                                            result = mbThread;
751    
752                                            cacheResult(mbThread);
753    
754                                            if ((mbThread.getUuid() == null) ||
755                                                            !mbThread.getUuid().equals(uuid) ||
756                                                            (mbThread.getGroupId() != groupId)) {
757                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
758                                                            finderArgs, mbThread);
759                                            }
760                                    }
761                            }
762                            catch (Exception e) {
763                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
764                                            finderArgs);
765    
766                                    throw processException(e);
767                            }
768                            finally {
769                                    closeSession(session);
770                            }
771                    }
772    
773                    if (result instanceof List<?>) {
774                            return null;
775                    }
776                    else {
777                            return (MBThread)result;
778                    }
779            }
780    
781            /**
782             * Removes the message boards thread where uuid = &#63; and groupId = &#63; from the database.
783             *
784             * @param uuid the uuid
785             * @param groupId the group ID
786             * @return the message boards thread that was removed
787             */
788            @Override
789            public MBThread removeByUUID_G(String uuid, long groupId)
790                    throws NoSuchThreadException {
791                    MBThread mbThread = findByUUID_G(uuid, groupId);
792    
793                    return remove(mbThread);
794            }
795    
796            /**
797             * Returns the number of message boards threads where uuid = &#63; and groupId = &#63;.
798             *
799             * @param uuid the uuid
800             * @param groupId the group ID
801             * @return the number of matching message boards threads
802             */
803            @Override
804            public int countByUUID_G(String uuid, long groupId) {
805                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
806    
807                    Object[] finderArgs = new Object[] { uuid, groupId };
808    
809                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
810                                    this);
811    
812                    if (count == null) {
813                            StringBundler query = new StringBundler(3);
814    
815                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
816    
817                            boolean bindUuid = false;
818    
819                            if (uuid == null) {
820                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
821                            }
822                            else if (uuid.equals(StringPool.BLANK)) {
823                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
824                            }
825                            else {
826                                    bindUuid = true;
827    
828                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
829                            }
830    
831                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
832    
833                            String sql = query.toString();
834    
835                            Session session = null;
836    
837                            try {
838                                    session = openSession();
839    
840                                    Query q = session.createQuery(sql);
841    
842                                    QueryPos qPos = QueryPos.getInstance(q);
843    
844                                    if (bindUuid) {
845                                            qPos.add(uuid);
846                                    }
847    
848                                    qPos.add(groupId);
849    
850                                    count = (Long)q.uniqueResult();
851    
852                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
853                            }
854                            catch (Exception e) {
855                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
856    
857                                    throw processException(e);
858                            }
859                            finally {
860                                    closeSession(session);
861                            }
862                    }
863    
864                    return count.intValue();
865            }
866    
867            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbThread.uuid IS NULL AND ";
868            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbThread.uuid = ? AND ";
869            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbThread.uuid IS NULL OR mbThread.uuid = '') AND ";
870            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbThread.groupId = ?";
871            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
872                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
873                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
874                            new String[] {
875                                    String.class.getName(), Long.class.getName(),
876                                    
877                            Integer.class.getName(), Integer.class.getName(),
878                                    OrderByComparator.class.getName()
879                            });
880            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
881                    new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
882                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
883                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
884                            new String[] { String.class.getName(), Long.class.getName() },
885                            MBThreadModelImpl.UUID_COLUMN_BITMASK |
886                            MBThreadModelImpl.COMPANYID_COLUMN_BITMASK |
887                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
888                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
889            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
890                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
891                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
892                            new String[] { String.class.getName(), Long.class.getName() });
893    
894            /**
895             * Returns all the message boards threads where uuid = &#63; and companyId = &#63;.
896             *
897             * @param uuid the uuid
898             * @param companyId the company ID
899             * @return the matching message boards threads
900             */
901            @Override
902            public List<MBThread> findByUuid_C(String uuid, long companyId) {
903                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
904                            QueryUtil.ALL_POS, null);
905            }
906    
907            /**
908             * Returns a range of all the message boards threads where uuid = &#63; and companyId = &#63;.
909             *
910             * <p>
911             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
912             * </p>
913             *
914             * @param uuid the uuid
915             * @param companyId the company ID
916             * @param start the lower bound of the range of message boards threads
917             * @param end the upper bound of the range of message boards threads (not inclusive)
918             * @return the range of matching message boards threads
919             */
920            @Override
921            public List<MBThread> findByUuid_C(String uuid, long companyId, int start,
922                    int end) {
923                    return findByUuid_C(uuid, companyId, start, end, null);
924            }
925    
926            /**
927             * Returns an ordered range of all the message boards threads where uuid = &#63; and companyId = &#63;.
928             *
929             * <p>
930             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
931             * </p>
932             *
933             * @param uuid the uuid
934             * @param companyId the company ID
935             * @param start the lower bound of the range of message boards threads
936             * @param end the upper bound of the range of message boards threads (not inclusive)
937             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
938             * @return the ordered range of matching message boards threads
939             */
940            @Override
941            public List<MBThread> findByUuid_C(String uuid, long companyId, int start,
942                    int end, OrderByComparator<MBThread> orderByComparator) {
943                    boolean pagination = true;
944                    FinderPath finderPath = null;
945                    Object[] finderArgs = null;
946    
947                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
948                                    (orderByComparator == null)) {
949                            pagination = false;
950                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
951                            finderArgs = new Object[] { uuid, companyId };
952                    }
953                    else {
954                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
955                            finderArgs = new Object[] {
956                                            uuid, companyId,
957                                            
958                                            start, end, orderByComparator
959                                    };
960                    }
961    
962                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
963                                    finderArgs, this);
964    
965                    if ((list != null) && !list.isEmpty()) {
966                            for (MBThread mbThread : list) {
967                                    if (!Validator.equals(uuid, mbThread.getUuid()) ||
968                                                    (companyId != mbThread.getCompanyId())) {
969                                            list = null;
970    
971                                            break;
972                                    }
973                            }
974                    }
975    
976                    if (list == null) {
977                            StringBundler query = null;
978    
979                            if (orderByComparator != null) {
980                                    query = new StringBundler(4 +
981                                                    (orderByComparator.getOrderByFields().length * 3));
982                            }
983                            else {
984                                    query = new StringBundler(4);
985                            }
986    
987                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
988    
989                            boolean bindUuid = false;
990    
991                            if (uuid == null) {
992                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
993                            }
994                            else if (uuid.equals(StringPool.BLANK)) {
995                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
996                            }
997                            else {
998                                    bindUuid = true;
999    
1000                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1001                            }
1002    
1003                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1004    
1005                            if (orderByComparator != null) {
1006                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1007                                            orderByComparator);
1008                            }
1009                            else
1010                             if (pagination) {
1011                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1012                            }
1013    
1014                            String sql = query.toString();
1015    
1016                            Session session = null;
1017    
1018                            try {
1019                                    session = openSession();
1020    
1021                                    Query q = session.createQuery(sql);
1022    
1023                                    QueryPos qPos = QueryPos.getInstance(q);
1024    
1025                                    if (bindUuid) {
1026                                            qPos.add(uuid);
1027                                    }
1028    
1029                                    qPos.add(companyId);
1030    
1031                                    if (!pagination) {
1032                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1033                                                            start, end, false);
1034    
1035                                            Collections.sort(list);
1036    
1037                                            list = Collections.unmodifiableList(list);
1038                                    }
1039                                    else {
1040                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1041                                                            start, end);
1042                                    }
1043    
1044                                    cacheResult(list);
1045    
1046                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1047                            }
1048                            catch (Exception e) {
1049                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1050    
1051                                    throw processException(e);
1052                            }
1053                            finally {
1054                                    closeSession(session);
1055                            }
1056                    }
1057    
1058                    return list;
1059            }
1060    
1061            /**
1062             * Returns the first message boards thread in the ordered set where uuid = &#63; and companyId = &#63;.
1063             *
1064             * @param uuid the uuid
1065             * @param companyId the company ID
1066             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1067             * @return the first matching message boards thread
1068             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
1069             */
1070            @Override
1071            public MBThread findByUuid_C_First(String uuid, long companyId,
1072                    OrderByComparator<MBThread> orderByComparator)
1073                    throws NoSuchThreadException {
1074                    MBThread mbThread = fetchByUuid_C_First(uuid, companyId,
1075                                    orderByComparator);
1076    
1077                    if (mbThread != null) {
1078                            return mbThread;
1079                    }
1080    
1081                    StringBundler msg = new StringBundler(6);
1082    
1083                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1084    
1085                    msg.append("uuid=");
1086                    msg.append(uuid);
1087    
1088                    msg.append(", companyId=");
1089                    msg.append(companyId);
1090    
1091                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1092    
1093                    throw new NoSuchThreadException(msg.toString());
1094            }
1095    
1096            /**
1097             * Returns the first message boards thread in the ordered set where uuid = &#63; and companyId = &#63;.
1098             *
1099             * @param uuid the uuid
1100             * @param companyId the company ID
1101             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1102             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1103             */
1104            @Override
1105            public MBThread fetchByUuid_C_First(String uuid, long companyId,
1106                    OrderByComparator<MBThread> orderByComparator) {
1107                    List<MBThread> list = findByUuid_C(uuid, companyId, 0, 1,
1108                                    orderByComparator);
1109    
1110                    if (!list.isEmpty()) {
1111                            return list.get(0);
1112                    }
1113    
1114                    return null;
1115            }
1116    
1117            /**
1118             * Returns the last message boards thread in the ordered set where uuid = &#63; and companyId = &#63;.
1119             *
1120             * @param uuid the uuid
1121             * @param companyId the company ID
1122             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1123             * @return the last matching message boards thread
1124             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
1125             */
1126            @Override
1127            public MBThread findByUuid_C_Last(String uuid, long companyId,
1128                    OrderByComparator<MBThread> orderByComparator)
1129                    throws NoSuchThreadException {
1130                    MBThread mbThread = fetchByUuid_C_Last(uuid, companyId,
1131                                    orderByComparator);
1132    
1133                    if (mbThread != null) {
1134                            return mbThread;
1135                    }
1136    
1137                    StringBundler msg = new StringBundler(6);
1138    
1139                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1140    
1141                    msg.append("uuid=");
1142                    msg.append(uuid);
1143    
1144                    msg.append(", companyId=");
1145                    msg.append(companyId);
1146    
1147                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1148    
1149                    throw new NoSuchThreadException(msg.toString());
1150            }
1151    
1152            /**
1153             * Returns the last message boards thread in the ordered set where uuid = &#63; and companyId = &#63;.
1154             *
1155             * @param uuid the uuid
1156             * @param companyId the company ID
1157             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1158             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1159             */
1160            @Override
1161            public MBThread fetchByUuid_C_Last(String uuid, long companyId,
1162                    OrderByComparator<MBThread> orderByComparator) {
1163                    int count = countByUuid_C(uuid, companyId);
1164    
1165                    if (count == 0) {
1166                            return null;
1167                    }
1168    
1169                    List<MBThread> list = findByUuid_C(uuid, companyId, count - 1, count,
1170                                    orderByComparator);
1171    
1172                    if (!list.isEmpty()) {
1173                            return list.get(0);
1174                    }
1175    
1176                    return null;
1177            }
1178    
1179            /**
1180             * Returns the message boards threads before and after the current message boards thread in the ordered set where uuid = &#63; and companyId = &#63;.
1181             *
1182             * @param threadId the primary key of the current message boards thread
1183             * @param uuid the uuid
1184             * @param companyId the company ID
1185             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1186             * @return the previous, current, and next message boards thread
1187             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
1188             */
1189            @Override
1190            public MBThread[] findByUuid_C_PrevAndNext(long threadId, String uuid,
1191                    long companyId, OrderByComparator<MBThread> orderByComparator)
1192                    throws NoSuchThreadException {
1193                    MBThread mbThread = findByPrimaryKey(threadId);
1194    
1195                    Session session = null;
1196    
1197                    try {
1198                            session = openSession();
1199    
1200                            MBThread[] array = new MBThreadImpl[3];
1201    
1202                            array[0] = getByUuid_C_PrevAndNext(session, mbThread, uuid,
1203                                            companyId, orderByComparator, true);
1204    
1205                            array[1] = mbThread;
1206    
1207                            array[2] = getByUuid_C_PrevAndNext(session, mbThread, uuid,
1208                                            companyId, orderByComparator, false);
1209    
1210                            return array;
1211                    }
1212                    catch (Exception e) {
1213                            throw processException(e);
1214                    }
1215                    finally {
1216                            closeSession(session);
1217                    }
1218            }
1219    
1220            protected MBThread getByUuid_C_PrevAndNext(Session session,
1221                    MBThread mbThread, String uuid, long companyId,
1222                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
1223                    StringBundler query = null;
1224    
1225                    if (orderByComparator != null) {
1226                            query = new StringBundler(6 +
1227                                            (orderByComparator.getOrderByFields().length * 6));
1228                    }
1229                    else {
1230                            query = new StringBundler(3);
1231                    }
1232    
1233                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1234    
1235                    boolean bindUuid = false;
1236    
1237                    if (uuid == null) {
1238                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1239                    }
1240                    else if (uuid.equals(StringPool.BLANK)) {
1241                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1242                    }
1243                    else {
1244                            bindUuid = true;
1245    
1246                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1247                    }
1248    
1249                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1250    
1251                    if (orderByComparator != null) {
1252                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1253    
1254                            if (orderByConditionFields.length > 0) {
1255                                    query.append(WHERE_AND);
1256                            }
1257    
1258                            for (int i = 0; i < orderByConditionFields.length; i++) {
1259                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1260                                    query.append(orderByConditionFields[i]);
1261    
1262                                    if ((i + 1) < orderByConditionFields.length) {
1263                                            if (orderByComparator.isAscending() ^ previous) {
1264                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1265                                            }
1266                                            else {
1267                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1268                                            }
1269                                    }
1270                                    else {
1271                                            if (orderByComparator.isAscending() ^ previous) {
1272                                                    query.append(WHERE_GREATER_THAN);
1273                                            }
1274                                            else {
1275                                                    query.append(WHERE_LESSER_THAN);
1276                                            }
1277                                    }
1278                            }
1279    
1280                            query.append(ORDER_BY_CLAUSE);
1281    
1282                            String[] orderByFields = orderByComparator.getOrderByFields();
1283    
1284                            for (int i = 0; i < orderByFields.length; i++) {
1285                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1286                                    query.append(orderByFields[i]);
1287    
1288                                    if ((i + 1) < orderByFields.length) {
1289                                            if (orderByComparator.isAscending() ^ previous) {
1290                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1291                                            }
1292                                            else {
1293                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1294                                            }
1295                                    }
1296                                    else {
1297                                            if (orderByComparator.isAscending() ^ previous) {
1298                                                    query.append(ORDER_BY_ASC);
1299                                            }
1300                                            else {
1301                                                    query.append(ORDER_BY_DESC);
1302                                            }
1303                                    }
1304                            }
1305                    }
1306                    else {
1307                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1308                    }
1309    
1310                    String sql = query.toString();
1311    
1312                    Query q = session.createQuery(sql);
1313    
1314                    q.setFirstResult(0);
1315                    q.setMaxResults(2);
1316    
1317                    QueryPos qPos = QueryPos.getInstance(q);
1318    
1319                    if (bindUuid) {
1320                            qPos.add(uuid);
1321                    }
1322    
1323                    qPos.add(companyId);
1324    
1325                    if (orderByComparator != null) {
1326                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1327    
1328                            for (Object value : values) {
1329                                    qPos.add(value);
1330                            }
1331                    }
1332    
1333                    List<MBThread> list = q.list();
1334    
1335                    if (list.size() == 2) {
1336                            return list.get(1);
1337                    }
1338                    else {
1339                            return null;
1340                    }
1341            }
1342    
1343            /**
1344             * Removes all the message boards threads where uuid = &#63; and companyId = &#63; from the database.
1345             *
1346             * @param uuid the uuid
1347             * @param companyId the company ID
1348             */
1349            @Override
1350            public void removeByUuid_C(String uuid, long companyId) {
1351                    for (MBThread mbThread : findByUuid_C(uuid, companyId,
1352                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1353                            remove(mbThread);
1354                    }
1355            }
1356    
1357            /**
1358             * Returns the number of message boards threads where uuid = &#63; and companyId = &#63;.
1359             *
1360             * @param uuid the uuid
1361             * @param companyId the company ID
1362             * @return the number of matching message boards threads
1363             */
1364            @Override
1365            public int countByUuid_C(String uuid, long companyId) {
1366                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1367    
1368                    Object[] finderArgs = new Object[] { uuid, companyId };
1369    
1370                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1371                                    this);
1372    
1373                    if (count == null) {
1374                            StringBundler query = new StringBundler(3);
1375    
1376                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
1377    
1378                            boolean bindUuid = false;
1379    
1380                            if (uuid == null) {
1381                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1382                            }
1383                            else if (uuid.equals(StringPool.BLANK)) {
1384                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1385                            }
1386                            else {
1387                                    bindUuid = true;
1388    
1389                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1390                            }
1391    
1392                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1393    
1394                            String sql = query.toString();
1395    
1396                            Session session = null;
1397    
1398                            try {
1399                                    session = openSession();
1400    
1401                                    Query q = session.createQuery(sql);
1402    
1403                                    QueryPos qPos = QueryPos.getInstance(q);
1404    
1405                                    if (bindUuid) {
1406                                            qPos.add(uuid);
1407                                    }
1408    
1409                                    qPos.add(companyId);
1410    
1411                                    count = (Long)q.uniqueResult();
1412    
1413                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1414                            }
1415                            catch (Exception e) {
1416                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1417    
1418                                    throw processException(e);
1419                            }
1420                            finally {
1421                                    closeSession(session);
1422                            }
1423                    }
1424    
1425                    return count.intValue();
1426            }
1427    
1428            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbThread.uuid IS NULL AND ";
1429            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbThread.uuid = ? AND ";
1430            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbThread.uuid IS NULL OR mbThread.uuid = '') AND ";
1431            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbThread.companyId = ?";
1432            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1433                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
1434                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1435                            new String[] {
1436                                    Long.class.getName(),
1437                                    
1438                            Integer.class.getName(), Integer.class.getName(),
1439                                    OrderByComparator.class.getName()
1440                            });
1441            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1442                    new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1443                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
1444                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1445                            new String[] { Long.class.getName() },
1446                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
1447                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
1448                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
1449            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1450                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
1451                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1452                            new String[] { Long.class.getName() });
1453    
1454            /**
1455             * Returns all the message boards threads where groupId = &#63;.
1456             *
1457             * @param groupId the group ID
1458             * @return the matching message boards threads
1459             */
1460            @Override
1461            public List<MBThread> findByGroupId(long groupId) {
1462                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1463            }
1464    
1465            /**
1466             * Returns a range of all the message boards threads where groupId = &#63;.
1467             *
1468             * <p>
1469             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1470             * </p>
1471             *
1472             * @param groupId the group ID
1473             * @param start the lower bound of the range of message boards threads
1474             * @param end the upper bound of the range of message boards threads (not inclusive)
1475             * @return the range of matching message boards threads
1476             */
1477            @Override
1478            public List<MBThread> findByGroupId(long groupId, int start, int end) {
1479                    return findByGroupId(groupId, start, end, null);
1480            }
1481    
1482            /**
1483             * Returns an ordered range of all the message boards threads where groupId = &#63;.
1484             *
1485             * <p>
1486             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1487             * </p>
1488             *
1489             * @param groupId the group ID
1490             * @param start the lower bound of the range of message boards threads
1491             * @param end the upper bound of the range of message boards threads (not inclusive)
1492             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1493             * @return the ordered range of matching message boards threads
1494             */
1495            @Override
1496            public List<MBThread> findByGroupId(long groupId, int start, int end,
1497                    OrderByComparator<MBThread> orderByComparator) {
1498                    boolean pagination = true;
1499                    FinderPath finderPath = null;
1500                    Object[] finderArgs = null;
1501    
1502                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1503                                    (orderByComparator == null)) {
1504                            pagination = false;
1505                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1506                            finderArgs = new Object[] { groupId };
1507                    }
1508                    else {
1509                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1510                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1511                    }
1512    
1513                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
1514                                    finderArgs, this);
1515    
1516                    if ((list != null) && !list.isEmpty()) {
1517                            for (MBThread mbThread : list) {
1518                                    if ((groupId != mbThread.getGroupId())) {
1519                                            list = null;
1520    
1521                                            break;
1522                                    }
1523                            }
1524                    }
1525    
1526                    if (list == null) {
1527                            StringBundler query = null;
1528    
1529                            if (orderByComparator != null) {
1530                                    query = new StringBundler(3 +
1531                                                    (orderByComparator.getOrderByFields().length * 3));
1532                            }
1533                            else {
1534                                    query = new StringBundler(3);
1535                            }
1536    
1537                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
1538    
1539                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1540    
1541                            if (orderByComparator != null) {
1542                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1543                                            orderByComparator);
1544                            }
1545                            else
1546                             if (pagination) {
1547                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1548                            }
1549    
1550                            String sql = query.toString();
1551    
1552                            Session session = null;
1553    
1554                            try {
1555                                    session = openSession();
1556    
1557                                    Query q = session.createQuery(sql);
1558    
1559                                    QueryPos qPos = QueryPos.getInstance(q);
1560    
1561                                    qPos.add(groupId);
1562    
1563                                    if (!pagination) {
1564                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1565                                                            start, end, false);
1566    
1567                                            Collections.sort(list);
1568    
1569                                            list = Collections.unmodifiableList(list);
1570                                    }
1571                                    else {
1572                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1573                                                            start, end);
1574                                    }
1575    
1576                                    cacheResult(list);
1577    
1578                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1579                            }
1580                            catch (Exception e) {
1581                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1582    
1583                                    throw processException(e);
1584                            }
1585                            finally {
1586                                    closeSession(session);
1587                            }
1588                    }
1589    
1590                    return list;
1591            }
1592    
1593            /**
1594             * Returns the first message boards thread in the ordered set where groupId = &#63;.
1595             *
1596             * @param groupId the group ID
1597             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1598             * @return the first matching message boards thread
1599             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
1600             */
1601            @Override
1602            public MBThread findByGroupId_First(long groupId,
1603                    OrderByComparator<MBThread> orderByComparator)
1604                    throws NoSuchThreadException {
1605                    MBThread mbThread = fetchByGroupId_First(groupId, orderByComparator);
1606    
1607                    if (mbThread != null) {
1608                            return mbThread;
1609                    }
1610    
1611                    StringBundler msg = new StringBundler(4);
1612    
1613                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1614    
1615                    msg.append("groupId=");
1616                    msg.append(groupId);
1617    
1618                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1619    
1620                    throw new NoSuchThreadException(msg.toString());
1621            }
1622    
1623            /**
1624             * Returns the first message boards thread in the ordered set where groupId = &#63;.
1625             *
1626             * @param groupId the group ID
1627             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1628             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1629             */
1630            @Override
1631            public MBThread fetchByGroupId_First(long groupId,
1632                    OrderByComparator<MBThread> orderByComparator) {
1633                    List<MBThread> list = findByGroupId(groupId, 0, 1, orderByComparator);
1634    
1635                    if (!list.isEmpty()) {
1636                            return list.get(0);
1637                    }
1638    
1639                    return null;
1640            }
1641    
1642            /**
1643             * Returns the last message boards thread in the ordered set where groupId = &#63;.
1644             *
1645             * @param groupId the group ID
1646             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1647             * @return the last matching message boards thread
1648             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
1649             */
1650            @Override
1651            public MBThread findByGroupId_Last(long groupId,
1652                    OrderByComparator<MBThread> orderByComparator)
1653                    throws NoSuchThreadException {
1654                    MBThread mbThread = fetchByGroupId_Last(groupId, orderByComparator);
1655    
1656                    if (mbThread != null) {
1657                            return mbThread;
1658                    }
1659    
1660                    StringBundler msg = new StringBundler(4);
1661    
1662                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1663    
1664                    msg.append("groupId=");
1665                    msg.append(groupId);
1666    
1667                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1668    
1669                    throw new NoSuchThreadException(msg.toString());
1670            }
1671    
1672            /**
1673             * Returns the last message boards thread in the ordered set where groupId = &#63;.
1674             *
1675             * @param groupId the group ID
1676             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1677             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1678             */
1679            @Override
1680            public MBThread fetchByGroupId_Last(long groupId,
1681                    OrderByComparator<MBThread> orderByComparator) {
1682                    int count = countByGroupId(groupId);
1683    
1684                    if (count == 0) {
1685                            return null;
1686                    }
1687    
1688                    List<MBThread> list = findByGroupId(groupId, count - 1, count,
1689                                    orderByComparator);
1690    
1691                    if (!list.isEmpty()) {
1692                            return list.get(0);
1693                    }
1694    
1695                    return null;
1696            }
1697    
1698            /**
1699             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63;.
1700             *
1701             * @param threadId the primary key of the current message boards thread
1702             * @param groupId the group ID
1703             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1704             * @return the previous, current, and next message boards thread
1705             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
1706             */
1707            @Override
1708            public MBThread[] findByGroupId_PrevAndNext(long threadId, long groupId,
1709                    OrderByComparator<MBThread> orderByComparator)
1710                    throws NoSuchThreadException {
1711                    MBThread mbThread = findByPrimaryKey(threadId);
1712    
1713                    Session session = null;
1714    
1715                    try {
1716                            session = openSession();
1717    
1718                            MBThread[] array = new MBThreadImpl[3];
1719    
1720                            array[0] = getByGroupId_PrevAndNext(session, mbThread, groupId,
1721                                            orderByComparator, true);
1722    
1723                            array[1] = mbThread;
1724    
1725                            array[2] = getByGroupId_PrevAndNext(session, mbThread, groupId,
1726                                            orderByComparator, false);
1727    
1728                            return array;
1729                    }
1730                    catch (Exception e) {
1731                            throw processException(e);
1732                    }
1733                    finally {
1734                            closeSession(session);
1735                    }
1736            }
1737    
1738            protected MBThread getByGroupId_PrevAndNext(Session session,
1739                    MBThread mbThread, long groupId,
1740                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
1741                    StringBundler query = null;
1742    
1743                    if (orderByComparator != null) {
1744                            query = new StringBundler(6 +
1745                                            (orderByComparator.getOrderByFields().length * 6));
1746                    }
1747                    else {
1748                            query = new StringBundler(3);
1749                    }
1750    
1751                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1752    
1753                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1754    
1755                    if (orderByComparator != null) {
1756                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1757    
1758                            if (orderByConditionFields.length > 0) {
1759                                    query.append(WHERE_AND);
1760                            }
1761    
1762                            for (int i = 0; i < orderByConditionFields.length; i++) {
1763                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1764                                    query.append(orderByConditionFields[i]);
1765    
1766                                    if ((i + 1) < orderByConditionFields.length) {
1767                                            if (orderByComparator.isAscending() ^ previous) {
1768                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1769                                            }
1770                                            else {
1771                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1772                                            }
1773                                    }
1774                                    else {
1775                                            if (orderByComparator.isAscending() ^ previous) {
1776                                                    query.append(WHERE_GREATER_THAN);
1777                                            }
1778                                            else {
1779                                                    query.append(WHERE_LESSER_THAN);
1780                                            }
1781                                    }
1782                            }
1783    
1784                            query.append(ORDER_BY_CLAUSE);
1785    
1786                            String[] orderByFields = orderByComparator.getOrderByFields();
1787    
1788                            for (int i = 0; i < orderByFields.length; i++) {
1789                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1790                                    query.append(orderByFields[i]);
1791    
1792                                    if ((i + 1) < orderByFields.length) {
1793                                            if (orderByComparator.isAscending() ^ previous) {
1794                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1795                                            }
1796                                            else {
1797                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1798                                            }
1799                                    }
1800                                    else {
1801                                            if (orderByComparator.isAscending() ^ previous) {
1802                                                    query.append(ORDER_BY_ASC);
1803                                            }
1804                                            else {
1805                                                    query.append(ORDER_BY_DESC);
1806                                            }
1807                                    }
1808                            }
1809                    }
1810                    else {
1811                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1812                    }
1813    
1814                    String sql = query.toString();
1815    
1816                    Query q = session.createQuery(sql);
1817    
1818                    q.setFirstResult(0);
1819                    q.setMaxResults(2);
1820    
1821                    QueryPos qPos = QueryPos.getInstance(q);
1822    
1823                    qPos.add(groupId);
1824    
1825                    if (orderByComparator != null) {
1826                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1827    
1828                            for (Object value : values) {
1829                                    qPos.add(value);
1830                            }
1831                    }
1832    
1833                    List<MBThread> list = q.list();
1834    
1835                    if (list.size() == 2) {
1836                            return list.get(1);
1837                    }
1838                    else {
1839                            return null;
1840                    }
1841            }
1842    
1843            /**
1844             * Returns all the message boards threads that the user has permission to view where groupId = &#63;.
1845             *
1846             * @param groupId the group ID
1847             * @return the matching message boards threads that the user has permission to view
1848             */
1849            @Override
1850            public List<MBThread> filterFindByGroupId(long groupId) {
1851                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1852                            QueryUtil.ALL_POS, null);
1853            }
1854    
1855            /**
1856             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63;.
1857             *
1858             * <p>
1859             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1860             * </p>
1861             *
1862             * @param groupId the group ID
1863             * @param start the lower bound of the range of message boards threads
1864             * @param end the upper bound of the range of message boards threads (not inclusive)
1865             * @return the range of matching message boards threads that the user has permission to view
1866             */
1867            @Override
1868            public List<MBThread> filterFindByGroupId(long groupId, int start, int end) {
1869                    return filterFindByGroupId(groupId, start, end, null);
1870            }
1871    
1872            /**
1873             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63;.
1874             *
1875             * <p>
1876             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1877             * </p>
1878             *
1879             * @param groupId the group ID
1880             * @param start the lower bound of the range of message boards threads
1881             * @param end the upper bound of the range of message boards threads (not inclusive)
1882             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1883             * @return the ordered range of matching message boards threads that the user has permission to view
1884             */
1885            @Override
1886            public List<MBThread> filterFindByGroupId(long groupId, int start, int end,
1887                    OrderByComparator<MBThread> orderByComparator) {
1888                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1889                            return findByGroupId(groupId, start, end, orderByComparator);
1890                    }
1891    
1892                    StringBundler query = null;
1893    
1894                    if (orderByComparator != null) {
1895                            query = new StringBundler(3 +
1896                                            (orderByComparator.getOrderByFields().length * 3));
1897                    }
1898                    else {
1899                            query = new StringBundler(3);
1900                    }
1901    
1902                    if (getDB().isSupportsInlineDistinct()) {
1903                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
1904                    }
1905                    else {
1906                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
1907                    }
1908    
1909                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1910    
1911                    if (!getDB().isSupportsInlineDistinct()) {
1912                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
1913                    }
1914    
1915                    if (orderByComparator != null) {
1916                            if (getDB().isSupportsInlineDistinct()) {
1917                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1918                                            orderByComparator, true);
1919                            }
1920                            else {
1921                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1922                                            orderByComparator, true);
1923                            }
1924                    }
1925                    else {
1926                            if (getDB().isSupportsInlineDistinct()) {
1927                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1928                            }
1929                            else {
1930                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
1931                            }
1932                    }
1933    
1934                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1935                                    MBThread.class.getName(),
1936                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1937    
1938                    Session session = null;
1939    
1940                    try {
1941                            session = openSession();
1942    
1943                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1944    
1945                            if (getDB().isSupportsInlineDistinct()) {
1946                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
1947                            }
1948                            else {
1949                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
1950                            }
1951    
1952                            QueryPos qPos = QueryPos.getInstance(q);
1953    
1954                            qPos.add(groupId);
1955    
1956                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
1957                    }
1958                    catch (Exception e) {
1959                            throw processException(e);
1960                    }
1961                    finally {
1962                            closeSession(session);
1963                    }
1964            }
1965    
1966            /**
1967             * Returns the message boards threads before and after the current message boards thread in the ordered set of message boards threads that the user has permission to view where groupId = &#63;.
1968             *
1969             * @param threadId the primary key of the current message boards thread
1970             * @param groupId the group ID
1971             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1972             * @return the previous, current, and next message boards thread
1973             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
1974             */
1975            @Override
1976            public MBThread[] filterFindByGroupId_PrevAndNext(long threadId,
1977                    long groupId, OrderByComparator<MBThread> orderByComparator)
1978                    throws NoSuchThreadException {
1979                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1980                            return findByGroupId_PrevAndNext(threadId, groupId,
1981                                    orderByComparator);
1982                    }
1983    
1984                    MBThread mbThread = findByPrimaryKey(threadId);
1985    
1986                    Session session = null;
1987    
1988                    try {
1989                            session = openSession();
1990    
1991                            MBThread[] array = new MBThreadImpl[3];
1992    
1993                            array[0] = filterGetByGroupId_PrevAndNext(session, mbThread,
1994                                            groupId, orderByComparator, true);
1995    
1996                            array[1] = mbThread;
1997    
1998                            array[2] = filterGetByGroupId_PrevAndNext(session, mbThread,
1999                                            groupId, orderByComparator, false);
2000    
2001                            return array;
2002                    }
2003                    catch (Exception e) {
2004                            throw processException(e);
2005                    }
2006                    finally {
2007                            closeSession(session);
2008                    }
2009            }
2010    
2011            protected MBThread filterGetByGroupId_PrevAndNext(Session session,
2012                    MBThread mbThread, long groupId,
2013                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
2014                    StringBundler query = null;
2015    
2016                    if (orderByComparator != null) {
2017                            query = new StringBundler(6 +
2018                                            (orderByComparator.getOrderByFields().length * 6));
2019                    }
2020                    else {
2021                            query = new StringBundler(3);
2022                    }
2023    
2024                    if (getDB().isSupportsInlineDistinct()) {
2025                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2026                    }
2027                    else {
2028                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2029                    }
2030    
2031                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2032    
2033                    if (!getDB().isSupportsInlineDistinct()) {
2034                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
2035                    }
2036    
2037                    if (orderByComparator != null) {
2038                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2039    
2040                            if (orderByConditionFields.length > 0) {
2041                                    query.append(WHERE_AND);
2042                            }
2043    
2044                            for (int i = 0; i < orderByConditionFields.length; i++) {
2045                                    if (getDB().isSupportsInlineDistinct()) {
2046                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2047                                    }
2048                                    else {
2049                                            query.append(_ORDER_BY_ENTITY_TABLE);
2050                                    }
2051    
2052                                    query.append(orderByConditionFields[i]);
2053    
2054                                    if ((i + 1) < orderByConditionFields.length) {
2055                                            if (orderByComparator.isAscending() ^ previous) {
2056                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2057                                            }
2058                                            else {
2059                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2060                                            }
2061                                    }
2062                                    else {
2063                                            if (orderByComparator.isAscending() ^ previous) {
2064                                                    query.append(WHERE_GREATER_THAN);
2065                                            }
2066                                            else {
2067                                                    query.append(WHERE_LESSER_THAN);
2068                                            }
2069                                    }
2070                            }
2071    
2072                            query.append(ORDER_BY_CLAUSE);
2073    
2074                            String[] orderByFields = orderByComparator.getOrderByFields();
2075    
2076                            for (int i = 0; i < orderByFields.length; i++) {
2077                                    if (getDB().isSupportsInlineDistinct()) {
2078                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2079                                    }
2080                                    else {
2081                                            query.append(_ORDER_BY_ENTITY_TABLE);
2082                                    }
2083    
2084                                    query.append(orderByFields[i]);
2085    
2086                                    if ((i + 1) < orderByFields.length) {
2087                                            if (orderByComparator.isAscending() ^ previous) {
2088                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2089                                            }
2090                                            else {
2091                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2092                                            }
2093                                    }
2094                                    else {
2095                                            if (orderByComparator.isAscending() ^ previous) {
2096                                                    query.append(ORDER_BY_ASC);
2097                                            }
2098                                            else {
2099                                                    query.append(ORDER_BY_DESC);
2100                                            }
2101                                    }
2102                            }
2103                    }
2104                    else {
2105                            if (getDB().isSupportsInlineDistinct()) {
2106                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2107                            }
2108                            else {
2109                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
2110                            }
2111                    }
2112    
2113                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2114                                    MBThread.class.getName(),
2115                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2116    
2117                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2118    
2119                    q.setFirstResult(0);
2120                    q.setMaxResults(2);
2121    
2122                    if (getDB().isSupportsInlineDistinct()) {
2123                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
2124                    }
2125                    else {
2126                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
2127                    }
2128    
2129                    QueryPos qPos = QueryPos.getInstance(q);
2130    
2131                    qPos.add(groupId);
2132    
2133                    if (orderByComparator != null) {
2134                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
2135    
2136                            for (Object value : values) {
2137                                    qPos.add(value);
2138                            }
2139                    }
2140    
2141                    List<MBThread> list = q.list();
2142    
2143                    if (list.size() == 2) {
2144                            return list.get(1);
2145                    }
2146                    else {
2147                            return null;
2148                    }
2149            }
2150    
2151            /**
2152             * Removes all the message boards threads where groupId = &#63; from the database.
2153             *
2154             * @param groupId the group ID
2155             */
2156            @Override
2157            public void removeByGroupId(long groupId) {
2158                    for (MBThread mbThread : findByGroupId(groupId, QueryUtil.ALL_POS,
2159                                    QueryUtil.ALL_POS, null)) {
2160                            remove(mbThread);
2161                    }
2162            }
2163    
2164            /**
2165             * Returns the number of message boards threads where groupId = &#63;.
2166             *
2167             * @param groupId the group ID
2168             * @return the number of matching message boards threads
2169             */
2170            @Override
2171            public int countByGroupId(long groupId) {
2172                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2173    
2174                    Object[] finderArgs = new Object[] { groupId };
2175    
2176                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2177                                    this);
2178    
2179                    if (count == null) {
2180                            StringBundler query = new StringBundler(2);
2181    
2182                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
2183    
2184                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2185    
2186                            String sql = query.toString();
2187    
2188                            Session session = null;
2189    
2190                            try {
2191                                    session = openSession();
2192    
2193                                    Query q = session.createQuery(sql);
2194    
2195                                    QueryPos qPos = QueryPos.getInstance(q);
2196    
2197                                    qPos.add(groupId);
2198    
2199                                    count = (Long)q.uniqueResult();
2200    
2201                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2202                            }
2203                            catch (Exception e) {
2204                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2205    
2206                                    throw processException(e);
2207                            }
2208                            finally {
2209                                    closeSession(session);
2210                            }
2211                    }
2212    
2213                    return count.intValue();
2214            }
2215    
2216            /**
2217             * Returns the number of message boards threads that the user has permission to view where groupId = &#63;.
2218             *
2219             * @param groupId the group ID
2220             * @return the number of matching message boards threads that the user has permission to view
2221             */
2222            @Override
2223            public int filterCountByGroupId(long groupId) {
2224                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2225                            return countByGroupId(groupId);
2226                    }
2227    
2228                    StringBundler query = new StringBundler(2);
2229    
2230                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
2231    
2232                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2233    
2234                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2235                                    MBThread.class.getName(),
2236                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2237    
2238                    Session session = null;
2239    
2240                    try {
2241                            session = openSession();
2242    
2243                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2244    
2245                            q.addScalar(COUNT_COLUMN_NAME,
2246                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2247    
2248                            QueryPos qPos = QueryPos.getInstance(q);
2249    
2250                            qPos.add(groupId);
2251    
2252                            Long count = (Long)q.uniqueResult();
2253    
2254                            return count.intValue();
2255                    }
2256                    catch (Exception e) {
2257                            throw processException(e);
2258                    }
2259                    finally {
2260                            closeSession(session);
2261                    }
2262            }
2263    
2264            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbThread.groupId = ? AND mbThread.categoryId != -1";
2265            public static final FinderPath FINDER_PATH_FETCH_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2266                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
2267                            FINDER_CLASS_NAME_ENTITY, "fetchByRootMessageId",
2268                            new String[] { Long.class.getName() },
2269                            MBThreadModelImpl.ROOTMESSAGEID_COLUMN_BITMASK);
2270            public static final FinderPath FINDER_PATH_COUNT_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2271                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
2272                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRootMessageId",
2273                            new String[] { Long.class.getName() });
2274    
2275            /**
2276             * Returns the message boards thread where rootMessageId = &#63; or throws a {@link com.liferay.portlet.messageboards.NoSuchThreadException} if it could not be found.
2277             *
2278             * @param rootMessageId the root message ID
2279             * @return the matching message boards thread
2280             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
2281             */
2282            @Override
2283            public MBThread findByRootMessageId(long rootMessageId)
2284                    throws NoSuchThreadException {
2285                    MBThread mbThread = fetchByRootMessageId(rootMessageId);
2286    
2287                    if (mbThread == null) {
2288                            StringBundler msg = new StringBundler(4);
2289    
2290                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2291    
2292                            msg.append("rootMessageId=");
2293                            msg.append(rootMessageId);
2294    
2295                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2296    
2297                            if (_log.isWarnEnabled()) {
2298                                    _log.warn(msg.toString());
2299                            }
2300    
2301                            throw new NoSuchThreadException(msg.toString());
2302                    }
2303    
2304                    return mbThread;
2305            }
2306    
2307            /**
2308             * Returns the message boards thread where rootMessageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2309             *
2310             * @param rootMessageId the root message ID
2311             * @return the matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
2312             */
2313            @Override
2314            public MBThread fetchByRootMessageId(long rootMessageId) {
2315                    return fetchByRootMessageId(rootMessageId, true);
2316            }
2317    
2318            /**
2319             * Returns the message boards thread where rootMessageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2320             *
2321             * @param rootMessageId the root message ID
2322             * @param retrieveFromCache whether to use the finder cache
2323             * @return the matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
2324             */
2325            @Override
2326            public MBThread fetchByRootMessageId(long rootMessageId,
2327                    boolean retrieveFromCache) {
2328                    Object[] finderArgs = new Object[] { rootMessageId };
2329    
2330                    Object result = null;
2331    
2332                    if (retrieveFromCache) {
2333                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2334                                            finderArgs, this);
2335                    }
2336    
2337                    if (result instanceof MBThread) {
2338                            MBThread mbThread = (MBThread)result;
2339    
2340                            if ((rootMessageId != mbThread.getRootMessageId())) {
2341                                    result = null;
2342                            }
2343                    }
2344    
2345                    if (result == null) {
2346                            StringBundler query = new StringBundler(3);
2347    
2348                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
2349    
2350                            query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
2351    
2352                            String sql = query.toString();
2353    
2354                            Session session = null;
2355    
2356                            try {
2357                                    session = openSession();
2358    
2359                                    Query q = session.createQuery(sql);
2360    
2361                                    QueryPos qPos = QueryPos.getInstance(q);
2362    
2363                                    qPos.add(rootMessageId);
2364    
2365                                    List<MBThread> list = q.list();
2366    
2367                                    if (list.isEmpty()) {
2368                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2369                                                    finderArgs, list);
2370                                    }
2371                                    else {
2372                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
2373                                                    _log.warn(
2374                                                            "MBThreadPersistenceImpl.fetchByRootMessageId(long, boolean) with parameters (" +
2375                                                            StringUtil.merge(finderArgs) +
2376                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
2377                                            }
2378    
2379                                            MBThread mbThread = list.get(0);
2380    
2381                                            result = mbThread;
2382    
2383                                            cacheResult(mbThread);
2384    
2385                                            if ((mbThread.getRootMessageId() != rootMessageId)) {
2386                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2387                                                            finderArgs, mbThread);
2388                                            }
2389                                    }
2390                            }
2391                            catch (Exception e) {
2392                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2393                                            finderArgs);
2394    
2395                                    throw processException(e);
2396                            }
2397                            finally {
2398                                    closeSession(session);
2399                            }
2400                    }
2401    
2402                    if (result instanceof List<?>) {
2403                            return null;
2404                    }
2405                    else {
2406                            return (MBThread)result;
2407                    }
2408            }
2409    
2410            /**
2411             * Removes the message boards thread where rootMessageId = &#63; from the database.
2412             *
2413             * @param rootMessageId the root message ID
2414             * @return the message boards thread that was removed
2415             */
2416            @Override
2417            public MBThread removeByRootMessageId(long rootMessageId)
2418                    throws NoSuchThreadException {
2419                    MBThread mbThread = findByRootMessageId(rootMessageId);
2420    
2421                    return remove(mbThread);
2422            }
2423    
2424            /**
2425             * Returns the number of message boards threads where rootMessageId = &#63;.
2426             *
2427             * @param rootMessageId the root message ID
2428             * @return the number of matching message boards threads
2429             */
2430            @Override
2431            public int countByRootMessageId(long rootMessageId) {
2432                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ROOTMESSAGEID;
2433    
2434                    Object[] finderArgs = new Object[] { rootMessageId };
2435    
2436                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2437                                    this);
2438    
2439                    if (count == null) {
2440                            StringBundler query = new StringBundler(2);
2441    
2442                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
2443    
2444                            query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
2445    
2446                            String sql = query.toString();
2447    
2448                            Session session = null;
2449    
2450                            try {
2451                                    session = openSession();
2452    
2453                                    Query q = session.createQuery(sql);
2454    
2455                                    QueryPos qPos = QueryPos.getInstance(q);
2456    
2457                                    qPos.add(rootMessageId);
2458    
2459                                    count = (Long)q.uniqueResult();
2460    
2461                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2462                            }
2463                            catch (Exception e) {
2464                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2465    
2466                                    throw processException(e);
2467                            }
2468                            finally {
2469                                    closeSession(session);
2470                            }
2471                    }
2472    
2473                    return count.intValue();
2474            }
2475    
2476            private static final String _FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2 = "mbThread.rootMessageId = ?";
2477            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2478                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
2479                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
2480                            new String[] {
2481                                    Long.class.getName(), Long.class.getName(),
2482                                    
2483                            Integer.class.getName(), Integer.class.getName(),
2484                                    OrderByComparator.class.getName()
2485                            });
2486            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2487                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
2488                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
2489                            new String[] { Long.class.getName(), Long.class.getName() },
2490                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
2491                            MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
2492                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
2493                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
2494            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2495                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
2496                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
2497                            new String[] { Long.class.getName(), Long.class.getName() });
2498            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2499                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
2500                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C",
2501                            new String[] { Long.class.getName(), Long.class.getName() });
2502    
2503            /**
2504             * Returns all the message boards threads where groupId = &#63; and categoryId = &#63;.
2505             *
2506             * @param groupId the group ID
2507             * @param categoryId the category ID
2508             * @return the matching message boards threads
2509             */
2510            @Override
2511            public List<MBThread> findByG_C(long groupId, long categoryId) {
2512                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
2513                            QueryUtil.ALL_POS, null);
2514            }
2515    
2516            /**
2517             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = &#63;.
2518             *
2519             * <p>
2520             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2521             * </p>
2522             *
2523             * @param groupId the group ID
2524             * @param categoryId the category ID
2525             * @param start the lower bound of the range of message boards threads
2526             * @param end the upper bound of the range of message boards threads (not inclusive)
2527             * @return the range of matching message boards threads
2528             */
2529            @Override
2530            public List<MBThread> findByG_C(long groupId, long categoryId, int start,
2531                    int end) {
2532                    return findByG_C(groupId, categoryId, start, end, null);
2533            }
2534    
2535            /**
2536             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63;.
2537             *
2538             * <p>
2539             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2540             * </p>
2541             *
2542             * @param groupId the group ID
2543             * @param categoryId the category ID
2544             * @param start the lower bound of the range of message boards threads
2545             * @param end the upper bound of the range of message boards threads (not inclusive)
2546             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2547             * @return the ordered range of matching message boards threads
2548             */
2549            @Override
2550            public List<MBThread> findByG_C(long groupId, long categoryId, int start,
2551                    int end, OrderByComparator<MBThread> orderByComparator) {
2552                    boolean pagination = true;
2553                    FinderPath finderPath = null;
2554                    Object[] finderArgs = null;
2555    
2556                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2557                                    (orderByComparator == null)) {
2558                            pagination = false;
2559                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
2560                            finderArgs = new Object[] { groupId, categoryId };
2561                    }
2562                    else {
2563                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
2564                            finderArgs = new Object[] {
2565                                            groupId, categoryId,
2566                                            
2567                                            start, end, orderByComparator
2568                                    };
2569                    }
2570    
2571                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
2572                                    finderArgs, this);
2573    
2574                    if ((list != null) && !list.isEmpty()) {
2575                            for (MBThread mbThread : list) {
2576                                    if ((groupId != mbThread.getGroupId()) ||
2577                                                    (categoryId != mbThread.getCategoryId())) {
2578                                            list = null;
2579    
2580                                            break;
2581                                    }
2582                            }
2583                    }
2584    
2585                    if (list == null) {
2586                            StringBundler query = null;
2587    
2588                            if (orderByComparator != null) {
2589                                    query = new StringBundler(4 +
2590                                                    (orderByComparator.getOrderByFields().length * 3));
2591                            }
2592                            else {
2593                                    query = new StringBundler(4);
2594                            }
2595    
2596                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
2597    
2598                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2599    
2600                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2601    
2602                            if (orderByComparator != null) {
2603                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2604                                            orderByComparator);
2605                            }
2606                            else
2607                             if (pagination) {
2608                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2609                            }
2610    
2611                            String sql = query.toString();
2612    
2613                            Session session = null;
2614    
2615                            try {
2616                                    session = openSession();
2617    
2618                                    Query q = session.createQuery(sql);
2619    
2620                                    QueryPos qPos = QueryPos.getInstance(q);
2621    
2622                                    qPos.add(groupId);
2623    
2624                                    qPos.add(categoryId);
2625    
2626                                    if (!pagination) {
2627                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2628                                                            start, end, false);
2629    
2630                                            Collections.sort(list);
2631    
2632                                            list = Collections.unmodifiableList(list);
2633                                    }
2634                                    else {
2635                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2636                                                            start, end);
2637                                    }
2638    
2639                                    cacheResult(list);
2640    
2641                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2642                            }
2643                            catch (Exception e) {
2644                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2645    
2646                                    throw processException(e);
2647                            }
2648                            finally {
2649                                    closeSession(session);
2650                            }
2651                    }
2652    
2653                    return list;
2654            }
2655    
2656            /**
2657             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
2658             *
2659             * @param groupId the group ID
2660             * @param categoryId the category ID
2661             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2662             * @return the first matching message boards thread
2663             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
2664             */
2665            @Override
2666            public MBThread findByG_C_First(long groupId, long categoryId,
2667                    OrderByComparator<MBThread> orderByComparator)
2668                    throws NoSuchThreadException {
2669                    MBThread mbThread = fetchByG_C_First(groupId, categoryId,
2670                                    orderByComparator);
2671    
2672                    if (mbThread != null) {
2673                            return mbThread;
2674                    }
2675    
2676                    StringBundler msg = new StringBundler(6);
2677    
2678                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2679    
2680                    msg.append("groupId=");
2681                    msg.append(groupId);
2682    
2683                    msg.append(", categoryId=");
2684                    msg.append(categoryId);
2685    
2686                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2687    
2688                    throw new NoSuchThreadException(msg.toString());
2689            }
2690    
2691            /**
2692             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
2693             *
2694             * @param groupId the group ID
2695             * @param categoryId the category ID
2696             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2697             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
2698             */
2699            @Override
2700            public MBThread fetchByG_C_First(long groupId, long categoryId,
2701                    OrderByComparator<MBThread> orderByComparator) {
2702                    List<MBThread> list = findByG_C(groupId, categoryId, 0, 1,
2703                                    orderByComparator);
2704    
2705                    if (!list.isEmpty()) {
2706                            return list.get(0);
2707                    }
2708    
2709                    return null;
2710            }
2711    
2712            /**
2713             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
2714             *
2715             * @param groupId the group ID
2716             * @param categoryId the category ID
2717             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2718             * @return the last matching message boards thread
2719             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
2720             */
2721            @Override
2722            public MBThread findByG_C_Last(long groupId, long categoryId,
2723                    OrderByComparator<MBThread> orderByComparator)
2724                    throws NoSuchThreadException {
2725                    MBThread mbThread = fetchByG_C_Last(groupId, categoryId,
2726                                    orderByComparator);
2727    
2728                    if (mbThread != null) {
2729                            return mbThread;
2730                    }
2731    
2732                    StringBundler msg = new StringBundler(6);
2733    
2734                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2735    
2736                    msg.append("groupId=");
2737                    msg.append(groupId);
2738    
2739                    msg.append(", categoryId=");
2740                    msg.append(categoryId);
2741    
2742                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2743    
2744                    throw new NoSuchThreadException(msg.toString());
2745            }
2746    
2747            /**
2748             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
2749             *
2750             * @param groupId the group ID
2751             * @param categoryId the category ID
2752             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2753             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
2754             */
2755            @Override
2756            public MBThread fetchByG_C_Last(long groupId, long categoryId,
2757                    OrderByComparator<MBThread> orderByComparator) {
2758                    int count = countByG_C(groupId, categoryId);
2759    
2760                    if (count == 0) {
2761                            return null;
2762                    }
2763    
2764                    List<MBThread> list = findByG_C(groupId, categoryId, count - 1, count,
2765                                    orderByComparator);
2766    
2767                    if (!list.isEmpty()) {
2768                            return list.get(0);
2769                    }
2770    
2771                    return null;
2772            }
2773    
2774            /**
2775             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
2776             *
2777             * @param threadId the primary key of the current message boards thread
2778             * @param groupId the group ID
2779             * @param categoryId the category ID
2780             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2781             * @return the previous, current, and next message boards thread
2782             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
2783             */
2784            @Override
2785            public MBThread[] findByG_C_PrevAndNext(long threadId, long groupId,
2786                    long categoryId, OrderByComparator<MBThread> orderByComparator)
2787                    throws NoSuchThreadException {
2788                    MBThread mbThread = findByPrimaryKey(threadId);
2789    
2790                    Session session = null;
2791    
2792                    try {
2793                            session = openSession();
2794    
2795                            MBThread[] array = new MBThreadImpl[3];
2796    
2797                            array[0] = getByG_C_PrevAndNext(session, mbThread, groupId,
2798                                            categoryId, orderByComparator, true);
2799    
2800                            array[1] = mbThread;
2801    
2802                            array[2] = getByG_C_PrevAndNext(session, mbThread, groupId,
2803                                            categoryId, orderByComparator, false);
2804    
2805                            return array;
2806                    }
2807                    catch (Exception e) {
2808                            throw processException(e);
2809                    }
2810                    finally {
2811                            closeSession(session);
2812                    }
2813            }
2814    
2815            protected MBThread getByG_C_PrevAndNext(Session session, MBThread mbThread,
2816                    long groupId, long categoryId,
2817                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
2818                    StringBundler query = null;
2819    
2820                    if (orderByComparator != null) {
2821                            query = new StringBundler(6 +
2822                                            (orderByComparator.getOrderByFields().length * 6));
2823                    }
2824                    else {
2825                            query = new StringBundler(3);
2826                    }
2827    
2828                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
2829    
2830                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2831    
2832                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2833    
2834                    if (orderByComparator != null) {
2835                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2836    
2837                            if (orderByConditionFields.length > 0) {
2838                                    query.append(WHERE_AND);
2839                            }
2840    
2841                            for (int i = 0; i < orderByConditionFields.length; i++) {
2842                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2843                                    query.append(orderByConditionFields[i]);
2844    
2845                                    if ((i + 1) < orderByConditionFields.length) {
2846                                            if (orderByComparator.isAscending() ^ previous) {
2847                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2848                                            }
2849                                            else {
2850                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2851                                            }
2852                                    }
2853                                    else {
2854                                            if (orderByComparator.isAscending() ^ previous) {
2855                                                    query.append(WHERE_GREATER_THAN);
2856                                            }
2857                                            else {
2858                                                    query.append(WHERE_LESSER_THAN);
2859                                            }
2860                                    }
2861                            }
2862    
2863                            query.append(ORDER_BY_CLAUSE);
2864    
2865                            String[] orderByFields = orderByComparator.getOrderByFields();
2866    
2867                            for (int i = 0; i < orderByFields.length; i++) {
2868                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2869                                    query.append(orderByFields[i]);
2870    
2871                                    if ((i + 1) < orderByFields.length) {
2872                                            if (orderByComparator.isAscending() ^ previous) {
2873                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2874                                            }
2875                                            else {
2876                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2877                                            }
2878                                    }
2879                                    else {
2880                                            if (orderByComparator.isAscending() ^ previous) {
2881                                                    query.append(ORDER_BY_ASC);
2882                                            }
2883                                            else {
2884                                                    query.append(ORDER_BY_DESC);
2885                                            }
2886                                    }
2887                            }
2888                    }
2889                    else {
2890                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2891                    }
2892    
2893                    String sql = query.toString();
2894    
2895                    Query q = session.createQuery(sql);
2896    
2897                    q.setFirstResult(0);
2898                    q.setMaxResults(2);
2899    
2900                    QueryPos qPos = QueryPos.getInstance(q);
2901    
2902                    qPos.add(groupId);
2903    
2904                    qPos.add(categoryId);
2905    
2906                    if (orderByComparator != null) {
2907                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
2908    
2909                            for (Object value : values) {
2910                                    qPos.add(value);
2911                            }
2912                    }
2913    
2914                    List<MBThread> list = q.list();
2915    
2916                    if (list.size() == 2) {
2917                            return list.get(1);
2918                    }
2919                    else {
2920                            return null;
2921                    }
2922            }
2923    
2924            /**
2925             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63;.
2926             *
2927             * @param groupId the group ID
2928             * @param categoryId the category ID
2929             * @return the matching message boards threads that the user has permission to view
2930             */
2931            @Override
2932            public List<MBThread> filterFindByG_C(long groupId, long categoryId) {
2933                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
2934                            QueryUtil.ALL_POS, null);
2935            }
2936    
2937            /**
2938             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63;.
2939             *
2940             * <p>
2941             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2942             * </p>
2943             *
2944             * @param groupId the group ID
2945             * @param categoryId the category ID
2946             * @param start the lower bound of the range of message boards threads
2947             * @param end the upper bound of the range of message boards threads (not inclusive)
2948             * @return the range of matching message boards threads that the user has permission to view
2949             */
2950            @Override
2951            public List<MBThread> filterFindByG_C(long groupId, long categoryId,
2952                    int start, int end) {
2953                    return filterFindByG_C(groupId, categoryId, start, end, null);
2954            }
2955    
2956            /**
2957             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
2958             *
2959             * <p>
2960             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2961             * </p>
2962             *
2963             * @param groupId the group ID
2964             * @param categoryId the category ID
2965             * @param start the lower bound of the range of message boards threads
2966             * @param end the upper bound of the range of message boards threads (not inclusive)
2967             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2968             * @return the ordered range of matching message boards threads that the user has permission to view
2969             */
2970            @Override
2971            public List<MBThread> filterFindByG_C(long groupId, long categoryId,
2972                    int start, int end, OrderByComparator<MBThread> orderByComparator) {
2973                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2974                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
2975                    }
2976    
2977                    StringBundler query = null;
2978    
2979                    if (orderByComparator != null) {
2980                            query = new StringBundler(4 +
2981                                            (orderByComparator.getOrderByFields().length * 3));
2982                    }
2983                    else {
2984                            query = new StringBundler(4);
2985                    }
2986    
2987                    if (getDB().isSupportsInlineDistinct()) {
2988                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2989                    }
2990                    else {
2991                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2992                    }
2993    
2994                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2995    
2996                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2997    
2998                    if (!getDB().isSupportsInlineDistinct()) {
2999                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3000                    }
3001    
3002                    if (orderByComparator != null) {
3003                            if (getDB().isSupportsInlineDistinct()) {
3004                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3005                                            orderByComparator, true);
3006                            }
3007                            else {
3008                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3009                                            orderByComparator, true);
3010                            }
3011                    }
3012                    else {
3013                            if (getDB().isSupportsInlineDistinct()) {
3014                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3015                            }
3016                            else {
3017                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
3018                            }
3019                    }
3020    
3021                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3022                                    MBThread.class.getName(),
3023                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3024    
3025                    Session session = null;
3026    
3027                    try {
3028                            session = openSession();
3029    
3030                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3031    
3032                            if (getDB().isSupportsInlineDistinct()) {
3033                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3034                            }
3035                            else {
3036                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3037                            }
3038    
3039                            QueryPos qPos = QueryPos.getInstance(q);
3040    
3041                            qPos.add(groupId);
3042    
3043                            qPos.add(categoryId);
3044    
3045                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3046                    }
3047                    catch (Exception e) {
3048                            throw processException(e);
3049                    }
3050                    finally {
3051                            closeSession(session);
3052                    }
3053            }
3054    
3055            /**
3056             * Returns the message boards threads before and after the current message boards thread in the ordered set of message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63;.
3057             *
3058             * @param threadId the primary key of the current message boards thread
3059             * @param groupId the group ID
3060             * @param categoryId the category ID
3061             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3062             * @return the previous, current, and next message boards thread
3063             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
3064             */
3065            @Override
3066            public MBThread[] filterFindByG_C_PrevAndNext(long threadId, long groupId,
3067                    long categoryId, OrderByComparator<MBThread> orderByComparator)
3068                    throws NoSuchThreadException {
3069                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3070                            return findByG_C_PrevAndNext(threadId, groupId, categoryId,
3071                                    orderByComparator);
3072                    }
3073    
3074                    MBThread mbThread = findByPrimaryKey(threadId);
3075    
3076                    Session session = null;
3077    
3078                    try {
3079                            session = openSession();
3080    
3081                            MBThread[] array = new MBThreadImpl[3];
3082    
3083                            array[0] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
3084                                            categoryId, orderByComparator, true);
3085    
3086                            array[1] = mbThread;
3087    
3088                            array[2] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
3089                                            categoryId, orderByComparator, false);
3090    
3091                            return array;
3092                    }
3093                    catch (Exception e) {
3094                            throw processException(e);
3095                    }
3096                    finally {
3097                            closeSession(session);
3098                    }
3099            }
3100    
3101            protected MBThread filterGetByG_C_PrevAndNext(Session session,
3102                    MBThread mbThread, long groupId, long categoryId,
3103                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
3104                    StringBundler query = null;
3105    
3106                    if (orderByComparator != null) {
3107                            query = new StringBundler(6 +
3108                                            (orderByComparator.getOrderByFields().length * 6));
3109                    }
3110                    else {
3111                            query = new StringBundler(3);
3112                    }
3113    
3114                    if (getDB().isSupportsInlineDistinct()) {
3115                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3116                    }
3117                    else {
3118                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3119                    }
3120    
3121                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3122    
3123                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3124    
3125                    if (!getDB().isSupportsInlineDistinct()) {
3126                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3127                    }
3128    
3129                    if (orderByComparator != null) {
3130                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3131    
3132                            if (orderByConditionFields.length > 0) {
3133                                    query.append(WHERE_AND);
3134                            }
3135    
3136                            for (int i = 0; i < orderByConditionFields.length; i++) {
3137                                    if (getDB().isSupportsInlineDistinct()) {
3138                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3139                                    }
3140                                    else {
3141                                            query.append(_ORDER_BY_ENTITY_TABLE);
3142                                    }
3143    
3144                                    query.append(orderByConditionFields[i]);
3145    
3146                                    if ((i + 1) < orderByConditionFields.length) {
3147                                            if (orderByComparator.isAscending() ^ previous) {
3148                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3149                                            }
3150                                            else {
3151                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3152                                            }
3153                                    }
3154                                    else {
3155                                            if (orderByComparator.isAscending() ^ previous) {
3156                                                    query.append(WHERE_GREATER_THAN);
3157                                            }
3158                                            else {
3159                                                    query.append(WHERE_LESSER_THAN);
3160                                            }
3161                                    }
3162                            }
3163    
3164                            query.append(ORDER_BY_CLAUSE);
3165    
3166                            String[] orderByFields = orderByComparator.getOrderByFields();
3167    
3168                            for (int i = 0; i < orderByFields.length; i++) {
3169                                    if (getDB().isSupportsInlineDistinct()) {
3170                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3171                                    }
3172                                    else {
3173                                            query.append(_ORDER_BY_ENTITY_TABLE);
3174                                    }
3175    
3176                                    query.append(orderByFields[i]);
3177    
3178                                    if ((i + 1) < orderByFields.length) {
3179                                            if (orderByComparator.isAscending() ^ previous) {
3180                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3181                                            }
3182                                            else {
3183                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3184                                            }
3185                                    }
3186                                    else {
3187                                            if (orderByComparator.isAscending() ^ previous) {
3188                                                    query.append(ORDER_BY_ASC);
3189                                            }
3190                                            else {
3191                                                    query.append(ORDER_BY_DESC);
3192                                            }
3193                                    }
3194                            }
3195                    }
3196                    else {
3197                            if (getDB().isSupportsInlineDistinct()) {
3198                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3199                            }
3200                            else {
3201                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
3202                            }
3203                    }
3204    
3205                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3206                                    MBThread.class.getName(),
3207                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3208    
3209                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
3210    
3211                    q.setFirstResult(0);
3212                    q.setMaxResults(2);
3213    
3214                    if (getDB().isSupportsInlineDistinct()) {
3215                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3216                    }
3217                    else {
3218                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3219                    }
3220    
3221                    QueryPos qPos = QueryPos.getInstance(q);
3222    
3223                    qPos.add(groupId);
3224    
3225                    qPos.add(categoryId);
3226    
3227                    if (orderByComparator != null) {
3228                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3229    
3230                            for (Object value : values) {
3231                                    qPos.add(value);
3232                            }
3233                    }
3234    
3235                    List<MBThread> list = q.list();
3236    
3237                    if (list.size() == 2) {
3238                            return list.get(1);
3239                    }
3240                    else {
3241                            return null;
3242                    }
3243            }
3244    
3245            /**
3246             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63;.
3247             *
3248             * @param groupId the group ID
3249             * @param categoryIds the category IDs
3250             * @return the matching message boards threads that the user has permission to view
3251             */
3252            @Override
3253            public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds) {
3254                    return filterFindByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
3255                            QueryUtil.ALL_POS, null);
3256            }
3257    
3258            /**
3259             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63;.
3260             *
3261             * <p>
3262             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3263             * </p>
3264             *
3265             * @param groupId the group ID
3266             * @param categoryIds the category IDs
3267             * @param start the lower bound of the range of message boards threads
3268             * @param end the upper bound of the range of message boards threads (not inclusive)
3269             * @return the range of matching message boards threads that the user has permission to view
3270             */
3271            @Override
3272            public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
3273                    int start, int end) {
3274                    return filterFindByG_C(groupId, categoryIds, start, end, null);
3275            }
3276    
3277            /**
3278             * Returns an ordered range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63;.
3279             *
3280             * <p>
3281             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3282             * </p>
3283             *
3284             * @param groupId the group ID
3285             * @param categoryIds the category IDs
3286             * @param start the lower bound of the range of message boards threads
3287             * @param end the upper bound of the range of message boards threads (not inclusive)
3288             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3289             * @return the ordered range of matching message boards threads that the user has permission to view
3290             */
3291            @Override
3292            public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
3293                    int start, int end, OrderByComparator<MBThread> orderByComparator) {
3294                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3295                            return findByG_C(groupId, categoryIds, start, end, orderByComparator);
3296                    }
3297    
3298                    if (categoryIds == null) {
3299                            categoryIds = new long[0];
3300                    }
3301                    else {
3302                            categoryIds = ArrayUtil.unique(categoryIds);
3303                    }
3304    
3305                    StringBundler query = new StringBundler();
3306    
3307                    if (getDB().isSupportsInlineDistinct()) {
3308                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3309                    }
3310                    else {
3311                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3312                    }
3313    
3314                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3315    
3316                    if (categoryIds.length > 0) {
3317                            query.append(StringPool.OPEN_PARENTHESIS);
3318    
3319                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_7);
3320    
3321                            query.append(StringUtil.merge(categoryIds));
3322    
3323                            query.append(StringPool.CLOSE_PARENTHESIS);
3324    
3325                            query.append(StringPool.CLOSE_PARENTHESIS);
3326                    }
3327    
3328                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
3329                            query.index() - 1);
3330    
3331                    if (!getDB().isSupportsInlineDistinct()) {
3332                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3333                    }
3334    
3335                    if (orderByComparator != null) {
3336                            if (getDB().isSupportsInlineDistinct()) {
3337                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3338                                            orderByComparator, true);
3339                            }
3340                            else {
3341                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3342                                            orderByComparator, true);
3343                            }
3344                    }
3345                    else {
3346                            if (getDB().isSupportsInlineDistinct()) {
3347                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3348                            }
3349                            else {
3350                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
3351                            }
3352                    }
3353    
3354                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3355                                    MBThread.class.getName(),
3356                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3357    
3358                    Session session = null;
3359    
3360                    try {
3361                            session = openSession();
3362    
3363                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3364    
3365                            if (getDB().isSupportsInlineDistinct()) {
3366                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3367                            }
3368                            else {
3369                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3370                            }
3371    
3372                            QueryPos qPos = QueryPos.getInstance(q);
3373    
3374                            qPos.add(groupId);
3375    
3376                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3377                    }
3378                    catch (Exception e) {
3379                            throw processException(e);
3380                    }
3381                    finally {
3382                            closeSession(session);
3383                    }
3384            }
3385    
3386            /**
3387             * Returns all the message boards threads where groupId = &#63; and categoryId = any &#63;.
3388             *
3389             * <p>
3390             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3391             * </p>
3392             *
3393             * @param groupId the group ID
3394             * @param categoryIds the category IDs
3395             * @return the matching message boards threads
3396             */
3397            @Override
3398            public List<MBThread> findByG_C(long groupId, long[] categoryIds) {
3399                    return findByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
3400                            QueryUtil.ALL_POS, null);
3401            }
3402    
3403            /**
3404             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = any &#63;.
3405             *
3406             * <p>
3407             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3408             * </p>
3409             *
3410             * @param groupId the group ID
3411             * @param categoryIds the category IDs
3412             * @param start the lower bound of the range of message boards threads
3413             * @param end the upper bound of the range of message boards threads (not inclusive)
3414             * @return the range of matching message boards threads
3415             */
3416            @Override
3417            public List<MBThread> findByG_C(long groupId, long[] categoryIds,
3418                    int start, int end) {
3419                    return findByG_C(groupId, categoryIds, start, end, null);
3420            }
3421    
3422            /**
3423             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = any &#63;.
3424             *
3425             * <p>
3426             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3427             * </p>
3428             *
3429             * @param groupId the group ID
3430             * @param categoryIds the category IDs
3431             * @param start the lower bound of the range of message boards threads
3432             * @param end the upper bound of the range of message boards threads (not inclusive)
3433             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3434             * @return the ordered range of matching message boards threads
3435             */
3436            @Override
3437            public List<MBThread> findByG_C(long groupId, long[] categoryIds,
3438                    int start, int end, OrderByComparator<MBThread> orderByComparator) {
3439                    if (categoryIds == null) {
3440                            categoryIds = new long[0];
3441                    }
3442                    else {
3443                            categoryIds = ArrayUtil.unique(categoryIds);
3444                    }
3445    
3446                    if (categoryIds.length == 1) {
3447                            return findByG_C(groupId, categoryIds[0], start, end,
3448                                    orderByComparator);
3449                    }
3450    
3451                    boolean pagination = true;
3452                    Object[] finderArgs = null;
3453    
3454                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3455                                    (orderByComparator == null)) {
3456                            pagination = false;
3457                            finderArgs = new Object[] { groupId, StringUtil.merge(categoryIds) };
3458                    }
3459                    else {
3460                            finderArgs = new Object[] {
3461                                            groupId, StringUtil.merge(categoryIds),
3462                                            
3463                                            start, end, orderByComparator
3464                                    };
3465                    }
3466    
3467                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
3468                                    finderArgs, this);
3469    
3470                    if ((list != null) && !list.isEmpty()) {
3471                            for (MBThread mbThread : list) {
3472                                    if ((groupId != mbThread.getGroupId()) ||
3473                                                    !ArrayUtil.contains(categoryIds,
3474                                                            mbThread.getCategoryId())) {
3475                                            list = null;
3476    
3477                                            break;
3478                                    }
3479                            }
3480                    }
3481    
3482                    if (list == null) {
3483                            StringBundler query = new StringBundler();
3484    
3485                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
3486    
3487                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3488    
3489                            if (categoryIds.length > 0) {
3490                                    query.append(StringPool.OPEN_PARENTHESIS);
3491    
3492                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_7);
3493    
3494                                    query.append(StringUtil.merge(categoryIds));
3495    
3496                                    query.append(StringPool.CLOSE_PARENTHESIS);
3497    
3498                                    query.append(StringPool.CLOSE_PARENTHESIS);
3499                            }
3500    
3501                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
3502                                                    1)), query.index() - 1);
3503    
3504                            if (orderByComparator != null) {
3505                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3506                                            orderByComparator);
3507                            }
3508                            else
3509                             if (pagination) {
3510                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3511                            }
3512    
3513                            String sql = query.toString();
3514    
3515                            Session session = null;
3516    
3517                            try {
3518                                    session = openSession();
3519    
3520                                    Query q = session.createQuery(sql);
3521    
3522                                    QueryPos qPos = QueryPos.getInstance(q);
3523    
3524                                    qPos.add(groupId);
3525    
3526                                    if (!pagination) {
3527                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3528                                                            start, end, false);
3529    
3530                                            Collections.sort(list);
3531    
3532                                            list = Collections.unmodifiableList(list);
3533                                    }
3534                                    else {
3535                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3536                                                            start, end);
3537                                    }
3538    
3539                                    cacheResult(list);
3540    
3541                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
3542                                            finderArgs, list);
3543                            }
3544                            catch (Exception e) {
3545                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
3546                                            finderArgs);
3547    
3548                                    throw processException(e);
3549                            }
3550                            finally {
3551                                    closeSession(session);
3552                            }
3553                    }
3554    
3555                    return list;
3556            }
3557    
3558            /**
3559             * Removes all the message boards threads where groupId = &#63; and categoryId = &#63; from the database.
3560             *
3561             * @param groupId the group ID
3562             * @param categoryId the category ID
3563             */
3564            @Override
3565            public void removeByG_C(long groupId, long categoryId) {
3566                    for (MBThread mbThread : findByG_C(groupId, categoryId,
3567                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3568                            remove(mbThread);
3569                    }
3570            }
3571    
3572            /**
3573             * Returns the number of message boards threads where groupId = &#63; and categoryId = &#63;.
3574             *
3575             * @param groupId the group ID
3576             * @param categoryId the category ID
3577             * @return the number of matching message boards threads
3578             */
3579            @Override
3580            public int countByG_C(long groupId, long categoryId) {
3581                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
3582    
3583                    Object[] finderArgs = new Object[] { groupId, categoryId };
3584    
3585                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3586                                    this);
3587    
3588                    if (count == null) {
3589                            StringBundler query = new StringBundler(3);
3590    
3591                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
3592    
3593                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3594    
3595                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3596    
3597                            String sql = query.toString();
3598    
3599                            Session session = null;
3600    
3601                            try {
3602                                    session = openSession();
3603    
3604                                    Query q = session.createQuery(sql);
3605    
3606                                    QueryPos qPos = QueryPos.getInstance(q);
3607    
3608                                    qPos.add(groupId);
3609    
3610                                    qPos.add(categoryId);
3611    
3612                                    count = (Long)q.uniqueResult();
3613    
3614                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3615                            }
3616                            catch (Exception e) {
3617                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3618    
3619                                    throw processException(e);
3620                            }
3621                            finally {
3622                                    closeSession(session);
3623                            }
3624                    }
3625    
3626                    return count.intValue();
3627            }
3628    
3629            /**
3630             * Returns the number of message boards threads where groupId = &#63; and categoryId = any &#63;.
3631             *
3632             * @param groupId the group ID
3633             * @param categoryIds the category IDs
3634             * @return the number of matching message boards threads
3635             */
3636            @Override
3637            public int countByG_C(long groupId, long[] categoryIds) {
3638                    if (categoryIds == null) {
3639                            categoryIds = new long[0];
3640                    }
3641                    else {
3642                            categoryIds = ArrayUtil.unique(categoryIds);
3643                    }
3644    
3645                    Object[] finderArgs = new Object[] {
3646                                    groupId, StringUtil.merge(categoryIds)
3647                            };
3648    
3649                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
3650                                    finderArgs, this);
3651    
3652                    if (count == null) {
3653                            StringBundler query = new StringBundler();
3654    
3655                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
3656    
3657                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3658    
3659                            if (categoryIds.length > 0) {
3660                                    query.append(StringPool.OPEN_PARENTHESIS);
3661    
3662                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_7);
3663    
3664                                    query.append(StringUtil.merge(categoryIds));
3665    
3666                                    query.append(StringPool.CLOSE_PARENTHESIS);
3667    
3668                                    query.append(StringPool.CLOSE_PARENTHESIS);
3669                            }
3670    
3671                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
3672                                                    1)), query.index() - 1);
3673    
3674                            String sql = query.toString();
3675    
3676                            Session session = null;
3677    
3678                            try {
3679                                    session = openSession();
3680    
3681                                    Query q = session.createQuery(sql);
3682    
3683                                    QueryPos qPos = QueryPos.getInstance(q);
3684    
3685                                    qPos.add(groupId);
3686    
3687                                    count = (Long)q.uniqueResult();
3688    
3689                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
3690                                            finderArgs, count);
3691                            }
3692                            catch (Exception e) {
3693                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
3694                                            finderArgs);
3695    
3696                                    throw processException(e);
3697                            }
3698                            finally {
3699                                    closeSession(session);
3700                            }
3701                    }
3702    
3703                    return count.intValue();
3704            }
3705    
3706            /**
3707             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63;.
3708             *
3709             * @param groupId the group ID
3710             * @param categoryId the category ID
3711             * @return the number of matching message boards threads that the user has permission to view
3712             */
3713            @Override
3714            public int filterCountByG_C(long groupId, long categoryId) {
3715                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3716                            return countByG_C(groupId, categoryId);
3717                    }
3718    
3719                    StringBundler query = new StringBundler(3);
3720    
3721                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
3722    
3723                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3724    
3725                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3726    
3727                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3728                                    MBThread.class.getName(),
3729                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3730    
3731                    Session session = null;
3732    
3733                    try {
3734                            session = openSession();
3735    
3736                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3737    
3738                            q.addScalar(COUNT_COLUMN_NAME,
3739                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3740    
3741                            QueryPos qPos = QueryPos.getInstance(q);
3742    
3743                            qPos.add(groupId);
3744    
3745                            qPos.add(categoryId);
3746    
3747                            Long count = (Long)q.uniqueResult();
3748    
3749                            return count.intValue();
3750                    }
3751                    catch (Exception e) {
3752                            throw processException(e);
3753                    }
3754                    finally {
3755                            closeSession(session);
3756                    }
3757            }
3758    
3759            /**
3760             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63;.
3761             *
3762             * @param groupId the group ID
3763             * @param categoryIds the category IDs
3764             * @return the number of matching message boards threads that the user has permission to view
3765             */
3766            @Override
3767            public int filterCountByG_C(long groupId, long[] categoryIds) {
3768                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3769                            return countByG_C(groupId, categoryIds);
3770                    }
3771    
3772                    if (categoryIds == null) {
3773                            categoryIds = new long[0];
3774                    }
3775                    else {
3776                            categoryIds = ArrayUtil.unique(categoryIds);
3777                    }
3778    
3779                    StringBundler query = new StringBundler();
3780    
3781                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
3782    
3783                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3784    
3785                    if (categoryIds.length > 0) {
3786                            query.append(StringPool.OPEN_PARENTHESIS);
3787    
3788                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_7);
3789    
3790                            query.append(StringUtil.merge(categoryIds));
3791    
3792                            query.append(StringPool.CLOSE_PARENTHESIS);
3793    
3794                            query.append(StringPool.CLOSE_PARENTHESIS);
3795                    }
3796    
3797                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
3798                            query.index() - 1);
3799    
3800                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3801                                    MBThread.class.getName(),
3802                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3803    
3804                    Session session = null;
3805    
3806                    try {
3807                            session = openSession();
3808    
3809                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3810    
3811                            q.addScalar(COUNT_COLUMN_NAME,
3812                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3813    
3814                            QueryPos qPos = QueryPos.getInstance(q);
3815    
3816                            qPos.add(groupId);
3817    
3818                            Long count = (Long)q.uniqueResult();
3819    
3820                            return count.intValue();
3821                    }
3822                    catch (Exception e) {
3823                            throw processException(e);
3824                    }
3825                    finally {
3826                            closeSession(session);
3827                    }
3828            }
3829    
3830            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbThread.groupId = ? AND ";
3831            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbThread.categoryId = ?";
3832            private static final String _FINDER_COLUMN_G_C_CATEGORYID_7 = "mbThread.categoryId IN (";
3833            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
3834                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
3835                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC",
3836                            new String[] {
3837                                    Long.class.getName(), Long.class.getName(),
3838                                    
3839                            Integer.class.getName(), Integer.class.getName(),
3840                                    OrderByComparator.class.getName()
3841                            });
3842            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
3843                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
3844                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC",
3845                            new String[] { Long.class.getName(), Long.class.getName() });
3846    
3847            /**
3848             * Returns all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
3849             *
3850             * @param groupId the group ID
3851             * @param categoryId the category ID
3852             * @return the matching message boards threads
3853             */
3854            @Override
3855            public List<MBThread> findByG_NotC(long groupId, long categoryId) {
3856                    return findByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
3857                            QueryUtil.ALL_POS, null);
3858            }
3859    
3860            /**
3861             * Returns a range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
3862             *
3863             * <p>
3864             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3865             * </p>
3866             *
3867             * @param groupId the group ID
3868             * @param categoryId the category ID
3869             * @param start the lower bound of the range of message boards threads
3870             * @param end the upper bound of the range of message boards threads (not inclusive)
3871             * @return the range of matching message boards threads
3872             */
3873            @Override
3874            public List<MBThread> findByG_NotC(long groupId, long categoryId,
3875                    int start, int end) {
3876                    return findByG_NotC(groupId, categoryId, start, end, null);
3877            }
3878    
3879            /**
3880             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
3881             *
3882             * <p>
3883             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3884             * </p>
3885             *
3886             * @param groupId the group ID
3887             * @param categoryId the category ID
3888             * @param start the lower bound of the range of message boards threads
3889             * @param end the upper bound of the range of message boards threads (not inclusive)
3890             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3891             * @return the ordered range of matching message boards threads
3892             */
3893            @Override
3894            public List<MBThread> findByG_NotC(long groupId, long categoryId,
3895                    int start, int end, OrderByComparator<MBThread> orderByComparator) {
3896                    boolean pagination = true;
3897                    FinderPath finderPath = null;
3898                    Object[] finderArgs = null;
3899    
3900                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC;
3901                    finderArgs = new Object[] {
3902                                    groupId, categoryId,
3903                                    
3904                                    start, end, orderByComparator
3905                            };
3906    
3907                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
3908                                    finderArgs, this);
3909    
3910                    if ((list != null) && !list.isEmpty()) {
3911                            for (MBThread mbThread : list) {
3912                                    if ((groupId != mbThread.getGroupId()) ||
3913                                                    (categoryId == mbThread.getCategoryId())) {
3914                                            list = null;
3915    
3916                                            break;
3917                                    }
3918                            }
3919                    }
3920    
3921                    if (list == null) {
3922                            StringBundler query = null;
3923    
3924                            if (orderByComparator != null) {
3925                                    query = new StringBundler(4 +
3926                                                    (orderByComparator.getOrderByFields().length * 3));
3927                            }
3928                            else {
3929                                    query = new StringBundler(4);
3930                            }
3931    
3932                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
3933    
3934                            query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
3935    
3936                            query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
3937    
3938                            if (orderByComparator != null) {
3939                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3940                                            orderByComparator);
3941                            }
3942                            else
3943                             if (pagination) {
3944                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3945                            }
3946    
3947                            String sql = query.toString();
3948    
3949                            Session session = null;
3950    
3951                            try {
3952                                    session = openSession();
3953    
3954                                    Query q = session.createQuery(sql);
3955    
3956                                    QueryPos qPos = QueryPos.getInstance(q);
3957    
3958                                    qPos.add(groupId);
3959    
3960                                    qPos.add(categoryId);
3961    
3962                                    if (!pagination) {
3963                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3964                                                            start, end, false);
3965    
3966                                            Collections.sort(list);
3967    
3968                                            list = Collections.unmodifiableList(list);
3969                                    }
3970                                    else {
3971                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3972                                                            start, end);
3973                                    }
3974    
3975                                    cacheResult(list);
3976    
3977                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3978                            }
3979                            catch (Exception e) {
3980                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3981    
3982                                    throw processException(e);
3983                            }
3984                            finally {
3985                                    closeSession(session);
3986                            }
3987                    }
3988    
3989                    return list;
3990            }
3991    
3992            /**
3993             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
3994             *
3995             * @param groupId the group ID
3996             * @param categoryId the category ID
3997             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3998             * @return the first matching message boards thread
3999             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
4000             */
4001            @Override
4002            public MBThread findByG_NotC_First(long groupId, long categoryId,
4003                    OrderByComparator<MBThread> orderByComparator)
4004                    throws NoSuchThreadException {
4005                    MBThread mbThread = fetchByG_NotC_First(groupId, categoryId,
4006                                    orderByComparator);
4007    
4008                    if (mbThread != null) {
4009                            return mbThread;
4010                    }
4011    
4012                    StringBundler msg = new StringBundler(6);
4013    
4014                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4015    
4016                    msg.append("groupId=");
4017                    msg.append(groupId);
4018    
4019                    msg.append(", categoryId=");
4020                    msg.append(categoryId);
4021    
4022                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4023    
4024                    throw new NoSuchThreadException(msg.toString());
4025            }
4026    
4027            /**
4028             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
4029             *
4030             * @param groupId the group ID
4031             * @param categoryId the category ID
4032             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4033             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
4034             */
4035            @Override
4036            public MBThread fetchByG_NotC_First(long groupId, long categoryId,
4037                    OrderByComparator<MBThread> orderByComparator) {
4038                    List<MBThread> list = findByG_NotC(groupId, categoryId, 0, 1,
4039                                    orderByComparator);
4040    
4041                    if (!list.isEmpty()) {
4042                            return list.get(0);
4043                    }
4044    
4045                    return null;
4046            }
4047    
4048            /**
4049             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
4050             *
4051             * @param groupId the group ID
4052             * @param categoryId the category ID
4053             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4054             * @return the last matching message boards thread
4055             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
4056             */
4057            @Override
4058            public MBThread findByG_NotC_Last(long groupId, long categoryId,
4059                    OrderByComparator<MBThread> orderByComparator)
4060                    throws NoSuchThreadException {
4061                    MBThread mbThread = fetchByG_NotC_Last(groupId, categoryId,
4062                                    orderByComparator);
4063    
4064                    if (mbThread != null) {
4065                            return mbThread;
4066                    }
4067    
4068                    StringBundler msg = new StringBundler(6);
4069    
4070                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4071    
4072                    msg.append("groupId=");
4073                    msg.append(groupId);
4074    
4075                    msg.append(", categoryId=");
4076                    msg.append(categoryId);
4077    
4078                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4079    
4080                    throw new NoSuchThreadException(msg.toString());
4081            }
4082    
4083            /**
4084             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
4085             *
4086             * @param groupId the group ID
4087             * @param categoryId the category ID
4088             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4089             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
4090             */
4091            @Override
4092            public MBThread fetchByG_NotC_Last(long groupId, long categoryId,
4093                    OrderByComparator<MBThread> orderByComparator) {
4094                    int count = countByG_NotC(groupId, categoryId);
4095    
4096                    if (count == 0) {
4097                            return null;
4098                    }
4099    
4100                    List<MBThread> list = findByG_NotC(groupId, categoryId, count - 1,
4101                                    count, orderByComparator);
4102    
4103                    if (!list.isEmpty()) {
4104                            return list.get(0);
4105                    }
4106    
4107                    return null;
4108            }
4109    
4110            /**
4111             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
4112             *
4113             * @param threadId the primary key of the current message boards thread
4114             * @param groupId the group ID
4115             * @param categoryId the category ID
4116             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4117             * @return the previous, current, and next message boards thread
4118             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
4119             */
4120            @Override
4121            public MBThread[] findByG_NotC_PrevAndNext(long threadId, long groupId,
4122                    long categoryId, OrderByComparator<MBThread> orderByComparator)
4123                    throws NoSuchThreadException {
4124                    MBThread mbThread = findByPrimaryKey(threadId);
4125    
4126                    Session session = null;
4127    
4128                    try {
4129                            session = openSession();
4130    
4131                            MBThread[] array = new MBThreadImpl[3];
4132    
4133                            array[0] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
4134                                            categoryId, orderByComparator, true);
4135    
4136                            array[1] = mbThread;
4137    
4138                            array[2] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
4139                                            categoryId, orderByComparator, false);
4140    
4141                            return array;
4142                    }
4143                    catch (Exception e) {
4144                            throw processException(e);
4145                    }
4146                    finally {
4147                            closeSession(session);
4148                    }
4149            }
4150    
4151            protected MBThread getByG_NotC_PrevAndNext(Session session,
4152                    MBThread mbThread, long groupId, long categoryId,
4153                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
4154                    StringBundler query = null;
4155    
4156                    if (orderByComparator != null) {
4157                            query = new StringBundler(6 +
4158                                            (orderByComparator.getOrderByFields().length * 6));
4159                    }
4160                    else {
4161                            query = new StringBundler(3);
4162                    }
4163    
4164                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
4165    
4166                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4167    
4168                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4169    
4170                    if (orderByComparator != null) {
4171                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4172    
4173                            if (orderByConditionFields.length > 0) {
4174                                    query.append(WHERE_AND);
4175                            }
4176    
4177                            for (int i = 0; i < orderByConditionFields.length; i++) {
4178                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4179                                    query.append(orderByConditionFields[i]);
4180    
4181                                    if ((i + 1) < orderByConditionFields.length) {
4182                                            if (orderByComparator.isAscending() ^ previous) {
4183                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4184                                            }
4185                                            else {
4186                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4187                                            }
4188                                    }
4189                                    else {
4190                                            if (orderByComparator.isAscending() ^ previous) {
4191                                                    query.append(WHERE_GREATER_THAN);
4192                                            }
4193                                            else {
4194                                                    query.append(WHERE_LESSER_THAN);
4195                                            }
4196                                    }
4197                            }
4198    
4199                            query.append(ORDER_BY_CLAUSE);
4200    
4201                            String[] orderByFields = orderByComparator.getOrderByFields();
4202    
4203                            for (int i = 0; i < orderByFields.length; i++) {
4204                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4205                                    query.append(orderByFields[i]);
4206    
4207                                    if ((i + 1) < orderByFields.length) {
4208                                            if (orderByComparator.isAscending() ^ previous) {
4209                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4210                                            }
4211                                            else {
4212                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4213                                            }
4214                                    }
4215                                    else {
4216                                            if (orderByComparator.isAscending() ^ previous) {
4217                                                    query.append(ORDER_BY_ASC);
4218                                            }
4219                                            else {
4220                                                    query.append(ORDER_BY_DESC);
4221                                            }
4222                                    }
4223                            }
4224                    }
4225                    else {
4226                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4227                    }
4228    
4229                    String sql = query.toString();
4230    
4231                    Query q = session.createQuery(sql);
4232    
4233                    q.setFirstResult(0);
4234                    q.setMaxResults(2);
4235    
4236                    QueryPos qPos = QueryPos.getInstance(q);
4237    
4238                    qPos.add(groupId);
4239    
4240                    qPos.add(categoryId);
4241    
4242                    if (orderByComparator != null) {
4243                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4244    
4245                            for (Object value : values) {
4246                                    qPos.add(value);
4247                            }
4248                    }
4249    
4250                    List<MBThread> list = q.list();
4251    
4252                    if (list.size() == 2) {
4253                            return list.get(1);
4254                    }
4255                    else {
4256                            return null;
4257                    }
4258            }
4259    
4260            /**
4261             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63;.
4262             *
4263             * @param groupId the group ID
4264             * @param categoryId the category ID
4265             * @return the matching message boards threads that the user has permission to view
4266             */
4267            @Override
4268            public List<MBThread> filterFindByG_NotC(long groupId, long categoryId) {
4269                    return filterFindByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
4270                            QueryUtil.ALL_POS, null);
4271            }
4272    
4273            /**
4274             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63;.
4275             *
4276             * <p>
4277             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4278             * </p>
4279             *
4280             * @param groupId the group ID
4281             * @param categoryId the category ID
4282             * @param start the lower bound of the range of message boards threads
4283             * @param end the upper bound of the range of message boards threads (not inclusive)
4284             * @return the range of matching message boards threads that the user has permission to view
4285             */
4286            @Override
4287            public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
4288                    int start, int end) {
4289                    return filterFindByG_NotC(groupId, categoryId, start, end, null);
4290            }
4291    
4292            /**
4293             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and categoryId &ne; &#63;.
4294             *
4295             * <p>
4296             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4297             * </p>
4298             *
4299             * @param groupId the group ID
4300             * @param categoryId the category ID
4301             * @param start the lower bound of the range of message boards threads
4302             * @param end the upper bound of the range of message boards threads (not inclusive)
4303             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4304             * @return the ordered range of matching message boards threads that the user has permission to view
4305             */
4306            @Override
4307            public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
4308                    int start, int end, OrderByComparator<MBThread> orderByComparator) {
4309                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4310                            return findByG_NotC(groupId, categoryId, start, end,
4311                                    orderByComparator);
4312                    }
4313    
4314                    StringBundler query = null;
4315    
4316                    if (orderByComparator != null) {
4317                            query = new StringBundler(4 +
4318                                            (orderByComparator.getOrderByFields().length * 3));
4319                    }
4320                    else {
4321                            query = new StringBundler(4);
4322                    }
4323    
4324                    if (getDB().isSupportsInlineDistinct()) {
4325                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
4326                    }
4327                    else {
4328                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
4329                    }
4330    
4331                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4332    
4333                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4334    
4335                    if (!getDB().isSupportsInlineDistinct()) {
4336                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
4337                    }
4338    
4339                    if (orderByComparator != null) {
4340                            if (getDB().isSupportsInlineDistinct()) {
4341                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4342                                            orderByComparator, true);
4343                            }
4344                            else {
4345                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4346                                            orderByComparator, true);
4347                            }
4348                    }
4349                    else {
4350                            if (getDB().isSupportsInlineDistinct()) {
4351                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4352                            }
4353                            else {
4354                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
4355                            }
4356                    }
4357    
4358                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4359                                    MBThread.class.getName(),
4360                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4361    
4362                    Session session = null;
4363    
4364                    try {
4365                            session = openSession();
4366    
4367                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4368    
4369                            if (getDB().isSupportsInlineDistinct()) {
4370                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
4371                            }
4372                            else {
4373                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
4374                            }
4375    
4376                            QueryPos qPos = QueryPos.getInstance(q);
4377    
4378                            qPos.add(groupId);
4379    
4380                            qPos.add(categoryId);
4381    
4382                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
4383                    }
4384                    catch (Exception e) {
4385                            throw processException(e);
4386                    }
4387                    finally {
4388                            closeSession(session);
4389                    }
4390            }
4391    
4392            /**
4393             * Returns the message boards threads before and after the current message boards thread in the ordered set of message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63;.
4394             *
4395             * @param threadId the primary key of the current message boards thread
4396             * @param groupId the group ID
4397             * @param categoryId the category ID
4398             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4399             * @return the previous, current, and next message boards thread
4400             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
4401             */
4402            @Override
4403            public MBThread[] filterFindByG_NotC_PrevAndNext(long threadId,
4404                    long groupId, long categoryId,
4405                    OrderByComparator<MBThread> orderByComparator)
4406                    throws NoSuchThreadException {
4407                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4408                            return findByG_NotC_PrevAndNext(threadId, groupId, categoryId,
4409                                    orderByComparator);
4410                    }
4411    
4412                    MBThread mbThread = findByPrimaryKey(threadId);
4413    
4414                    Session session = null;
4415    
4416                    try {
4417                            session = openSession();
4418    
4419                            MBThread[] array = new MBThreadImpl[3];
4420    
4421                            array[0] = filterGetByG_NotC_PrevAndNext(session, mbThread,
4422                                            groupId, categoryId, orderByComparator, true);
4423    
4424                            array[1] = mbThread;
4425    
4426                            array[2] = filterGetByG_NotC_PrevAndNext(session, mbThread,
4427                                            groupId, categoryId, orderByComparator, false);
4428    
4429                            return array;
4430                    }
4431                    catch (Exception e) {
4432                            throw processException(e);
4433                    }
4434                    finally {
4435                            closeSession(session);
4436                    }
4437            }
4438    
4439            protected MBThread filterGetByG_NotC_PrevAndNext(Session session,
4440                    MBThread mbThread, long groupId, long categoryId,
4441                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
4442                    StringBundler query = null;
4443    
4444                    if (orderByComparator != null) {
4445                            query = new StringBundler(6 +
4446                                            (orderByComparator.getOrderByFields().length * 6));
4447                    }
4448                    else {
4449                            query = new StringBundler(3);
4450                    }
4451    
4452                    if (getDB().isSupportsInlineDistinct()) {
4453                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
4454                    }
4455                    else {
4456                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
4457                    }
4458    
4459                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4460    
4461                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4462    
4463                    if (!getDB().isSupportsInlineDistinct()) {
4464                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
4465                    }
4466    
4467                    if (orderByComparator != null) {
4468                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4469    
4470                            if (orderByConditionFields.length > 0) {
4471                                    query.append(WHERE_AND);
4472                            }
4473    
4474                            for (int i = 0; i < orderByConditionFields.length; i++) {
4475                                    if (getDB().isSupportsInlineDistinct()) {
4476                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4477                                    }
4478                                    else {
4479                                            query.append(_ORDER_BY_ENTITY_TABLE);
4480                                    }
4481    
4482                                    query.append(orderByConditionFields[i]);
4483    
4484                                    if ((i + 1) < orderByConditionFields.length) {
4485                                            if (orderByComparator.isAscending() ^ previous) {
4486                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4487                                            }
4488                                            else {
4489                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4490                                            }
4491                                    }
4492                                    else {
4493                                            if (orderByComparator.isAscending() ^ previous) {
4494                                                    query.append(WHERE_GREATER_THAN);
4495                                            }
4496                                            else {
4497                                                    query.append(WHERE_LESSER_THAN);
4498                                            }
4499                                    }
4500                            }
4501    
4502                            query.append(ORDER_BY_CLAUSE);
4503    
4504                            String[] orderByFields = orderByComparator.getOrderByFields();
4505    
4506                            for (int i = 0; i < orderByFields.length; i++) {
4507                                    if (getDB().isSupportsInlineDistinct()) {
4508                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4509                                    }
4510                                    else {
4511                                            query.append(_ORDER_BY_ENTITY_TABLE);
4512                                    }
4513    
4514                                    query.append(orderByFields[i]);
4515    
4516                                    if ((i + 1) < orderByFields.length) {
4517                                            if (orderByComparator.isAscending() ^ previous) {
4518                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4519                                            }
4520                                            else {
4521                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4522                                            }
4523                                    }
4524                                    else {
4525                                            if (orderByComparator.isAscending() ^ previous) {
4526                                                    query.append(ORDER_BY_ASC);
4527                                            }
4528                                            else {
4529                                                    query.append(ORDER_BY_DESC);
4530                                            }
4531                                    }
4532                            }
4533                    }
4534                    else {
4535                            if (getDB().isSupportsInlineDistinct()) {
4536                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4537                            }
4538                            else {
4539                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
4540                            }
4541                    }
4542    
4543                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4544                                    MBThread.class.getName(),
4545                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4546    
4547                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
4548    
4549                    q.setFirstResult(0);
4550                    q.setMaxResults(2);
4551    
4552                    if (getDB().isSupportsInlineDistinct()) {
4553                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
4554                    }
4555                    else {
4556                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
4557                    }
4558    
4559                    QueryPos qPos = QueryPos.getInstance(q);
4560    
4561                    qPos.add(groupId);
4562    
4563                    qPos.add(categoryId);
4564    
4565                    if (orderByComparator != null) {
4566                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4567    
4568                            for (Object value : values) {
4569                                    qPos.add(value);
4570                            }
4571                    }
4572    
4573                    List<MBThread> list = q.list();
4574    
4575                    if (list.size() == 2) {
4576                            return list.get(1);
4577                    }
4578                    else {
4579                            return null;
4580                    }
4581            }
4582    
4583            /**
4584             * Removes all the message boards threads where groupId = &#63; and categoryId &ne; &#63; from the database.
4585             *
4586             * @param groupId the group ID
4587             * @param categoryId the category ID
4588             */
4589            @Override
4590            public void removeByG_NotC(long groupId, long categoryId) {
4591                    for (MBThread mbThread : findByG_NotC(groupId, categoryId,
4592                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4593                            remove(mbThread);
4594                    }
4595            }
4596    
4597            /**
4598             * Returns the number of message boards threads where groupId = &#63; and categoryId &ne; &#63;.
4599             *
4600             * @param groupId the group ID
4601             * @param categoryId the category ID
4602             * @return the number of matching message boards threads
4603             */
4604            @Override
4605            public int countByG_NotC(long groupId, long categoryId) {
4606                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC;
4607    
4608                    Object[] finderArgs = new Object[] { groupId, categoryId };
4609    
4610                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4611                                    this);
4612    
4613                    if (count == null) {
4614                            StringBundler query = new StringBundler(3);
4615    
4616                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
4617    
4618                            query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4619    
4620                            query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4621    
4622                            String sql = query.toString();
4623    
4624                            Session session = null;
4625    
4626                            try {
4627                                    session = openSession();
4628    
4629                                    Query q = session.createQuery(sql);
4630    
4631                                    QueryPos qPos = QueryPos.getInstance(q);
4632    
4633                                    qPos.add(groupId);
4634    
4635                                    qPos.add(categoryId);
4636    
4637                                    count = (Long)q.uniqueResult();
4638    
4639                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4640                            }
4641                            catch (Exception e) {
4642                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4643    
4644                                    throw processException(e);
4645                            }
4646                            finally {
4647                                    closeSession(session);
4648                            }
4649                    }
4650    
4651                    return count.intValue();
4652            }
4653    
4654            /**
4655             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63;.
4656             *
4657             * @param groupId the group ID
4658             * @param categoryId the category ID
4659             * @return the number of matching message boards threads that the user has permission to view
4660             */
4661            @Override
4662            public int filterCountByG_NotC(long groupId, long categoryId) {
4663                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4664                            return countByG_NotC(groupId, categoryId);
4665                    }
4666    
4667                    StringBundler query = new StringBundler(3);
4668    
4669                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
4670    
4671                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4672    
4673                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4674    
4675                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4676                                    MBThread.class.getName(),
4677                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4678    
4679                    Session session = null;
4680    
4681                    try {
4682                            session = openSession();
4683    
4684                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4685    
4686                            q.addScalar(COUNT_COLUMN_NAME,
4687                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4688    
4689                            QueryPos qPos = QueryPos.getInstance(q);
4690    
4691                            qPos.add(groupId);
4692    
4693                            qPos.add(categoryId);
4694    
4695                            Long count = (Long)q.uniqueResult();
4696    
4697                            return count.intValue();
4698                    }
4699                    catch (Exception e) {
4700                            throw processException(e);
4701                    }
4702                    finally {
4703                            closeSession(session);
4704                    }
4705            }
4706    
4707            private static final String _FINDER_COLUMN_G_NOTC_GROUPID_2 = "mbThread.groupId = ? AND ";
4708            private static final String _FINDER_COLUMN_G_NOTC_CATEGORYID_2 = "mbThread.categoryId != ?";
4709            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4710                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
4711                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
4712                            new String[] {
4713                                    Long.class.getName(), Integer.class.getName(),
4714                                    
4715                            Integer.class.getName(), Integer.class.getName(),
4716                                    OrderByComparator.class.getName()
4717                            });
4718            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4719                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
4720                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
4721                            new String[] { Long.class.getName(), Integer.class.getName() },
4722                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
4723                            MBThreadModelImpl.STATUS_COLUMN_BITMASK |
4724                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
4725                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
4726            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4727                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
4728                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
4729                            new String[] { Long.class.getName(), Integer.class.getName() });
4730    
4731            /**
4732             * Returns all the message boards threads where groupId = &#63; and status = &#63;.
4733             *
4734             * @param groupId the group ID
4735             * @param status the status
4736             * @return the matching message boards threads
4737             */
4738            @Override
4739            public List<MBThread> findByG_S(long groupId, int status) {
4740                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4741                            null);
4742            }
4743    
4744            /**
4745             * Returns a range of all the message boards threads where groupId = &#63; and status = &#63;.
4746             *
4747             * <p>
4748             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4749             * </p>
4750             *
4751             * @param groupId the group ID
4752             * @param status the status
4753             * @param start the lower bound of the range of message boards threads
4754             * @param end the upper bound of the range of message boards threads (not inclusive)
4755             * @return the range of matching message boards threads
4756             */
4757            @Override
4758            public List<MBThread> findByG_S(long groupId, int status, int start, int end) {
4759                    return findByG_S(groupId, status, start, end, null);
4760            }
4761    
4762            /**
4763             * Returns an ordered range of all the message boards threads where groupId = &#63; and status = &#63;.
4764             *
4765             * <p>
4766             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4767             * </p>
4768             *
4769             * @param groupId the group ID
4770             * @param status the status
4771             * @param start the lower bound of the range of message boards threads
4772             * @param end the upper bound of the range of message boards threads (not inclusive)
4773             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4774             * @return the ordered range of matching message boards threads
4775             */
4776            @Override
4777            public List<MBThread> findByG_S(long groupId, int status, int start,
4778                    int end, OrderByComparator<MBThread> orderByComparator) {
4779                    boolean pagination = true;
4780                    FinderPath finderPath = null;
4781                    Object[] finderArgs = null;
4782    
4783                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4784                                    (orderByComparator == null)) {
4785                            pagination = false;
4786                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
4787                            finderArgs = new Object[] { groupId, status };
4788                    }
4789                    else {
4790                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
4791                            finderArgs = new Object[] {
4792                                            groupId, status,
4793                                            
4794                                            start, end, orderByComparator
4795                                    };
4796                    }
4797    
4798                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
4799                                    finderArgs, this);
4800    
4801                    if ((list != null) && !list.isEmpty()) {
4802                            for (MBThread mbThread : list) {
4803                                    if ((groupId != mbThread.getGroupId()) ||
4804                                                    (status != mbThread.getStatus())) {
4805                                            list = null;
4806    
4807                                            break;
4808                                    }
4809                            }
4810                    }
4811    
4812                    if (list == null) {
4813                            StringBundler query = null;
4814    
4815                            if (orderByComparator != null) {
4816                                    query = new StringBundler(4 +
4817                                                    (orderByComparator.getOrderByFields().length * 3));
4818                            }
4819                            else {
4820                                    query = new StringBundler(4);
4821                            }
4822    
4823                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
4824    
4825                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4826    
4827                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
4828    
4829                            if (orderByComparator != null) {
4830                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4831                                            orderByComparator);
4832                            }
4833                            else
4834                             if (pagination) {
4835                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4836                            }
4837    
4838                            String sql = query.toString();
4839    
4840                            Session session = null;
4841    
4842                            try {
4843                                    session = openSession();
4844    
4845                                    Query q = session.createQuery(sql);
4846    
4847                                    QueryPos qPos = QueryPos.getInstance(q);
4848    
4849                                    qPos.add(groupId);
4850    
4851                                    qPos.add(status);
4852    
4853                                    if (!pagination) {
4854                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
4855                                                            start, end, false);
4856    
4857                                            Collections.sort(list);
4858    
4859                                            list = Collections.unmodifiableList(list);
4860                                    }
4861                                    else {
4862                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
4863                                                            start, end);
4864                                    }
4865    
4866                                    cacheResult(list);
4867    
4868                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4869                            }
4870                            catch (Exception e) {
4871                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4872    
4873                                    throw processException(e);
4874                            }
4875                            finally {
4876                                    closeSession(session);
4877                            }
4878                    }
4879    
4880                    return list;
4881            }
4882    
4883            /**
4884             * Returns the first message boards thread in the ordered set where groupId = &#63; and status = &#63;.
4885             *
4886             * @param groupId the group ID
4887             * @param status the status
4888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4889             * @return the first matching message boards thread
4890             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
4891             */
4892            @Override
4893            public MBThread findByG_S_First(long groupId, int status,
4894                    OrderByComparator<MBThread> orderByComparator)
4895                    throws NoSuchThreadException {
4896                    MBThread mbThread = fetchByG_S_First(groupId, status, orderByComparator);
4897    
4898                    if (mbThread != null) {
4899                            return mbThread;
4900                    }
4901    
4902                    StringBundler msg = new StringBundler(6);
4903    
4904                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4905    
4906                    msg.append("groupId=");
4907                    msg.append(groupId);
4908    
4909                    msg.append(", status=");
4910                    msg.append(status);
4911    
4912                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4913    
4914                    throw new NoSuchThreadException(msg.toString());
4915            }
4916    
4917            /**
4918             * Returns the first message boards thread in the ordered set where groupId = &#63; and status = &#63;.
4919             *
4920             * @param groupId the group ID
4921             * @param status the status
4922             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4923             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
4924             */
4925            @Override
4926            public MBThread fetchByG_S_First(long groupId, int status,
4927                    OrderByComparator<MBThread> orderByComparator) {
4928                    List<MBThread> list = findByG_S(groupId, status, 0, 1, orderByComparator);
4929    
4930                    if (!list.isEmpty()) {
4931                            return list.get(0);
4932                    }
4933    
4934                    return null;
4935            }
4936    
4937            /**
4938             * Returns the last message boards thread in the ordered set where groupId = &#63; and status = &#63;.
4939             *
4940             * @param groupId the group ID
4941             * @param status the status
4942             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4943             * @return the last matching message boards thread
4944             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
4945             */
4946            @Override
4947            public MBThread findByG_S_Last(long groupId, int status,
4948                    OrderByComparator<MBThread> orderByComparator)
4949                    throws NoSuchThreadException {
4950                    MBThread mbThread = fetchByG_S_Last(groupId, status, orderByComparator);
4951    
4952                    if (mbThread != null) {
4953                            return mbThread;
4954                    }
4955    
4956                    StringBundler msg = new StringBundler(6);
4957    
4958                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4959    
4960                    msg.append("groupId=");
4961                    msg.append(groupId);
4962    
4963                    msg.append(", status=");
4964                    msg.append(status);
4965    
4966                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4967    
4968                    throw new NoSuchThreadException(msg.toString());
4969            }
4970    
4971            /**
4972             * Returns the last message boards thread in the ordered set where groupId = &#63; and status = &#63;.
4973             *
4974             * @param groupId the group ID
4975             * @param status the status
4976             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4977             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
4978             */
4979            @Override
4980            public MBThread fetchByG_S_Last(long groupId, int status,
4981                    OrderByComparator<MBThread> orderByComparator) {
4982                    int count = countByG_S(groupId, status);
4983    
4984                    if (count == 0) {
4985                            return null;
4986                    }
4987    
4988                    List<MBThread> list = findByG_S(groupId, status, count - 1, count,
4989                                    orderByComparator);
4990    
4991                    if (!list.isEmpty()) {
4992                            return list.get(0);
4993                    }
4994    
4995                    return null;
4996            }
4997    
4998            /**
4999             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and status = &#63;.
5000             *
5001             * @param threadId the primary key of the current message boards thread
5002             * @param groupId the group ID
5003             * @param status the status
5004             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5005             * @return the previous, current, and next message boards thread
5006             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
5007             */
5008            @Override
5009            public MBThread[] findByG_S_PrevAndNext(long threadId, long groupId,
5010                    int status, OrderByComparator<MBThread> orderByComparator)
5011                    throws NoSuchThreadException {
5012                    MBThread mbThread = findByPrimaryKey(threadId);
5013    
5014                    Session session = null;
5015    
5016                    try {
5017                            session = openSession();
5018    
5019                            MBThread[] array = new MBThreadImpl[3];
5020    
5021                            array[0] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
5022                                            orderByComparator, true);
5023    
5024                            array[1] = mbThread;
5025    
5026                            array[2] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
5027                                            orderByComparator, false);
5028    
5029                            return array;
5030                    }
5031                    catch (Exception e) {
5032                            throw processException(e);
5033                    }
5034                    finally {
5035                            closeSession(session);
5036                    }
5037            }
5038    
5039            protected MBThread getByG_S_PrevAndNext(Session session, MBThread mbThread,
5040                    long groupId, int status,
5041                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
5042                    StringBundler query = null;
5043    
5044                    if (orderByComparator != null) {
5045                            query = new StringBundler(6 +
5046                                            (orderByComparator.getOrderByFields().length * 6));
5047                    }
5048                    else {
5049                            query = new StringBundler(3);
5050                    }
5051    
5052                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
5053    
5054                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5055    
5056                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
5057    
5058                    if (orderByComparator != null) {
5059                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5060    
5061                            if (orderByConditionFields.length > 0) {
5062                                    query.append(WHERE_AND);
5063                            }
5064    
5065                            for (int i = 0; i < orderByConditionFields.length; i++) {
5066                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5067                                    query.append(orderByConditionFields[i]);
5068    
5069                                    if ((i + 1) < orderByConditionFields.length) {
5070                                            if (orderByComparator.isAscending() ^ previous) {
5071                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5072                                            }
5073                                            else {
5074                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5075                                            }
5076                                    }
5077                                    else {
5078                                            if (orderByComparator.isAscending() ^ previous) {
5079                                                    query.append(WHERE_GREATER_THAN);
5080                                            }
5081                                            else {
5082                                                    query.append(WHERE_LESSER_THAN);
5083                                            }
5084                                    }
5085                            }
5086    
5087                            query.append(ORDER_BY_CLAUSE);
5088    
5089                            String[] orderByFields = orderByComparator.getOrderByFields();
5090    
5091                            for (int i = 0; i < orderByFields.length; i++) {
5092                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5093                                    query.append(orderByFields[i]);
5094    
5095                                    if ((i + 1) < orderByFields.length) {
5096                                            if (orderByComparator.isAscending() ^ previous) {
5097                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5098                                            }
5099                                            else {
5100                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5101                                            }
5102                                    }
5103                                    else {
5104                                            if (orderByComparator.isAscending() ^ previous) {
5105                                                    query.append(ORDER_BY_ASC);
5106                                            }
5107                                            else {
5108                                                    query.append(ORDER_BY_DESC);
5109                                            }
5110                                    }
5111                            }
5112                    }
5113                    else {
5114                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5115                    }
5116    
5117                    String sql = query.toString();
5118    
5119                    Query q = session.createQuery(sql);
5120    
5121                    q.setFirstResult(0);
5122                    q.setMaxResults(2);
5123    
5124                    QueryPos qPos = QueryPos.getInstance(q);
5125    
5126                    qPos.add(groupId);
5127    
5128                    qPos.add(status);
5129    
5130                    if (orderByComparator != null) {
5131                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5132    
5133                            for (Object value : values) {
5134                                    qPos.add(value);
5135                            }
5136                    }
5137    
5138                    List<MBThread> list = q.list();
5139    
5140                    if (list.size() == 2) {
5141                            return list.get(1);
5142                    }
5143                    else {
5144                            return null;
5145                    }
5146            }
5147    
5148            /**
5149             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and status = &#63;.
5150             *
5151             * @param groupId the group ID
5152             * @param status the status
5153             * @return the matching message boards threads that the user has permission to view
5154             */
5155            @Override
5156            public List<MBThread> filterFindByG_S(long groupId, int status) {
5157                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
5158                            QueryUtil.ALL_POS, null);
5159            }
5160    
5161            /**
5162             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and status = &#63;.
5163             *
5164             * <p>
5165             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5166             * </p>
5167             *
5168             * @param groupId the group ID
5169             * @param status the status
5170             * @param start the lower bound of the range of message boards threads
5171             * @param end the upper bound of the range of message boards threads (not inclusive)
5172             * @return the range of matching message boards threads that the user has permission to view
5173             */
5174            @Override
5175            public List<MBThread> filterFindByG_S(long groupId, int status, int start,
5176                    int end) {
5177                    return filterFindByG_S(groupId, status, start, end, null);
5178            }
5179    
5180            /**
5181             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and status = &#63;.
5182             *
5183             * <p>
5184             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5185             * </p>
5186             *
5187             * @param groupId the group ID
5188             * @param status the status
5189             * @param start the lower bound of the range of message boards threads
5190             * @param end the upper bound of the range of message boards threads (not inclusive)
5191             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5192             * @return the ordered range of matching message boards threads that the user has permission to view
5193             */
5194            @Override
5195            public List<MBThread> filterFindByG_S(long groupId, int status, int start,
5196                    int end, OrderByComparator<MBThread> orderByComparator) {
5197                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5198                            return findByG_S(groupId, status, start, end, orderByComparator);
5199                    }
5200    
5201                    StringBundler query = null;
5202    
5203                    if (orderByComparator != null) {
5204                            query = new StringBundler(4 +
5205                                            (orderByComparator.getOrderByFields().length * 3));
5206                    }
5207                    else {
5208                            query = new StringBundler(4);
5209                    }
5210    
5211                    if (getDB().isSupportsInlineDistinct()) {
5212                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5213                    }
5214                    else {
5215                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5216                    }
5217    
5218                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5219    
5220                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
5221    
5222                    if (!getDB().isSupportsInlineDistinct()) {
5223                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5224                    }
5225    
5226                    if (orderByComparator != null) {
5227                            if (getDB().isSupportsInlineDistinct()) {
5228                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5229                                            orderByComparator, true);
5230                            }
5231                            else {
5232                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5233                                            orderByComparator, true);
5234                            }
5235                    }
5236                    else {
5237                            if (getDB().isSupportsInlineDistinct()) {
5238                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5239                            }
5240                            else {
5241                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
5242                            }
5243                    }
5244    
5245                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5246                                    MBThread.class.getName(),
5247                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5248    
5249                    Session session = null;
5250    
5251                    try {
5252                            session = openSession();
5253    
5254                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5255    
5256                            if (getDB().isSupportsInlineDistinct()) {
5257                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5258                            }
5259                            else {
5260                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5261                            }
5262    
5263                            QueryPos qPos = QueryPos.getInstance(q);
5264    
5265                            qPos.add(groupId);
5266    
5267                            qPos.add(status);
5268    
5269                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
5270                    }
5271                    catch (Exception e) {
5272                            throw processException(e);
5273                    }
5274                    finally {
5275                            closeSession(session);
5276                    }
5277            }
5278    
5279            /**
5280             * Returns the message boards threads before and after the current message boards thread in the ordered set of message boards threads that the user has permission to view where groupId = &#63; and status = &#63;.
5281             *
5282             * @param threadId the primary key of the current message boards thread
5283             * @param groupId the group ID
5284             * @param status the status
5285             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5286             * @return the previous, current, and next message boards thread
5287             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
5288             */
5289            @Override
5290            public MBThread[] filterFindByG_S_PrevAndNext(long threadId, long groupId,
5291                    int status, OrderByComparator<MBThread> orderByComparator)
5292                    throws NoSuchThreadException {
5293                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5294                            return findByG_S_PrevAndNext(threadId, groupId, status,
5295                                    orderByComparator);
5296                    }
5297    
5298                    MBThread mbThread = findByPrimaryKey(threadId);
5299    
5300                    Session session = null;
5301    
5302                    try {
5303                            session = openSession();
5304    
5305                            MBThread[] array = new MBThreadImpl[3];
5306    
5307                            array[0] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
5308                                            status, orderByComparator, true);
5309    
5310                            array[1] = mbThread;
5311    
5312                            array[2] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
5313                                            status, orderByComparator, false);
5314    
5315                            return array;
5316                    }
5317                    catch (Exception e) {
5318                            throw processException(e);
5319                    }
5320                    finally {
5321                            closeSession(session);
5322                    }
5323            }
5324    
5325            protected MBThread filterGetByG_S_PrevAndNext(Session session,
5326                    MBThread mbThread, long groupId, int status,
5327                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
5328                    StringBundler query = null;
5329    
5330                    if (orderByComparator != null) {
5331                            query = new StringBundler(6 +
5332                                            (orderByComparator.getOrderByFields().length * 6));
5333                    }
5334                    else {
5335                            query = new StringBundler(3);
5336                    }
5337    
5338                    if (getDB().isSupportsInlineDistinct()) {
5339                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5340                    }
5341                    else {
5342                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5343                    }
5344    
5345                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5346    
5347                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
5348    
5349                    if (!getDB().isSupportsInlineDistinct()) {
5350                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5351                    }
5352    
5353                    if (orderByComparator != null) {
5354                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5355    
5356                            if (orderByConditionFields.length > 0) {
5357                                    query.append(WHERE_AND);
5358                            }
5359    
5360                            for (int i = 0; i < orderByConditionFields.length; i++) {
5361                                    if (getDB().isSupportsInlineDistinct()) {
5362                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5363                                    }
5364                                    else {
5365                                            query.append(_ORDER_BY_ENTITY_TABLE);
5366                                    }
5367    
5368                                    query.append(orderByConditionFields[i]);
5369    
5370                                    if ((i + 1) < orderByConditionFields.length) {
5371                                            if (orderByComparator.isAscending() ^ previous) {
5372                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5373                                            }
5374                                            else {
5375                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5376                                            }
5377                                    }
5378                                    else {
5379                                            if (orderByComparator.isAscending() ^ previous) {
5380                                                    query.append(WHERE_GREATER_THAN);
5381                                            }
5382                                            else {
5383                                                    query.append(WHERE_LESSER_THAN);
5384                                            }
5385                                    }
5386                            }
5387    
5388                            query.append(ORDER_BY_CLAUSE);
5389    
5390                            String[] orderByFields = orderByComparator.getOrderByFields();
5391    
5392                            for (int i = 0; i < orderByFields.length; i++) {
5393                                    if (getDB().isSupportsInlineDistinct()) {
5394                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5395                                    }
5396                                    else {
5397                                            query.append(_ORDER_BY_ENTITY_TABLE);
5398                                    }
5399    
5400                                    query.append(orderByFields[i]);
5401    
5402                                    if ((i + 1) < orderByFields.length) {
5403                                            if (orderByComparator.isAscending() ^ previous) {
5404                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5405                                            }
5406                                            else {
5407                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5408                                            }
5409                                    }
5410                                    else {
5411                                            if (orderByComparator.isAscending() ^ previous) {
5412                                                    query.append(ORDER_BY_ASC);
5413                                            }
5414                                            else {
5415                                                    query.append(ORDER_BY_DESC);
5416                                            }
5417                                    }
5418                            }
5419                    }
5420                    else {
5421                            if (getDB().isSupportsInlineDistinct()) {
5422                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5423                            }
5424                            else {
5425                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
5426                            }
5427                    }
5428    
5429                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5430                                    MBThread.class.getName(),
5431                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5432    
5433                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
5434    
5435                    q.setFirstResult(0);
5436                    q.setMaxResults(2);
5437    
5438                    if (getDB().isSupportsInlineDistinct()) {
5439                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5440                    }
5441                    else {
5442                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5443                    }
5444    
5445                    QueryPos qPos = QueryPos.getInstance(q);
5446    
5447                    qPos.add(groupId);
5448    
5449                    qPos.add(status);
5450    
5451                    if (orderByComparator != null) {
5452                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5453    
5454                            for (Object value : values) {
5455                                    qPos.add(value);
5456                            }
5457                    }
5458    
5459                    List<MBThread> list = q.list();
5460    
5461                    if (list.size() == 2) {
5462                            return list.get(1);
5463                    }
5464                    else {
5465                            return null;
5466                    }
5467            }
5468    
5469            /**
5470             * Removes all the message boards threads where groupId = &#63; and status = &#63; from the database.
5471             *
5472             * @param groupId the group ID
5473             * @param status the status
5474             */
5475            @Override
5476            public void removeByG_S(long groupId, int status) {
5477                    for (MBThread mbThread : findByG_S(groupId, status, QueryUtil.ALL_POS,
5478                                    QueryUtil.ALL_POS, null)) {
5479                            remove(mbThread);
5480                    }
5481            }
5482    
5483            /**
5484             * Returns the number of message boards threads where groupId = &#63; and status = &#63;.
5485             *
5486             * @param groupId the group ID
5487             * @param status the status
5488             * @return the number of matching message boards threads
5489             */
5490            @Override
5491            public int countByG_S(long groupId, int status) {
5492                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
5493    
5494                    Object[] finderArgs = new Object[] { groupId, status };
5495    
5496                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5497                                    this);
5498    
5499                    if (count == null) {
5500                            StringBundler query = new StringBundler(3);
5501    
5502                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
5503    
5504                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5505    
5506                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
5507    
5508                            String sql = query.toString();
5509    
5510                            Session session = null;
5511    
5512                            try {
5513                                    session = openSession();
5514    
5515                                    Query q = session.createQuery(sql);
5516    
5517                                    QueryPos qPos = QueryPos.getInstance(q);
5518    
5519                                    qPos.add(groupId);
5520    
5521                                    qPos.add(status);
5522    
5523                                    count = (Long)q.uniqueResult();
5524    
5525                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5526                            }
5527                            catch (Exception e) {
5528                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5529    
5530                                    throw processException(e);
5531                            }
5532                            finally {
5533                                    closeSession(session);
5534                            }
5535                    }
5536    
5537                    return count.intValue();
5538            }
5539    
5540            /**
5541             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and status = &#63;.
5542             *
5543             * @param groupId the group ID
5544             * @param status the status
5545             * @return the number of matching message boards threads that the user has permission to view
5546             */
5547            @Override
5548            public int filterCountByG_S(long groupId, int status) {
5549                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5550                            return countByG_S(groupId, status);
5551                    }
5552    
5553                    StringBundler query = new StringBundler(3);
5554    
5555                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
5556    
5557                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5558    
5559                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
5560    
5561                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5562                                    MBThread.class.getName(),
5563                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5564    
5565                    Session session = null;
5566    
5567                    try {
5568                            session = openSession();
5569    
5570                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5571    
5572                            q.addScalar(COUNT_COLUMN_NAME,
5573                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5574    
5575                            QueryPos qPos = QueryPos.getInstance(q);
5576    
5577                            qPos.add(groupId);
5578    
5579                            qPos.add(status);
5580    
5581                            Long count = (Long)q.uniqueResult();
5582    
5583                            return count.intValue();
5584                    }
5585                    catch (Exception e) {
5586                            throw processException(e);
5587                    }
5588                    finally {
5589                            closeSession(session);
5590                    }
5591            }
5592    
5593            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbThread.groupId = ? AND ";
5594            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbThread.status = ? AND mbThread.categoryId != -1";
5595            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5596                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
5597                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
5598                            new String[] {
5599                                    Long.class.getName(), Double.class.getName(),
5600                                    
5601                            Integer.class.getName(), Integer.class.getName(),
5602                                    OrderByComparator.class.getName()
5603                            });
5604            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5605                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
5606                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
5607                            new String[] { Long.class.getName(), Double.class.getName() },
5608                            MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
5609                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
5610                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
5611            public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5612                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
5613                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
5614                            new String[] { Long.class.getName(), Double.class.getName() });
5615    
5616            /**
5617             * Returns all the message boards threads where categoryId = &#63; and priority = &#63;.
5618             *
5619             * @param categoryId the category ID
5620             * @param priority the priority
5621             * @return the matching message boards threads
5622             */
5623            @Override
5624            public List<MBThread> findByC_P(long categoryId, double priority) {
5625                    return findByC_P(categoryId, priority, QueryUtil.ALL_POS,
5626                            QueryUtil.ALL_POS, null);
5627            }
5628    
5629            /**
5630             * Returns a range of all the message boards threads where categoryId = &#63; and priority = &#63;.
5631             *
5632             * <p>
5633             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5634             * </p>
5635             *
5636             * @param categoryId the category ID
5637             * @param priority the priority
5638             * @param start the lower bound of the range of message boards threads
5639             * @param end the upper bound of the range of message boards threads (not inclusive)
5640             * @return the range of matching message boards threads
5641             */
5642            @Override
5643            public List<MBThread> findByC_P(long categoryId, double priority,
5644                    int start, int end) {
5645                    return findByC_P(categoryId, priority, start, end, null);
5646            }
5647    
5648            /**
5649             * Returns an ordered range of all the message boards threads where categoryId = &#63; and priority = &#63;.
5650             *
5651             * <p>
5652             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5653             * </p>
5654             *
5655             * @param categoryId the category ID
5656             * @param priority the priority
5657             * @param start the lower bound of the range of message boards threads
5658             * @param end the upper bound of the range of message boards threads (not inclusive)
5659             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5660             * @return the ordered range of matching message boards threads
5661             */
5662            @Override
5663            public List<MBThread> findByC_P(long categoryId, double priority,
5664                    int start, int end, OrderByComparator<MBThread> orderByComparator) {
5665                    boolean pagination = true;
5666                    FinderPath finderPath = null;
5667                    Object[] finderArgs = null;
5668    
5669                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5670                                    (orderByComparator == null)) {
5671                            pagination = false;
5672                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
5673                            finderArgs = new Object[] { categoryId, priority };
5674                    }
5675                    else {
5676                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
5677                            finderArgs = new Object[] {
5678                                            categoryId, priority,
5679                                            
5680                                            start, end, orderByComparator
5681                                    };
5682                    }
5683    
5684                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
5685                                    finderArgs, this);
5686    
5687                    if ((list != null) && !list.isEmpty()) {
5688                            for (MBThread mbThread : list) {
5689                                    if ((categoryId != mbThread.getCategoryId()) ||
5690                                                    (priority != mbThread.getPriority())) {
5691                                            list = null;
5692    
5693                                            break;
5694                                    }
5695                            }
5696                    }
5697    
5698                    if (list == null) {
5699                            StringBundler query = null;
5700    
5701                            if (orderByComparator != null) {
5702                                    query = new StringBundler(4 +
5703                                                    (orderByComparator.getOrderByFields().length * 3));
5704                            }
5705                            else {
5706                                    query = new StringBundler(4);
5707                            }
5708    
5709                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
5710    
5711                            query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
5712    
5713                            query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
5714    
5715                            if (orderByComparator != null) {
5716                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5717                                            orderByComparator);
5718                            }
5719                            else
5720                             if (pagination) {
5721                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5722                            }
5723    
5724                            String sql = query.toString();
5725    
5726                            Session session = null;
5727    
5728                            try {
5729                                    session = openSession();
5730    
5731                                    Query q = session.createQuery(sql);
5732    
5733                                    QueryPos qPos = QueryPos.getInstance(q);
5734    
5735                                    qPos.add(categoryId);
5736    
5737                                    qPos.add(priority);
5738    
5739                                    if (!pagination) {
5740                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
5741                                                            start, end, false);
5742    
5743                                            Collections.sort(list);
5744    
5745                                            list = Collections.unmodifiableList(list);
5746                                    }
5747                                    else {
5748                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
5749                                                            start, end);
5750                                    }
5751    
5752                                    cacheResult(list);
5753    
5754                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5755                            }
5756                            catch (Exception e) {
5757                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5758    
5759                                    throw processException(e);
5760                            }
5761                            finally {
5762                                    closeSession(session);
5763                            }
5764                    }
5765    
5766                    return list;
5767            }
5768    
5769            /**
5770             * Returns the first message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
5771             *
5772             * @param categoryId the category ID
5773             * @param priority the priority
5774             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5775             * @return the first matching message boards thread
5776             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
5777             */
5778            @Override
5779            public MBThread findByC_P_First(long categoryId, double priority,
5780                    OrderByComparator<MBThread> orderByComparator)
5781                    throws NoSuchThreadException {
5782                    MBThread mbThread = fetchByC_P_First(categoryId, priority,
5783                                    orderByComparator);
5784    
5785                    if (mbThread != null) {
5786                            return mbThread;
5787                    }
5788    
5789                    StringBundler msg = new StringBundler(6);
5790    
5791                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5792    
5793                    msg.append("categoryId=");
5794                    msg.append(categoryId);
5795    
5796                    msg.append(", priority=");
5797                    msg.append(priority);
5798    
5799                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5800    
5801                    throw new NoSuchThreadException(msg.toString());
5802            }
5803    
5804            /**
5805             * Returns the first message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
5806             *
5807             * @param categoryId the category ID
5808             * @param priority the priority
5809             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5810             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
5811             */
5812            @Override
5813            public MBThread fetchByC_P_First(long categoryId, double priority,
5814                    OrderByComparator<MBThread> orderByComparator) {
5815                    List<MBThread> list = findByC_P(categoryId, priority, 0, 1,
5816                                    orderByComparator);
5817    
5818                    if (!list.isEmpty()) {
5819                            return list.get(0);
5820                    }
5821    
5822                    return null;
5823            }
5824    
5825            /**
5826             * Returns the last message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
5827             *
5828             * @param categoryId the category ID
5829             * @param priority the priority
5830             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5831             * @return the last matching message boards thread
5832             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
5833             */
5834            @Override
5835            public MBThread findByC_P_Last(long categoryId, double priority,
5836                    OrderByComparator<MBThread> orderByComparator)
5837                    throws NoSuchThreadException {
5838                    MBThread mbThread = fetchByC_P_Last(categoryId, priority,
5839                                    orderByComparator);
5840    
5841                    if (mbThread != null) {
5842                            return mbThread;
5843                    }
5844    
5845                    StringBundler msg = new StringBundler(6);
5846    
5847                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5848    
5849                    msg.append("categoryId=");
5850                    msg.append(categoryId);
5851    
5852                    msg.append(", priority=");
5853                    msg.append(priority);
5854    
5855                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5856    
5857                    throw new NoSuchThreadException(msg.toString());
5858            }
5859    
5860            /**
5861             * Returns the last message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
5862             *
5863             * @param categoryId the category ID
5864             * @param priority the priority
5865             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5866             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
5867             */
5868            @Override
5869            public MBThread fetchByC_P_Last(long categoryId, double priority,
5870                    OrderByComparator<MBThread> orderByComparator) {
5871                    int count = countByC_P(categoryId, priority);
5872    
5873                    if (count == 0) {
5874                            return null;
5875                    }
5876    
5877                    List<MBThread> list = findByC_P(categoryId, priority, count - 1, count,
5878                                    orderByComparator);
5879    
5880                    if (!list.isEmpty()) {
5881                            return list.get(0);
5882                    }
5883    
5884                    return null;
5885            }
5886    
5887            /**
5888             * Returns the message boards threads before and after the current message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
5889             *
5890             * @param threadId the primary key of the current message boards thread
5891             * @param categoryId the category ID
5892             * @param priority the priority
5893             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5894             * @return the previous, current, and next message boards thread
5895             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
5896             */
5897            @Override
5898            public MBThread[] findByC_P_PrevAndNext(long threadId, long categoryId,
5899                    double priority, OrderByComparator<MBThread> orderByComparator)
5900                    throws NoSuchThreadException {
5901                    MBThread mbThread = findByPrimaryKey(threadId);
5902    
5903                    Session session = null;
5904    
5905                    try {
5906                            session = openSession();
5907    
5908                            MBThread[] array = new MBThreadImpl[3];
5909    
5910                            array[0] = getByC_P_PrevAndNext(session, mbThread, categoryId,
5911                                            priority, orderByComparator, true);
5912    
5913                            array[1] = mbThread;
5914    
5915                            array[2] = getByC_P_PrevAndNext(session, mbThread, categoryId,
5916                                            priority, orderByComparator, false);
5917    
5918                            return array;
5919                    }
5920                    catch (Exception e) {
5921                            throw processException(e);
5922                    }
5923                    finally {
5924                            closeSession(session);
5925                    }
5926            }
5927    
5928            protected MBThread getByC_P_PrevAndNext(Session session, MBThread mbThread,
5929                    long categoryId, double priority,
5930                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
5931                    StringBundler query = null;
5932    
5933                    if (orderByComparator != null) {
5934                            query = new StringBundler(6 +
5935                                            (orderByComparator.getOrderByFields().length * 6));
5936                    }
5937                    else {
5938                            query = new StringBundler(3);
5939                    }
5940    
5941                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
5942    
5943                    query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
5944    
5945                    query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
5946    
5947                    if (orderByComparator != null) {
5948                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5949    
5950                            if (orderByConditionFields.length > 0) {
5951                                    query.append(WHERE_AND);
5952                            }
5953    
5954                            for (int i = 0; i < orderByConditionFields.length; i++) {
5955                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5956                                    query.append(orderByConditionFields[i]);
5957    
5958                                    if ((i + 1) < orderByConditionFields.length) {
5959                                            if (orderByComparator.isAscending() ^ previous) {
5960                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5961                                            }
5962                                            else {
5963                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5964                                            }
5965                                    }
5966                                    else {
5967                                            if (orderByComparator.isAscending() ^ previous) {
5968                                                    query.append(WHERE_GREATER_THAN);
5969                                            }
5970                                            else {
5971                                                    query.append(WHERE_LESSER_THAN);
5972                                            }
5973                                    }
5974                            }
5975    
5976                            query.append(ORDER_BY_CLAUSE);
5977    
5978                            String[] orderByFields = orderByComparator.getOrderByFields();
5979    
5980                            for (int i = 0; i < orderByFields.length; i++) {
5981                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5982                                    query.append(orderByFields[i]);
5983    
5984                                    if ((i + 1) < orderByFields.length) {
5985                                            if (orderByComparator.isAscending() ^ previous) {
5986                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5987                                            }
5988                                            else {
5989                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5990                                            }
5991                                    }
5992                                    else {
5993                                            if (orderByComparator.isAscending() ^ previous) {
5994                                                    query.append(ORDER_BY_ASC);
5995                                            }
5996                                            else {
5997                                                    query.append(ORDER_BY_DESC);
5998                                            }
5999                                    }
6000                            }
6001                    }
6002                    else {
6003                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6004                    }
6005    
6006                    String sql = query.toString();
6007    
6008                    Query q = session.createQuery(sql);
6009    
6010                    q.setFirstResult(0);
6011                    q.setMaxResults(2);
6012    
6013                    QueryPos qPos = QueryPos.getInstance(q);
6014    
6015                    qPos.add(categoryId);
6016    
6017                    qPos.add(priority);
6018    
6019                    if (orderByComparator != null) {
6020                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
6021    
6022                            for (Object value : values) {
6023                                    qPos.add(value);
6024                            }
6025                    }
6026    
6027                    List<MBThread> list = q.list();
6028    
6029                    if (list.size() == 2) {
6030                            return list.get(1);
6031                    }
6032                    else {
6033                            return null;
6034                    }
6035            }
6036    
6037            /**
6038             * Removes all the message boards threads where categoryId = &#63; and priority = &#63; from the database.
6039             *
6040             * @param categoryId the category ID
6041             * @param priority the priority
6042             */
6043            @Override
6044            public void removeByC_P(long categoryId, double priority) {
6045                    for (MBThread mbThread : findByC_P(categoryId, priority,
6046                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6047                            remove(mbThread);
6048                    }
6049            }
6050    
6051            /**
6052             * Returns the number of message boards threads where categoryId = &#63; and priority = &#63;.
6053             *
6054             * @param categoryId the category ID
6055             * @param priority the priority
6056             * @return the number of matching message boards threads
6057             */
6058            @Override
6059            public int countByC_P(long categoryId, double priority) {
6060                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_P;
6061    
6062                    Object[] finderArgs = new Object[] { categoryId, priority };
6063    
6064                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6065                                    this);
6066    
6067                    if (count == null) {
6068                            StringBundler query = new StringBundler(3);
6069    
6070                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
6071    
6072                            query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
6073    
6074                            query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
6075    
6076                            String sql = query.toString();
6077    
6078                            Session session = null;
6079    
6080                            try {
6081                                    session = openSession();
6082    
6083                                    Query q = session.createQuery(sql);
6084    
6085                                    QueryPos qPos = QueryPos.getInstance(q);
6086    
6087                                    qPos.add(categoryId);
6088    
6089                                    qPos.add(priority);
6090    
6091                                    count = (Long)q.uniqueResult();
6092    
6093                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6094                            }
6095                            catch (Exception e) {
6096                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6097    
6098                                    throw processException(e);
6099                            }
6100                            finally {
6101                                    closeSession(session);
6102                            }
6103                    }
6104    
6105                    return count.intValue();
6106            }
6107    
6108            private static final String _FINDER_COLUMN_C_P_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
6109            private static final String _FINDER_COLUMN_C_P_PRIORITY_2 = "mbThread.priority = ?";
6110            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6111                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6112                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByL_P",
6113                            new String[] {
6114                                    Date.class.getName(), Double.class.getName(),
6115                                    
6116                            Integer.class.getName(), Integer.class.getName(),
6117                                    OrderByComparator.class.getName()
6118                            });
6119            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6120                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6121                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByL_P",
6122                            new String[] { Date.class.getName(), Double.class.getName() },
6123                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK |
6124                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
6125            public static final FinderPath FINDER_PATH_COUNT_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6126                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
6127                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByL_P",
6128                            new String[] { Date.class.getName(), Double.class.getName() });
6129    
6130            /**
6131             * Returns all the message boards threads where lastPostDate = &#63; and priority = &#63;.
6132             *
6133             * @param lastPostDate the last post date
6134             * @param priority the priority
6135             * @return the matching message boards threads
6136             */
6137            @Override
6138            public List<MBThread> findByL_P(Date lastPostDate, double priority) {
6139                    return findByL_P(lastPostDate, priority, QueryUtil.ALL_POS,
6140                            QueryUtil.ALL_POS, null);
6141            }
6142    
6143            /**
6144             * Returns a range of all the message boards threads where lastPostDate = &#63; and priority = &#63;.
6145             *
6146             * <p>
6147             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6148             * </p>
6149             *
6150             * @param lastPostDate the last post date
6151             * @param priority the priority
6152             * @param start the lower bound of the range of message boards threads
6153             * @param end the upper bound of the range of message boards threads (not inclusive)
6154             * @return the range of matching message boards threads
6155             */
6156            @Override
6157            public List<MBThread> findByL_P(Date lastPostDate, double priority,
6158                    int start, int end) {
6159                    return findByL_P(lastPostDate, priority, start, end, null);
6160            }
6161    
6162            /**
6163             * Returns an ordered range of all the message boards threads where lastPostDate = &#63; and priority = &#63;.
6164             *
6165             * <p>
6166             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6167             * </p>
6168             *
6169             * @param lastPostDate the last post date
6170             * @param priority the priority
6171             * @param start the lower bound of the range of message boards threads
6172             * @param end the upper bound of the range of message boards threads (not inclusive)
6173             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6174             * @return the ordered range of matching message boards threads
6175             */
6176            @Override
6177            public List<MBThread> findByL_P(Date lastPostDate, double priority,
6178                    int start, int end, OrderByComparator<MBThread> orderByComparator) {
6179                    boolean pagination = true;
6180                    FinderPath finderPath = null;
6181                    Object[] finderArgs = null;
6182    
6183                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6184                                    (orderByComparator == null)) {
6185                            pagination = false;
6186                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P;
6187                            finderArgs = new Object[] { lastPostDate, priority };
6188                    }
6189                    else {
6190                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P;
6191                            finderArgs = new Object[] {
6192                                            lastPostDate, priority,
6193                                            
6194                                            start, end, orderByComparator
6195                                    };
6196                    }
6197    
6198                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
6199                                    finderArgs, this);
6200    
6201                    if ((list != null) && !list.isEmpty()) {
6202                            for (MBThread mbThread : list) {
6203                                    if (!Validator.equals(lastPostDate, mbThread.getLastPostDate()) ||
6204                                                    (priority != mbThread.getPriority())) {
6205                                            list = null;
6206    
6207                                            break;
6208                                    }
6209                            }
6210                    }
6211    
6212                    if (list == null) {
6213                            StringBundler query = null;
6214    
6215                            if (orderByComparator != null) {
6216                                    query = new StringBundler(4 +
6217                                                    (orderByComparator.getOrderByFields().length * 3));
6218                            }
6219                            else {
6220                                    query = new StringBundler(4);
6221                            }
6222    
6223                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
6224    
6225                            boolean bindLastPostDate = false;
6226    
6227                            if (lastPostDate == null) {
6228                                    query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
6229                            }
6230                            else {
6231                                    bindLastPostDate = true;
6232    
6233                                    query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
6234                            }
6235    
6236                            query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
6237    
6238                            if (orderByComparator != null) {
6239                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6240                                            orderByComparator);
6241                            }
6242                            else
6243                             if (pagination) {
6244                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6245                            }
6246    
6247                            String sql = query.toString();
6248    
6249                            Session session = null;
6250    
6251                            try {
6252                                    session = openSession();
6253    
6254                                    Query q = session.createQuery(sql);
6255    
6256                                    QueryPos qPos = QueryPos.getInstance(q);
6257    
6258                                    if (bindLastPostDate) {
6259                                            qPos.add(new Timestamp(lastPostDate.getTime()));
6260                                    }
6261    
6262                                    qPos.add(priority);
6263    
6264                                    if (!pagination) {
6265                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
6266                                                            start, end, false);
6267    
6268                                            Collections.sort(list);
6269    
6270                                            list = Collections.unmodifiableList(list);
6271                                    }
6272                                    else {
6273                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
6274                                                            start, end);
6275                                    }
6276    
6277                                    cacheResult(list);
6278    
6279                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6280                            }
6281                            catch (Exception e) {
6282                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6283    
6284                                    throw processException(e);
6285                            }
6286                            finally {
6287                                    closeSession(session);
6288                            }
6289                    }
6290    
6291                    return list;
6292            }
6293    
6294            /**
6295             * Returns the first message boards thread in the ordered set where lastPostDate = &#63; and priority = &#63;.
6296             *
6297             * @param lastPostDate the last post date
6298             * @param priority the priority
6299             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6300             * @return the first matching message boards thread
6301             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
6302             */
6303            @Override
6304            public MBThread findByL_P_First(Date lastPostDate, double priority,
6305                    OrderByComparator<MBThread> orderByComparator)
6306                    throws NoSuchThreadException {
6307                    MBThread mbThread = fetchByL_P_First(lastPostDate, priority,
6308                                    orderByComparator);
6309    
6310                    if (mbThread != null) {
6311                            return mbThread;
6312                    }
6313    
6314                    StringBundler msg = new StringBundler(6);
6315    
6316                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6317    
6318                    msg.append("lastPostDate=");
6319                    msg.append(lastPostDate);
6320    
6321                    msg.append(", priority=");
6322                    msg.append(priority);
6323    
6324                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6325    
6326                    throw new NoSuchThreadException(msg.toString());
6327            }
6328    
6329            /**
6330             * Returns the first message boards thread in the ordered set where lastPostDate = &#63; and priority = &#63;.
6331             *
6332             * @param lastPostDate the last post date
6333             * @param priority the priority
6334             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6335             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
6336             */
6337            @Override
6338            public MBThread fetchByL_P_First(Date lastPostDate, double priority,
6339                    OrderByComparator<MBThread> orderByComparator) {
6340                    List<MBThread> list = findByL_P(lastPostDate, priority, 0, 1,
6341                                    orderByComparator);
6342    
6343                    if (!list.isEmpty()) {
6344                            return list.get(0);
6345                    }
6346    
6347                    return null;
6348            }
6349    
6350            /**
6351             * Returns the last message boards thread in the ordered set where lastPostDate = &#63; and priority = &#63;.
6352             *
6353             * @param lastPostDate the last post date
6354             * @param priority the priority
6355             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6356             * @return the last matching message boards thread
6357             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
6358             */
6359            @Override
6360            public MBThread findByL_P_Last(Date lastPostDate, double priority,
6361                    OrderByComparator<MBThread> orderByComparator)
6362                    throws NoSuchThreadException {
6363                    MBThread mbThread = fetchByL_P_Last(lastPostDate, priority,
6364                                    orderByComparator);
6365    
6366                    if (mbThread != null) {
6367                            return mbThread;
6368                    }
6369    
6370                    StringBundler msg = new StringBundler(6);
6371    
6372                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6373    
6374                    msg.append("lastPostDate=");
6375                    msg.append(lastPostDate);
6376    
6377                    msg.append(", priority=");
6378                    msg.append(priority);
6379    
6380                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6381    
6382                    throw new NoSuchThreadException(msg.toString());
6383            }
6384    
6385            /**
6386             * Returns the last message boards thread in the ordered set where lastPostDate = &#63; and priority = &#63;.
6387             *
6388             * @param lastPostDate the last post date
6389             * @param priority the priority
6390             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6391             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
6392             */
6393            @Override
6394            public MBThread fetchByL_P_Last(Date lastPostDate, double priority,
6395                    OrderByComparator<MBThread> orderByComparator) {
6396                    int count = countByL_P(lastPostDate, priority);
6397    
6398                    if (count == 0) {
6399                            return null;
6400                    }
6401    
6402                    List<MBThread> list = findByL_P(lastPostDate, priority, count - 1,
6403                                    count, orderByComparator);
6404    
6405                    if (!list.isEmpty()) {
6406                            return list.get(0);
6407                    }
6408    
6409                    return null;
6410            }
6411    
6412            /**
6413             * Returns the message boards threads before and after the current message boards thread in the ordered set where lastPostDate = &#63; and priority = &#63;.
6414             *
6415             * @param threadId the primary key of the current message boards thread
6416             * @param lastPostDate the last post date
6417             * @param priority the priority
6418             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6419             * @return the previous, current, and next message boards thread
6420             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
6421             */
6422            @Override
6423            public MBThread[] findByL_P_PrevAndNext(long threadId, Date lastPostDate,
6424                    double priority, OrderByComparator<MBThread> orderByComparator)
6425                    throws NoSuchThreadException {
6426                    MBThread mbThread = findByPrimaryKey(threadId);
6427    
6428                    Session session = null;
6429    
6430                    try {
6431                            session = openSession();
6432    
6433                            MBThread[] array = new MBThreadImpl[3];
6434    
6435                            array[0] = getByL_P_PrevAndNext(session, mbThread, lastPostDate,
6436                                            priority, orderByComparator, true);
6437    
6438                            array[1] = mbThread;
6439    
6440                            array[2] = getByL_P_PrevAndNext(session, mbThread, lastPostDate,
6441                                            priority, orderByComparator, false);
6442    
6443                            return array;
6444                    }
6445                    catch (Exception e) {
6446                            throw processException(e);
6447                    }
6448                    finally {
6449                            closeSession(session);
6450                    }
6451            }
6452    
6453            protected MBThread getByL_P_PrevAndNext(Session session, MBThread mbThread,
6454                    Date lastPostDate, double priority,
6455                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
6456                    StringBundler query = null;
6457    
6458                    if (orderByComparator != null) {
6459                            query = new StringBundler(6 +
6460                                            (orderByComparator.getOrderByFields().length * 6));
6461                    }
6462                    else {
6463                            query = new StringBundler(3);
6464                    }
6465    
6466                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
6467    
6468                    boolean bindLastPostDate = false;
6469    
6470                    if (lastPostDate == null) {
6471                            query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
6472                    }
6473                    else {
6474                            bindLastPostDate = true;
6475    
6476                            query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
6477                    }
6478    
6479                    query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
6480    
6481                    if (orderByComparator != null) {
6482                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6483    
6484                            if (orderByConditionFields.length > 0) {
6485                                    query.append(WHERE_AND);
6486                            }
6487    
6488                            for (int i = 0; i < orderByConditionFields.length; i++) {
6489                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6490                                    query.append(orderByConditionFields[i]);
6491    
6492                                    if ((i + 1) < orderByConditionFields.length) {
6493                                            if (orderByComparator.isAscending() ^ previous) {
6494                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6495                                            }
6496                                            else {
6497                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6498                                            }
6499                                    }
6500                                    else {
6501                                            if (orderByComparator.isAscending() ^ previous) {
6502                                                    query.append(WHERE_GREATER_THAN);
6503                                            }
6504                                            else {
6505                                                    query.append(WHERE_LESSER_THAN);
6506                                            }
6507                                    }
6508                            }
6509    
6510                            query.append(ORDER_BY_CLAUSE);
6511    
6512                            String[] orderByFields = orderByComparator.getOrderByFields();
6513    
6514                            for (int i = 0; i < orderByFields.length; i++) {
6515                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6516                                    query.append(orderByFields[i]);
6517    
6518                                    if ((i + 1) < orderByFields.length) {
6519                                            if (orderByComparator.isAscending() ^ previous) {
6520                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6521                                            }
6522                                            else {
6523                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6524                                            }
6525                                    }
6526                                    else {
6527                                            if (orderByComparator.isAscending() ^ previous) {
6528                                                    query.append(ORDER_BY_ASC);
6529                                            }
6530                                            else {
6531                                                    query.append(ORDER_BY_DESC);
6532                                            }
6533                                    }
6534                            }
6535                    }
6536                    else {
6537                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6538                    }
6539    
6540                    String sql = query.toString();
6541    
6542                    Query q = session.createQuery(sql);
6543    
6544                    q.setFirstResult(0);
6545                    q.setMaxResults(2);
6546    
6547                    QueryPos qPos = QueryPos.getInstance(q);
6548    
6549                    if (bindLastPostDate) {
6550                            qPos.add(new Timestamp(lastPostDate.getTime()));
6551                    }
6552    
6553                    qPos.add(priority);
6554    
6555                    if (orderByComparator != null) {
6556                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
6557    
6558                            for (Object value : values) {
6559                                    qPos.add(value);
6560                            }
6561                    }
6562    
6563                    List<MBThread> list = q.list();
6564    
6565                    if (list.size() == 2) {
6566                            return list.get(1);
6567                    }
6568                    else {
6569                            return null;
6570                    }
6571            }
6572    
6573            /**
6574             * Removes all the message boards threads where lastPostDate = &#63; and priority = &#63; from the database.
6575             *
6576             * @param lastPostDate the last post date
6577             * @param priority the priority
6578             */
6579            @Override
6580            public void removeByL_P(Date lastPostDate, double priority) {
6581                    for (MBThread mbThread : findByL_P(lastPostDate, priority,
6582                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6583                            remove(mbThread);
6584                    }
6585            }
6586    
6587            /**
6588             * Returns the number of message boards threads where lastPostDate = &#63; and priority = &#63;.
6589             *
6590             * @param lastPostDate the last post date
6591             * @param priority the priority
6592             * @return the number of matching message boards threads
6593             */
6594            @Override
6595            public int countByL_P(Date lastPostDate, double priority) {
6596                    FinderPath finderPath = FINDER_PATH_COUNT_BY_L_P;
6597    
6598                    Object[] finderArgs = new Object[] { lastPostDate, priority };
6599    
6600                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6601                                    this);
6602    
6603                    if (count == null) {
6604                            StringBundler query = new StringBundler(3);
6605    
6606                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
6607    
6608                            boolean bindLastPostDate = false;
6609    
6610                            if (lastPostDate == null) {
6611                                    query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
6612                            }
6613                            else {
6614                                    bindLastPostDate = true;
6615    
6616                                    query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
6617                            }
6618    
6619                            query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
6620    
6621                            String sql = query.toString();
6622    
6623                            Session session = null;
6624    
6625                            try {
6626                                    session = openSession();
6627    
6628                                    Query q = session.createQuery(sql);
6629    
6630                                    QueryPos qPos = QueryPos.getInstance(q);
6631    
6632                                    if (bindLastPostDate) {
6633                                            qPos.add(new Timestamp(lastPostDate.getTime()));
6634                                    }
6635    
6636                                    qPos.add(priority);
6637    
6638                                    count = (Long)q.uniqueResult();
6639    
6640                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6641                            }
6642                            catch (Exception e) {
6643                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6644    
6645                                    throw processException(e);
6646                            }
6647                            finally {
6648                                    closeSession(session);
6649                            }
6650                    }
6651    
6652                    return count.intValue();
6653            }
6654    
6655            private static final String _FINDER_COLUMN_L_P_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL AND ";
6656            private static final String _FINDER_COLUMN_L_P_LASTPOSTDATE_2 = "mbThread.lastPostDate = ? AND ";
6657            private static final String _FINDER_COLUMN_L_P_PRIORITY_2 = "mbThread.priority = ? AND mbThread.categoryId != -1";
6658            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6659                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6660                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_L",
6661                            new String[] {
6662                                    Long.class.getName(), Long.class.getName(), Date.class.getName(),
6663                                    
6664                            Integer.class.getName(), Integer.class.getName(),
6665                                    OrderByComparator.class.getName()
6666                            });
6667            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6668                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6669                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_L",
6670                            new String[] {
6671                                    Long.class.getName(), Long.class.getName(), Date.class.getName()
6672                            },
6673                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
6674                            MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
6675                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK |
6676                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
6677            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6678                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
6679                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_L",
6680                            new String[] {
6681                                    Long.class.getName(), Long.class.getName(), Date.class.getName()
6682                            });
6683    
6684            /**
6685             * Returns all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
6686             *
6687             * @param groupId the group ID
6688             * @param categoryId the category ID
6689             * @param lastPostDate the last post date
6690             * @return the matching message boards threads
6691             */
6692            @Override
6693            public List<MBThread> findByG_C_L(long groupId, long categoryId,
6694                    Date lastPostDate) {
6695                    return findByG_C_L(groupId, categoryId, lastPostDate,
6696                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6697            }
6698    
6699            /**
6700             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
6701             *
6702             * <p>
6703             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6704             * </p>
6705             *
6706             * @param groupId the group ID
6707             * @param categoryId the category ID
6708             * @param lastPostDate the last post date
6709             * @param start the lower bound of the range of message boards threads
6710             * @param end the upper bound of the range of message boards threads (not inclusive)
6711             * @return the range of matching message boards threads
6712             */
6713            @Override
6714            public List<MBThread> findByG_C_L(long groupId, long categoryId,
6715                    Date lastPostDate, int start, int end) {
6716                    return findByG_C_L(groupId, categoryId, lastPostDate, start, end, null);
6717            }
6718    
6719            /**
6720             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
6721             *
6722             * <p>
6723             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6724             * </p>
6725             *
6726             * @param groupId the group ID
6727             * @param categoryId the category ID
6728             * @param lastPostDate the last post date
6729             * @param start the lower bound of the range of message boards threads
6730             * @param end the upper bound of the range of message boards threads (not inclusive)
6731             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6732             * @return the ordered range of matching message boards threads
6733             */
6734            @Override
6735            public List<MBThread> findByG_C_L(long groupId, long categoryId,
6736                    Date lastPostDate, int start, int end,
6737                    OrderByComparator<MBThread> orderByComparator) {
6738                    boolean pagination = true;
6739                    FinderPath finderPath = null;
6740                    Object[] finderArgs = null;
6741    
6742                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6743                                    (orderByComparator == null)) {
6744                            pagination = false;
6745                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L;
6746                            finderArgs = new Object[] { groupId, categoryId, lastPostDate };
6747                    }
6748                    else {
6749                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L;
6750                            finderArgs = new Object[] {
6751                                            groupId, categoryId, lastPostDate,
6752                                            
6753                                            start, end, orderByComparator
6754                                    };
6755                    }
6756    
6757                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
6758                                    finderArgs, this);
6759    
6760                    if ((list != null) && !list.isEmpty()) {
6761                            for (MBThread mbThread : list) {
6762                                    if ((groupId != mbThread.getGroupId()) ||
6763                                                    (categoryId != mbThread.getCategoryId()) ||
6764                                                    !Validator.equals(lastPostDate,
6765                                                            mbThread.getLastPostDate())) {
6766                                            list = null;
6767    
6768                                            break;
6769                                    }
6770                            }
6771                    }
6772    
6773                    if (list == null) {
6774                            StringBundler query = null;
6775    
6776                            if (orderByComparator != null) {
6777                                    query = new StringBundler(5 +
6778                                                    (orderByComparator.getOrderByFields().length * 3));
6779                            }
6780                            else {
6781                                    query = new StringBundler(5);
6782                            }
6783    
6784                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
6785    
6786                            query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
6787    
6788                            query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
6789    
6790                            boolean bindLastPostDate = false;
6791    
6792                            if (lastPostDate == null) {
6793                                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
6794                            }
6795                            else {
6796                                    bindLastPostDate = true;
6797    
6798                                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
6799                            }
6800    
6801                            if (orderByComparator != null) {
6802                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6803                                            orderByComparator);
6804                            }
6805                            else
6806                             if (pagination) {
6807                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6808                            }
6809    
6810                            String sql = query.toString();
6811    
6812                            Session session = null;
6813    
6814                            try {
6815                                    session = openSession();
6816    
6817                                    Query q = session.createQuery(sql);
6818    
6819                                    QueryPos qPos = QueryPos.getInstance(q);
6820    
6821                                    qPos.add(groupId);
6822    
6823                                    qPos.add(categoryId);
6824    
6825                                    if (bindLastPostDate) {
6826                                            qPos.add(new Timestamp(lastPostDate.getTime()));
6827                                    }
6828    
6829                                    if (!pagination) {
6830                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
6831                                                            start, end, false);
6832    
6833                                            Collections.sort(list);
6834    
6835                                            list = Collections.unmodifiableList(list);
6836                                    }
6837                                    else {
6838                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
6839                                                            start, end);
6840                                    }
6841    
6842                                    cacheResult(list);
6843    
6844                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6845                            }
6846                            catch (Exception e) {
6847                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6848    
6849                                    throw processException(e);
6850                            }
6851                            finally {
6852                                    closeSession(session);
6853                            }
6854                    }
6855    
6856                    return list;
6857            }
6858    
6859            /**
6860             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
6861             *
6862             * @param groupId the group ID
6863             * @param categoryId the category ID
6864             * @param lastPostDate the last post date
6865             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6866             * @return the first matching message boards thread
6867             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
6868             */
6869            @Override
6870            public MBThread findByG_C_L_First(long groupId, long categoryId,
6871                    Date lastPostDate, OrderByComparator<MBThread> orderByComparator)
6872                    throws NoSuchThreadException {
6873                    MBThread mbThread = fetchByG_C_L_First(groupId, categoryId,
6874                                    lastPostDate, orderByComparator);
6875    
6876                    if (mbThread != null) {
6877                            return mbThread;
6878                    }
6879    
6880                    StringBundler msg = new StringBundler(8);
6881    
6882                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6883    
6884                    msg.append("groupId=");
6885                    msg.append(groupId);
6886    
6887                    msg.append(", categoryId=");
6888                    msg.append(categoryId);
6889    
6890                    msg.append(", lastPostDate=");
6891                    msg.append(lastPostDate);
6892    
6893                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6894    
6895                    throw new NoSuchThreadException(msg.toString());
6896            }
6897    
6898            /**
6899             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
6900             *
6901             * @param groupId the group ID
6902             * @param categoryId the category ID
6903             * @param lastPostDate the last post date
6904             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6905             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
6906             */
6907            @Override
6908            public MBThread fetchByG_C_L_First(long groupId, long categoryId,
6909                    Date lastPostDate, OrderByComparator<MBThread> orderByComparator) {
6910                    List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate, 0,
6911                                    1, orderByComparator);
6912    
6913                    if (!list.isEmpty()) {
6914                            return list.get(0);
6915                    }
6916    
6917                    return null;
6918            }
6919    
6920            /**
6921             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
6922             *
6923             * @param groupId the group ID
6924             * @param categoryId the category ID
6925             * @param lastPostDate the last post date
6926             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6927             * @return the last matching message boards thread
6928             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
6929             */
6930            @Override
6931            public MBThread findByG_C_L_Last(long groupId, long categoryId,
6932                    Date lastPostDate, OrderByComparator<MBThread> orderByComparator)
6933                    throws NoSuchThreadException {
6934                    MBThread mbThread = fetchByG_C_L_Last(groupId, categoryId,
6935                                    lastPostDate, orderByComparator);
6936    
6937                    if (mbThread != null) {
6938                            return mbThread;
6939                    }
6940    
6941                    StringBundler msg = new StringBundler(8);
6942    
6943                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6944    
6945                    msg.append("groupId=");
6946                    msg.append(groupId);
6947    
6948                    msg.append(", categoryId=");
6949                    msg.append(categoryId);
6950    
6951                    msg.append(", lastPostDate=");
6952                    msg.append(lastPostDate);
6953    
6954                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6955    
6956                    throw new NoSuchThreadException(msg.toString());
6957            }
6958    
6959            /**
6960             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
6961             *
6962             * @param groupId the group ID
6963             * @param categoryId the category ID
6964             * @param lastPostDate the last post date
6965             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6966             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
6967             */
6968            @Override
6969            public MBThread fetchByG_C_L_Last(long groupId, long categoryId,
6970                    Date lastPostDate, OrderByComparator<MBThread> orderByComparator) {
6971                    int count = countByG_C_L(groupId, categoryId, lastPostDate);
6972    
6973                    if (count == 0) {
6974                            return null;
6975                    }
6976    
6977                    List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate,
6978                                    count - 1, count, orderByComparator);
6979    
6980                    if (!list.isEmpty()) {
6981                            return list.get(0);
6982                    }
6983    
6984                    return null;
6985            }
6986    
6987            /**
6988             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
6989             *
6990             * @param threadId the primary key of the current message boards thread
6991             * @param groupId the group ID
6992             * @param categoryId the category ID
6993             * @param lastPostDate the last post date
6994             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6995             * @return the previous, current, and next message boards thread
6996             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
6997             */
6998            @Override
6999            public MBThread[] findByG_C_L_PrevAndNext(long threadId, long groupId,
7000                    long categoryId, Date lastPostDate,
7001                    OrderByComparator<MBThread> orderByComparator)
7002                    throws NoSuchThreadException {
7003                    MBThread mbThread = findByPrimaryKey(threadId);
7004    
7005                    Session session = null;
7006    
7007                    try {
7008                            session = openSession();
7009    
7010                            MBThread[] array = new MBThreadImpl[3];
7011    
7012                            array[0] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
7013                                            categoryId, lastPostDate, orderByComparator, true);
7014    
7015                            array[1] = mbThread;
7016    
7017                            array[2] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
7018                                            categoryId, lastPostDate, orderByComparator, false);
7019    
7020                            return array;
7021                    }
7022                    catch (Exception e) {
7023                            throw processException(e);
7024                    }
7025                    finally {
7026                            closeSession(session);
7027                    }
7028            }
7029    
7030            protected MBThread getByG_C_L_PrevAndNext(Session session,
7031                    MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
7032                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
7033                    StringBundler query = null;
7034    
7035                    if (orderByComparator != null) {
7036                            query = new StringBundler(6 +
7037                                            (orderByComparator.getOrderByFields().length * 6));
7038                    }
7039                    else {
7040                            query = new StringBundler(3);
7041                    }
7042    
7043                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
7044    
7045                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7046    
7047                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7048    
7049                    boolean bindLastPostDate = false;
7050    
7051                    if (lastPostDate == null) {
7052                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7053                    }
7054                    else {
7055                            bindLastPostDate = true;
7056    
7057                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7058                    }
7059    
7060                    if (orderByComparator != null) {
7061                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7062    
7063                            if (orderByConditionFields.length > 0) {
7064                                    query.append(WHERE_AND);
7065                            }
7066    
7067                            for (int i = 0; i < orderByConditionFields.length; i++) {
7068                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7069                                    query.append(orderByConditionFields[i]);
7070    
7071                                    if ((i + 1) < orderByConditionFields.length) {
7072                                            if (orderByComparator.isAscending() ^ previous) {
7073                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7074                                            }
7075                                            else {
7076                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7077                                            }
7078                                    }
7079                                    else {
7080                                            if (orderByComparator.isAscending() ^ previous) {
7081                                                    query.append(WHERE_GREATER_THAN);
7082                                            }
7083                                            else {
7084                                                    query.append(WHERE_LESSER_THAN);
7085                                            }
7086                                    }
7087                            }
7088    
7089                            query.append(ORDER_BY_CLAUSE);
7090    
7091                            String[] orderByFields = orderByComparator.getOrderByFields();
7092    
7093                            for (int i = 0; i < orderByFields.length; i++) {
7094                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7095                                    query.append(orderByFields[i]);
7096    
7097                                    if ((i + 1) < orderByFields.length) {
7098                                            if (orderByComparator.isAscending() ^ previous) {
7099                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7100                                            }
7101                                            else {
7102                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7103                                            }
7104                                    }
7105                                    else {
7106                                            if (orderByComparator.isAscending() ^ previous) {
7107                                                    query.append(ORDER_BY_ASC);
7108                                            }
7109                                            else {
7110                                                    query.append(ORDER_BY_DESC);
7111                                            }
7112                                    }
7113                            }
7114                    }
7115                    else {
7116                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7117                    }
7118    
7119                    String sql = query.toString();
7120    
7121                    Query q = session.createQuery(sql);
7122    
7123                    q.setFirstResult(0);
7124                    q.setMaxResults(2);
7125    
7126                    QueryPos qPos = QueryPos.getInstance(q);
7127    
7128                    qPos.add(groupId);
7129    
7130                    qPos.add(categoryId);
7131    
7132                    if (bindLastPostDate) {
7133                            qPos.add(new Timestamp(lastPostDate.getTime()));
7134                    }
7135    
7136                    if (orderByComparator != null) {
7137                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
7138    
7139                            for (Object value : values) {
7140                                    qPos.add(value);
7141                            }
7142                    }
7143    
7144                    List<MBThread> list = q.list();
7145    
7146                    if (list.size() == 2) {
7147                            return list.get(1);
7148                    }
7149                    else {
7150                            return null;
7151                    }
7152            }
7153    
7154            /**
7155             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
7156             *
7157             * @param groupId the group ID
7158             * @param categoryId the category ID
7159             * @param lastPostDate the last post date
7160             * @return the matching message boards threads that the user has permission to view
7161             */
7162            @Override
7163            public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
7164                    Date lastPostDate) {
7165                    return filterFindByG_C_L(groupId, categoryId, lastPostDate,
7166                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7167            }
7168    
7169            /**
7170             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
7171             *
7172             * <p>
7173             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7174             * </p>
7175             *
7176             * @param groupId the group ID
7177             * @param categoryId the category ID
7178             * @param lastPostDate the last post date
7179             * @param start the lower bound of the range of message boards threads
7180             * @param end the upper bound of the range of message boards threads (not inclusive)
7181             * @return the range of matching message boards threads that the user has permission to view
7182             */
7183            @Override
7184            public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
7185                    Date lastPostDate, int start, int end) {
7186                    return filterFindByG_C_L(groupId, categoryId, lastPostDate, start, end,
7187                            null);
7188            }
7189    
7190            /**
7191             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
7192             *
7193             * <p>
7194             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7195             * </p>
7196             *
7197             * @param groupId the group ID
7198             * @param categoryId the category ID
7199             * @param lastPostDate the last post date
7200             * @param start the lower bound of the range of message boards threads
7201             * @param end the upper bound of the range of message boards threads (not inclusive)
7202             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7203             * @return the ordered range of matching message boards threads that the user has permission to view
7204             */
7205            @Override
7206            public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
7207                    Date lastPostDate, int start, int end,
7208                    OrderByComparator<MBThread> orderByComparator) {
7209                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7210                            return findByG_C_L(groupId, categoryId, lastPostDate, start, end,
7211                                    orderByComparator);
7212                    }
7213    
7214                    StringBundler query = null;
7215    
7216                    if (orderByComparator != null) {
7217                            query = new StringBundler(5 +
7218                                            (orderByComparator.getOrderByFields().length * 3));
7219                    }
7220                    else {
7221                            query = new StringBundler(5);
7222                    }
7223    
7224                    if (getDB().isSupportsInlineDistinct()) {
7225                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
7226                    }
7227                    else {
7228                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
7229                    }
7230    
7231                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7232    
7233                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7234    
7235                    boolean bindLastPostDate = false;
7236    
7237                    if (lastPostDate == null) {
7238                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7239                    }
7240                    else {
7241                            bindLastPostDate = true;
7242    
7243                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7244                    }
7245    
7246                    if (!getDB().isSupportsInlineDistinct()) {
7247                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
7248                    }
7249    
7250                    if (orderByComparator != null) {
7251                            if (getDB().isSupportsInlineDistinct()) {
7252                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7253                                            orderByComparator, true);
7254                            }
7255                            else {
7256                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7257                                            orderByComparator, true);
7258                            }
7259                    }
7260                    else {
7261                            if (getDB().isSupportsInlineDistinct()) {
7262                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7263                            }
7264                            else {
7265                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
7266                            }
7267                    }
7268    
7269                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7270                                    MBThread.class.getName(),
7271                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7272    
7273                    Session session = null;
7274    
7275                    try {
7276                            session = openSession();
7277    
7278                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
7279    
7280                            if (getDB().isSupportsInlineDistinct()) {
7281                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
7282                            }
7283                            else {
7284                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
7285                            }
7286    
7287                            QueryPos qPos = QueryPos.getInstance(q);
7288    
7289                            qPos.add(groupId);
7290    
7291                            qPos.add(categoryId);
7292    
7293                            if (bindLastPostDate) {
7294                                    qPos.add(new Timestamp(lastPostDate.getTime()));
7295                            }
7296    
7297                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
7298                    }
7299                    catch (Exception e) {
7300                            throw processException(e);
7301                    }
7302                    finally {
7303                            closeSession(session);
7304                    }
7305            }
7306    
7307            /**
7308             * Returns the message boards threads before and after the current message boards thread in the ordered set of message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
7309             *
7310             * @param threadId the primary key of the current message boards thread
7311             * @param groupId the group ID
7312             * @param categoryId the category ID
7313             * @param lastPostDate the last post date
7314             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7315             * @return the previous, current, and next message boards thread
7316             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
7317             */
7318            @Override
7319            public MBThread[] filterFindByG_C_L_PrevAndNext(long threadId,
7320                    long groupId, long categoryId, Date lastPostDate,
7321                    OrderByComparator<MBThread> orderByComparator)
7322                    throws NoSuchThreadException {
7323                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7324                            return findByG_C_L_PrevAndNext(threadId, groupId, categoryId,
7325                                    lastPostDate, orderByComparator);
7326                    }
7327    
7328                    MBThread mbThread = findByPrimaryKey(threadId);
7329    
7330                    Session session = null;
7331    
7332                    try {
7333                            session = openSession();
7334    
7335                            MBThread[] array = new MBThreadImpl[3];
7336    
7337                            array[0] = filterGetByG_C_L_PrevAndNext(session, mbThread, groupId,
7338                                            categoryId, lastPostDate, orderByComparator, true);
7339    
7340                            array[1] = mbThread;
7341    
7342                            array[2] = filterGetByG_C_L_PrevAndNext(session, mbThread, groupId,
7343                                            categoryId, lastPostDate, orderByComparator, false);
7344    
7345                            return array;
7346                    }
7347                    catch (Exception e) {
7348                            throw processException(e);
7349                    }
7350                    finally {
7351                            closeSession(session);
7352                    }
7353            }
7354    
7355            protected MBThread filterGetByG_C_L_PrevAndNext(Session session,
7356                    MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
7357                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
7358                    StringBundler query = null;
7359    
7360                    if (orderByComparator != null) {
7361                            query = new StringBundler(6 +
7362                                            (orderByComparator.getOrderByFields().length * 6));
7363                    }
7364                    else {
7365                            query = new StringBundler(3);
7366                    }
7367    
7368                    if (getDB().isSupportsInlineDistinct()) {
7369                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
7370                    }
7371                    else {
7372                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
7373                    }
7374    
7375                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7376    
7377                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7378    
7379                    boolean bindLastPostDate = false;
7380    
7381                    if (lastPostDate == null) {
7382                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7383                    }
7384                    else {
7385                            bindLastPostDate = true;
7386    
7387                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7388                    }
7389    
7390                    if (!getDB().isSupportsInlineDistinct()) {
7391                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
7392                    }
7393    
7394                    if (orderByComparator != null) {
7395                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7396    
7397                            if (orderByConditionFields.length > 0) {
7398                                    query.append(WHERE_AND);
7399                            }
7400    
7401                            for (int i = 0; i < orderByConditionFields.length; i++) {
7402                                    if (getDB().isSupportsInlineDistinct()) {
7403                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7404                                    }
7405                                    else {
7406                                            query.append(_ORDER_BY_ENTITY_TABLE);
7407                                    }
7408    
7409                                    query.append(orderByConditionFields[i]);
7410    
7411                                    if ((i + 1) < orderByConditionFields.length) {
7412                                            if (orderByComparator.isAscending() ^ previous) {
7413                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7414                                            }
7415                                            else {
7416                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7417                                            }
7418                                    }
7419                                    else {
7420                                            if (orderByComparator.isAscending() ^ previous) {
7421                                                    query.append(WHERE_GREATER_THAN);
7422                                            }
7423                                            else {
7424                                                    query.append(WHERE_LESSER_THAN);
7425                                            }
7426                                    }
7427                            }
7428    
7429                            query.append(ORDER_BY_CLAUSE);
7430    
7431                            String[] orderByFields = orderByComparator.getOrderByFields();
7432    
7433                            for (int i = 0; i < orderByFields.length; i++) {
7434                                    if (getDB().isSupportsInlineDistinct()) {
7435                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7436                                    }
7437                                    else {
7438                                            query.append(_ORDER_BY_ENTITY_TABLE);
7439                                    }
7440    
7441                                    query.append(orderByFields[i]);
7442    
7443                                    if ((i + 1) < orderByFields.length) {
7444                                            if (orderByComparator.isAscending() ^ previous) {
7445                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7446                                            }
7447                                            else {
7448                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7449                                            }
7450                                    }
7451                                    else {
7452                                            if (orderByComparator.isAscending() ^ previous) {
7453                                                    query.append(ORDER_BY_ASC);
7454                                            }
7455                                            else {
7456                                                    query.append(ORDER_BY_DESC);
7457                                            }
7458                                    }
7459                            }
7460                    }
7461                    else {
7462                            if (getDB().isSupportsInlineDistinct()) {
7463                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7464                            }
7465                            else {
7466                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
7467                            }
7468                    }
7469    
7470                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7471                                    MBThread.class.getName(),
7472                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7473    
7474                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
7475    
7476                    q.setFirstResult(0);
7477                    q.setMaxResults(2);
7478    
7479                    if (getDB().isSupportsInlineDistinct()) {
7480                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
7481                    }
7482                    else {
7483                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
7484                    }
7485    
7486                    QueryPos qPos = QueryPos.getInstance(q);
7487    
7488                    qPos.add(groupId);
7489    
7490                    qPos.add(categoryId);
7491    
7492                    if (bindLastPostDate) {
7493                            qPos.add(new Timestamp(lastPostDate.getTime()));
7494                    }
7495    
7496                    if (orderByComparator != null) {
7497                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
7498    
7499                            for (Object value : values) {
7500                                    qPos.add(value);
7501                            }
7502                    }
7503    
7504                    List<MBThread> list = q.list();
7505    
7506                    if (list.size() == 2) {
7507                            return list.get(1);
7508                    }
7509                    else {
7510                            return null;
7511                    }
7512            }
7513    
7514            /**
7515             * Removes all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63; from the database.
7516             *
7517             * @param groupId the group ID
7518             * @param categoryId the category ID
7519             * @param lastPostDate the last post date
7520             */
7521            @Override
7522            public void removeByG_C_L(long groupId, long categoryId, Date lastPostDate) {
7523                    for (MBThread mbThread : findByG_C_L(groupId, categoryId, lastPostDate,
7524                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7525                            remove(mbThread);
7526                    }
7527            }
7528    
7529            /**
7530             * Returns the number of message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
7531             *
7532             * @param groupId the group ID
7533             * @param categoryId the category ID
7534             * @param lastPostDate the last post date
7535             * @return the number of matching message boards threads
7536             */
7537            @Override
7538            public int countByG_C_L(long groupId, long categoryId, Date lastPostDate) {
7539                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_L;
7540    
7541                    Object[] finderArgs = new Object[] { groupId, categoryId, lastPostDate };
7542    
7543                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7544                                    this);
7545    
7546                    if (count == null) {
7547                            StringBundler query = new StringBundler(4);
7548    
7549                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
7550    
7551                            query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7552    
7553                            query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7554    
7555                            boolean bindLastPostDate = false;
7556    
7557                            if (lastPostDate == null) {
7558                                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7559                            }
7560                            else {
7561                                    bindLastPostDate = true;
7562    
7563                                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7564                            }
7565    
7566                            String sql = query.toString();
7567    
7568                            Session session = null;
7569    
7570                            try {
7571                                    session = openSession();
7572    
7573                                    Query q = session.createQuery(sql);
7574    
7575                                    QueryPos qPos = QueryPos.getInstance(q);
7576    
7577                                    qPos.add(groupId);
7578    
7579                                    qPos.add(categoryId);
7580    
7581                                    if (bindLastPostDate) {
7582                                            qPos.add(new Timestamp(lastPostDate.getTime()));
7583                                    }
7584    
7585                                    count = (Long)q.uniqueResult();
7586    
7587                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7588                            }
7589                            catch (Exception e) {
7590                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7591    
7592                                    throw processException(e);
7593                            }
7594                            finally {
7595                                    closeSession(session);
7596                            }
7597                    }
7598    
7599                    return count.intValue();
7600            }
7601    
7602            /**
7603             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
7604             *
7605             * @param groupId the group ID
7606             * @param categoryId the category ID
7607             * @param lastPostDate the last post date
7608             * @return the number of matching message boards threads that the user has permission to view
7609             */
7610            @Override
7611            public int filterCountByG_C_L(long groupId, long categoryId,
7612                    Date lastPostDate) {
7613                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7614                            return countByG_C_L(groupId, categoryId, lastPostDate);
7615                    }
7616    
7617                    StringBundler query = new StringBundler(4);
7618    
7619                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
7620    
7621                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7622    
7623                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7624    
7625                    boolean bindLastPostDate = false;
7626    
7627                    if (lastPostDate == null) {
7628                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7629                    }
7630                    else {
7631                            bindLastPostDate = true;
7632    
7633                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7634                    }
7635    
7636                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7637                                    MBThread.class.getName(),
7638                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7639    
7640                    Session session = null;
7641    
7642                    try {
7643                            session = openSession();
7644    
7645                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
7646    
7647                            q.addScalar(COUNT_COLUMN_NAME,
7648                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7649    
7650                            QueryPos qPos = QueryPos.getInstance(q);
7651    
7652                            qPos.add(groupId);
7653    
7654                            qPos.add(categoryId);
7655    
7656                            if (bindLastPostDate) {
7657                                    qPos.add(new Timestamp(lastPostDate.getTime()));
7658                            }
7659    
7660                            Long count = (Long)q.uniqueResult();
7661    
7662                            return count.intValue();
7663                    }
7664                    catch (Exception e) {
7665                            throw processException(e);
7666                    }
7667                    finally {
7668                            closeSession(session);
7669                    }
7670            }
7671    
7672            private static final String _FINDER_COLUMN_G_C_L_GROUPID_2 = "mbThread.groupId = ? AND ";
7673            private static final String _FINDER_COLUMN_G_C_L_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
7674            private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL";
7675            private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_2 = "mbThread.lastPostDate = ?";
7676            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7677                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
7678                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
7679                            new String[] {
7680                                    Long.class.getName(), Long.class.getName(),
7681                                    Integer.class.getName(),
7682                                    
7683                            Integer.class.getName(), Integer.class.getName(),
7684                                    OrderByComparator.class.getName()
7685                            });
7686            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7687                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
7688                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
7689                            new String[] {
7690                                    Long.class.getName(), Long.class.getName(),
7691                                    Integer.class.getName()
7692                            },
7693                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
7694                            MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
7695                            MBThreadModelImpl.STATUS_COLUMN_BITMASK |
7696                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
7697                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
7698            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7699                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
7700                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
7701                            new String[] {
7702                                    Long.class.getName(), Long.class.getName(),
7703                                    Integer.class.getName()
7704                            });
7705            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7706                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
7707                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C_S",
7708                            new String[] {
7709                                    Long.class.getName(), Long.class.getName(),
7710                                    Integer.class.getName()
7711                            });
7712    
7713            /**
7714             * Returns all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63;.
7715             *
7716             * @param groupId the group ID
7717             * @param categoryId the category ID
7718             * @param status the status
7719             * @return the matching message boards threads
7720             */
7721            @Override
7722            public List<MBThread> findByG_C_S(long groupId, long categoryId, int status) {
7723                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
7724                            QueryUtil.ALL_POS, null);
7725            }
7726    
7727            /**
7728             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63;.
7729             *
7730             * <p>
7731             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7732             * </p>
7733             *
7734             * @param groupId the group ID
7735             * @param categoryId the category ID
7736             * @param status the status
7737             * @param start the lower bound of the range of message boards threads
7738             * @param end the upper bound of the range of message boards threads (not inclusive)
7739             * @return the range of matching message boards threads
7740             */
7741            @Override
7742            public List<MBThread> findByG_C_S(long groupId, long categoryId,
7743                    int status, int start, int end) {
7744                    return findByG_C_S(groupId, categoryId, status, start, end, null);
7745            }
7746    
7747            /**
7748             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63;.
7749             *
7750             * <p>
7751             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7752             * </p>
7753             *
7754             * @param groupId the group ID
7755             * @param categoryId the category ID
7756             * @param status the status
7757             * @param start the lower bound of the range of message boards threads
7758             * @param end the upper bound of the range of message boards threads (not inclusive)
7759             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7760             * @return the ordered range of matching message boards threads
7761             */
7762            @Override
7763            public List<MBThread> findByG_C_S(long groupId, long categoryId,
7764                    int status, int start, int end,
7765                    OrderByComparator<MBThread> orderByComparator) {
7766                    boolean pagination = true;
7767                    FinderPath finderPath = null;
7768                    Object[] finderArgs = null;
7769    
7770                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7771                                    (orderByComparator == null)) {
7772                            pagination = false;
7773                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
7774                            finderArgs = new Object[] { groupId, categoryId, status };
7775                    }
7776                    else {
7777                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
7778                            finderArgs = new Object[] {
7779                                            groupId, categoryId, status,
7780                                            
7781                                            start, end, orderByComparator
7782                                    };
7783                    }
7784    
7785                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
7786                                    finderArgs, this);
7787    
7788                    if ((list != null) && !list.isEmpty()) {
7789                            for (MBThread mbThread : list) {
7790                                    if ((groupId != mbThread.getGroupId()) ||
7791                                                    (categoryId != mbThread.getCategoryId()) ||
7792                                                    (status != mbThread.getStatus())) {
7793                                            list = null;
7794    
7795                                            break;
7796                                    }
7797                            }
7798                    }
7799    
7800                    if (list == null) {
7801                            StringBundler query = null;
7802    
7803                            if (orderByComparator != null) {
7804                                    query = new StringBundler(5 +
7805                                                    (orderByComparator.getOrderByFields().length * 3));
7806                            }
7807                            else {
7808                                    query = new StringBundler(5);
7809                            }
7810    
7811                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
7812    
7813                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
7814    
7815                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
7816    
7817                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
7818    
7819                            if (orderByComparator != null) {
7820                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7821                                            orderByComparator);
7822                            }
7823                            else
7824                             if (pagination) {
7825                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7826                            }
7827    
7828                            String sql = query.toString();
7829    
7830                            Session session = null;
7831    
7832                            try {
7833                                    session = openSession();
7834    
7835                                    Query q = session.createQuery(sql);
7836    
7837                                    QueryPos qPos = QueryPos.getInstance(q);
7838    
7839                                    qPos.add(groupId);
7840    
7841                                    qPos.add(categoryId);
7842    
7843                                    qPos.add(status);
7844    
7845                                    if (!pagination) {
7846                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
7847                                                            start, end, false);
7848    
7849                                            Collections.sort(list);
7850    
7851                                            list = Collections.unmodifiableList(list);
7852                                    }
7853                                    else {
7854                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
7855                                                            start, end);
7856                                    }
7857    
7858                                    cacheResult(list);
7859    
7860                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7861                            }
7862                            catch (Exception e) {
7863                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7864    
7865                                    throw processException(e);
7866                            }
7867                            finally {
7868                                    closeSession(session);
7869                            }
7870                    }
7871    
7872                    return list;
7873            }
7874    
7875            /**
7876             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
7877             *
7878             * @param groupId the group ID
7879             * @param categoryId the category ID
7880             * @param status the status
7881             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7882             * @return the first matching message boards thread
7883             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
7884             */
7885            @Override
7886            public MBThread findByG_C_S_First(long groupId, long categoryId,
7887                    int status, OrderByComparator<MBThread> orderByComparator)
7888                    throws NoSuchThreadException {
7889                    MBThread mbThread = fetchByG_C_S_First(groupId, categoryId, status,
7890                                    orderByComparator);
7891    
7892                    if (mbThread != null) {
7893                            return mbThread;
7894                    }
7895    
7896                    StringBundler msg = new StringBundler(8);
7897    
7898                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7899    
7900                    msg.append("groupId=");
7901                    msg.append(groupId);
7902    
7903                    msg.append(", categoryId=");
7904                    msg.append(categoryId);
7905    
7906                    msg.append(", status=");
7907                    msg.append(status);
7908    
7909                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7910    
7911                    throw new NoSuchThreadException(msg.toString());
7912            }
7913    
7914            /**
7915             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
7916             *
7917             * @param groupId the group ID
7918             * @param categoryId the category ID
7919             * @param status the status
7920             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7921             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
7922             */
7923            @Override
7924            public MBThread fetchByG_C_S_First(long groupId, long categoryId,
7925                    int status, OrderByComparator<MBThread> orderByComparator) {
7926                    List<MBThread> list = findByG_C_S(groupId, categoryId, status, 0, 1,
7927                                    orderByComparator);
7928    
7929                    if (!list.isEmpty()) {
7930                            return list.get(0);
7931                    }
7932    
7933                    return null;
7934            }
7935    
7936            /**
7937             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
7938             *
7939             * @param groupId the group ID
7940             * @param categoryId the category ID
7941             * @param status the status
7942             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7943             * @return the last matching message boards thread
7944             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
7945             */
7946            @Override
7947            public MBThread findByG_C_S_Last(long groupId, long categoryId, int status,
7948                    OrderByComparator<MBThread> orderByComparator)
7949                    throws NoSuchThreadException {
7950                    MBThread mbThread = fetchByG_C_S_Last(groupId, categoryId, status,
7951                                    orderByComparator);
7952    
7953                    if (mbThread != null) {
7954                            return mbThread;
7955                    }
7956    
7957                    StringBundler msg = new StringBundler(8);
7958    
7959                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7960    
7961                    msg.append("groupId=");
7962                    msg.append(groupId);
7963    
7964                    msg.append(", categoryId=");
7965                    msg.append(categoryId);
7966    
7967                    msg.append(", status=");
7968                    msg.append(status);
7969    
7970                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7971    
7972                    throw new NoSuchThreadException(msg.toString());
7973            }
7974    
7975            /**
7976             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
7977             *
7978             * @param groupId the group ID
7979             * @param categoryId the category ID
7980             * @param status the status
7981             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7982             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
7983             */
7984            @Override
7985            public MBThread fetchByG_C_S_Last(long groupId, long categoryId,
7986                    int status, OrderByComparator<MBThread> orderByComparator) {
7987                    int count = countByG_C_S(groupId, categoryId, status);
7988    
7989                    if (count == 0) {
7990                            return null;
7991                    }
7992    
7993                    List<MBThread> list = findByG_C_S(groupId, categoryId, status,
7994                                    count - 1, count, orderByComparator);
7995    
7996                    if (!list.isEmpty()) {
7997                            return list.get(0);
7998                    }
7999    
8000                    return null;
8001            }
8002    
8003            /**
8004             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
8005             *
8006             * @param threadId the primary key of the current message boards thread
8007             * @param groupId the group ID
8008             * @param categoryId the category ID
8009             * @param status the status
8010             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8011             * @return the previous, current, and next message boards thread
8012             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
8013             */
8014            @Override
8015            public MBThread[] findByG_C_S_PrevAndNext(long threadId, long groupId,
8016                    long categoryId, int status,
8017                    OrderByComparator<MBThread> orderByComparator)
8018                    throws NoSuchThreadException {
8019                    MBThread mbThread = findByPrimaryKey(threadId);
8020    
8021                    Session session = null;
8022    
8023                    try {
8024                            session = openSession();
8025    
8026                            MBThread[] array = new MBThreadImpl[3];
8027    
8028                            array[0] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
8029                                            categoryId, status, orderByComparator, true);
8030    
8031                            array[1] = mbThread;
8032    
8033                            array[2] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
8034                                            categoryId, status, orderByComparator, false);
8035    
8036                            return array;
8037                    }
8038                    catch (Exception e) {
8039                            throw processException(e);
8040                    }
8041                    finally {
8042                            closeSession(session);
8043                    }
8044            }
8045    
8046            protected MBThread getByG_C_S_PrevAndNext(Session session,
8047                    MBThread mbThread, long groupId, long categoryId, int status,
8048                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
8049                    StringBundler query = null;
8050    
8051                    if (orderByComparator != null) {
8052                            query = new StringBundler(6 +
8053                                            (orderByComparator.getOrderByFields().length * 6));
8054                    }
8055                    else {
8056                            query = new StringBundler(3);
8057                    }
8058    
8059                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
8060    
8061                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8062    
8063                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8064    
8065                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8066    
8067                    if (orderByComparator != null) {
8068                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8069    
8070                            if (orderByConditionFields.length > 0) {
8071                                    query.append(WHERE_AND);
8072                            }
8073    
8074                            for (int i = 0; i < orderByConditionFields.length; i++) {
8075                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8076                                    query.append(orderByConditionFields[i]);
8077    
8078                                    if ((i + 1) < orderByConditionFields.length) {
8079                                            if (orderByComparator.isAscending() ^ previous) {
8080                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8081                                            }
8082                                            else {
8083                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8084                                            }
8085                                    }
8086                                    else {
8087                                            if (orderByComparator.isAscending() ^ previous) {
8088                                                    query.append(WHERE_GREATER_THAN);
8089                                            }
8090                                            else {
8091                                                    query.append(WHERE_LESSER_THAN);
8092                                            }
8093                                    }
8094                            }
8095    
8096                            query.append(ORDER_BY_CLAUSE);
8097    
8098                            String[] orderByFields = orderByComparator.getOrderByFields();
8099    
8100                            for (int i = 0; i < orderByFields.length; i++) {
8101                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8102                                    query.append(orderByFields[i]);
8103    
8104                                    if ((i + 1) < orderByFields.length) {
8105                                            if (orderByComparator.isAscending() ^ previous) {
8106                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8107                                            }
8108                                            else {
8109                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8110                                            }
8111                                    }
8112                                    else {
8113                                            if (orderByComparator.isAscending() ^ previous) {
8114                                                    query.append(ORDER_BY_ASC);
8115                                            }
8116                                            else {
8117                                                    query.append(ORDER_BY_DESC);
8118                                            }
8119                                    }
8120                            }
8121                    }
8122                    else {
8123                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8124                    }
8125    
8126                    String sql = query.toString();
8127    
8128                    Query q = session.createQuery(sql);
8129    
8130                    q.setFirstResult(0);
8131                    q.setMaxResults(2);
8132    
8133                    QueryPos qPos = QueryPos.getInstance(q);
8134    
8135                    qPos.add(groupId);
8136    
8137                    qPos.add(categoryId);
8138    
8139                    qPos.add(status);
8140    
8141                    if (orderByComparator != null) {
8142                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
8143    
8144                            for (Object value : values) {
8145                                    qPos.add(value);
8146                            }
8147                    }
8148    
8149                    List<MBThread> list = q.list();
8150    
8151                    if (list.size() == 2) {
8152                            return list.get(1);
8153                    }
8154                    else {
8155                            return null;
8156                    }
8157            }
8158    
8159            /**
8160             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
8161             *
8162             * @param groupId the group ID
8163             * @param categoryId the category ID
8164             * @param status the status
8165             * @return the matching message boards threads that the user has permission to view
8166             */
8167            @Override
8168            public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
8169                    int status) {
8170                    return filterFindByG_C_S(groupId, categoryId, status,
8171                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8172            }
8173    
8174            /**
8175             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
8176             *
8177             * <p>
8178             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8179             * </p>
8180             *
8181             * @param groupId the group ID
8182             * @param categoryId the category ID
8183             * @param status the status
8184             * @param start the lower bound of the range of message boards threads
8185             * @param end the upper bound of the range of message boards threads (not inclusive)
8186             * @return the range of matching message boards threads that the user has permission to view
8187             */
8188            @Override
8189            public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
8190                    int status, int start, int end) {
8191                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
8192            }
8193    
8194            /**
8195             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
8196             *
8197             * <p>
8198             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8199             * </p>
8200             *
8201             * @param groupId the group ID
8202             * @param categoryId the category ID
8203             * @param status the status
8204             * @param start the lower bound of the range of message boards threads
8205             * @param end the upper bound of the range of message boards threads (not inclusive)
8206             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8207             * @return the ordered range of matching message boards threads that the user has permission to view
8208             */
8209            @Override
8210            public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
8211                    int status, int start, int end,
8212                    OrderByComparator<MBThread> orderByComparator) {
8213                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8214                            return findByG_C_S(groupId, categoryId, status, start, end,
8215                                    orderByComparator);
8216                    }
8217    
8218                    StringBundler query = null;
8219    
8220                    if (orderByComparator != null) {
8221                            query = new StringBundler(5 +
8222                                            (orderByComparator.getOrderByFields().length * 3));
8223                    }
8224                    else {
8225                            query = new StringBundler(5);
8226                    }
8227    
8228                    if (getDB().isSupportsInlineDistinct()) {
8229                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
8230                    }
8231                    else {
8232                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
8233                    }
8234    
8235                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8236    
8237                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8238    
8239                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8240    
8241                    if (!getDB().isSupportsInlineDistinct()) {
8242                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
8243                    }
8244    
8245                    if (orderByComparator != null) {
8246                            if (getDB().isSupportsInlineDistinct()) {
8247                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8248                                            orderByComparator, true);
8249                            }
8250                            else {
8251                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8252                                            orderByComparator, true);
8253                            }
8254                    }
8255                    else {
8256                            if (getDB().isSupportsInlineDistinct()) {
8257                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8258                            }
8259                            else {
8260                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
8261                            }
8262                    }
8263    
8264                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8265                                    MBThread.class.getName(),
8266                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8267    
8268                    Session session = null;
8269    
8270                    try {
8271                            session = openSession();
8272    
8273                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
8274    
8275                            if (getDB().isSupportsInlineDistinct()) {
8276                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
8277                            }
8278                            else {
8279                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
8280                            }
8281    
8282                            QueryPos qPos = QueryPos.getInstance(q);
8283    
8284                            qPos.add(groupId);
8285    
8286                            qPos.add(categoryId);
8287    
8288                            qPos.add(status);
8289    
8290                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
8291                    }
8292                    catch (Exception e) {
8293                            throw processException(e);
8294                    }
8295                    finally {
8296                            closeSession(session);
8297                    }
8298            }
8299    
8300            /**
8301             * Returns the message boards threads before and after the current message boards thread in the ordered set of message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
8302             *
8303             * @param threadId the primary key of the current message boards thread
8304             * @param groupId the group ID
8305             * @param categoryId the category ID
8306             * @param status the status
8307             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8308             * @return the previous, current, and next message boards thread
8309             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
8310             */
8311            @Override
8312            public MBThread[] filterFindByG_C_S_PrevAndNext(long threadId,
8313                    long groupId, long categoryId, int status,
8314                    OrderByComparator<MBThread> orderByComparator)
8315                    throws NoSuchThreadException {
8316                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8317                            return findByG_C_S_PrevAndNext(threadId, groupId, categoryId,
8318                                    status, orderByComparator);
8319                    }
8320    
8321                    MBThread mbThread = findByPrimaryKey(threadId);
8322    
8323                    Session session = null;
8324    
8325                    try {
8326                            session = openSession();
8327    
8328                            MBThread[] array = new MBThreadImpl[3];
8329    
8330                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbThread, groupId,
8331                                            categoryId, status, orderByComparator, true);
8332    
8333                            array[1] = mbThread;
8334    
8335                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbThread, groupId,
8336                                            categoryId, status, orderByComparator, false);
8337    
8338                            return array;
8339                    }
8340                    catch (Exception e) {
8341                            throw processException(e);
8342                    }
8343                    finally {
8344                            closeSession(session);
8345                    }
8346            }
8347    
8348            protected MBThread filterGetByG_C_S_PrevAndNext(Session session,
8349                    MBThread mbThread, long groupId, long categoryId, int status,
8350                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
8351                    StringBundler query = null;
8352    
8353                    if (orderByComparator != null) {
8354                            query = new StringBundler(6 +
8355                                            (orderByComparator.getOrderByFields().length * 6));
8356                    }
8357                    else {
8358                            query = new StringBundler(3);
8359                    }
8360    
8361                    if (getDB().isSupportsInlineDistinct()) {
8362                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
8363                    }
8364                    else {
8365                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
8366                    }
8367    
8368                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8369    
8370                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8371    
8372                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8373    
8374                    if (!getDB().isSupportsInlineDistinct()) {
8375                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
8376                    }
8377    
8378                    if (orderByComparator != null) {
8379                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8380    
8381                            if (orderByConditionFields.length > 0) {
8382                                    query.append(WHERE_AND);
8383                            }
8384    
8385                            for (int i = 0; i < orderByConditionFields.length; i++) {
8386                                    if (getDB().isSupportsInlineDistinct()) {
8387                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8388                                    }
8389                                    else {
8390                                            query.append(_ORDER_BY_ENTITY_TABLE);
8391                                    }
8392    
8393                                    query.append(orderByConditionFields[i]);
8394    
8395                                    if ((i + 1) < orderByConditionFields.length) {
8396                                            if (orderByComparator.isAscending() ^ previous) {
8397                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8398                                            }
8399                                            else {
8400                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8401                                            }
8402                                    }
8403                                    else {
8404                                            if (orderByComparator.isAscending() ^ previous) {
8405                                                    query.append(WHERE_GREATER_THAN);
8406                                            }
8407                                            else {
8408                                                    query.append(WHERE_LESSER_THAN);
8409                                            }
8410                                    }
8411                            }
8412    
8413                            query.append(ORDER_BY_CLAUSE);
8414    
8415                            String[] orderByFields = orderByComparator.getOrderByFields();
8416    
8417                            for (int i = 0; i < orderByFields.length; i++) {
8418                                    if (getDB().isSupportsInlineDistinct()) {
8419                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8420                                    }
8421                                    else {
8422                                            query.append(_ORDER_BY_ENTITY_TABLE);
8423                                    }
8424    
8425                                    query.append(orderByFields[i]);
8426    
8427                                    if ((i + 1) < orderByFields.length) {
8428                                            if (orderByComparator.isAscending() ^ previous) {
8429                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8430                                            }
8431                                            else {
8432                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8433                                            }
8434                                    }
8435                                    else {
8436                                            if (orderByComparator.isAscending() ^ previous) {
8437                                                    query.append(ORDER_BY_ASC);
8438                                            }
8439                                            else {
8440                                                    query.append(ORDER_BY_DESC);
8441                                            }
8442                                    }
8443                            }
8444                    }
8445                    else {
8446                            if (getDB().isSupportsInlineDistinct()) {
8447                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8448                            }
8449                            else {
8450                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
8451                            }
8452                    }
8453    
8454                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8455                                    MBThread.class.getName(),
8456                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8457    
8458                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
8459    
8460                    q.setFirstResult(0);
8461                    q.setMaxResults(2);
8462    
8463                    if (getDB().isSupportsInlineDistinct()) {
8464                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
8465                    }
8466                    else {
8467                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
8468                    }
8469    
8470                    QueryPos qPos = QueryPos.getInstance(q);
8471    
8472                    qPos.add(groupId);
8473    
8474                    qPos.add(categoryId);
8475    
8476                    qPos.add(status);
8477    
8478                    if (orderByComparator != null) {
8479                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
8480    
8481                            for (Object value : values) {
8482                                    qPos.add(value);
8483                            }
8484                    }
8485    
8486                    List<MBThread> list = q.list();
8487    
8488                    if (list.size() == 2) {
8489                            return list.get(1);
8490                    }
8491                    else {
8492                            return null;
8493                    }
8494            }
8495    
8496            /**
8497             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63; and status = &#63;.
8498             *
8499             * @param groupId the group ID
8500             * @param categoryIds the category IDs
8501             * @param status the status
8502             * @return the matching message boards threads that the user has permission to view
8503             */
8504            @Override
8505            public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
8506                    int status) {
8507                    return filterFindByG_C_S(groupId, categoryIds, status,
8508                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8509            }
8510    
8511            /**
8512             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63; and status = &#63;.
8513             *
8514             * <p>
8515             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8516             * </p>
8517             *
8518             * @param groupId the group ID
8519             * @param categoryIds the category IDs
8520             * @param status the status
8521             * @param start the lower bound of the range of message boards threads
8522             * @param end the upper bound of the range of message boards threads (not inclusive)
8523             * @return the range of matching message boards threads that the user has permission to view
8524             */
8525            @Override
8526            public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
8527                    int status, int start, int end) {
8528                    return filterFindByG_C_S(groupId, categoryIds, status, start, end, null);
8529            }
8530    
8531            /**
8532             * Returns an ordered range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63; and status = &#63;.
8533             *
8534             * <p>
8535             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8536             * </p>
8537             *
8538             * @param groupId the group ID
8539             * @param categoryIds the category IDs
8540             * @param status the status
8541             * @param start the lower bound of the range of message boards threads
8542             * @param end the upper bound of the range of message boards threads (not inclusive)
8543             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8544             * @return the ordered range of matching message boards threads that the user has permission to view
8545             */
8546            @Override
8547            public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
8548                    int status, int start, int end,
8549                    OrderByComparator<MBThread> orderByComparator) {
8550                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8551                            return findByG_C_S(groupId, categoryIds, status, start, end,
8552                                    orderByComparator);
8553                    }
8554    
8555                    if (categoryIds == null) {
8556                            categoryIds = new long[0];
8557                    }
8558                    else {
8559                            categoryIds = ArrayUtil.unique(categoryIds);
8560                    }
8561    
8562                    StringBundler query = new StringBundler();
8563    
8564                    if (getDB().isSupportsInlineDistinct()) {
8565                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
8566                    }
8567                    else {
8568                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
8569                    }
8570    
8571                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8572    
8573                    if (categoryIds.length > 0) {
8574                            query.append(StringPool.OPEN_PARENTHESIS);
8575    
8576                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_7);
8577    
8578                            query.append(StringUtil.merge(categoryIds));
8579    
8580                            query.append(StringPool.CLOSE_PARENTHESIS);
8581    
8582                            query.append(StringPool.CLOSE_PARENTHESIS);
8583    
8584                            query.append(WHERE_AND);
8585                    }
8586    
8587                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8588    
8589                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
8590                            query.index() - 1);
8591    
8592                    if (!getDB().isSupportsInlineDistinct()) {
8593                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
8594                    }
8595    
8596                    if (orderByComparator != null) {
8597                            if (getDB().isSupportsInlineDistinct()) {
8598                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8599                                            orderByComparator, true);
8600                            }
8601                            else {
8602                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8603                                            orderByComparator, true);
8604                            }
8605                    }
8606                    else {
8607                            if (getDB().isSupportsInlineDistinct()) {
8608                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8609                            }
8610                            else {
8611                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
8612                            }
8613                    }
8614    
8615                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8616                                    MBThread.class.getName(),
8617                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8618    
8619                    Session session = null;
8620    
8621                    try {
8622                            session = openSession();
8623    
8624                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
8625    
8626                            if (getDB().isSupportsInlineDistinct()) {
8627                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
8628                            }
8629                            else {
8630                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
8631                            }
8632    
8633                            QueryPos qPos = QueryPos.getInstance(q);
8634    
8635                            qPos.add(groupId);
8636    
8637                            qPos.add(status);
8638    
8639                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
8640                    }
8641                    catch (Exception e) {
8642                            throw processException(e);
8643                    }
8644                    finally {
8645                            closeSession(session);
8646                    }
8647            }
8648    
8649            /**
8650             * Returns all the message boards threads where groupId = &#63; and categoryId = any &#63; and status = &#63;.
8651             *
8652             * <p>
8653             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8654             * </p>
8655             *
8656             * @param groupId the group ID
8657             * @param categoryIds the category IDs
8658             * @param status the status
8659             * @return the matching message boards threads
8660             */
8661            @Override
8662            public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
8663                    int status) {
8664                    return findByG_C_S(groupId, categoryIds, status, QueryUtil.ALL_POS,
8665                            QueryUtil.ALL_POS, null);
8666            }
8667    
8668            /**
8669             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = any &#63; and status = &#63;.
8670             *
8671             * <p>
8672             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8673             * </p>
8674             *
8675             * @param groupId the group ID
8676             * @param categoryIds the category IDs
8677             * @param status the status
8678             * @param start the lower bound of the range of message boards threads
8679             * @param end the upper bound of the range of message boards threads (not inclusive)
8680             * @return the range of matching message boards threads
8681             */
8682            @Override
8683            public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
8684                    int status, int start, int end) {
8685                    return findByG_C_S(groupId, categoryIds, status, start, end, null);
8686            }
8687    
8688            /**
8689             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = any &#63; and status = &#63;.
8690             *
8691             * <p>
8692             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8693             * </p>
8694             *
8695             * @param groupId the group ID
8696             * @param categoryIds the category IDs
8697             * @param status the status
8698             * @param start the lower bound of the range of message boards threads
8699             * @param end the upper bound of the range of message boards threads (not inclusive)
8700             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8701             * @return the ordered range of matching message boards threads
8702             */
8703            @Override
8704            public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
8705                    int status, int start, int end,
8706                    OrderByComparator<MBThread> orderByComparator) {
8707                    if (categoryIds == null) {
8708                            categoryIds = new long[0];
8709                    }
8710                    else {
8711                            categoryIds = ArrayUtil.unique(categoryIds);
8712                    }
8713    
8714                    if (categoryIds.length == 1) {
8715                            return findByG_C_S(groupId, categoryIds[0], status, start, end,
8716                                    orderByComparator);
8717                    }
8718    
8719                    boolean pagination = true;
8720                    Object[] finderArgs = null;
8721    
8722                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8723                                    (orderByComparator == null)) {
8724                            pagination = false;
8725                            finderArgs = new Object[] {
8726                                            groupId, StringUtil.merge(categoryIds), status
8727                                    };
8728                    }
8729                    else {
8730                            finderArgs = new Object[] {
8731                                            groupId, StringUtil.merge(categoryIds), status,
8732                                            
8733                                            start, end, orderByComparator
8734                                    };
8735                    }
8736    
8737                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S,
8738                                    finderArgs, this);
8739    
8740                    if ((list != null) && !list.isEmpty()) {
8741                            for (MBThread mbThread : list) {
8742                                    if ((groupId != mbThread.getGroupId()) ||
8743                                                    !ArrayUtil.contains(categoryIds,
8744                                                            mbThread.getCategoryId()) ||
8745                                                    (status != mbThread.getStatus())) {
8746                                            list = null;
8747    
8748                                            break;
8749                                    }
8750                            }
8751                    }
8752    
8753                    if (list == null) {
8754                            StringBundler query = new StringBundler();
8755    
8756                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
8757    
8758                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8759    
8760                            if (categoryIds.length > 0) {
8761                                    query.append(StringPool.OPEN_PARENTHESIS);
8762    
8763                                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_7);
8764    
8765                                    query.append(StringUtil.merge(categoryIds));
8766    
8767                                    query.append(StringPool.CLOSE_PARENTHESIS);
8768    
8769                                    query.append(StringPool.CLOSE_PARENTHESIS);
8770    
8771                                    query.append(WHERE_AND);
8772                            }
8773    
8774                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8775    
8776                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8777                                                    1)), query.index() - 1);
8778    
8779                            if (orderByComparator != null) {
8780                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8781                                            orderByComparator);
8782                            }
8783                            else
8784                             if (pagination) {
8785                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8786                            }
8787    
8788                            String sql = query.toString();
8789    
8790                            Session session = null;
8791    
8792                            try {
8793                                    session = openSession();
8794    
8795                                    Query q = session.createQuery(sql);
8796    
8797                                    QueryPos qPos = QueryPos.getInstance(q);
8798    
8799                                    qPos.add(groupId);
8800    
8801                                    qPos.add(status);
8802    
8803                                    if (!pagination) {
8804                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
8805                                                            start, end, false);
8806    
8807                                            Collections.sort(list);
8808    
8809                                            list = Collections.unmodifiableList(list);
8810                                    }
8811                                    else {
8812                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
8813                                                            start, end);
8814                                    }
8815    
8816                                    cacheResult(list);
8817    
8818                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S,
8819                                            finderArgs, list);
8820                            }
8821                            catch (Exception e) {
8822                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S,
8823                                            finderArgs);
8824    
8825                                    throw processException(e);
8826                            }
8827                            finally {
8828                                    closeSession(session);
8829                            }
8830                    }
8831    
8832                    return list;
8833            }
8834    
8835            /**
8836             * Removes all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
8837             *
8838             * @param groupId the group ID
8839             * @param categoryId the category ID
8840             * @param status the status
8841             */
8842            @Override
8843            public void removeByG_C_S(long groupId, long categoryId, int status) {
8844                    for (MBThread mbThread : findByG_C_S(groupId, categoryId, status,
8845                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8846                            remove(mbThread);
8847                    }
8848            }
8849    
8850            /**
8851             * Returns the number of message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63;.
8852             *
8853             * @param groupId the group ID
8854             * @param categoryId the category ID
8855             * @param status the status
8856             * @return the number of matching message boards threads
8857             */
8858            @Override
8859            public int countByG_C_S(long groupId, long categoryId, int status) {
8860                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
8861    
8862                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
8863    
8864                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8865                                    this);
8866    
8867                    if (count == null) {
8868                            StringBundler query = new StringBundler(4);
8869    
8870                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
8871    
8872                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8873    
8874                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8875    
8876                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8877    
8878                            String sql = query.toString();
8879    
8880                            Session session = null;
8881    
8882                            try {
8883                                    session = openSession();
8884    
8885                                    Query q = session.createQuery(sql);
8886    
8887                                    QueryPos qPos = QueryPos.getInstance(q);
8888    
8889                                    qPos.add(groupId);
8890    
8891                                    qPos.add(categoryId);
8892    
8893                                    qPos.add(status);
8894    
8895                                    count = (Long)q.uniqueResult();
8896    
8897                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8898                            }
8899                            catch (Exception e) {
8900                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8901    
8902                                    throw processException(e);
8903                            }
8904                            finally {
8905                                    closeSession(session);
8906                            }
8907                    }
8908    
8909                    return count.intValue();
8910            }
8911    
8912            /**
8913             * Returns the number of message boards threads where groupId = &#63; and categoryId = any &#63; and status = &#63;.
8914             *
8915             * @param groupId the group ID
8916             * @param categoryIds the category IDs
8917             * @param status the status
8918             * @return the number of matching message boards threads
8919             */
8920            @Override
8921            public int countByG_C_S(long groupId, long[] categoryIds, int status) {
8922                    if (categoryIds == null) {
8923                            categoryIds = new long[0];
8924                    }
8925                    else {
8926                            categoryIds = ArrayUtil.unique(categoryIds);
8927                    }
8928    
8929                    Object[] finderArgs = new Object[] {
8930                                    groupId, StringUtil.merge(categoryIds), status
8931                            };
8932    
8933                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
8934                                    finderArgs, this);
8935    
8936                    if (count == null) {
8937                            StringBundler query = new StringBundler();
8938    
8939                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
8940    
8941                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8942    
8943                            if (categoryIds.length > 0) {
8944                                    query.append(StringPool.OPEN_PARENTHESIS);
8945    
8946                                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_7);
8947    
8948                                    query.append(StringUtil.merge(categoryIds));
8949    
8950                                    query.append(StringPool.CLOSE_PARENTHESIS);
8951    
8952                                    query.append(StringPool.CLOSE_PARENTHESIS);
8953    
8954                                    query.append(WHERE_AND);
8955                            }
8956    
8957                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8958    
8959                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8960                                                    1)), query.index() - 1);
8961    
8962                            String sql = query.toString();
8963    
8964                            Session session = null;
8965    
8966                            try {
8967                                    session = openSession();
8968    
8969                                    Query q = session.createQuery(sql);
8970    
8971                                    QueryPos qPos = QueryPos.getInstance(q);
8972    
8973                                    qPos.add(groupId);
8974    
8975                                    qPos.add(status);
8976    
8977                                    count = (Long)q.uniqueResult();
8978    
8979                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
8980                                            finderArgs, count);
8981                            }
8982                            catch (Exception e) {
8983                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
8984                                            finderArgs);
8985    
8986                                    throw processException(e);
8987                            }
8988                            finally {
8989                                    closeSession(session);
8990                            }
8991                    }
8992    
8993                    return count.intValue();
8994            }
8995    
8996            /**
8997             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
8998             *
8999             * @param groupId the group ID
9000             * @param categoryId the category ID
9001             * @param status the status
9002             * @return the number of matching message boards threads that the user has permission to view
9003             */
9004            @Override
9005            public int filterCountByG_C_S(long groupId, long categoryId, int status) {
9006                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9007                            return countByG_C_S(groupId, categoryId, status);
9008                    }
9009    
9010                    StringBundler query = new StringBundler(4);
9011    
9012                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
9013    
9014                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
9015    
9016                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
9017    
9018                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
9019    
9020                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9021                                    MBThread.class.getName(),
9022                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9023    
9024                    Session session = null;
9025    
9026                    try {
9027                            session = openSession();
9028    
9029                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
9030    
9031                            q.addScalar(COUNT_COLUMN_NAME,
9032                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9033    
9034                            QueryPos qPos = QueryPos.getInstance(q);
9035    
9036                            qPos.add(groupId);
9037    
9038                            qPos.add(categoryId);
9039    
9040                            qPos.add(status);
9041    
9042                            Long count = (Long)q.uniqueResult();
9043    
9044                            return count.intValue();
9045                    }
9046                    catch (Exception e) {
9047                            throw processException(e);
9048                    }
9049                    finally {
9050                            closeSession(session);
9051                    }
9052            }
9053    
9054            /**
9055             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63; and status = &#63;.
9056             *
9057             * @param groupId the group ID
9058             * @param categoryIds the category IDs
9059             * @param status the status
9060             * @return the number of matching message boards threads that the user has permission to view
9061             */
9062            @Override
9063            public int filterCountByG_C_S(long groupId, long[] categoryIds, int status) {
9064                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9065                            return countByG_C_S(groupId, categoryIds, status);
9066                    }
9067    
9068                    if (categoryIds == null) {
9069                            categoryIds = new long[0];
9070                    }
9071                    else {
9072                            categoryIds = ArrayUtil.unique(categoryIds);
9073                    }
9074    
9075                    StringBundler query = new StringBundler();
9076    
9077                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
9078    
9079                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
9080    
9081                    if (categoryIds.length > 0) {
9082                            query.append(StringPool.OPEN_PARENTHESIS);
9083    
9084                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_7);
9085    
9086                            query.append(StringUtil.merge(categoryIds));
9087    
9088                            query.append(StringPool.CLOSE_PARENTHESIS);
9089    
9090                            query.append(StringPool.CLOSE_PARENTHESIS);
9091    
9092                            query.append(WHERE_AND);
9093                    }
9094    
9095                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
9096    
9097                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
9098                            query.index() - 1);
9099    
9100                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9101                                    MBThread.class.getName(),
9102                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9103    
9104                    Session session = null;
9105    
9106                    try {
9107                            session = openSession();
9108    
9109                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
9110    
9111                            q.addScalar(COUNT_COLUMN_NAME,
9112                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9113    
9114                            QueryPos qPos = QueryPos.getInstance(q);
9115    
9116                            qPos.add(groupId);
9117    
9118                            qPos.add(status);
9119    
9120                            Long count = (Long)q.uniqueResult();
9121    
9122                            return count.intValue();
9123                    }
9124                    catch (Exception e) {
9125                            throw processException(e);
9126                    }
9127                    finally {
9128                            closeSession(session);
9129                    }
9130            }
9131    
9132            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbThread.groupId = ? AND ";
9133            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
9134            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_7 = "mbThread.categoryId IN (";
9135            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbThread.status = ?";
9136            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
9137                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
9138                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_NotS",
9139                            new String[] {
9140                                    Long.class.getName(), Long.class.getName(),
9141                                    Integer.class.getName(),
9142                                    
9143                            Integer.class.getName(), Integer.class.getName(),
9144                                    OrderByComparator.class.getName()
9145                            });
9146            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS =
9147                    new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
9148                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
9149                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C_NotS",
9150                            new String[] {
9151                                    Long.class.getName(), Long.class.getName(),
9152                                    Integer.class.getName()
9153                            });
9154    
9155            /**
9156             * Returns all the message boards threads where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9157             *
9158             * @param groupId the group ID
9159             * @param categoryId the category ID
9160             * @param status the status
9161             * @return the matching message boards threads
9162             */
9163            @Override
9164            public List<MBThread> findByG_C_NotS(long groupId, long categoryId,
9165                    int status) {
9166                    return findByG_C_NotS(groupId, categoryId, status, QueryUtil.ALL_POS,
9167                            QueryUtil.ALL_POS, null);
9168            }
9169    
9170            /**
9171             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9172             *
9173             * <p>
9174             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9175             * </p>
9176             *
9177             * @param groupId the group ID
9178             * @param categoryId the category ID
9179             * @param status the status
9180             * @param start the lower bound of the range of message boards threads
9181             * @param end the upper bound of the range of message boards threads (not inclusive)
9182             * @return the range of matching message boards threads
9183             */
9184            @Override
9185            public List<MBThread> findByG_C_NotS(long groupId, long categoryId,
9186                    int status, int start, int end) {
9187                    return findByG_C_NotS(groupId, categoryId, status, start, end, null);
9188            }
9189    
9190            /**
9191             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9192             *
9193             * <p>
9194             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9195             * </p>
9196             *
9197             * @param groupId the group ID
9198             * @param categoryId the category ID
9199             * @param status the status
9200             * @param start the lower bound of the range of message boards threads
9201             * @param end the upper bound of the range of message boards threads (not inclusive)
9202             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9203             * @return the ordered range of matching message boards threads
9204             */
9205            @Override
9206            public List<MBThread> findByG_C_NotS(long groupId, long categoryId,
9207                    int status, int start, int end,
9208                    OrderByComparator<MBThread> orderByComparator) {
9209                    boolean pagination = true;
9210                    FinderPath finderPath = null;
9211                    Object[] finderArgs = null;
9212    
9213                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS;
9214                    finderArgs = new Object[] {
9215                                    groupId, categoryId, status,
9216                                    
9217                                    start, end, orderByComparator
9218                            };
9219    
9220                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
9221                                    finderArgs, this);
9222    
9223                    if ((list != null) && !list.isEmpty()) {
9224                            for (MBThread mbThread : list) {
9225                                    if ((groupId != mbThread.getGroupId()) ||
9226                                                    (categoryId != mbThread.getCategoryId()) ||
9227                                                    (status == mbThread.getStatus())) {
9228                                            list = null;
9229    
9230                                            break;
9231                                    }
9232                            }
9233                    }
9234    
9235                    if (list == null) {
9236                            StringBundler query = null;
9237    
9238                            if (orderByComparator != null) {
9239                                    query = new StringBundler(5 +
9240                                                    (orderByComparator.getOrderByFields().length * 3));
9241                            }
9242                            else {
9243                                    query = new StringBundler(5);
9244                            }
9245    
9246                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
9247    
9248                            query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9249    
9250                            query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9251    
9252                            query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9253    
9254                            if (orderByComparator != null) {
9255                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9256                                            orderByComparator);
9257                            }
9258                            else
9259                             if (pagination) {
9260                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9261                            }
9262    
9263                            String sql = query.toString();
9264    
9265                            Session session = null;
9266    
9267                            try {
9268                                    session = openSession();
9269    
9270                                    Query q = session.createQuery(sql);
9271    
9272                                    QueryPos qPos = QueryPos.getInstance(q);
9273    
9274                                    qPos.add(groupId);
9275    
9276                                    qPos.add(categoryId);
9277    
9278                                    qPos.add(status);
9279    
9280                                    if (!pagination) {
9281                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
9282                                                            start, end, false);
9283    
9284                                            Collections.sort(list);
9285    
9286                                            list = Collections.unmodifiableList(list);
9287                                    }
9288                                    else {
9289                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
9290                                                            start, end);
9291                                    }
9292    
9293                                    cacheResult(list);
9294    
9295                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9296                            }
9297                            catch (Exception e) {
9298                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9299    
9300                                    throw processException(e);
9301                            }
9302                            finally {
9303                                    closeSession(session);
9304                            }
9305                    }
9306    
9307                    return list;
9308            }
9309    
9310            /**
9311             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9312             *
9313             * @param groupId the group ID
9314             * @param categoryId the category ID
9315             * @param status the status
9316             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9317             * @return the first matching message boards thread
9318             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
9319             */
9320            @Override
9321            public MBThread findByG_C_NotS_First(long groupId, long categoryId,
9322                    int status, OrderByComparator<MBThread> orderByComparator)
9323                    throws NoSuchThreadException {
9324                    MBThread mbThread = fetchByG_C_NotS_First(groupId, categoryId, status,
9325                                    orderByComparator);
9326    
9327                    if (mbThread != null) {
9328                            return mbThread;
9329                    }
9330    
9331                    StringBundler msg = new StringBundler(8);
9332    
9333                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9334    
9335                    msg.append("groupId=");
9336                    msg.append(groupId);
9337    
9338                    msg.append(", categoryId=");
9339                    msg.append(categoryId);
9340    
9341                    msg.append(", status=");
9342                    msg.append(status);
9343    
9344                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9345    
9346                    throw new NoSuchThreadException(msg.toString());
9347            }
9348    
9349            /**
9350             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9351             *
9352             * @param groupId the group ID
9353             * @param categoryId the category ID
9354             * @param status the status
9355             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9356             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
9357             */
9358            @Override
9359            public MBThread fetchByG_C_NotS_First(long groupId, long categoryId,
9360                    int status, OrderByComparator<MBThread> orderByComparator) {
9361                    List<MBThread> list = findByG_C_NotS(groupId, categoryId, status, 0, 1,
9362                                    orderByComparator);
9363    
9364                    if (!list.isEmpty()) {
9365                            return list.get(0);
9366                    }
9367    
9368                    return null;
9369            }
9370    
9371            /**
9372             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9373             *
9374             * @param groupId the group ID
9375             * @param categoryId the category ID
9376             * @param status the status
9377             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9378             * @return the last matching message boards thread
9379             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
9380             */
9381            @Override
9382            public MBThread findByG_C_NotS_Last(long groupId, long categoryId,
9383                    int status, OrderByComparator<MBThread> orderByComparator)
9384                    throws NoSuchThreadException {
9385                    MBThread mbThread = fetchByG_C_NotS_Last(groupId, categoryId, status,
9386                                    orderByComparator);
9387    
9388                    if (mbThread != null) {
9389                            return mbThread;
9390                    }
9391    
9392                    StringBundler msg = new StringBundler(8);
9393    
9394                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9395    
9396                    msg.append("groupId=");
9397                    msg.append(groupId);
9398    
9399                    msg.append(", categoryId=");
9400                    msg.append(categoryId);
9401    
9402                    msg.append(", status=");
9403                    msg.append(status);
9404    
9405                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9406    
9407                    throw new NoSuchThreadException(msg.toString());
9408            }
9409    
9410            /**
9411             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9412             *
9413             * @param groupId the group ID
9414             * @param categoryId the category ID
9415             * @param status the status
9416             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9417             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
9418             */
9419            @Override
9420            public MBThread fetchByG_C_NotS_Last(long groupId, long categoryId,
9421                    int status, OrderByComparator<MBThread> orderByComparator) {
9422                    int count = countByG_C_NotS(groupId, categoryId, status);
9423    
9424                    if (count == 0) {
9425                            return null;
9426                    }
9427    
9428                    List<MBThread> list = findByG_C_NotS(groupId, categoryId, status,
9429                                    count - 1, count, orderByComparator);
9430    
9431                    if (!list.isEmpty()) {
9432                            return list.get(0);
9433                    }
9434    
9435                    return null;
9436            }
9437    
9438            /**
9439             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9440             *
9441             * @param threadId the primary key of the current message boards thread
9442             * @param groupId the group ID
9443             * @param categoryId the category ID
9444             * @param status the status
9445             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9446             * @return the previous, current, and next message boards thread
9447             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
9448             */
9449            @Override
9450            public MBThread[] findByG_C_NotS_PrevAndNext(long threadId, long groupId,
9451                    long categoryId, int status,
9452                    OrderByComparator<MBThread> orderByComparator)
9453                    throws NoSuchThreadException {
9454                    MBThread mbThread = findByPrimaryKey(threadId);
9455    
9456                    Session session = null;
9457    
9458                    try {
9459                            session = openSession();
9460    
9461                            MBThread[] array = new MBThreadImpl[3];
9462    
9463                            array[0] = getByG_C_NotS_PrevAndNext(session, mbThread, groupId,
9464                                            categoryId, status, orderByComparator, true);
9465    
9466                            array[1] = mbThread;
9467    
9468                            array[2] = getByG_C_NotS_PrevAndNext(session, mbThread, groupId,
9469                                            categoryId, status, orderByComparator, false);
9470    
9471                            return array;
9472                    }
9473                    catch (Exception e) {
9474                            throw processException(e);
9475                    }
9476                    finally {
9477                            closeSession(session);
9478                    }
9479            }
9480    
9481            protected MBThread getByG_C_NotS_PrevAndNext(Session session,
9482                    MBThread mbThread, long groupId, long categoryId, int status,
9483                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
9484                    StringBundler query = null;
9485    
9486                    if (orderByComparator != null) {
9487                            query = new StringBundler(6 +
9488                                            (orderByComparator.getOrderByFields().length * 6));
9489                    }
9490                    else {
9491                            query = new StringBundler(3);
9492                    }
9493    
9494                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
9495    
9496                    query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9497    
9498                    query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9499    
9500                    query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9501    
9502                    if (orderByComparator != null) {
9503                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9504    
9505                            if (orderByConditionFields.length > 0) {
9506                                    query.append(WHERE_AND);
9507                            }
9508    
9509                            for (int i = 0; i < orderByConditionFields.length; i++) {
9510                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9511                                    query.append(orderByConditionFields[i]);
9512    
9513                                    if ((i + 1) < orderByConditionFields.length) {
9514                                            if (orderByComparator.isAscending() ^ previous) {
9515                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9516                                            }
9517                                            else {
9518                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9519                                            }
9520                                    }
9521                                    else {
9522                                            if (orderByComparator.isAscending() ^ previous) {
9523                                                    query.append(WHERE_GREATER_THAN);
9524                                            }
9525                                            else {
9526                                                    query.append(WHERE_LESSER_THAN);
9527                                            }
9528                                    }
9529                            }
9530    
9531                            query.append(ORDER_BY_CLAUSE);
9532    
9533                            String[] orderByFields = orderByComparator.getOrderByFields();
9534    
9535                            for (int i = 0; i < orderByFields.length; i++) {
9536                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9537                                    query.append(orderByFields[i]);
9538    
9539                                    if ((i + 1) < orderByFields.length) {
9540                                            if (orderByComparator.isAscending() ^ previous) {
9541                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9542                                            }
9543                                            else {
9544                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9545                                            }
9546                                    }
9547                                    else {
9548                                            if (orderByComparator.isAscending() ^ previous) {
9549                                                    query.append(ORDER_BY_ASC);
9550                                            }
9551                                            else {
9552                                                    query.append(ORDER_BY_DESC);
9553                                            }
9554                                    }
9555                            }
9556                    }
9557                    else {
9558                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9559                    }
9560    
9561                    String sql = query.toString();
9562    
9563                    Query q = session.createQuery(sql);
9564    
9565                    q.setFirstResult(0);
9566                    q.setMaxResults(2);
9567    
9568                    QueryPos qPos = QueryPos.getInstance(q);
9569    
9570                    qPos.add(groupId);
9571    
9572                    qPos.add(categoryId);
9573    
9574                    qPos.add(status);
9575    
9576                    if (orderByComparator != null) {
9577                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
9578    
9579                            for (Object value : values) {
9580                                    qPos.add(value);
9581                            }
9582                    }
9583    
9584                    List<MBThread> list = q.list();
9585    
9586                    if (list.size() == 2) {
9587                            return list.get(1);
9588                    }
9589                    else {
9590                            return null;
9591                    }
9592            }
9593    
9594            /**
9595             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9596             *
9597             * @param groupId the group ID
9598             * @param categoryId the category ID
9599             * @param status the status
9600             * @return the matching message boards threads that the user has permission to view
9601             */
9602            @Override
9603            public List<MBThread> filterFindByG_C_NotS(long groupId, long categoryId,
9604                    int status) {
9605                    return filterFindByG_C_NotS(groupId, categoryId, status,
9606                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9607            }
9608    
9609            /**
9610             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9611             *
9612             * <p>
9613             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9614             * </p>
9615             *
9616             * @param groupId the group ID
9617             * @param categoryId the category ID
9618             * @param status the status
9619             * @param start the lower bound of the range of message boards threads
9620             * @param end the upper bound of the range of message boards threads (not inclusive)
9621             * @return the range of matching message boards threads that the user has permission to view
9622             */
9623            @Override
9624            public List<MBThread> filterFindByG_C_NotS(long groupId, long categoryId,
9625                    int status, int start, int end) {
9626                    return filterFindByG_C_NotS(groupId, categoryId, status, start, end,
9627                            null);
9628            }
9629    
9630            /**
9631             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9632             *
9633             * <p>
9634             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9635             * </p>
9636             *
9637             * @param groupId the group ID
9638             * @param categoryId the category ID
9639             * @param status the status
9640             * @param start the lower bound of the range of message boards threads
9641             * @param end the upper bound of the range of message boards threads (not inclusive)
9642             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9643             * @return the ordered range of matching message boards threads that the user has permission to view
9644             */
9645            @Override
9646            public List<MBThread> filterFindByG_C_NotS(long groupId, long categoryId,
9647                    int status, int start, int end,
9648                    OrderByComparator<MBThread> orderByComparator) {
9649                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9650                            return findByG_C_NotS(groupId, categoryId, status, start, end,
9651                                    orderByComparator);
9652                    }
9653    
9654                    StringBundler query = null;
9655    
9656                    if (orderByComparator != null) {
9657                            query = new StringBundler(5 +
9658                                            (orderByComparator.getOrderByFields().length * 3));
9659                    }
9660                    else {
9661                            query = new StringBundler(5);
9662                    }
9663    
9664                    if (getDB().isSupportsInlineDistinct()) {
9665                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
9666                    }
9667                    else {
9668                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
9669                    }
9670    
9671                    query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9672    
9673                    query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9674    
9675                    query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9676    
9677                    if (!getDB().isSupportsInlineDistinct()) {
9678                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
9679                    }
9680    
9681                    if (orderByComparator != null) {
9682                            if (getDB().isSupportsInlineDistinct()) {
9683                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9684                                            orderByComparator, true);
9685                            }
9686                            else {
9687                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
9688                                            orderByComparator, true);
9689                            }
9690                    }
9691                    else {
9692                            if (getDB().isSupportsInlineDistinct()) {
9693                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9694                            }
9695                            else {
9696                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
9697                            }
9698                    }
9699    
9700                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9701                                    MBThread.class.getName(),
9702                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9703    
9704                    Session session = null;
9705    
9706                    try {
9707                            session = openSession();
9708    
9709                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
9710    
9711                            if (getDB().isSupportsInlineDistinct()) {
9712                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
9713                            }
9714                            else {
9715                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
9716                            }
9717    
9718                            QueryPos qPos = QueryPos.getInstance(q);
9719    
9720                            qPos.add(groupId);
9721    
9722                            qPos.add(categoryId);
9723    
9724                            qPos.add(status);
9725    
9726                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
9727                    }
9728                    catch (Exception e) {
9729                            throw processException(e);
9730                    }
9731                    finally {
9732                            closeSession(session);
9733                    }
9734            }
9735    
9736            /**
9737             * Returns the message boards threads before and after the current message boards thread in the ordered set of message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9738             *
9739             * @param threadId the primary key of the current message boards thread
9740             * @param groupId the group ID
9741             * @param categoryId the category ID
9742             * @param status the status
9743             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9744             * @return the previous, current, and next message boards thread
9745             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
9746             */
9747            @Override
9748            public MBThread[] filterFindByG_C_NotS_PrevAndNext(long threadId,
9749                    long groupId, long categoryId, int status,
9750                    OrderByComparator<MBThread> orderByComparator)
9751                    throws NoSuchThreadException {
9752                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9753                            return findByG_C_NotS_PrevAndNext(threadId, groupId, categoryId,
9754                                    status, orderByComparator);
9755                    }
9756    
9757                    MBThread mbThread = findByPrimaryKey(threadId);
9758    
9759                    Session session = null;
9760    
9761                    try {
9762                            session = openSession();
9763    
9764                            MBThread[] array = new MBThreadImpl[3];
9765    
9766                            array[0] = filterGetByG_C_NotS_PrevAndNext(session, mbThread,
9767                                            groupId, categoryId, status, orderByComparator, true);
9768    
9769                            array[1] = mbThread;
9770    
9771                            array[2] = filterGetByG_C_NotS_PrevAndNext(session, mbThread,
9772                                            groupId, categoryId, status, orderByComparator, false);
9773    
9774                            return array;
9775                    }
9776                    catch (Exception e) {
9777                            throw processException(e);
9778                    }
9779                    finally {
9780                            closeSession(session);
9781                    }
9782            }
9783    
9784            protected MBThread filterGetByG_C_NotS_PrevAndNext(Session session,
9785                    MBThread mbThread, long groupId, long categoryId, int status,
9786                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
9787                    StringBundler query = null;
9788    
9789                    if (orderByComparator != null) {
9790                            query = new StringBundler(6 +
9791                                            (orderByComparator.getOrderByFields().length * 6));
9792                    }
9793                    else {
9794                            query = new StringBundler(3);
9795                    }
9796    
9797                    if (getDB().isSupportsInlineDistinct()) {
9798                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
9799                    }
9800                    else {
9801                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
9802                    }
9803    
9804                    query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9805    
9806                    query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9807    
9808                    query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9809    
9810                    if (!getDB().isSupportsInlineDistinct()) {
9811                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
9812                    }
9813    
9814                    if (orderByComparator != null) {
9815                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9816    
9817                            if (orderByConditionFields.length > 0) {
9818                                    query.append(WHERE_AND);
9819                            }
9820    
9821                            for (int i = 0; i < orderByConditionFields.length; i++) {
9822                                    if (getDB().isSupportsInlineDistinct()) {
9823                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9824                                    }
9825                                    else {
9826                                            query.append(_ORDER_BY_ENTITY_TABLE);
9827                                    }
9828    
9829                                    query.append(orderByConditionFields[i]);
9830    
9831                                    if ((i + 1) < orderByConditionFields.length) {
9832                                            if (orderByComparator.isAscending() ^ previous) {
9833                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9834                                            }
9835                                            else {
9836                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9837                                            }
9838                                    }
9839                                    else {
9840                                            if (orderByComparator.isAscending() ^ previous) {
9841                                                    query.append(WHERE_GREATER_THAN);
9842                                            }
9843                                            else {
9844                                                    query.append(WHERE_LESSER_THAN);
9845                                            }
9846                                    }
9847                            }
9848    
9849                            query.append(ORDER_BY_CLAUSE);
9850    
9851                            String[] orderByFields = orderByComparator.getOrderByFields();
9852    
9853                            for (int i = 0; i < orderByFields.length; i++) {
9854                                    if (getDB().isSupportsInlineDistinct()) {
9855                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9856                                    }
9857                                    else {
9858                                            query.append(_ORDER_BY_ENTITY_TABLE);
9859                                    }
9860    
9861                                    query.append(orderByFields[i]);
9862    
9863                                    if ((i + 1) < orderByFields.length) {
9864                                            if (orderByComparator.isAscending() ^ previous) {
9865                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9866                                            }
9867                                            else {
9868                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9869                                            }
9870                                    }
9871                                    else {
9872                                            if (orderByComparator.isAscending() ^ previous) {
9873                                                    query.append(ORDER_BY_ASC);
9874                                            }
9875                                            else {
9876                                                    query.append(ORDER_BY_DESC);
9877                                            }
9878                                    }
9879                            }
9880                    }
9881                    else {
9882                            if (getDB().isSupportsInlineDistinct()) {
9883                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9884                            }
9885                            else {
9886                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
9887                            }
9888                    }
9889    
9890                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9891                                    MBThread.class.getName(),
9892                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9893    
9894                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
9895    
9896                    q.setFirstResult(0);
9897                    q.setMaxResults(2);
9898    
9899                    if (getDB().isSupportsInlineDistinct()) {
9900                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
9901                    }
9902                    else {
9903                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
9904                    }
9905    
9906                    QueryPos qPos = QueryPos.getInstance(q);
9907    
9908                    qPos.add(groupId);
9909    
9910                    qPos.add(categoryId);
9911    
9912                    qPos.add(status);
9913    
9914                    if (orderByComparator != null) {
9915                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
9916    
9917                            for (Object value : values) {
9918                                    qPos.add(value);
9919                            }
9920                    }
9921    
9922                    List<MBThread> list = q.list();
9923    
9924                    if (list.size() == 2) {
9925                            return list.get(1);
9926                    }
9927                    else {
9928                            return null;
9929                    }
9930            }
9931    
9932            /**
9933             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63; and status &ne; &#63;.
9934             *
9935             * @param groupId the group ID
9936             * @param categoryIds the category IDs
9937             * @param status the status
9938             * @return the matching message boards threads that the user has permission to view
9939             */
9940            @Override
9941            public List<MBThread> filterFindByG_C_NotS(long groupId,
9942                    long[] categoryIds, int status) {
9943                    return filterFindByG_C_NotS(groupId, categoryIds, status,
9944                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9945            }
9946    
9947            /**
9948             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63; and status &ne; &#63;.
9949             *
9950             * <p>
9951             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9952             * </p>
9953             *
9954             * @param groupId the group ID
9955             * @param categoryIds the category IDs
9956             * @param status the status
9957             * @param start the lower bound of the range of message boards threads
9958             * @param end the upper bound of the range of message boards threads (not inclusive)
9959             * @return the range of matching message boards threads that the user has permission to view
9960             */
9961            @Override
9962            public List<MBThread> filterFindByG_C_NotS(long groupId,
9963                    long[] categoryIds, int status, int start, int end) {
9964                    return filterFindByG_C_NotS(groupId, categoryIds, status, start, end,
9965                            null);
9966            }
9967    
9968            /**
9969             * Returns an ordered range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63; and status &ne; &#63;.
9970             *
9971             * <p>
9972             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9973             * </p>
9974             *
9975             * @param groupId the group ID
9976             * @param categoryIds the category IDs
9977             * @param status the status
9978             * @param start the lower bound of the range of message boards threads
9979             * @param end the upper bound of the range of message boards threads (not inclusive)
9980             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9981             * @return the ordered range of matching message boards threads that the user has permission to view
9982             */
9983            @Override
9984            public List<MBThread> filterFindByG_C_NotS(long groupId,
9985                    long[] categoryIds, int status, int start, int end,
9986                    OrderByComparator<MBThread> orderByComparator) {
9987                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9988                            return findByG_C_NotS(groupId, categoryIds, status, start, end,
9989                                    orderByComparator);
9990                    }
9991    
9992                    if (categoryIds == null) {
9993                            categoryIds = new long[0];
9994                    }
9995                    else {
9996                            categoryIds = ArrayUtil.unique(categoryIds);
9997                    }
9998    
9999                    StringBundler query = new StringBundler();
10000    
10001                    if (getDB().isSupportsInlineDistinct()) {
10002                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
10003                    }
10004                    else {
10005                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
10006                    }
10007    
10008                    query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10009    
10010                    if (categoryIds.length > 0) {
10011                            query.append(StringPool.OPEN_PARENTHESIS);
10012    
10013                            query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_7);
10014    
10015                            query.append(StringUtil.merge(categoryIds));
10016    
10017                            query.append(StringPool.CLOSE_PARENTHESIS);
10018    
10019                            query.append(StringPool.CLOSE_PARENTHESIS);
10020    
10021                            query.append(WHERE_AND);
10022                    }
10023    
10024                    query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10025    
10026                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
10027                            query.index() - 1);
10028    
10029                    if (!getDB().isSupportsInlineDistinct()) {
10030                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
10031                    }
10032    
10033                    if (orderByComparator != null) {
10034                            if (getDB().isSupportsInlineDistinct()) {
10035                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10036                                            orderByComparator, true);
10037                            }
10038                            else {
10039                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10040                                            orderByComparator, true);
10041                            }
10042                    }
10043                    else {
10044                            if (getDB().isSupportsInlineDistinct()) {
10045                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10046                            }
10047                            else {
10048                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
10049                            }
10050                    }
10051    
10052                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10053                                    MBThread.class.getName(),
10054                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10055    
10056                    Session session = null;
10057    
10058                    try {
10059                            session = openSession();
10060    
10061                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
10062    
10063                            if (getDB().isSupportsInlineDistinct()) {
10064                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
10065                            }
10066                            else {
10067                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
10068                            }
10069    
10070                            QueryPos qPos = QueryPos.getInstance(q);
10071    
10072                            qPos.add(groupId);
10073    
10074                            qPos.add(status);
10075    
10076                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
10077                    }
10078                    catch (Exception e) {
10079                            throw processException(e);
10080                    }
10081                    finally {
10082                            closeSession(session);
10083                    }
10084            }
10085    
10086            /**
10087             * Returns all the message boards threads where groupId = &#63; and categoryId = any &#63; and status &ne; &#63;.
10088             *
10089             * <p>
10090             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10091             * </p>
10092             *
10093             * @param groupId the group ID
10094             * @param categoryIds the category IDs
10095             * @param status the status
10096             * @return the matching message boards threads
10097             */
10098            @Override
10099            public List<MBThread> findByG_C_NotS(long groupId, long[] categoryIds,
10100                    int status) {
10101                    return findByG_C_NotS(groupId, categoryIds, status, QueryUtil.ALL_POS,
10102                            QueryUtil.ALL_POS, null);
10103            }
10104    
10105            /**
10106             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = any &#63; and status &ne; &#63;.
10107             *
10108             * <p>
10109             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10110             * </p>
10111             *
10112             * @param groupId the group ID
10113             * @param categoryIds the category IDs
10114             * @param status the status
10115             * @param start the lower bound of the range of message boards threads
10116             * @param end the upper bound of the range of message boards threads (not inclusive)
10117             * @return the range of matching message boards threads
10118             */
10119            @Override
10120            public List<MBThread> findByG_C_NotS(long groupId, long[] categoryIds,
10121                    int status, int start, int end) {
10122                    return findByG_C_NotS(groupId, categoryIds, status, start, end, null);
10123            }
10124    
10125            /**
10126             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = any &#63; and status &ne; &#63;.
10127             *
10128             * <p>
10129             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10130             * </p>
10131             *
10132             * @param groupId the group ID
10133             * @param categoryIds the category IDs
10134             * @param status the status
10135             * @param start the lower bound of the range of message boards threads
10136             * @param end the upper bound of the range of message boards threads (not inclusive)
10137             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10138             * @return the ordered range of matching message boards threads
10139             */
10140            @Override
10141            public List<MBThread> findByG_C_NotS(long groupId, long[] categoryIds,
10142                    int status, int start, int end,
10143                    OrderByComparator<MBThread> orderByComparator) {
10144                    if (categoryIds == null) {
10145                            categoryIds = new long[0];
10146                    }
10147                    else {
10148                            categoryIds = ArrayUtil.unique(categoryIds);
10149                    }
10150    
10151                    if (categoryIds.length == 1) {
10152                            return findByG_C_NotS(groupId, categoryIds[0], status, start, end,
10153                                    orderByComparator);
10154                    }
10155    
10156                    boolean pagination = true;
10157                    Object[] finderArgs = null;
10158    
10159                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10160                                    (orderByComparator == null)) {
10161                            pagination = false;
10162                            finderArgs = new Object[] {
10163                                            groupId, StringUtil.merge(categoryIds), status
10164                                    };
10165                    }
10166                    else {
10167                            finderArgs = new Object[] {
10168                                            groupId, StringUtil.merge(categoryIds), status,
10169                                            
10170                                            start, end, orderByComparator
10171                                    };
10172                    }
10173    
10174                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS,
10175                                    finderArgs, this);
10176    
10177                    if ((list != null) && !list.isEmpty()) {
10178                            for (MBThread mbThread : list) {
10179                                    if ((groupId != mbThread.getGroupId()) ||
10180                                                    !ArrayUtil.contains(categoryIds,
10181                                                            mbThread.getCategoryId()) ||
10182                                                    (status != mbThread.getStatus())) {
10183                                            list = null;
10184    
10185                                            break;
10186                                    }
10187                            }
10188                    }
10189    
10190                    if (list == null) {
10191                            StringBundler query = new StringBundler();
10192    
10193                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
10194    
10195                            query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10196    
10197                            if (categoryIds.length > 0) {
10198                                    query.append(StringPool.OPEN_PARENTHESIS);
10199    
10200                                    query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_7);
10201    
10202                                    query.append(StringUtil.merge(categoryIds));
10203    
10204                                    query.append(StringPool.CLOSE_PARENTHESIS);
10205    
10206                                    query.append(StringPool.CLOSE_PARENTHESIS);
10207    
10208                                    query.append(WHERE_AND);
10209                            }
10210    
10211                            query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10212    
10213                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
10214                                                    1)), query.index() - 1);
10215    
10216                            if (orderByComparator != null) {
10217                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10218                                            orderByComparator);
10219                            }
10220                            else
10221                             if (pagination) {
10222                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10223                            }
10224    
10225                            String sql = query.toString();
10226    
10227                            Session session = null;
10228    
10229                            try {
10230                                    session = openSession();
10231    
10232                                    Query q = session.createQuery(sql);
10233    
10234                                    QueryPos qPos = QueryPos.getInstance(q);
10235    
10236                                    qPos.add(groupId);
10237    
10238                                    qPos.add(status);
10239    
10240                                    if (!pagination) {
10241                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
10242                                                            start, end, false);
10243    
10244                                            Collections.sort(list);
10245    
10246                                            list = Collections.unmodifiableList(list);
10247                                    }
10248                                    else {
10249                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
10250                                                            start, end);
10251                                    }
10252    
10253                                    cacheResult(list);
10254    
10255                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS,
10256                                            finderArgs, list);
10257                            }
10258                            catch (Exception e) {
10259                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS,
10260                                            finderArgs);
10261    
10262                                    throw processException(e);
10263                            }
10264                            finally {
10265                                    closeSession(session);
10266                            }
10267                    }
10268    
10269                    return list;
10270            }
10271    
10272            /**
10273             * Removes all the message boards threads where groupId = &#63; and categoryId = &#63; and status &ne; &#63; from the database.
10274             *
10275             * @param groupId the group ID
10276             * @param categoryId the category ID
10277             * @param status the status
10278             */
10279            @Override
10280            public void removeByG_C_NotS(long groupId, long categoryId, int status) {
10281                    for (MBThread mbThread : findByG_C_NotS(groupId, categoryId, status,
10282                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10283                            remove(mbThread);
10284                    }
10285            }
10286    
10287            /**
10288             * Returns the number of message boards threads where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
10289             *
10290             * @param groupId the group ID
10291             * @param categoryId the category ID
10292             * @param status the status
10293             * @return the number of matching message boards threads
10294             */
10295            @Override
10296            public int countByG_C_NotS(long groupId, long categoryId, int status) {
10297                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS;
10298    
10299                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
10300    
10301                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10302                                    this);
10303    
10304                    if (count == null) {
10305                            StringBundler query = new StringBundler(4);
10306    
10307                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
10308    
10309                            query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10310    
10311                            query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
10312    
10313                            query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10314    
10315                            String sql = query.toString();
10316    
10317                            Session session = null;
10318    
10319                            try {
10320                                    session = openSession();
10321    
10322                                    Query q = session.createQuery(sql);
10323    
10324                                    QueryPos qPos = QueryPos.getInstance(q);
10325    
10326                                    qPos.add(groupId);
10327    
10328                                    qPos.add(categoryId);
10329    
10330                                    qPos.add(status);
10331    
10332                                    count = (Long)q.uniqueResult();
10333    
10334                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10335                            }
10336                            catch (Exception e) {
10337                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10338    
10339                                    throw processException(e);
10340                            }
10341                            finally {
10342                                    closeSession(session);
10343                            }
10344                    }
10345    
10346                    return count.intValue();
10347            }
10348    
10349            /**
10350             * Returns the number of message boards threads where groupId = &#63; and categoryId = any &#63; and status &ne; &#63;.
10351             *
10352             * @param groupId the group ID
10353             * @param categoryIds the category IDs
10354             * @param status the status
10355             * @return the number of matching message boards threads
10356             */
10357            @Override
10358            public int countByG_C_NotS(long groupId, long[] categoryIds, int status) {
10359                    if (categoryIds == null) {
10360                            categoryIds = new long[0];
10361                    }
10362                    else {
10363                            categoryIds = ArrayUtil.unique(categoryIds);
10364                    }
10365    
10366                    Object[] finderArgs = new Object[] {
10367                                    groupId, StringUtil.merge(categoryIds), status
10368                            };
10369    
10370                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS,
10371                                    finderArgs, this);
10372    
10373                    if (count == null) {
10374                            StringBundler query = new StringBundler();
10375    
10376                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
10377    
10378                            query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10379    
10380                            if (categoryIds.length > 0) {
10381                                    query.append(StringPool.OPEN_PARENTHESIS);
10382    
10383                                    query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_7);
10384    
10385                                    query.append(StringUtil.merge(categoryIds));
10386    
10387                                    query.append(StringPool.CLOSE_PARENTHESIS);
10388    
10389                                    query.append(StringPool.CLOSE_PARENTHESIS);
10390    
10391                                    query.append(WHERE_AND);
10392                            }
10393    
10394                            query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10395    
10396                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
10397                                                    1)), query.index() - 1);
10398    
10399                            String sql = query.toString();
10400    
10401                            Session session = null;
10402    
10403                            try {
10404                                    session = openSession();
10405    
10406                                    Query q = session.createQuery(sql);
10407    
10408                                    QueryPos qPos = QueryPos.getInstance(q);
10409    
10410                                    qPos.add(groupId);
10411    
10412                                    qPos.add(status);
10413    
10414                                    count = (Long)q.uniqueResult();
10415    
10416                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS,
10417                                            finderArgs, count);
10418                            }
10419                            catch (Exception e) {
10420                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS,
10421                                            finderArgs);
10422    
10423                                    throw processException(e);
10424                            }
10425                            finally {
10426                                    closeSession(session);
10427                            }
10428                    }
10429    
10430                    return count.intValue();
10431            }
10432    
10433            /**
10434             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
10435             *
10436             * @param groupId the group ID
10437             * @param categoryId the category ID
10438             * @param status the status
10439             * @return the number of matching message boards threads that the user has permission to view
10440             */
10441            @Override
10442            public int filterCountByG_C_NotS(long groupId, long categoryId, int status) {
10443                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10444                            return countByG_C_NotS(groupId, categoryId, status);
10445                    }
10446    
10447                    StringBundler query = new StringBundler(4);
10448    
10449                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
10450    
10451                    query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10452    
10453                    query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
10454    
10455                    query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10456    
10457                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10458                                    MBThread.class.getName(),
10459                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10460    
10461                    Session session = null;
10462    
10463                    try {
10464                            session = openSession();
10465    
10466                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
10467    
10468                            q.addScalar(COUNT_COLUMN_NAME,
10469                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
10470    
10471                            QueryPos qPos = QueryPos.getInstance(q);
10472    
10473                            qPos.add(groupId);
10474    
10475                            qPos.add(categoryId);
10476    
10477                            qPos.add(status);
10478    
10479                            Long count = (Long)q.uniqueResult();
10480    
10481                            return count.intValue();
10482                    }
10483                    catch (Exception e) {
10484                            throw processException(e);
10485                    }
10486                    finally {
10487                            closeSession(session);
10488                    }
10489            }
10490    
10491            /**
10492             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63; and status &ne; &#63;.
10493             *
10494             * @param groupId the group ID
10495             * @param categoryIds the category IDs
10496             * @param status the status
10497             * @return the number of matching message boards threads that the user has permission to view
10498             */
10499            @Override
10500            public int filterCountByG_C_NotS(long groupId, long[] categoryIds,
10501                    int status) {
10502                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10503                            return countByG_C_NotS(groupId, categoryIds, status);
10504                    }
10505    
10506                    if (categoryIds == null) {
10507                            categoryIds = new long[0];
10508                    }
10509                    else {
10510                            categoryIds = ArrayUtil.unique(categoryIds);
10511                    }
10512    
10513                    StringBundler query = new StringBundler();
10514    
10515                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
10516    
10517                    query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10518    
10519                    if (categoryIds.length > 0) {
10520                            query.append(StringPool.OPEN_PARENTHESIS);
10521    
10522                            query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_7);
10523    
10524                            query.append(StringUtil.merge(categoryIds));
10525    
10526                            query.append(StringPool.CLOSE_PARENTHESIS);
10527    
10528                            query.append(StringPool.CLOSE_PARENTHESIS);
10529    
10530                            query.append(WHERE_AND);
10531                    }
10532    
10533                    query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10534    
10535                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
10536                            query.index() - 1);
10537    
10538                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10539                                    MBThread.class.getName(),
10540                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10541    
10542                    Session session = null;
10543    
10544                    try {
10545                            session = openSession();
10546    
10547                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
10548    
10549                            q.addScalar(COUNT_COLUMN_NAME,
10550                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
10551    
10552                            QueryPos qPos = QueryPos.getInstance(q);
10553    
10554                            qPos.add(groupId);
10555    
10556                            qPos.add(status);
10557    
10558                            Long count = (Long)q.uniqueResult();
10559    
10560                            return count.intValue();
10561                    }
10562                    catch (Exception e) {
10563                            throw processException(e);
10564                    }
10565                    finally {
10566                            closeSession(session);
10567                    }
10568            }
10569    
10570            private static final String _FINDER_COLUMN_G_C_NOTS_GROUPID_2 = "mbThread.groupId = ? AND ";
10571            private static final String _FINDER_COLUMN_G_C_NOTS_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
10572            private static final String _FINDER_COLUMN_G_C_NOTS_CATEGORYID_7 = "mbThread.categoryId IN (";
10573            private static final String _FINDER_COLUMN_G_C_NOTS_STATUS_2 = "mbThread.status != ?";
10574            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
10575                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
10576                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC_S",
10577                            new String[] {
10578                                    Long.class.getName(), Long.class.getName(),
10579                                    Integer.class.getName(),
10580                                    
10581                            Integer.class.getName(), Integer.class.getName(),
10582                                    OrderByComparator.class.getName()
10583                            });
10584            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_S =
10585                    new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
10586                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
10587                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC_S",
10588                            new String[] {
10589                                    Long.class.getName(), Long.class.getName(),
10590                                    Integer.class.getName()
10591                            });
10592    
10593            /**
10594             * Returns all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
10595             *
10596             * @param groupId the group ID
10597             * @param categoryId the category ID
10598             * @param status the status
10599             * @return the matching message boards threads
10600             */
10601            @Override
10602            public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
10603                    int status) {
10604                    return findByG_NotC_S(groupId, categoryId, status, QueryUtil.ALL_POS,
10605                            QueryUtil.ALL_POS, null);
10606            }
10607    
10608            /**
10609             * Returns a range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
10610             *
10611             * <p>
10612             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10613             * </p>
10614             *
10615             * @param groupId the group ID
10616             * @param categoryId the category ID
10617             * @param status the status
10618             * @param start the lower bound of the range of message boards threads
10619             * @param end the upper bound of the range of message boards threads (not inclusive)
10620             * @return the range of matching message boards threads
10621             */
10622            @Override
10623            public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
10624                    int status, int start, int end) {
10625                    return findByG_NotC_S(groupId, categoryId, status, start, end, null);
10626            }
10627    
10628            /**
10629             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
10630             *
10631             * <p>
10632             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10633             * </p>
10634             *
10635             * @param groupId the group ID
10636             * @param categoryId the category ID
10637             * @param status the status
10638             * @param start the lower bound of the range of message boards threads
10639             * @param end the upper bound of the range of message boards threads (not inclusive)
10640             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10641             * @return the ordered range of matching message boards threads
10642             */
10643            @Override
10644            public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
10645                    int status, int start, int end,
10646                    OrderByComparator<MBThread> orderByComparator) {
10647                    boolean pagination = true;
10648                    FinderPath finderPath = null;
10649                    Object[] finderArgs = null;
10650    
10651                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_S;
10652                    finderArgs = new Object[] {
10653                                    groupId, categoryId, status,
10654                                    
10655                                    start, end, orderByComparator
10656                            };
10657    
10658                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
10659                                    finderArgs, this);
10660    
10661                    if ((list != null) && !list.isEmpty()) {
10662                            for (MBThread mbThread : list) {
10663                                    if ((groupId != mbThread.getGroupId()) ||
10664                                                    (categoryId == mbThread.getCategoryId()) ||
10665                                                    (status != mbThread.getStatus())) {
10666                                            list = null;
10667    
10668                                            break;
10669                                    }
10670                            }
10671                    }
10672    
10673                    if (list == null) {
10674                            StringBundler query = null;
10675    
10676                            if (orderByComparator != null) {
10677                                    query = new StringBundler(5 +
10678                                                    (orderByComparator.getOrderByFields().length * 3));
10679                            }
10680                            else {
10681                                    query = new StringBundler(5);
10682                            }
10683    
10684                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
10685    
10686                            query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
10687    
10688                            query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
10689    
10690                            query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
10691    
10692                            if (orderByComparator != null) {
10693                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10694                                            orderByComparator);
10695                            }
10696                            else
10697                             if (pagination) {
10698                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10699                            }
10700    
10701                            String sql = query.toString();
10702    
10703                            Session session = null;
10704    
10705                            try {
10706                                    session = openSession();
10707    
10708                                    Query q = session.createQuery(sql);
10709    
10710                                    QueryPos qPos = QueryPos.getInstance(q);
10711    
10712                                    qPos.add(groupId);
10713    
10714                                    qPos.add(categoryId);
10715    
10716                                    qPos.add(status);
10717    
10718                                    if (!pagination) {
10719                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
10720                                                            start, end, false);
10721    
10722                                            Collections.sort(list);
10723    
10724                                            list = Collections.unmodifiableList(list);
10725                                    }
10726                                    else {
10727                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
10728                                                            start, end);
10729                                    }
10730    
10731                                    cacheResult(list);
10732    
10733                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10734                            }
10735                            catch (Exception e) {
10736                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10737    
10738                                    throw processException(e);
10739                            }
10740                            finally {
10741                                    closeSession(session);
10742                            }
10743                    }
10744    
10745                    return list;
10746            }
10747    
10748            /**
10749             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
10750             *
10751             * @param groupId the group ID
10752             * @param categoryId the category ID
10753             * @param status the status
10754             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10755             * @return the first matching message boards thread
10756             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
10757             */
10758            @Override
10759            public MBThread findByG_NotC_S_First(long groupId, long categoryId,
10760                    int status, OrderByComparator<MBThread> orderByComparator)
10761                    throws NoSuchThreadException {
10762                    MBThread mbThread = fetchByG_NotC_S_First(groupId, categoryId, status,
10763                                    orderByComparator);
10764    
10765                    if (mbThread != null) {
10766                            return mbThread;
10767                    }
10768    
10769                    StringBundler msg = new StringBundler(8);
10770    
10771                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10772    
10773                    msg.append("groupId=");
10774                    msg.append(groupId);
10775    
10776                    msg.append(", categoryId=");
10777                    msg.append(categoryId);
10778    
10779                    msg.append(", status=");
10780                    msg.append(status);
10781    
10782                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10783    
10784                    throw new NoSuchThreadException(msg.toString());
10785            }
10786    
10787            /**
10788             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
10789             *
10790             * @param groupId the group ID
10791             * @param categoryId the category ID
10792             * @param status the status
10793             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10794             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
10795             */
10796            @Override
10797            public MBThread fetchByG_NotC_S_First(long groupId, long categoryId,
10798                    int status, OrderByComparator<MBThread> orderByComparator) {
10799                    List<MBThread> list = findByG_NotC_S(groupId, categoryId, status, 0, 1,
10800                                    orderByComparator);
10801    
10802                    if (!list.isEmpty()) {
10803                            return list.get(0);
10804                    }
10805    
10806                    return null;
10807            }
10808    
10809            /**
10810             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
10811             *
10812             * @param groupId the group ID
10813             * @param categoryId the category ID
10814             * @param status the status
10815             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10816             * @return the last matching message boards thread
10817             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
10818             */
10819            @Override
10820            public MBThread findByG_NotC_S_Last(long groupId, long categoryId,
10821                    int status, OrderByComparator<MBThread> orderByComparator)
10822                    throws NoSuchThreadException {
10823                    MBThread mbThread = fetchByG_NotC_S_Last(groupId, categoryId, status,
10824                                    orderByComparator);
10825    
10826                    if (mbThread != null) {
10827                            return mbThread;
10828                    }
10829    
10830                    StringBundler msg = new StringBundler(8);
10831    
10832                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10833    
10834                    msg.append("groupId=");
10835                    msg.append(groupId);
10836    
10837                    msg.append(", categoryId=");
10838                    msg.append(categoryId);
10839    
10840                    msg.append(", status=");
10841                    msg.append(status);
10842    
10843                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10844    
10845                    throw new NoSuchThreadException(msg.toString());
10846            }
10847    
10848            /**
10849             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
10850             *
10851             * @param groupId the group ID
10852             * @param categoryId the category ID
10853             * @param status the status
10854             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10855             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
10856             */
10857            @Override
10858            public MBThread fetchByG_NotC_S_Last(long groupId, long categoryId,
10859                    int status, OrderByComparator<MBThread> orderByComparator) {
10860                    int count = countByG_NotC_S(groupId, categoryId, status);
10861    
10862                    if (count == 0) {
10863                            return null;
10864                    }
10865    
10866                    List<MBThread> list = findByG_NotC_S(groupId, categoryId, status,
10867                                    count - 1, count, orderByComparator);
10868    
10869                    if (!list.isEmpty()) {
10870                            return list.get(0);
10871                    }
10872    
10873                    return null;
10874            }
10875    
10876            /**
10877             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
10878             *
10879             * @param threadId the primary key of the current message boards thread
10880             * @param groupId the group ID
10881             * @param categoryId the category ID
10882             * @param status the status
10883             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10884             * @return the previous, current, and next message boards thread
10885             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
10886             */
10887            @Override
10888            public MBThread[] findByG_NotC_S_PrevAndNext(long threadId, long groupId,
10889                    long categoryId, int status,
10890                    OrderByComparator<MBThread> orderByComparator)
10891                    throws NoSuchThreadException {
10892                    MBThread mbThread = findByPrimaryKey(threadId);
10893    
10894                    Session session = null;
10895    
10896                    try {
10897                            session = openSession();
10898    
10899                            MBThread[] array = new MBThreadImpl[3];
10900    
10901                            array[0] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
10902                                            categoryId, status, orderByComparator, true);
10903    
10904                            array[1] = mbThread;
10905    
10906                            array[2] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
10907                                            categoryId, status, orderByComparator, false);
10908    
10909                            return array;
10910                    }
10911                    catch (Exception e) {
10912                            throw processException(e);
10913                    }
10914                    finally {
10915                            closeSession(session);
10916                    }
10917            }
10918    
10919            protected MBThread getByG_NotC_S_PrevAndNext(Session session,
10920                    MBThread mbThread, long groupId, long categoryId, int status,
10921                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
10922                    StringBundler query = null;
10923    
10924                    if (orderByComparator != null) {
10925                            query = new StringBundler(6 +
10926                                            (orderByComparator.getOrderByFields().length * 6));
10927                    }
10928                    else {
10929                            query = new StringBundler(3);
10930                    }
10931    
10932                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
10933    
10934                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
10935    
10936                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
10937    
10938                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
10939    
10940                    if (orderByComparator != null) {
10941                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10942    
10943                            if (orderByConditionFields.length > 0) {
10944                                    query.append(WHERE_AND);
10945                            }
10946    
10947                            for (int i = 0; i < orderByConditionFields.length; i++) {
10948                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10949                                    query.append(orderByConditionFields[i]);
10950    
10951                                    if ((i + 1) < orderByConditionFields.length) {
10952                                            if (orderByComparator.isAscending() ^ previous) {
10953                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10954                                            }
10955                                            else {
10956                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10957                                            }
10958                                    }
10959                                    else {
10960                                            if (orderByComparator.isAscending() ^ previous) {
10961                                                    query.append(WHERE_GREATER_THAN);
10962                                            }
10963                                            else {
10964                                                    query.append(WHERE_LESSER_THAN);
10965                                            }
10966                                    }
10967                            }
10968    
10969                            query.append(ORDER_BY_CLAUSE);
10970    
10971                            String[] orderByFields = orderByComparator.getOrderByFields();
10972    
10973                            for (int i = 0; i < orderByFields.length; i++) {
10974                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10975                                    query.append(orderByFields[i]);
10976    
10977                                    if ((i + 1) < orderByFields.length) {
10978                                            if (orderByComparator.isAscending() ^ previous) {
10979                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10980                                            }
10981                                            else {
10982                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10983                                            }
10984                                    }
10985                                    else {
10986                                            if (orderByComparator.isAscending() ^ previous) {
10987                                                    query.append(ORDER_BY_ASC);
10988                                            }
10989                                            else {
10990                                                    query.append(ORDER_BY_DESC);
10991                                            }
10992                                    }
10993                            }
10994                    }
10995                    else {
10996                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10997                    }
10998    
10999                    String sql = query.toString();
11000    
11001                    Query q = session.createQuery(sql);
11002    
11003                    q.setFirstResult(0);
11004                    q.setMaxResults(2);
11005    
11006                    QueryPos qPos = QueryPos.getInstance(q);
11007    
11008                    qPos.add(groupId);
11009    
11010                    qPos.add(categoryId);
11011    
11012                    qPos.add(status);
11013    
11014                    if (orderByComparator != null) {
11015                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
11016    
11017                            for (Object value : values) {
11018                                    qPos.add(value);
11019                            }
11020                    }
11021    
11022                    List<MBThread> list = q.list();
11023    
11024                    if (list.size() == 2) {
11025                            return list.get(1);
11026                    }
11027                    else {
11028                            return null;
11029                    }
11030            }
11031    
11032            /**
11033             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
11034             *
11035             * @param groupId the group ID
11036             * @param categoryId the category ID
11037             * @param status the status
11038             * @return the matching message boards threads that the user has permission to view
11039             */
11040            @Override
11041            public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
11042                    int status) {
11043                    return filterFindByG_NotC_S(groupId, categoryId, status,
11044                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11045            }
11046    
11047            /**
11048             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
11049             *
11050             * <p>
11051             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11052             * </p>
11053             *
11054             * @param groupId the group ID
11055             * @param categoryId the category ID
11056             * @param status the status
11057             * @param start the lower bound of the range of message boards threads
11058             * @param end the upper bound of the range of message boards threads (not inclusive)
11059             * @return the range of matching message boards threads that the user has permission to view
11060             */
11061            @Override
11062            public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
11063                    int status, int start, int end) {
11064                    return filterFindByG_NotC_S(groupId, categoryId, status, start, end,
11065                            null);
11066            }
11067    
11068            /**
11069             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
11070             *
11071             * <p>
11072             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11073             * </p>
11074             *
11075             * @param groupId the group ID
11076             * @param categoryId the category ID
11077             * @param status the status
11078             * @param start the lower bound of the range of message boards threads
11079             * @param end the upper bound of the range of message boards threads (not inclusive)
11080             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11081             * @return the ordered range of matching message boards threads that the user has permission to view
11082             */
11083            @Override
11084            public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
11085                    int status, int start, int end,
11086                    OrderByComparator<MBThread> orderByComparator) {
11087                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11088                            return findByG_NotC_S(groupId, categoryId, status, start, end,
11089                                    orderByComparator);
11090                    }
11091    
11092                    StringBundler query = null;
11093    
11094                    if (orderByComparator != null) {
11095                            query = new StringBundler(5 +
11096                                            (orderByComparator.getOrderByFields().length * 3));
11097                    }
11098                    else {
11099                            query = new StringBundler(5);
11100                    }
11101    
11102                    if (getDB().isSupportsInlineDistinct()) {
11103                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
11104                    }
11105                    else {
11106                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
11107                    }
11108    
11109                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11110    
11111                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11112    
11113                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11114    
11115                    if (!getDB().isSupportsInlineDistinct()) {
11116                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
11117                    }
11118    
11119                    if (orderByComparator != null) {
11120                            if (getDB().isSupportsInlineDistinct()) {
11121                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11122                                            orderByComparator, true);
11123                            }
11124                            else {
11125                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11126                                            orderByComparator, true);
11127                            }
11128                    }
11129                    else {
11130                            if (getDB().isSupportsInlineDistinct()) {
11131                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11132                            }
11133                            else {
11134                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
11135                            }
11136                    }
11137    
11138                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11139                                    MBThread.class.getName(),
11140                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11141    
11142                    Session session = null;
11143    
11144                    try {
11145                            session = openSession();
11146    
11147                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
11148    
11149                            if (getDB().isSupportsInlineDistinct()) {
11150                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
11151                            }
11152                            else {
11153                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
11154                            }
11155    
11156                            QueryPos qPos = QueryPos.getInstance(q);
11157    
11158                            qPos.add(groupId);
11159    
11160                            qPos.add(categoryId);
11161    
11162                            qPos.add(status);
11163    
11164                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
11165                    }
11166                    catch (Exception e) {
11167                            throw processException(e);
11168                    }
11169                    finally {
11170                            closeSession(session);
11171                    }
11172            }
11173    
11174            /**
11175             * Returns the message boards threads before and after the current message boards thread in the ordered set of message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
11176             *
11177             * @param threadId the primary key of the current message boards thread
11178             * @param groupId the group ID
11179             * @param categoryId the category ID
11180             * @param status the status
11181             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11182             * @return the previous, current, and next message boards thread
11183             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
11184             */
11185            @Override
11186            public MBThread[] filterFindByG_NotC_S_PrevAndNext(long threadId,
11187                    long groupId, long categoryId, int status,
11188                    OrderByComparator<MBThread> orderByComparator)
11189                    throws NoSuchThreadException {
11190                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11191                            return findByG_NotC_S_PrevAndNext(threadId, groupId, categoryId,
11192                                    status, orderByComparator);
11193                    }
11194    
11195                    MBThread mbThread = findByPrimaryKey(threadId);
11196    
11197                    Session session = null;
11198    
11199                    try {
11200                            session = openSession();
11201    
11202                            MBThread[] array = new MBThreadImpl[3];
11203    
11204                            array[0] = filterGetByG_NotC_S_PrevAndNext(session, mbThread,
11205                                            groupId, categoryId, status, orderByComparator, true);
11206    
11207                            array[1] = mbThread;
11208    
11209                            array[2] = filterGetByG_NotC_S_PrevAndNext(session, mbThread,
11210                                            groupId, categoryId, status, orderByComparator, false);
11211    
11212                            return array;
11213                    }
11214                    catch (Exception e) {
11215                            throw processException(e);
11216                    }
11217                    finally {
11218                            closeSession(session);
11219                    }
11220            }
11221    
11222            protected MBThread filterGetByG_NotC_S_PrevAndNext(Session session,
11223                    MBThread mbThread, long groupId, long categoryId, int status,
11224                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
11225                    StringBundler query = null;
11226    
11227                    if (orderByComparator != null) {
11228                            query = new StringBundler(6 +
11229                                            (orderByComparator.getOrderByFields().length * 6));
11230                    }
11231                    else {
11232                            query = new StringBundler(3);
11233                    }
11234    
11235                    if (getDB().isSupportsInlineDistinct()) {
11236                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
11237                    }
11238                    else {
11239                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
11240                    }
11241    
11242                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11243    
11244                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11245    
11246                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11247    
11248                    if (!getDB().isSupportsInlineDistinct()) {
11249                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
11250                    }
11251    
11252                    if (orderByComparator != null) {
11253                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11254    
11255                            if (orderByConditionFields.length > 0) {
11256                                    query.append(WHERE_AND);
11257                            }
11258    
11259                            for (int i = 0; i < orderByConditionFields.length; i++) {
11260                                    if (getDB().isSupportsInlineDistinct()) {
11261                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11262                                    }
11263                                    else {
11264                                            query.append(_ORDER_BY_ENTITY_TABLE);
11265                                    }
11266    
11267                                    query.append(orderByConditionFields[i]);
11268    
11269                                    if ((i + 1) < orderByConditionFields.length) {
11270                                            if (orderByComparator.isAscending() ^ previous) {
11271                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11272                                            }
11273                                            else {
11274                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11275                                            }
11276                                    }
11277                                    else {
11278                                            if (orderByComparator.isAscending() ^ previous) {
11279                                                    query.append(WHERE_GREATER_THAN);
11280                                            }
11281                                            else {
11282                                                    query.append(WHERE_LESSER_THAN);
11283                                            }
11284                                    }
11285                            }
11286    
11287                            query.append(ORDER_BY_CLAUSE);
11288    
11289                            String[] orderByFields = orderByComparator.getOrderByFields();
11290    
11291                            for (int i = 0; i < orderByFields.length; i++) {
11292                                    if (getDB().isSupportsInlineDistinct()) {
11293                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11294                                    }
11295                                    else {
11296                                            query.append(_ORDER_BY_ENTITY_TABLE);
11297                                    }
11298    
11299                                    query.append(orderByFields[i]);
11300    
11301                                    if ((i + 1) < orderByFields.length) {
11302                                            if (orderByComparator.isAscending() ^ previous) {
11303                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11304                                            }
11305                                            else {
11306                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11307                                            }
11308                                    }
11309                                    else {
11310                                            if (orderByComparator.isAscending() ^ previous) {
11311                                                    query.append(ORDER_BY_ASC);
11312                                            }
11313                                            else {
11314                                                    query.append(ORDER_BY_DESC);
11315                                            }
11316                                    }
11317                            }
11318                    }
11319                    else {
11320                            if (getDB().isSupportsInlineDistinct()) {
11321                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11322                            }
11323                            else {
11324                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
11325                            }
11326                    }
11327    
11328                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11329                                    MBThread.class.getName(),
11330                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11331    
11332                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
11333    
11334                    q.setFirstResult(0);
11335                    q.setMaxResults(2);
11336    
11337                    if (getDB().isSupportsInlineDistinct()) {
11338                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
11339                    }
11340                    else {
11341                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
11342                    }
11343    
11344                    QueryPos qPos = QueryPos.getInstance(q);
11345    
11346                    qPos.add(groupId);
11347    
11348                    qPos.add(categoryId);
11349    
11350                    qPos.add(status);
11351    
11352                    if (orderByComparator != null) {
11353                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
11354    
11355                            for (Object value : values) {
11356                                    qPos.add(value);
11357                            }
11358                    }
11359    
11360                    List<MBThread> list = q.list();
11361    
11362                    if (list.size() == 2) {
11363                            return list.get(1);
11364                    }
11365                    else {
11366                            return null;
11367                    }
11368            }
11369    
11370            /**
11371             * Removes all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63; from the database.
11372             *
11373             * @param groupId the group ID
11374             * @param categoryId the category ID
11375             * @param status the status
11376             */
11377            @Override
11378            public void removeByG_NotC_S(long groupId, long categoryId, int status) {
11379                    for (MBThread mbThread : findByG_NotC_S(groupId, categoryId, status,
11380                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11381                            remove(mbThread);
11382                    }
11383            }
11384    
11385            /**
11386             * Returns the number of message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
11387             *
11388             * @param groupId the group ID
11389             * @param categoryId the category ID
11390             * @param status the status
11391             * @return the number of matching message boards threads
11392             */
11393            @Override
11394            public int countByG_NotC_S(long groupId, long categoryId, int status) {
11395                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_S;
11396    
11397                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
11398    
11399                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11400                                    this);
11401    
11402                    if (count == null) {
11403                            StringBundler query = new StringBundler(4);
11404    
11405                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
11406    
11407                            query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11408    
11409                            query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11410    
11411                            query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11412    
11413                            String sql = query.toString();
11414    
11415                            Session session = null;
11416    
11417                            try {
11418                                    session = openSession();
11419    
11420                                    Query q = session.createQuery(sql);
11421    
11422                                    QueryPos qPos = QueryPos.getInstance(q);
11423    
11424                                    qPos.add(groupId);
11425    
11426                                    qPos.add(categoryId);
11427    
11428                                    qPos.add(status);
11429    
11430                                    count = (Long)q.uniqueResult();
11431    
11432                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
11433                            }
11434                            catch (Exception e) {
11435                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11436    
11437                                    throw processException(e);
11438                            }
11439                            finally {
11440                                    closeSession(session);
11441                            }
11442                    }
11443    
11444                    return count.intValue();
11445            }
11446    
11447            /**
11448             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
11449             *
11450             * @param groupId the group ID
11451             * @param categoryId the category ID
11452             * @param status the status
11453             * @return the number of matching message boards threads that the user has permission to view
11454             */
11455            @Override
11456            public int filterCountByG_NotC_S(long groupId, long categoryId, int status) {
11457                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11458                            return countByG_NotC_S(groupId, categoryId, status);
11459                    }
11460    
11461                    StringBundler query = new StringBundler(4);
11462    
11463                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
11464    
11465                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11466    
11467                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11468    
11469                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11470    
11471                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11472                                    MBThread.class.getName(),
11473                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11474    
11475                    Session session = null;
11476    
11477                    try {
11478                            session = openSession();
11479    
11480                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
11481    
11482                            q.addScalar(COUNT_COLUMN_NAME,
11483                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
11484    
11485                            QueryPos qPos = QueryPos.getInstance(q);
11486    
11487                            qPos.add(groupId);
11488    
11489                            qPos.add(categoryId);
11490    
11491                            qPos.add(status);
11492    
11493                            Long count = (Long)q.uniqueResult();
11494    
11495                            return count.intValue();
11496                    }
11497                    catch (Exception e) {
11498                            throw processException(e);
11499                    }
11500                    finally {
11501                            closeSession(session);
11502                    }
11503            }
11504    
11505            private static final String _FINDER_COLUMN_G_NOTC_S_GROUPID_2 = "mbThread.groupId = ? AND ";
11506            private static final String _FINDER_COLUMN_G_NOTC_S_CATEGORYID_2 = "mbThread.categoryId != ? AND ";
11507            private static final String _FINDER_COLUMN_G_NOTC_S_STATUS_2 = "mbThread.status = ?";
11508            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_NOTS =
11509                    new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
11510                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
11511                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC_NotS",
11512                            new String[] {
11513                                    Long.class.getName(), Long.class.getName(),
11514                                    Integer.class.getName(),
11515                                    
11516                            Integer.class.getName(), Integer.class.getName(),
11517                                    OrderByComparator.class.getName()
11518                            });
11519            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_NOTS =
11520                    new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
11521                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
11522                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC_NotS",
11523                            new String[] {
11524                                    Long.class.getName(), Long.class.getName(),
11525                                    Integer.class.getName()
11526                            });
11527    
11528            /**
11529             * Returns all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11530             *
11531             * @param groupId the group ID
11532             * @param categoryId the category ID
11533             * @param status the status
11534             * @return the matching message boards threads
11535             */
11536            @Override
11537            public List<MBThread> findByG_NotC_NotS(long groupId, long categoryId,
11538                    int status) {
11539                    return findByG_NotC_NotS(groupId, categoryId, status,
11540                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11541            }
11542    
11543            /**
11544             * Returns a range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11545             *
11546             * <p>
11547             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11548             * </p>
11549             *
11550             * @param groupId the group ID
11551             * @param categoryId the category ID
11552             * @param status the status
11553             * @param start the lower bound of the range of message boards threads
11554             * @param end the upper bound of the range of message boards threads (not inclusive)
11555             * @return the range of matching message boards threads
11556             */
11557            @Override
11558            public List<MBThread> findByG_NotC_NotS(long groupId, long categoryId,
11559                    int status, int start, int end) {
11560                    return findByG_NotC_NotS(groupId, categoryId, status, start, end, null);
11561            }
11562    
11563            /**
11564             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11565             *
11566             * <p>
11567             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11568             * </p>
11569             *
11570             * @param groupId the group ID
11571             * @param categoryId the category ID
11572             * @param status the status
11573             * @param start the lower bound of the range of message boards threads
11574             * @param end the upper bound of the range of message boards threads (not inclusive)
11575             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11576             * @return the ordered range of matching message boards threads
11577             */
11578            @Override
11579            public List<MBThread> findByG_NotC_NotS(long groupId, long categoryId,
11580                    int status, int start, int end,
11581                    OrderByComparator<MBThread> orderByComparator) {
11582                    boolean pagination = true;
11583                    FinderPath finderPath = null;
11584                    Object[] finderArgs = null;
11585    
11586                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_NOTS;
11587                    finderArgs = new Object[] {
11588                                    groupId, categoryId, status,
11589                                    
11590                                    start, end, orderByComparator
11591                            };
11592    
11593                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
11594                                    finderArgs, this);
11595    
11596                    if ((list != null) && !list.isEmpty()) {
11597                            for (MBThread mbThread : list) {
11598                                    if ((groupId != mbThread.getGroupId()) ||
11599                                                    (categoryId == mbThread.getCategoryId()) ||
11600                                                    (status == mbThread.getStatus())) {
11601                                            list = null;
11602    
11603                                            break;
11604                                    }
11605                            }
11606                    }
11607    
11608                    if (list == null) {
11609                            StringBundler query = null;
11610    
11611                            if (orderByComparator != null) {
11612                                    query = new StringBundler(5 +
11613                                                    (orderByComparator.getOrderByFields().length * 3));
11614                            }
11615                            else {
11616                                    query = new StringBundler(5);
11617                            }
11618    
11619                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
11620    
11621                            query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
11622    
11623                            query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
11624    
11625                            query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
11626    
11627                            if (orderByComparator != null) {
11628                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11629                                            orderByComparator);
11630                            }
11631                            else
11632                             if (pagination) {
11633                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11634                            }
11635    
11636                            String sql = query.toString();
11637    
11638                            Session session = null;
11639    
11640                            try {
11641                                    session = openSession();
11642    
11643                                    Query q = session.createQuery(sql);
11644    
11645                                    QueryPos qPos = QueryPos.getInstance(q);
11646    
11647                                    qPos.add(groupId);
11648    
11649                                    qPos.add(categoryId);
11650    
11651                                    qPos.add(status);
11652    
11653                                    if (!pagination) {
11654                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
11655                                                            start, end, false);
11656    
11657                                            Collections.sort(list);
11658    
11659                                            list = Collections.unmodifiableList(list);
11660                                    }
11661                                    else {
11662                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
11663                                                            start, end);
11664                                    }
11665    
11666                                    cacheResult(list);
11667    
11668                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11669                            }
11670                            catch (Exception e) {
11671                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11672    
11673                                    throw processException(e);
11674                            }
11675                            finally {
11676                                    closeSession(session);
11677                            }
11678                    }
11679    
11680                    return list;
11681            }
11682    
11683            /**
11684             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11685             *
11686             * @param groupId the group ID
11687             * @param categoryId the category ID
11688             * @param status the status
11689             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11690             * @return the first matching message boards thread
11691             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
11692             */
11693            @Override
11694            public MBThread findByG_NotC_NotS_First(long groupId, long categoryId,
11695                    int status, OrderByComparator<MBThread> orderByComparator)
11696                    throws NoSuchThreadException {
11697                    MBThread mbThread = fetchByG_NotC_NotS_First(groupId, categoryId,
11698                                    status, orderByComparator);
11699    
11700                    if (mbThread != null) {
11701                            return mbThread;
11702                    }
11703    
11704                    StringBundler msg = new StringBundler(8);
11705    
11706                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11707    
11708                    msg.append("groupId=");
11709                    msg.append(groupId);
11710    
11711                    msg.append(", categoryId=");
11712                    msg.append(categoryId);
11713    
11714                    msg.append(", status=");
11715                    msg.append(status);
11716    
11717                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11718    
11719                    throw new NoSuchThreadException(msg.toString());
11720            }
11721    
11722            /**
11723             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11724             *
11725             * @param groupId the group ID
11726             * @param categoryId the category ID
11727             * @param status the status
11728             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11729             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
11730             */
11731            @Override
11732            public MBThread fetchByG_NotC_NotS_First(long groupId, long categoryId,
11733                    int status, OrderByComparator<MBThread> orderByComparator) {
11734                    List<MBThread> list = findByG_NotC_NotS(groupId, categoryId, status, 0,
11735                                    1, orderByComparator);
11736    
11737                    if (!list.isEmpty()) {
11738                            return list.get(0);
11739                    }
11740    
11741                    return null;
11742            }
11743    
11744            /**
11745             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11746             *
11747             * @param groupId the group ID
11748             * @param categoryId the category ID
11749             * @param status the status
11750             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11751             * @return the last matching message boards thread
11752             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
11753             */
11754            @Override
11755            public MBThread findByG_NotC_NotS_Last(long groupId, long categoryId,
11756                    int status, OrderByComparator<MBThread> orderByComparator)
11757                    throws NoSuchThreadException {
11758                    MBThread mbThread = fetchByG_NotC_NotS_Last(groupId, categoryId,
11759                                    status, orderByComparator);
11760    
11761                    if (mbThread != null) {
11762                            return mbThread;
11763                    }
11764    
11765                    StringBundler msg = new StringBundler(8);
11766    
11767                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11768    
11769                    msg.append("groupId=");
11770                    msg.append(groupId);
11771    
11772                    msg.append(", categoryId=");
11773                    msg.append(categoryId);
11774    
11775                    msg.append(", status=");
11776                    msg.append(status);
11777    
11778                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11779    
11780                    throw new NoSuchThreadException(msg.toString());
11781            }
11782    
11783            /**
11784             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11785             *
11786             * @param groupId the group ID
11787             * @param categoryId the category ID
11788             * @param status the status
11789             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11790             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
11791             */
11792            @Override
11793            public MBThread fetchByG_NotC_NotS_Last(long groupId, long categoryId,
11794                    int status, OrderByComparator<MBThread> orderByComparator) {
11795                    int count = countByG_NotC_NotS(groupId, categoryId, status);
11796    
11797                    if (count == 0) {
11798                            return null;
11799                    }
11800    
11801                    List<MBThread> list = findByG_NotC_NotS(groupId, categoryId, status,
11802                                    count - 1, count, orderByComparator);
11803    
11804                    if (!list.isEmpty()) {
11805                            return list.get(0);
11806                    }
11807    
11808                    return null;
11809            }
11810    
11811            /**
11812             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11813             *
11814             * @param threadId the primary key of the current message boards thread
11815             * @param groupId the group ID
11816             * @param categoryId the category ID
11817             * @param status the status
11818             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11819             * @return the previous, current, and next message boards thread
11820             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
11821             */
11822            @Override
11823            public MBThread[] findByG_NotC_NotS_PrevAndNext(long threadId,
11824                    long groupId, long categoryId, int status,
11825                    OrderByComparator<MBThread> orderByComparator)
11826                    throws NoSuchThreadException {
11827                    MBThread mbThread = findByPrimaryKey(threadId);
11828    
11829                    Session session = null;
11830    
11831                    try {
11832                            session = openSession();
11833    
11834                            MBThread[] array = new MBThreadImpl[3];
11835    
11836                            array[0] = getByG_NotC_NotS_PrevAndNext(session, mbThread, groupId,
11837                                            categoryId, status, orderByComparator, true);
11838    
11839                            array[1] = mbThread;
11840    
11841                            array[2] = getByG_NotC_NotS_PrevAndNext(session, mbThread, groupId,
11842                                            categoryId, status, orderByComparator, false);
11843    
11844                            return array;
11845                    }
11846                    catch (Exception e) {
11847                            throw processException(e);
11848                    }
11849                    finally {
11850                            closeSession(session);
11851                    }
11852            }
11853    
11854            protected MBThread getByG_NotC_NotS_PrevAndNext(Session session,
11855                    MBThread mbThread, long groupId, long categoryId, int status,
11856                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
11857                    StringBundler query = null;
11858    
11859                    if (orderByComparator != null) {
11860                            query = new StringBundler(6 +
11861                                            (orderByComparator.getOrderByFields().length * 6));
11862                    }
11863                    else {
11864                            query = new StringBundler(3);
11865                    }
11866    
11867                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
11868    
11869                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
11870    
11871                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
11872    
11873                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
11874    
11875                    if (orderByComparator != null) {
11876                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11877    
11878                            if (orderByConditionFields.length > 0) {
11879                                    query.append(WHERE_AND);
11880                            }
11881    
11882                            for (int i = 0; i < orderByConditionFields.length; i++) {
11883                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11884                                    query.append(orderByConditionFields[i]);
11885    
11886                                    if ((i + 1) < orderByConditionFields.length) {
11887                                            if (orderByComparator.isAscending() ^ previous) {
11888                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11889                                            }
11890                                            else {
11891                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11892                                            }
11893                                    }
11894                                    else {
11895                                            if (orderByComparator.isAscending() ^ previous) {
11896                                                    query.append(WHERE_GREATER_THAN);
11897                                            }
11898                                            else {
11899                                                    query.append(WHERE_LESSER_THAN);
11900                                            }
11901                                    }
11902                            }
11903    
11904                            query.append(ORDER_BY_CLAUSE);
11905    
11906                            String[] orderByFields = orderByComparator.getOrderByFields();
11907    
11908                            for (int i = 0; i < orderByFields.length; i++) {
11909                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11910                                    query.append(orderByFields[i]);
11911    
11912                                    if ((i + 1) < orderByFields.length) {
11913                                            if (orderByComparator.isAscending() ^ previous) {
11914                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11915                                            }
11916                                            else {
11917                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11918                                            }
11919                                    }
11920                                    else {
11921                                            if (orderByComparator.isAscending() ^ previous) {
11922                                                    query.append(ORDER_BY_ASC);
11923                                            }
11924                                            else {
11925                                                    query.append(ORDER_BY_DESC);
11926                                            }
11927                                    }
11928                            }
11929                    }
11930                    else {
11931                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11932                    }
11933    
11934                    String sql = query.toString();
11935    
11936                    Query q = session.createQuery(sql);
11937    
11938                    q.setFirstResult(0);
11939                    q.setMaxResults(2);
11940    
11941                    QueryPos qPos = QueryPos.getInstance(q);
11942    
11943                    qPos.add(groupId);
11944    
11945                    qPos.add(categoryId);
11946    
11947                    qPos.add(status);
11948    
11949                    if (orderByComparator != null) {
11950                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
11951    
11952                            for (Object value : values) {
11953                                    qPos.add(value);
11954                            }
11955                    }
11956    
11957                    List<MBThread> list = q.list();
11958    
11959                    if (list.size() == 2) {
11960                            return list.get(1);
11961                    }
11962                    else {
11963                            return null;
11964                    }
11965            }
11966    
11967            /**
11968             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11969             *
11970             * @param groupId the group ID
11971             * @param categoryId the category ID
11972             * @param status the status
11973             * @return the matching message boards threads that the user has permission to view
11974             */
11975            @Override
11976            public List<MBThread> filterFindByG_NotC_NotS(long groupId,
11977                    long categoryId, int status) {
11978                    return filterFindByG_NotC_NotS(groupId, categoryId, status,
11979                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11980            }
11981    
11982            /**
11983             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11984             *
11985             * <p>
11986             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11987             * </p>
11988             *
11989             * @param groupId the group ID
11990             * @param categoryId the category ID
11991             * @param status the status
11992             * @param start the lower bound of the range of message boards threads
11993             * @param end the upper bound of the range of message boards threads (not inclusive)
11994             * @return the range of matching message boards threads that the user has permission to view
11995             */
11996            @Override
11997            public List<MBThread> filterFindByG_NotC_NotS(long groupId,
11998                    long categoryId, int status, int start, int end) {
11999                    return filterFindByG_NotC_NotS(groupId, categoryId, status, start, end,
12000                            null);
12001            }
12002    
12003            /**
12004             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
12005             *
12006             * <p>
12007             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12008             * </p>
12009             *
12010             * @param groupId the group ID
12011             * @param categoryId the category ID
12012             * @param status the status
12013             * @param start the lower bound of the range of message boards threads
12014             * @param end the upper bound of the range of message boards threads (not inclusive)
12015             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12016             * @return the ordered range of matching message boards threads that the user has permission to view
12017             */
12018            @Override
12019            public List<MBThread> filterFindByG_NotC_NotS(long groupId,
12020                    long categoryId, int status, int start, int end,
12021                    OrderByComparator<MBThread> orderByComparator) {
12022                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12023                            return findByG_NotC_NotS(groupId, categoryId, status, start, end,
12024                                    orderByComparator);
12025                    }
12026    
12027                    StringBundler query = null;
12028    
12029                    if (orderByComparator != null) {
12030                            query = new StringBundler(5 +
12031                                            (orderByComparator.getOrderByFields().length * 3));
12032                    }
12033                    else {
12034                            query = new StringBundler(5);
12035                    }
12036    
12037                    if (getDB().isSupportsInlineDistinct()) {
12038                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
12039                    }
12040                    else {
12041                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
12042                    }
12043    
12044                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12045    
12046                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12047    
12048                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12049    
12050                    if (!getDB().isSupportsInlineDistinct()) {
12051                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
12052                    }
12053    
12054                    if (orderByComparator != null) {
12055                            if (getDB().isSupportsInlineDistinct()) {
12056                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12057                                            orderByComparator, true);
12058                            }
12059                            else {
12060                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12061                                            orderByComparator, true);
12062                            }
12063                    }
12064                    else {
12065                            if (getDB().isSupportsInlineDistinct()) {
12066                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
12067                            }
12068                            else {
12069                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
12070                            }
12071                    }
12072    
12073                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12074                                    MBThread.class.getName(),
12075                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12076    
12077                    Session session = null;
12078    
12079                    try {
12080                            session = openSession();
12081    
12082                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12083    
12084                            if (getDB().isSupportsInlineDistinct()) {
12085                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
12086                            }
12087                            else {
12088                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
12089                            }
12090    
12091                            QueryPos qPos = QueryPos.getInstance(q);
12092    
12093                            qPos.add(groupId);
12094    
12095                            qPos.add(categoryId);
12096    
12097                            qPos.add(status);
12098    
12099                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
12100                    }
12101                    catch (Exception e) {
12102                            throw processException(e);
12103                    }
12104                    finally {
12105                            closeSession(session);
12106                    }
12107            }
12108    
12109            /**
12110             * Returns the message boards threads before and after the current message boards thread in the ordered set of message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
12111             *
12112             * @param threadId the primary key of the current message boards thread
12113             * @param groupId the group ID
12114             * @param categoryId the category ID
12115             * @param status the status
12116             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12117             * @return the previous, current, and next message boards thread
12118             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
12119             */
12120            @Override
12121            public MBThread[] filterFindByG_NotC_NotS_PrevAndNext(long threadId,
12122                    long groupId, long categoryId, int status,
12123                    OrderByComparator<MBThread> orderByComparator)
12124                    throws NoSuchThreadException {
12125                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12126                            return findByG_NotC_NotS_PrevAndNext(threadId, groupId, categoryId,
12127                                    status, orderByComparator);
12128                    }
12129    
12130                    MBThread mbThread = findByPrimaryKey(threadId);
12131    
12132                    Session session = null;
12133    
12134                    try {
12135                            session = openSession();
12136    
12137                            MBThread[] array = new MBThreadImpl[3];
12138    
12139                            array[0] = filterGetByG_NotC_NotS_PrevAndNext(session, mbThread,
12140                                            groupId, categoryId, status, orderByComparator, true);
12141    
12142                            array[1] = mbThread;
12143    
12144                            array[2] = filterGetByG_NotC_NotS_PrevAndNext(session, mbThread,
12145                                            groupId, categoryId, status, orderByComparator, false);
12146    
12147                            return array;
12148                    }
12149                    catch (Exception e) {
12150                            throw processException(e);
12151                    }
12152                    finally {
12153                            closeSession(session);
12154                    }
12155            }
12156    
12157            protected MBThread filterGetByG_NotC_NotS_PrevAndNext(Session session,
12158                    MBThread mbThread, long groupId, long categoryId, int status,
12159                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
12160                    StringBundler query = null;
12161    
12162                    if (orderByComparator != null) {
12163                            query = new StringBundler(6 +
12164                                            (orderByComparator.getOrderByFields().length * 6));
12165                    }
12166                    else {
12167                            query = new StringBundler(3);
12168                    }
12169    
12170                    if (getDB().isSupportsInlineDistinct()) {
12171                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
12172                    }
12173                    else {
12174                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
12175                    }
12176    
12177                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12178    
12179                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12180    
12181                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12182    
12183                    if (!getDB().isSupportsInlineDistinct()) {
12184                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
12185                    }
12186    
12187                    if (orderByComparator != null) {
12188                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12189    
12190                            if (orderByConditionFields.length > 0) {
12191                                    query.append(WHERE_AND);
12192                            }
12193    
12194                            for (int i = 0; i < orderByConditionFields.length; i++) {
12195                                    if (getDB().isSupportsInlineDistinct()) {
12196                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12197                                    }
12198                                    else {
12199                                            query.append(_ORDER_BY_ENTITY_TABLE);
12200                                    }
12201    
12202                                    query.append(orderByConditionFields[i]);
12203    
12204                                    if ((i + 1) < orderByConditionFields.length) {
12205                                            if (orderByComparator.isAscending() ^ previous) {
12206                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12207                                            }
12208                                            else {
12209                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12210                                            }
12211                                    }
12212                                    else {
12213                                            if (orderByComparator.isAscending() ^ previous) {
12214                                                    query.append(WHERE_GREATER_THAN);
12215                                            }
12216                                            else {
12217                                                    query.append(WHERE_LESSER_THAN);
12218                                            }
12219                                    }
12220                            }
12221    
12222                            query.append(ORDER_BY_CLAUSE);
12223    
12224                            String[] orderByFields = orderByComparator.getOrderByFields();
12225    
12226                            for (int i = 0; i < orderByFields.length; i++) {
12227                                    if (getDB().isSupportsInlineDistinct()) {
12228                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12229                                    }
12230                                    else {
12231                                            query.append(_ORDER_BY_ENTITY_TABLE);
12232                                    }
12233    
12234                                    query.append(orderByFields[i]);
12235    
12236                                    if ((i + 1) < orderByFields.length) {
12237                                            if (orderByComparator.isAscending() ^ previous) {
12238                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12239                                            }
12240                                            else {
12241                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12242                                            }
12243                                    }
12244                                    else {
12245                                            if (orderByComparator.isAscending() ^ previous) {
12246                                                    query.append(ORDER_BY_ASC);
12247                                            }
12248                                            else {
12249                                                    query.append(ORDER_BY_DESC);
12250                                            }
12251                                    }
12252                            }
12253                    }
12254                    else {
12255                            if (getDB().isSupportsInlineDistinct()) {
12256                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
12257                            }
12258                            else {
12259                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
12260                            }
12261                    }
12262    
12263                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12264                                    MBThread.class.getName(),
12265                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12266    
12267                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
12268    
12269                    q.setFirstResult(0);
12270                    q.setMaxResults(2);
12271    
12272                    if (getDB().isSupportsInlineDistinct()) {
12273                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
12274                    }
12275                    else {
12276                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
12277                    }
12278    
12279                    QueryPos qPos = QueryPos.getInstance(q);
12280    
12281                    qPos.add(groupId);
12282    
12283                    qPos.add(categoryId);
12284    
12285                    qPos.add(status);
12286    
12287                    if (orderByComparator != null) {
12288                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
12289    
12290                            for (Object value : values) {
12291                                    qPos.add(value);
12292                            }
12293                    }
12294    
12295                    List<MBThread> list = q.list();
12296    
12297                    if (list.size() == 2) {
12298                            return list.get(1);
12299                    }
12300                    else {
12301                            return null;
12302                    }
12303            }
12304    
12305            /**
12306             * Removes all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63; from the database.
12307             *
12308             * @param groupId the group ID
12309             * @param categoryId the category ID
12310             * @param status the status
12311             */
12312            @Override
12313            public void removeByG_NotC_NotS(long groupId, long categoryId, int status) {
12314                    for (MBThread mbThread : findByG_NotC_NotS(groupId, categoryId, status,
12315                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12316                            remove(mbThread);
12317                    }
12318            }
12319    
12320            /**
12321             * Returns the number of message boards threads where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
12322             *
12323             * @param groupId the group ID
12324             * @param categoryId the category ID
12325             * @param status the status
12326             * @return the number of matching message boards threads
12327             */
12328            @Override
12329            public int countByG_NotC_NotS(long groupId, long categoryId, int status) {
12330                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_NOTS;
12331    
12332                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
12333    
12334                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12335                                    this);
12336    
12337                    if (count == null) {
12338                            StringBundler query = new StringBundler(4);
12339    
12340                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
12341    
12342                            query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12343    
12344                            query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12345    
12346                            query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12347    
12348                            String sql = query.toString();
12349    
12350                            Session session = null;
12351    
12352                            try {
12353                                    session = openSession();
12354    
12355                                    Query q = session.createQuery(sql);
12356    
12357                                    QueryPos qPos = QueryPos.getInstance(q);
12358    
12359                                    qPos.add(groupId);
12360    
12361                                    qPos.add(categoryId);
12362    
12363                                    qPos.add(status);
12364    
12365                                    count = (Long)q.uniqueResult();
12366    
12367                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
12368                            }
12369                            catch (Exception e) {
12370                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12371    
12372                                    throw processException(e);
12373                            }
12374                            finally {
12375                                    closeSession(session);
12376                            }
12377                    }
12378    
12379                    return count.intValue();
12380            }
12381    
12382            /**
12383             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
12384             *
12385             * @param groupId the group ID
12386             * @param categoryId the category ID
12387             * @param status the status
12388             * @return the number of matching message boards threads that the user has permission to view
12389             */
12390            @Override
12391            public int filterCountByG_NotC_NotS(long groupId, long categoryId,
12392                    int status) {
12393                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12394                            return countByG_NotC_NotS(groupId, categoryId, status);
12395                    }
12396    
12397                    StringBundler query = new StringBundler(4);
12398    
12399                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
12400    
12401                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12402    
12403                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12404    
12405                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12406    
12407                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12408                                    MBThread.class.getName(),
12409                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12410    
12411                    Session session = null;
12412    
12413                    try {
12414                            session = openSession();
12415    
12416                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
12417    
12418                            q.addScalar(COUNT_COLUMN_NAME,
12419                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12420    
12421                            QueryPos qPos = QueryPos.getInstance(q);
12422    
12423                            qPos.add(groupId);
12424    
12425                            qPos.add(categoryId);
12426    
12427                            qPos.add(status);
12428    
12429                            Long count = (Long)q.uniqueResult();
12430    
12431                            return count.intValue();
12432                    }
12433                    catch (Exception e) {
12434                            throw processException(e);
12435                    }
12436                    finally {
12437                            closeSession(session);
12438                    }
12439            }
12440    
12441            private static final String _FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2 = "mbThread.groupId = ? AND ";
12442            private static final String _FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2 = "mbThread.categoryId != ? AND ";
12443            private static final String _FINDER_COLUMN_G_NOTC_NOTS_STATUS_2 = "mbThread.status != ?";
12444    
12445            public MBThreadPersistenceImpl() {
12446                    setModelClass(MBThread.class);
12447            }
12448    
12449            /**
12450             * Caches the message boards thread in the entity cache if it is enabled.
12451             *
12452             * @param mbThread the message boards thread
12453             */
12454            @Override
12455            public void cacheResult(MBThread mbThread) {
12456                    EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12457                            MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
12458    
12459                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
12460                            new Object[] { mbThread.getUuid(), mbThread.getGroupId() }, mbThread);
12461    
12462                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
12463                            new Object[] { mbThread.getRootMessageId() }, mbThread);
12464    
12465                    mbThread.resetOriginalValues();
12466            }
12467    
12468            /**
12469             * Caches the message boards threads in the entity cache if it is enabled.
12470             *
12471             * @param mbThreads the message boards threads
12472             */
12473            @Override
12474            public void cacheResult(List<MBThread> mbThreads) {
12475                    for (MBThread mbThread : mbThreads) {
12476                            if (EntityCacheUtil.getResult(
12477                                                    MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12478                                                    MBThreadImpl.class, mbThread.getPrimaryKey()) == null) {
12479                                    cacheResult(mbThread);
12480                            }
12481                            else {
12482                                    mbThread.resetOriginalValues();
12483                            }
12484                    }
12485            }
12486    
12487            /**
12488             * Clears the cache for all message boards threads.
12489             *
12490             * <p>
12491             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
12492             * </p>
12493             */
12494            @Override
12495            public void clearCache() {
12496                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
12497                            CacheRegistryUtil.clear(MBThreadImpl.class.getName());
12498                    }
12499    
12500                    EntityCacheUtil.clearCache(MBThreadImpl.class);
12501    
12502                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
12503                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12504                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12505            }
12506    
12507            /**
12508             * Clears the cache for the message boards thread.
12509             *
12510             * <p>
12511             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
12512             * </p>
12513             */
12514            @Override
12515            public void clearCache(MBThread mbThread) {
12516                    EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12517                            MBThreadImpl.class, mbThread.getPrimaryKey());
12518    
12519                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12520                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12521    
12522                    clearUniqueFindersCache(mbThread);
12523            }
12524    
12525            @Override
12526            public void clearCache(List<MBThread> mbThreads) {
12527                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12528                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12529    
12530                    for (MBThread mbThread : mbThreads) {
12531                            EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12532                                    MBThreadImpl.class, mbThread.getPrimaryKey());
12533    
12534                            clearUniqueFindersCache(mbThread);
12535                    }
12536            }
12537    
12538            protected void cacheUniqueFindersCache(MBThread mbThread) {
12539                    if (mbThread.isNew()) {
12540                            Object[] args = new Object[] {
12541                                            mbThread.getUuid(), mbThread.getGroupId()
12542                                    };
12543    
12544                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
12545                                    Long.valueOf(1));
12546                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
12547                                    mbThread);
12548    
12549                            args = new Object[] { mbThread.getRootMessageId() };
12550    
12551                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID, args,
12552                                    Long.valueOf(1));
12553                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID, args,
12554                                    mbThread);
12555                    }
12556                    else {
12557                            MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
12558    
12559                            if ((mbThreadModelImpl.getColumnBitmask() &
12560                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
12561                                    Object[] args = new Object[] {
12562                                                    mbThread.getUuid(), mbThread.getGroupId()
12563                                            };
12564    
12565                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
12566                                            Long.valueOf(1));
12567                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
12568                                            mbThread);
12569                            }
12570    
12571                            if ((mbThreadModelImpl.getColumnBitmask() &
12572                                            FINDER_PATH_FETCH_BY_ROOTMESSAGEID.getColumnBitmask()) != 0) {
12573                                    Object[] args = new Object[] { mbThread.getRootMessageId() };
12574    
12575                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
12576                                            args, Long.valueOf(1));
12577                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
12578                                            args, mbThread);
12579                            }
12580                    }
12581            }
12582    
12583            protected void clearUniqueFindersCache(MBThread mbThread) {
12584                    MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
12585    
12586                    Object[] args = new Object[] { mbThread.getUuid(), mbThread.getGroupId() };
12587    
12588                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
12589                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
12590    
12591                    if ((mbThreadModelImpl.getColumnBitmask() &
12592                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
12593                            args = new Object[] {
12594                                            mbThreadModelImpl.getOriginalUuid(),
12595                                            mbThreadModelImpl.getOriginalGroupId()
12596                                    };
12597    
12598                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
12599                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
12600                    }
12601    
12602                    args = new Object[] { mbThread.getRootMessageId() };
12603    
12604                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID, args);
12605                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID, args);
12606    
12607                    if ((mbThreadModelImpl.getColumnBitmask() &
12608                                    FINDER_PATH_FETCH_BY_ROOTMESSAGEID.getColumnBitmask()) != 0) {
12609                            args = new Object[] { mbThreadModelImpl.getOriginalRootMessageId() };
12610    
12611                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
12612                                    args);
12613                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
12614                                    args);
12615                    }
12616            }
12617    
12618            /**
12619             * Creates a new message boards thread with the primary key. Does not add the message boards thread to the database.
12620             *
12621             * @param threadId the primary key for the new message boards thread
12622             * @return the new message boards thread
12623             */
12624            @Override
12625            public MBThread create(long threadId) {
12626                    MBThread mbThread = new MBThreadImpl();
12627    
12628                    mbThread.setNew(true);
12629                    mbThread.setPrimaryKey(threadId);
12630    
12631                    String uuid = PortalUUIDUtil.generate();
12632    
12633                    mbThread.setUuid(uuid);
12634    
12635                    return mbThread;
12636            }
12637    
12638            /**
12639             * Removes the message boards thread with the primary key from the database. Also notifies the appropriate model listeners.
12640             *
12641             * @param threadId the primary key of the message boards thread
12642             * @return the message boards thread that was removed
12643             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
12644             */
12645            @Override
12646            public MBThread remove(long threadId) throws NoSuchThreadException {
12647                    return remove((Serializable)threadId);
12648            }
12649    
12650            /**
12651             * Removes the message boards thread with the primary key from the database. Also notifies the appropriate model listeners.
12652             *
12653             * @param primaryKey the primary key of the message boards thread
12654             * @return the message boards thread that was removed
12655             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
12656             */
12657            @Override
12658            public MBThread remove(Serializable primaryKey)
12659                    throws NoSuchThreadException {
12660                    Session session = null;
12661    
12662                    try {
12663                            session = openSession();
12664    
12665                            MBThread mbThread = (MBThread)session.get(MBThreadImpl.class,
12666                                            primaryKey);
12667    
12668                            if (mbThread == null) {
12669                                    if (_log.isWarnEnabled()) {
12670                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
12671                                    }
12672    
12673                                    throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
12674                                            primaryKey);
12675                            }
12676    
12677                            return remove(mbThread);
12678                    }
12679                    catch (NoSuchThreadException nsee) {
12680                            throw nsee;
12681                    }
12682                    catch (Exception e) {
12683                            throw processException(e);
12684                    }
12685                    finally {
12686                            closeSession(session);
12687                    }
12688            }
12689    
12690            @Override
12691            protected MBThread removeImpl(MBThread mbThread) {
12692                    mbThread = toUnwrappedModel(mbThread);
12693    
12694                    Session session = null;
12695    
12696                    try {
12697                            session = openSession();
12698    
12699                            if (!session.contains(mbThread)) {
12700                                    mbThread = (MBThread)session.get(MBThreadImpl.class,
12701                                                    mbThread.getPrimaryKeyObj());
12702                            }
12703    
12704                            if (mbThread != null) {
12705                                    session.delete(mbThread);
12706                            }
12707                    }
12708                    catch (Exception e) {
12709                            throw processException(e);
12710                    }
12711                    finally {
12712                            closeSession(session);
12713                    }
12714    
12715                    if (mbThread != null) {
12716                            clearCache(mbThread);
12717                    }
12718    
12719                    return mbThread;
12720            }
12721    
12722            @Override
12723            public MBThread updateImpl(
12724                    com.liferay.portlet.messageboards.model.MBThread mbThread) {
12725                    mbThread = toUnwrappedModel(mbThread);
12726    
12727                    boolean isNew = mbThread.isNew();
12728    
12729                    MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
12730    
12731                    if (Validator.isNull(mbThread.getUuid())) {
12732                            String uuid = PortalUUIDUtil.generate();
12733    
12734                            mbThread.setUuid(uuid);
12735                    }
12736    
12737                    Session session = null;
12738    
12739                    try {
12740                            session = openSession();
12741    
12742                            if (mbThread.isNew()) {
12743                                    session.save(mbThread);
12744    
12745                                    mbThread.setNew(false);
12746                            }
12747                            else {
12748                                    session.merge(mbThread);
12749                            }
12750                    }
12751                    catch (Exception e) {
12752                            throw processException(e);
12753                    }
12754                    finally {
12755                            closeSession(session);
12756                    }
12757    
12758                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12759    
12760                    if (isNew || !MBThreadModelImpl.COLUMN_BITMASK_ENABLED) {
12761                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12762                    }
12763    
12764                    else {
12765                            if ((mbThreadModelImpl.getColumnBitmask() &
12766                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
12767                                    Object[] args = new Object[] { mbThreadModelImpl.getOriginalUuid() };
12768    
12769                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
12770                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
12771                                            args);
12772    
12773                                    args = new Object[] { mbThreadModelImpl.getUuid() };
12774    
12775                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
12776                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
12777                                            args);
12778                            }
12779    
12780                            if ((mbThreadModelImpl.getColumnBitmask() &
12781                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
12782                                    Object[] args = new Object[] {
12783                                                    mbThreadModelImpl.getOriginalUuid(),
12784                                                    mbThreadModelImpl.getOriginalCompanyId()
12785                                            };
12786    
12787                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
12788                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
12789                                            args);
12790    
12791                                    args = new Object[] {
12792                                                    mbThreadModelImpl.getUuid(),
12793                                                    mbThreadModelImpl.getCompanyId()
12794                                            };
12795    
12796                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
12797                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
12798                                            args);
12799                            }
12800    
12801                            if ((mbThreadModelImpl.getColumnBitmask() &
12802                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
12803                                    Object[] args = new Object[] {
12804                                                    mbThreadModelImpl.getOriginalGroupId()
12805                                            };
12806    
12807                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
12808                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
12809                                            args);
12810    
12811                                    args = new Object[] { mbThreadModelImpl.getGroupId() };
12812    
12813                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
12814                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
12815                                            args);
12816                            }
12817    
12818                            if ((mbThreadModelImpl.getColumnBitmask() &
12819                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
12820                                    Object[] args = new Object[] {
12821                                                    mbThreadModelImpl.getOriginalGroupId(),
12822                                                    mbThreadModelImpl.getOriginalCategoryId()
12823                                            };
12824    
12825                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
12826                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
12827                                            args);
12828    
12829                                    args = new Object[] {
12830                                                    mbThreadModelImpl.getGroupId(),
12831                                                    mbThreadModelImpl.getCategoryId()
12832                                            };
12833    
12834                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
12835                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
12836                                            args);
12837                            }
12838    
12839                            if ((mbThreadModelImpl.getColumnBitmask() &
12840                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
12841                                    Object[] args = new Object[] {
12842                                                    mbThreadModelImpl.getOriginalGroupId(),
12843                                                    mbThreadModelImpl.getOriginalStatus()
12844                                            };
12845    
12846                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
12847                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
12848                                            args);
12849    
12850                                    args = new Object[] {
12851                                                    mbThreadModelImpl.getGroupId(),
12852                                                    mbThreadModelImpl.getStatus()
12853                                            };
12854    
12855                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
12856                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
12857                                            args);
12858                            }
12859    
12860                            if ((mbThreadModelImpl.getColumnBitmask() &
12861                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
12862                                    Object[] args = new Object[] {
12863                                                    mbThreadModelImpl.getOriginalCategoryId(),
12864                                                    mbThreadModelImpl.getOriginalPriority()
12865                                            };
12866    
12867                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
12868                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
12869                                            args);
12870    
12871                                    args = new Object[] {
12872                                                    mbThreadModelImpl.getCategoryId(),
12873                                                    mbThreadModelImpl.getPriority()
12874                                            };
12875    
12876                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
12877                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
12878                                            args);
12879                            }
12880    
12881                            if ((mbThreadModelImpl.getColumnBitmask() &
12882                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P.getColumnBitmask()) != 0) {
12883                                    Object[] args = new Object[] {
12884                                                    mbThreadModelImpl.getOriginalLastPostDate(),
12885                                                    mbThreadModelImpl.getOriginalPriority()
12886                                            };
12887    
12888                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
12889                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
12890                                            args);
12891    
12892                                    args = new Object[] {
12893                                                    mbThreadModelImpl.getLastPostDate(),
12894                                                    mbThreadModelImpl.getPriority()
12895                                            };
12896    
12897                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
12898                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
12899                                            args);
12900                            }
12901    
12902                            if ((mbThreadModelImpl.getColumnBitmask() &
12903                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L.getColumnBitmask()) != 0) {
12904                                    Object[] args = new Object[] {
12905                                                    mbThreadModelImpl.getOriginalGroupId(),
12906                                                    mbThreadModelImpl.getOriginalCategoryId(),
12907                                                    mbThreadModelImpl.getOriginalLastPostDate()
12908                                            };
12909    
12910                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
12911                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
12912                                            args);
12913    
12914                                    args = new Object[] {
12915                                                    mbThreadModelImpl.getGroupId(),
12916                                                    mbThreadModelImpl.getCategoryId(),
12917                                                    mbThreadModelImpl.getLastPostDate()
12918                                            };
12919    
12920                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
12921                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
12922                                            args);
12923                            }
12924    
12925                            if ((mbThreadModelImpl.getColumnBitmask() &
12926                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
12927                                    Object[] args = new Object[] {
12928                                                    mbThreadModelImpl.getOriginalGroupId(),
12929                                                    mbThreadModelImpl.getOriginalCategoryId(),
12930                                                    mbThreadModelImpl.getOriginalStatus()
12931                                            };
12932    
12933                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
12934                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
12935                                            args);
12936    
12937                                    args = new Object[] {
12938                                                    mbThreadModelImpl.getGroupId(),
12939                                                    mbThreadModelImpl.getCategoryId(),
12940                                                    mbThreadModelImpl.getStatus()
12941                                            };
12942    
12943                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
12944                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
12945                                            args);
12946                            }
12947                    }
12948    
12949                    EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12950                            MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread, false);
12951    
12952                    clearUniqueFindersCache(mbThread);
12953                    cacheUniqueFindersCache(mbThread);
12954    
12955                    mbThread.resetOriginalValues();
12956    
12957                    return mbThread;
12958            }
12959    
12960            protected MBThread toUnwrappedModel(MBThread mbThread) {
12961                    if (mbThread instanceof MBThreadImpl) {
12962                            return mbThread;
12963                    }
12964    
12965                    MBThreadImpl mbThreadImpl = new MBThreadImpl();
12966    
12967                    mbThreadImpl.setNew(mbThread.isNew());
12968                    mbThreadImpl.setPrimaryKey(mbThread.getPrimaryKey());
12969    
12970                    mbThreadImpl.setUuid(mbThread.getUuid());
12971                    mbThreadImpl.setThreadId(mbThread.getThreadId());
12972                    mbThreadImpl.setGroupId(mbThread.getGroupId());
12973                    mbThreadImpl.setCompanyId(mbThread.getCompanyId());
12974                    mbThreadImpl.setUserId(mbThread.getUserId());
12975                    mbThreadImpl.setUserName(mbThread.getUserName());
12976                    mbThreadImpl.setCreateDate(mbThread.getCreateDate());
12977                    mbThreadImpl.setModifiedDate(mbThread.getModifiedDate());
12978                    mbThreadImpl.setCategoryId(mbThread.getCategoryId());
12979                    mbThreadImpl.setRootMessageId(mbThread.getRootMessageId());
12980                    mbThreadImpl.setRootMessageUserId(mbThread.getRootMessageUserId());
12981                    mbThreadImpl.setMessageCount(mbThread.getMessageCount());
12982                    mbThreadImpl.setViewCount(mbThread.getViewCount());
12983                    mbThreadImpl.setLastPostByUserId(mbThread.getLastPostByUserId());
12984                    mbThreadImpl.setLastPostDate(mbThread.getLastPostDate());
12985                    mbThreadImpl.setPriority(mbThread.getPriority());
12986                    mbThreadImpl.setQuestion(mbThread.isQuestion());
12987                    mbThreadImpl.setStatus(mbThread.getStatus());
12988                    mbThreadImpl.setStatusByUserId(mbThread.getStatusByUserId());
12989                    mbThreadImpl.setStatusByUserName(mbThread.getStatusByUserName());
12990                    mbThreadImpl.setStatusDate(mbThread.getStatusDate());
12991    
12992                    return mbThreadImpl;
12993            }
12994    
12995            /**
12996             * Returns the message boards thread with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
12997             *
12998             * @param primaryKey the primary key of the message boards thread
12999             * @return the message boards thread
13000             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
13001             */
13002            @Override
13003            public MBThread findByPrimaryKey(Serializable primaryKey)
13004                    throws NoSuchThreadException {
13005                    MBThread mbThread = fetchByPrimaryKey(primaryKey);
13006    
13007                    if (mbThread == null) {
13008                            if (_log.isWarnEnabled()) {
13009                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
13010                            }
13011    
13012                            throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
13013                                    primaryKey);
13014                    }
13015    
13016                    return mbThread;
13017            }
13018    
13019            /**
13020             * Returns the message boards thread with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchThreadException} if it could not be found.
13021             *
13022             * @param threadId the primary key of the message boards thread
13023             * @return the message boards thread
13024             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
13025             */
13026            @Override
13027            public MBThread findByPrimaryKey(long threadId)
13028                    throws NoSuchThreadException {
13029                    return findByPrimaryKey((Serializable)threadId);
13030            }
13031    
13032            /**
13033             * Returns the message boards thread with the primary key or returns <code>null</code> if it could not be found.
13034             *
13035             * @param primaryKey the primary key of the message boards thread
13036             * @return the message boards thread, or <code>null</code> if a message boards thread with the primary key could not be found
13037             */
13038            @Override
13039            public MBThread fetchByPrimaryKey(Serializable primaryKey) {
13040                    MBThread mbThread = (MBThread)EntityCacheUtil.getResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13041                                    MBThreadImpl.class, primaryKey);
13042    
13043                    if (mbThread == _nullMBThread) {
13044                            return null;
13045                    }
13046    
13047                    if (mbThread == null) {
13048                            Session session = null;
13049    
13050                            try {
13051                                    session = openSession();
13052    
13053                                    mbThread = (MBThread)session.get(MBThreadImpl.class, primaryKey);
13054    
13055                                    if (mbThread != null) {
13056                                            cacheResult(mbThread);
13057                                    }
13058                                    else {
13059                                            EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13060                                                    MBThreadImpl.class, primaryKey, _nullMBThread);
13061                                    }
13062                            }
13063                            catch (Exception e) {
13064                                    EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13065                                            MBThreadImpl.class, primaryKey);
13066    
13067                                    throw processException(e);
13068                            }
13069                            finally {
13070                                    closeSession(session);
13071                            }
13072                    }
13073    
13074                    return mbThread;
13075            }
13076    
13077            /**
13078             * Returns the message boards thread with the primary key or returns <code>null</code> if it could not be found.
13079             *
13080             * @param threadId the primary key of the message boards thread
13081             * @return the message boards thread, or <code>null</code> if a message boards thread with the primary key could not be found
13082             */
13083            @Override
13084            public MBThread fetchByPrimaryKey(long threadId) {
13085                    return fetchByPrimaryKey((Serializable)threadId);
13086            }
13087    
13088            @Override
13089            public Map<Serializable, MBThread> fetchByPrimaryKeys(
13090                    Set<Serializable> primaryKeys) {
13091                    if (primaryKeys.isEmpty()) {
13092                            return Collections.emptyMap();
13093                    }
13094    
13095                    Map<Serializable, MBThread> map = new HashMap<Serializable, MBThread>();
13096    
13097                    if (primaryKeys.size() == 1) {
13098                            Iterator<Serializable> iterator = primaryKeys.iterator();
13099    
13100                            Serializable primaryKey = iterator.next();
13101    
13102                            MBThread mbThread = fetchByPrimaryKey(primaryKey);
13103    
13104                            if (mbThread != null) {
13105                                    map.put(primaryKey, mbThread);
13106                            }
13107    
13108                            return map;
13109                    }
13110    
13111                    Set<Serializable> uncachedPrimaryKeys = null;
13112    
13113                    for (Serializable primaryKey : primaryKeys) {
13114                            MBThread mbThread = (MBThread)EntityCacheUtil.getResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13115                                            MBThreadImpl.class, primaryKey);
13116    
13117                            if (mbThread == null) {
13118                                    if (uncachedPrimaryKeys == null) {
13119                                            uncachedPrimaryKeys = new HashSet<Serializable>();
13120                                    }
13121    
13122                                    uncachedPrimaryKeys.add(primaryKey);
13123                            }
13124                            else {
13125                                    map.put(primaryKey, mbThread);
13126                            }
13127                    }
13128    
13129                    if (uncachedPrimaryKeys == null) {
13130                            return map;
13131                    }
13132    
13133                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
13134                                    1);
13135    
13136                    query.append(_SQL_SELECT_MBTHREAD_WHERE_PKS_IN);
13137    
13138                    for (Serializable primaryKey : uncachedPrimaryKeys) {
13139                            query.append(String.valueOf(primaryKey));
13140    
13141                            query.append(StringPool.COMMA);
13142                    }
13143    
13144                    query.setIndex(query.index() - 1);
13145    
13146                    query.append(StringPool.CLOSE_PARENTHESIS);
13147    
13148                    String sql = query.toString();
13149    
13150                    Session session = null;
13151    
13152                    try {
13153                            session = openSession();
13154    
13155                            Query q = session.createQuery(sql);
13156    
13157                            for (MBThread mbThread : (List<MBThread>)q.list()) {
13158                                    map.put(mbThread.getPrimaryKeyObj(), mbThread);
13159    
13160                                    cacheResult(mbThread);
13161    
13162                                    uncachedPrimaryKeys.remove(mbThread.getPrimaryKeyObj());
13163                            }
13164    
13165                            for (Serializable primaryKey : uncachedPrimaryKeys) {
13166                                    EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13167                                            MBThreadImpl.class, primaryKey, _nullMBThread);
13168                            }
13169                    }
13170                    catch (Exception e) {
13171                            throw processException(e);
13172                    }
13173                    finally {
13174                            closeSession(session);
13175                    }
13176    
13177                    return map;
13178            }
13179    
13180            /**
13181             * Returns all the message boards threads.
13182             *
13183             * @return the message boards threads
13184             */
13185            @Override
13186            public List<MBThread> findAll() {
13187                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13188            }
13189    
13190            /**
13191             * Returns a range of all the message boards threads.
13192             *
13193             * <p>
13194             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13195             * </p>
13196             *
13197             * @param start the lower bound of the range of message boards threads
13198             * @param end the upper bound of the range of message boards threads (not inclusive)
13199             * @return the range of message boards threads
13200             */
13201            @Override
13202            public List<MBThread> findAll(int start, int end) {
13203                    return findAll(start, end, null);
13204            }
13205    
13206            /**
13207             * Returns an ordered range of all the message boards threads.
13208             *
13209             * <p>
13210             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13211             * </p>
13212             *
13213             * @param start the lower bound of the range of message boards threads
13214             * @param end the upper bound of the range of message boards threads (not inclusive)
13215             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13216             * @return the ordered range of message boards threads
13217             */
13218            @Override
13219            public List<MBThread> findAll(int start, int end,
13220                    OrderByComparator<MBThread> orderByComparator) {
13221                    boolean pagination = true;
13222                    FinderPath finderPath = null;
13223                    Object[] finderArgs = null;
13224    
13225                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13226                                    (orderByComparator == null)) {
13227                            pagination = false;
13228                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
13229                            finderArgs = FINDER_ARGS_EMPTY;
13230                    }
13231                    else {
13232                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
13233                            finderArgs = new Object[] { start, end, orderByComparator };
13234                    }
13235    
13236                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
13237                                    finderArgs, this);
13238    
13239                    if (list == null) {
13240                            StringBundler query = null;
13241                            String sql = null;
13242    
13243                            if (orderByComparator != null) {
13244                                    query = new StringBundler(2 +
13245                                                    (orderByComparator.getOrderByFields().length * 3));
13246    
13247                                    query.append(_SQL_SELECT_MBTHREAD);
13248    
13249                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13250                                            orderByComparator);
13251    
13252                                    sql = query.toString();
13253                            }
13254                            else {
13255                                    sql = _SQL_SELECT_MBTHREAD;
13256    
13257                                    if (pagination) {
13258                                            sql = sql.concat(MBThreadModelImpl.ORDER_BY_JPQL);
13259                                    }
13260                            }
13261    
13262                            Session session = null;
13263    
13264                            try {
13265                                    session = openSession();
13266    
13267                                    Query q = session.createQuery(sql);
13268    
13269                                    if (!pagination) {
13270                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
13271                                                            start, end, false);
13272    
13273                                            Collections.sort(list);
13274    
13275                                            list = Collections.unmodifiableList(list);
13276                                    }
13277                                    else {
13278                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
13279                                                            start, end);
13280                                    }
13281    
13282                                    cacheResult(list);
13283    
13284                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13285                            }
13286                            catch (Exception e) {
13287                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13288    
13289                                    throw processException(e);
13290                            }
13291                            finally {
13292                                    closeSession(session);
13293                            }
13294                    }
13295    
13296                    return list;
13297            }
13298    
13299            /**
13300             * Removes all the message boards threads from the database.
13301             *
13302             */
13303            @Override
13304            public void removeAll() {
13305                    for (MBThread mbThread : findAll()) {
13306                            remove(mbThread);
13307                    }
13308            }
13309    
13310            /**
13311             * Returns the number of message boards threads.
13312             *
13313             * @return the number of message boards threads
13314             */
13315            @Override
13316            public int countAll() {
13317                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
13318                                    FINDER_ARGS_EMPTY, this);
13319    
13320                    if (count == null) {
13321                            Session session = null;
13322    
13323                            try {
13324                                    session = openSession();
13325    
13326                                    Query q = session.createQuery(_SQL_COUNT_MBTHREAD);
13327    
13328                                    count = (Long)q.uniqueResult();
13329    
13330                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
13331                                            FINDER_ARGS_EMPTY, count);
13332                            }
13333                            catch (Exception e) {
13334                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
13335                                            FINDER_ARGS_EMPTY);
13336    
13337                                    throw processException(e);
13338                            }
13339                            finally {
13340                                    closeSession(session);
13341                            }
13342                    }
13343    
13344                    return count.intValue();
13345            }
13346    
13347            @Override
13348            protected Set<String> getBadColumnNames() {
13349                    return _badColumnNames;
13350            }
13351    
13352            /**
13353             * Initializes the message boards thread persistence.
13354             */
13355            public void afterPropertiesSet() {
13356            }
13357    
13358            public void destroy() {
13359                    EntityCacheUtil.removeCache(MBThreadImpl.class.getName());
13360                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
13361                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
13362                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
13363            }
13364    
13365            private static final String _SQL_SELECT_MBTHREAD = "SELECT mbThread FROM MBThread mbThread";
13366            private static final String _SQL_SELECT_MBTHREAD_WHERE_PKS_IN = "SELECT mbThread FROM MBThread mbThread WHERE threadId IN (";
13367            private static final String _SQL_SELECT_MBTHREAD_WHERE = "SELECT mbThread FROM MBThread mbThread WHERE ";
13368            private static final String _SQL_COUNT_MBTHREAD = "SELECT COUNT(mbThread) FROM MBThread mbThread";
13369            private static final String _SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(mbThread) FROM MBThread mbThread WHERE ";
13370            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbThread.threadId";
13371            private static final String _FILTER_SQL_SELECT_MBTHREAD_WHERE = "SELECT DISTINCT {mbThread.*} FROM MBThread mbThread WHERE ";
13372            private static final String _FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1 =
13373                    "SELECT {MBThread.*} FROM (SELECT DISTINCT mbThread.threadId FROM MBThread mbThread WHERE ";
13374            private static final String _FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2 =
13375                    ") TEMP_TABLE INNER JOIN MBThread ON TEMP_TABLE.threadId = MBThread.threadId";
13376            private static final String _FILTER_SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(DISTINCT mbThread.threadId) AS COUNT_VALUE FROM MBThread mbThread WHERE ";
13377            private static final String _FILTER_ENTITY_ALIAS = "mbThread";
13378            private static final String _FILTER_ENTITY_TABLE = "MBThread";
13379            private static final String _ORDER_BY_ENTITY_ALIAS = "mbThread.";
13380            private static final String _ORDER_BY_ENTITY_TABLE = "MBThread.";
13381            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBThread exists with the primary key ";
13382            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBThread exists with the key {";
13383            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
13384            private static final Log _log = LogFactoryUtil.getLog(MBThreadPersistenceImpl.class);
13385            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
13386                                    "uuid"
13387                            });
13388            private static final MBThread _nullMBThread = new MBThreadImpl() {
13389                            @Override
13390                            public Object clone() {
13391                                    return this;
13392                            }
13393    
13394                            @Override
13395                            public CacheModel<MBThread> toCacheModel() {
13396                                    return _nullMBThreadCacheModel;
13397                            }
13398                    };
13399    
13400            private static final CacheModel<MBThread> _nullMBThreadCacheModel = new CacheModel<MBThread>() {
13401                            @Override
13402                            public MBThread toEntityModel() {
13403                                    return _nullMBThread;
13404                            }
13405                    };
13406    }