001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.SQLQuery;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.ArrayUtil;
030    import com.liferay.portal.kernel.util.CalendarUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.SetUtil;
035    import com.liferay.portal.kernel.util.StringBundler;
036    import com.liferay.portal.kernel.util.StringPool;
037    import com.liferay.portal.kernel.util.StringUtil;
038    import com.liferay.portal.kernel.util.UnmodifiableList;
039    import com.liferay.portal.kernel.util.Validator;
040    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
041    import com.liferay.portal.model.CacheModel;
042    import com.liferay.portal.model.ModelListener;
043    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
044    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045    
046    import com.liferay.portlet.messageboards.NoSuchThreadException;
047    import com.liferay.portlet.messageboards.model.MBThread;
048    import com.liferay.portlet.messageboards.model.impl.MBThreadImpl;
049    import com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl;
050    
051    import java.io.Serializable;
052    
053    import java.util.ArrayList;
054    import java.util.Collections;
055    import java.util.Date;
056    import java.util.List;
057    import java.util.Set;
058    
059    /**
060     * The persistence implementation for the message boards thread service.
061     *
062     * <p>
063     * Caching information and settings can be found in <code>portal.properties</code>
064     * </p>
065     *
066     * @author Brian Wing Shun Chan
067     * @see MBThreadPersistence
068     * @see MBThreadUtil
069     * @generated
070     */
071    public class MBThreadPersistenceImpl extends BasePersistenceImpl<MBThread>
072            implements MBThreadPersistence {
073            /*
074             * NOTE FOR DEVELOPERS:
075             *
076             * 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.
077             */
078            public static final String FINDER_CLASS_NAME_ENTITY = MBThreadImpl.class.getName();
079            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List1";
081            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082                    ".List2";
083            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
084                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
086            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
087                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
090                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
092            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
093                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
094                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
095                            new String[] {
096                                    String.class.getName(),
097                                    
098                            Integer.class.getName(), Integer.class.getName(),
099                                    OrderByComparator.class.getName()
100                            });
101            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
102                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
104                            new String[] { String.class.getName() },
105                            MBThreadModelImpl.UUID_COLUMN_BITMASK |
106                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
107                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
109                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
111                            new String[] { String.class.getName() });
112    
113            /**
114             * Returns all the message boards threads where uuid = &#63;.
115             *
116             * @param uuid the uuid
117             * @return the matching message boards threads
118             * @throws SystemException if a system exception occurred
119             */
120            public List<MBThread> findByUuid(String uuid) throws SystemException {
121                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
122            }
123    
124            /**
125             * Returns a range of all the message boards threads where uuid = &#63;.
126             *
127             * <p>
128             * 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.
129             * </p>
130             *
131             * @param uuid the uuid
132             * @param start the lower bound of the range of message boards threads
133             * @param end the upper bound of the range of message boards threads (not inclusive)
134             * @return the range of matching message boards threads
135             * @throws SystemException if a system exception occurred
136             */
137            public List<MBThread> findByUuid(String uuid, int start, int end)
138                    throws SystemException {
139                    return findByUuid(uuid, start, end, null);
140            }
141    
142            /**
143             * Returns an ordered range of all the message boards threads where uuid = &#63;.
144             *
145             * <p>
146             * 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.
147             * </p>
148             *
149             * @param uuid the uuid
150             * @param start the lower bound of the range of message boards threads
151             * @param end the upper bound of the range of message boards threads (not inclusive)
152             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
153             * @return the ordered range of matching message boards threads
154             * @throws SystemException if a system exception occurred
155             */
156            public List<MBThread> findByUuid(String uuid, int start, int end,
157                    OrderByComparator orderByComparator) throws SystemException {
158                    boolean pagination = true;
159                    FinderPath finderPath = null;
160                    Object[] finderArgs = null;
161    
162                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
163                                    (orderByComparator == null)) {
164                            pagination = false;
165                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
166                            finderArgs = new Object[] { uuid };
167                    }
168                    else {
169                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
170                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
171                    }
172    
173                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
174                                    finderArgs, this);
175    
176                    if ((list != null) && !list.isEmpty()) {
177                            for (MBThread mbThread : list) {
178                                    if (!Validator.equals(uuid, mbThread.getUuid())) {
179                                            list = null;
180    
181                                            break;
182                                    }
183                            }
184                    }
185    
186                    if (list == null) {
187                            StringBundler query = null;
188    
189                            if (orderByComparator != null) {
190                                    query = new StringBundler(3 +
191                                                    (orderByComparator.getOrderByFields().length * 3));
192                            }
193                            else {
194                                    query = new StringBundler(3);
195                            }
196    
197                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
198    
199                            boolean bindUuid = false;
200    
201                            if (uuid == null) {
202                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
203                            }
204                            else if (uuid.equals(StringPool.BLANK)) {
205                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
206                            }
207                            else {
208                                    bindUuid = true;
209    
210                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
211                            }
212    
213                            if (orderByComparator != null) {
214                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
215                                            orderByComparator);
216                            }
217                            else
218                             if (pagination) {
219                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
220                            }
221    
222                            String sql = query.toString();
223    
224                            Session session = null;
225    
226                            try {
227                                    session = openSession();
228    
229                                    Query q = session.createQuery(sql);
230    
231                                    QueryPos qPos = QueryPos.getInstance(q);
232    
233                                    if (bindUuid) {
234                                            qPos.add(uuid);
235                                    }
236    
237                                    if (!pagination) {
238                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
239                                                            start, end, false);
240    
241                                            Collections.sort(list);
242    
243                                            list = new UnmodifiableList<MBThread>(list);
244                                    }
245                                    else {
246                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
247                                                            start, end);
248                                    }
249    
250                                    cacheResult(list);
251    
252                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
253                            }
254                            catch (Exception e) {
255                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
256    
257                                    throw processException(e);
258                            }
259                            finally {
260                                    closeSession(session);
261                            }
262                    }
263    
264                    return list;
265            }
266    
267            /**
268             * Returns the first message boards thread in the ordered set where uuid = &#63;.
269             *
270             * @param uuid the uuid
271             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
272             * @return the first matching message boards thread
273             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
274             * @throws SystemException if a system exception occurred
275             */
276            public MBThread findByUuid_First(String uuid,
277                    OrderByComparator orderByComparator)
278                    throws NoSuchThreadException, SystemException {
279                    MBThread mbThread = fetchByUuid_First(uuid, orderByComparator);
280    
281                    if (mbThread != null) {
282                            return mbThread;
283                    }
284    
285                    StringBundler msg = new StringBundler(4);
286    
287                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
288    
289                    msg.append("uuid=");
290                    msg.append(uuid);
291    
292                    msg.append(StringPool.CLOSE_CURLY_BRACE);
293    
294                    throw new NoSuchThreadException(msg.toString());
295            }
296    
297            /**
298             * Returns the first message boards thread in the ordered set where uuid = &#63;.
299             *
300             * @param uuid the uuid
301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
302             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
303             * @throws SystemException if a system exception occurred
304             */
305            public MBThread fetchByUuid_First(String uuid,
306                    OrderByComparator orderByComparator) throws SystemException {
307                    List<MBThread> list = findByUuid(uuid, 0, 1, orderByComparator);
308    
309                    if (!list.isEmpty()) {
310                            return list.get(0);
311                    }
312    
313                    return null;
314            }
315    
316            /**
317             * Returns the last message boards thread in the ordered set where uuid = &#63;.
318             *
319             * @param uuid the uuid
320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
321             * @return the last matching message boards thread
322             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
323             * @throws SystemException if a system exception occurred
324             */
325            public MBThread findByUuid_Last(String uuid,
326                    OrderByComparator orderByComparator)
327                    throws NoSuchThreadException, SystemException {
328                    MBThread mbThread = fetchByUuid_Last(uuid, orderByComparator);
329    
330                    if (mbThread != null) {
331                            return mbThread;
332                    }
333    
334                    StringBundler msg = new StringBundler(4);
335    
336                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
337    
338                    msg.append("uuid=");
339                    msg.append(uuid);
340    
341                    msg.append(StringPool.CLOSE_CURLY_BRACE);
342    
343                    throw new NoSuchThreadException(msg.toString());
344            }
345    
346            /**
347             * Returns the last message boards thread in the ordered set where uuid = &#63;.
348             *
349             * @param uuid the uuid
350             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
351             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
352             * @throws SystemException if a system exception occurred
353             */
354            public MBThread fetchByUuid_Last(String uuid,
355                    OrderByComparator orderByComparator) throws SystemException {
356                    int count = countByUuid(uuid);
357    
358                    List<MBThread> list = findByUuid(uuid, count - 1, count,
359                                    orderByComparator);
360    
361                    if (!list.isEmpty()) {
362                            return list.get(0);
363                    }
364    
365                    return null;
366            }
367    
368            /**
369             * Returns the message boards threads before and after the current message boards thread in the ordered set where uuid = &#63;.
370             *
371             * @param threadId the primary key of the current message boards thread
372             * @param uuid the uuid
373             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
374             * @return the previous, current, and next message boards thread
375             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
376             * @throws SystemException if a system exception occurred
377             */
378            public MBThread[] findByUuid_PrevAndNext(long threadId, String uuid,
379                    OrderByComparator orderByComparator)
380                    throws NoSuchThreadException, SystemException {
381                    MBThread mbThread = findByPrimaryKey(threadId);
382    
383                    Session session = null;
384    
385                    try {
386                            session = openSession();
387    
388                            MBThread[] array = new MBThreadImpl[3];
389    
390                            array[0] = getByUuid_PrevAndNext(session, mbThread, uuid,
391                                            orderByComparator, true);
392    
393                            array[1] = mbThread;
394    
395                            array[2] = getByUuid_PrevAndNext(session, mbThread, uuid,
396                                            orderByComparator, false);
397    
398                            return array;
399                    }
400                    catch (Exception e) {
401                            throw processException(e);
402                    }
403                    finally {
404                            closeSession(session);
405                    }
406            }
407    
408            protected MBThread getByUuid_PrevAndNext(Session session,
409                    MBThread mbThread, String uuid, OrderByComparator orderByComparator,
410                    boolean previous) {
411                    StringBundler query = null;
412    
413                    if (orderByComparator != null) {
414                            query = new StringBundler(6 +
415                                            (orderByComparator.getOrderByFields().length * 6));
416                    }
417                    else {
418                            query = new StringBundler(3);
419                    }
420    
421                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
422    
423                    boolean bindUuid = false;
424    
425                    if (uuid == null) {
426                            query.append(_FINDER_COLUMN_UUID_UUID_1);
427                    }
428                    else if (uuid.equals(StringPool.BLANK)) {
429                            query.append(_FINDER_COLUMN_UUID_UUID_3);
430                    }
431                    else {
432                            bindUuid = true;
433    
434                            query.append(_FINDER_COLUMN_UUID_UUID_2);
435                    }
436    
437                    if (orderByComparator != null) {
438                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
439    
440                            if (orderByConditionFields.length > 0) {
441                                    query.append(WHERE_AND);
442                            }
443    
444                            for (int i = 0; i < orderByConditionFields.length; i++) {
445                                    query.append(_ORDER_BY_ENTITY_ALIAS);
446                                    query.append(orderByConditionFields[i]);
447    
448                                    if ((i + 1) < orderByConditionFields.length) {
449                                            if (orderByComparator.isAscending() ^ previous) {
450                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
451                                            }
452                                            else {
453                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
454                                            }
455                                    }
456                                    else {
457                                            if (orderByComparator.isAscending() ^ previous) {
458                                                    query.append(WHERE_GREATER_THAN);
459                                            }
460                                            else {
461                                                    query.append(WHERE_LESSER_THAN);
462                                            }
463                                    }
464                            }
465    
466                            query.append(ORDER_BY_CLAUSE);
467    
468                            String[] orderByFields = orderByComparator.getOrderByFields();
469    
470                            for (int i = 0; i < orderByFields.length; i++) {
471                                    query.append(_ORDER_BY_ENTITY_ALIAS);
472                                    query.append(orderByFields[i]);
473    
474                                    if ((i + 1) < orderByFields.length) {
475                                            if (orderByComparator.isAscending() ^ previous) {
476                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
477                                            }
478                                            else {
479                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
480                                            }
481                                    }
482                                    else {
483                                            if (orderByComparator.isAscending() ^ previous) {
484                                                    query.append(ORDER_BY_ASC);
485                                            }
486                                            else {
487                                                    query.append(ORDER_BY_DESC);
488                                            }
489                                    }
490                            }
491                    }
492                    else {
493                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
494                    }
495    
496                    String sql = query.toString();
497    
498                    Query q = session.createQuery(sql);
499    
500                    q.setFirstResult(0);
501                    q.setMaxResults(2);
502    
503                    QueryPos qPos = QueryPos.getInstance(q);
504    
505                    if (bindUuid) {
506                            qPos.add(uuid);
507                    }
508    
509                    if (orderByComparator != null) {
510                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
511    
512                            for (Object value : values) {
513                                    qPos.add(value);
514                            }
515                    }
516    
517                    List<MBThread> list = q.list();
518    
519                    if (list.size() == 2) {
520                            return list.get(1);
521                    }
522                    else {
523                            return null;
524                    }
525            }
526    
527            /**
528             * Removes all the message boards threads where uuid = &#63; from the database.
529             *
530             * @param uuid the uuid
531             * @throws SystemException if a system exception occurred
532             */
533            public void removeByUuid(String uuid) throws SystemException {
534                    for (MBThread mbThread : findByUuid(uuid, QueryUtil.ALL_POS,
535                                    QueryUtil.ALL_POS, null)) {
536                            remove(mbThread);
537                    }
538            }
539    
540            /**
541             * Returns the number of message boards threads where uuid = &#63;.
542             *
543             * @param uuid the uuid
544             * @return the number of matching message boards threads
545             * @throws SystemException if a system exception occurred
546             */
547            public int countByUuid(String uuid) throws SystemException {
548                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
549    
550                    Object[] finderArgs = new Object[] { uuid };
551    
552                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
553                                    this);
554    
555                    if (count == null) {
556                            StringBundler query = new StringBundler(2);
557    
558                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
559    
560                            boolean bindUuid = false;
561    
562                            if (uuid == null) {
563                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
564                            }
565                            else if (uuid.equals(StringPool.BLANK)) {
566                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
567                            }
568                            else {
569                                    bindUuid = true;
570    
571                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
572                            }
573    
574                            String sql = query.toString();
575    
576                            Session session = null;
577    
578                            try {
579                                    session = openSession();
580    
581                                    Query q = session.createQuery(sql);
582    
583                                    QueryPos qPos = QueryPos.getInstance(q);
584    
585                                    if (bindUuid) {
586                                            qPos.add(uuid);
587                                    }
588    
589                                    count = (Long)q.uniqueResult();
590    
591                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
592                            }
593                            catch (Exception e) {
594                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
595    
596                                    throw processException(e);
597                            }
598                            finally {
599                                    closeSession(session);
600                            }
601                    }
602    
603                    return count.intValue();
604            }
605    
606            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbThread.uuid IS NULL";
607            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbThread.uuid = ?";
608            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbThread.uuid IS NULL OR mbThread.uuid = '')";
609            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
610                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
611                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
612                            new String[] { String.class.getName(), Long.class.getName() },
613                            MBThreadModelImpl.UUID_COLUMN_BITMASK |
614                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK);
615            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
616                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
617                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
618                            new String[] { String.class.getName(), Long.class.getName() });
619    
620            /**
621             * 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.
622             *
623             * @param uuid the uuid
624             * @param groupId the group ID
625             * @return the matching message boards thread
626             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
627             * @throws SystemException if a system exception occurred
628             */
629            public MBThread findByUUID_G(String uuid, long groupId)
630                    throws NoSuchThreadException, SystemException {
631                    MBThread mbThread = fetchByUUID_G(uuid, groupId);
632    
633                    if (mbThread == null) {
634                            StringBundler msg = new StringBundler(6);
635    
636                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
637    
638                            msg.append("uuid=");
639                            msg.append(uuid);
640    
641                            msg.append(", groupId=");
642                            msg.append(groupId);
643    
644                            msg.append(StringPool.CLOSE_CURLY_BRACE);
645    
646                            if (_log.isWarnEnabled()) {
647                                    _log.warn(msg.toString());
648                            }
649    
650                            throw new NoSuchThreadException(msg.toString());
651                    }
652    
653                    return mbThread;
654            }
655    
656            /**
657             * 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.
658             *
659             * @param uuid the uuid
660             * @param groupId the group ID
661             * @return the matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
662             * @throws SystemException if a system exception occurred
663             */
664            public MBThread fetchByUUID_G(String uuid, long groupId)
665                    throws SystemException {
666                    return fetchByUUID_G(uuid, groupId, true);
667            }
668    
669            /**
670             * 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.
671             *
672             * @param uuid the uuid
673             * @param groupId the group ID
674             * @param retrieveFromCache whether to use the finder cache
675             * @return the matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
676             * @throws SystemException if a system exception occurred
677             */
678            public MBThread fetchByUUID_G(String uuid, long groupId,
679                    boolean retrieveFromCache) throws SystemException {
680                    Object[] finderArgs = new Object[] { uuid, groupId };
681    
682                    Object result = null;
683    
684                    if (retrieveFromCache) {
685                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
686                                            finderArgs, this);
687                    }
688    
689                    if (result instanceof MBThread) {
690                            MBThread mbThread = (MBThread)result;
691    
692                            if (!Validator.equals(uuid, mbThread.getUuid()) ||
693                                            (groupId != mbThread.getGroupId())) {
694                                    result = null;
695                            }
696                    }
697    
698                    if (result == null) {
699                            StringBundler query = new StringBundler(4);
700    
701                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
702    
703                            boolean bindUuid = false;
704    
705                            if (uuid == null) {
706                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
707                            }
708                            else if (uuid.equals(StringPool.BLANK)) {
709                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
710                            }
711                            else {
712                                    bindUuid = true;
713    
714                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
715                            }
716    
717                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
718    
719                            String sql = query.toString();
720    
721                            Session session = null;
722    
723                            try {
724                                    session = openSession();
725    
726                                    Query q = session.createQuery(sql);
727    
728                                    QueryPos qPos = QueryPos.getInstance(q);
729    
730                                    if (bindUuid) {
731                                            qPos.add(uuid);
732                                    }
733    
734                                    qPos.add(groupId);
735    
736                                    List<MBThread> list = q.list();
737    
738                                    if (list.isEmpty()) {
739                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
740                                                    finderArgs, list);
741                                    }
742                                    else {
743                                            MBThread mbThread = list.get(0);
744    
745                                            result = mbThread;
746    
747                                            cacheResult(mbThread);
748    
749                                            if ((mbThread.getUuid() == null) ||
750                                                            !mbThread.getUuid().equals(uuid) ||
751                                                            (mbThread.getGroupId() != groupId)) {
752                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
753                                                            finderArgs, mbThread);
754                                            }
755                                    }
756                            }
757                            catch (Exception e) {
758                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
759                                            finderArgs);
760    
761                                    throw processException(e);
762                            }
763                            finally {
764                                    closeSession(session);
765                            }
766                    }
767    
768                    if (result instanceof List<?>) {
769                            return null;
770                    }
771                    else {
772                            return (MBThread)result;
773                    }
774            }
775    
776            /**
777             * Removes the message boards thread where uuid = &#63; and groupId = &#63; from the database.
778             *
779             * @param uuid the uuid
780             * @param groupId the group ID
781             * @return the message boards thread that was removed
782             * @throws SystemException if a system exception occurred
783             */
784            public MBThread removeByUUID_G(String uuid, long groupId)
785                    throws NoSuchThreadException, SystemException {
786                    MBThread mbThread = findByUUID_G(uuid, groupId);
787    
788                    return remove(mbThread);
789            }
790    
791            /**
792             * Returns the number of message boards threads where uuid = &#63; and groupId = &#63;.
793             *
794             * @param uuid the uuid
795             * @param groupId the group ID
796             * @return the number of matching message boards threads
797             * @throws SystemException if a system exception occurred
798             */
799            public int countByUUID_G(String uuid, long groupId)
800                    throws SystemException {
801                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
802    
803                    Object[] finderArgs = new Object[] { uuid, groupId };
804    
805                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
806                                    this);
807    
808                    if (count == null) {
809                            StringBundler query = new StringBundler(3);
810    
811                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
812    
813                            boolean bindUuid = false;
814    
815                            if (uuid == null) {
816                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
817                            }
818                            else if (uuid.equals(StringPool.BLANK)) {
819                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
820                            }
821                            else {
822                                    bindUuid = true;
823    
824                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
825                            }
826    
827                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
828    
829                            String sql = query.toString();
830    
831                            Session session = null;
832    
833                            try {
834                                    session = openSession();
835    
836                                    Query q = session.createQuery(sql);
837    
838                                    QueryPos qPos = QueryPos.getInstance(q);
839    
840                                    if (bindUuid) {
841                                            qPos.add(uuid);
842                                    }
843    
844                                    qPos.add(groupId);
845    
846                                    count = (Long)q.uniqueResult();
847    
848                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
849                            }
850                            catch (Exception e) {
851                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
852    
853                                    throw processException(e);
854                            }
855                            finally {
856                                    closeSession(session);
857                            }
858                    }
859    
860                    return count.intValue();
861            }
862    
863            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbThread.uuid IS NULL AND ";
864            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbThread.uuid = ? AND ";
865            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbThread.uuid IS NULL OR mbThread.uuid = '') AND ";
866            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbThread.groupId = ?";
867            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
868                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
869                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
870                            new String[] {
871                                    String.class.getName(), Long.class.getName(),
872                                    
873                            Integer.class.getName(), Integer.class.getName(),
874                                    OrderByComparator.class.getName()
875                            });
876            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
877                    new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
878                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
879                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
880                            new String[] { String.class.getName(), Long.class.getName() },
881                            MBThreadModelImpl.UUID_COLUMN_BITMASK |
882                            MBThreadModelImpl.COMPANYID_COLUMN_BITMASK |
883                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
884                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
885            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
886                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
887                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
888                            new String[] { String.class.getName(), Long.class.getName() });
889    
890            /**
891             * Returns all the message boards threads where uuid = &#63; and companyId = &#63;.
892             *
893             * @param uuid the uuid
894             * @param companyId the company ID
895             * @return the matching message boards threads
896             * @throws SystemException if a system exception occurred
897             */
898            public List<MBThread> findByUuid_C(String uuid, long companyId)
899                    throws SystemException {
900                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
901                            QueryUtil.ALL_POS, null);
902            }
903    
904            /**
905             * Returns a range of all the message boards threads where uuid = &#63; and companyId = &#63;.
906             *
907             * <p>
908             * 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.
909             * </p>
910             *
911             * @param uuid the uuid
912             * @param companyId the company ID
913             * @param start the lower bound of the range of message boards threads
914             * @param end the upper bound of the range of message boards threads (not inclusive)
915             * @return the range of matching message boards threads
916             * @throws SystemException if a system exception occurred
917             */
918            public List<MBThread> findByUuid_C(String uuid, long companyId, int start,
919                    int end) throws SystemException {
920                    return findByUuid_C(uuid, companyId, start, end, null);
921            }
922    
923            /**
924             * Returns an ordered range of all the message boards threads where uuid = &#63; and companyId = &#63;.
925             *
926             * <p>
927             * 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.
928             * </p>
929             *
930             * @param uuid the uuid
931             * @param companyId the company ID
932             * @param start the lower bound of the range of message boards threads
933             * @param end the upper bound of the range of message boards threads (not inclusive)
934             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
935             * @return the ordered range of matching message boards threads
936             * @throws SystemException if a system exception occurred
937             */
938            public List<MBThread> findByUuid_C(String uuid, long companyId, int start,
939                    int end, OrderByComparator orderByComparator) throws SystemException {
940                    boolean pagination = true;
941                    FinderPath finderPath = null;
942                    Object[] finderArgs = null;
943    
944                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
945                                    (orderByComparator == null)) {
946                            pagination = false;
947                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
948                            finderArgs = new Object[] { uuid, companyId };
949                    }
950                    else {
951                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
952                            finderArgs = new Object[] {
953                                            uuid, companyId,
954                                            
955                                            start, end, orderByComparator
956                                    };
957                    }
958    
959                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
960                                    finderArgs, this);
961    
962                    if ((list != null) && !list.isEmpty()) {
963                            for (MBThread mbThread : list) {
964                                    if (!Validator.equals(uuid, mbThread.getUuid()) ||
965                                                    (companyId != mbThread.getCompanyId())) {
966                                            list = null;
967    
968                                            break;
969                                    }
970                            }
971                    }
972    
973                    if (list == null) {
974                            StringBundler query = null;
975    
976                            if (orderByComparator != null) {
977                                    query = new StringBundler(4 +
978                                                    (orderByComparator.getOrderByFields().length * 3));
979                            }
980                            else {
981                                    query = new StringBundler(4);
982                            }
983    
984                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
985    
986                            boolean bindUuid = false;
987    
988                            if (uuid == null) {
989                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
990                            }
991                            else if (uuid.equals(StringPool.BLANK)) {
992                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
993                            }
994                            else {
995                                    bindUuid = true;
996    
997                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
998                            }
999    
1000                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1001    
1002                            if (orderByComparator != null) {
1003                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1004                                            orderByComparator);
1005                            }
1006                            else
1007                             if (pagination) {
1008                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1009                            }
1010    
1011                            String sql = query.toString();
1012    
1013                            Session session = null;
1014    
1015                            try {
1016                                    session = openSession();
1017    
1018                                    Query q = session.createQuery(sql);
1019    
1020                                    QueryPos qPos = QueryPos.getInstance(q);
1021    
1022                                    if (bindUuid) {
1023                                            qPos.add(uuid);
1024                                    }
1025    
1026                                    qPos.add(companyId);
1027    
1028                                    if (!pagination) {
1029                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1030                                                            start, end, false);
1031    
1032                                            Collections.sort(list);
1033    
1034                                            list = new UnmodifiableList<MBThread>(list);
1035                                    }
1036                                    else {
1037                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1038                                                            start, end);
1039                                    }
1040    
1041                                    cacheResult(list);
1042    
1043                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1044                            }
1045                            catch (Exception e) {
1046                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1047    
1048                                    throw processException(e);
1049                            }
1050                            finally {
1051                                    closeSession(session);
1052                            }
1053                    }
1054    
1055                    return list;
1056            }
1057    
1058            /**
1059             * Returns the first message boards thread in the ordered set where uuid = &#63; and companyId = &#63;.
1060             *
1061             * @param uuid the uuid
1062             * @param companyId the company ID
1063             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1064             * @return the first matching message boards thread
1065             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
1066             * @throws SystemException if a system exception occurred
1067             */
1068            public MBThread findByUuid_C_First(String uuid, long companyId,
1069                    OrderByComparator orderByComparator)
1070                    throws NoSuchThreadException, SystemException {
1071                    MBThread mbThread = fetchByUuid_C_First(uuid, companyId,
1072                                    orderByComparator);
1073    
1074                    if (mbThread != null) {
1075                            return mbThread;
1076                    }
1077    
1078                    StringBundler msg = new StringBundler(6);
1079    
1080                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1081    
1082                    msg.append("uuid=");
1083                    msg.append(uuid);
1084    
1085                    msg.append(", companyId=");
1086                    msg.append(companyId);
1087    
1088                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1089    
1090                    throw new NoSuchThreadException(msg.toString());
1091            }
1092    
1093            /**
1094             * Returns the first message boards thread in the ordered set where uuid = &#63; and companyId = &#63;.
1095             *
1096             * @param uuid the uuid
1097             * @param companyId the company ID
1098             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1099             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1100             * @throws SystemException if a system exception occurred
1101             */
1102            public MBThread fetchByUuid_C_First(String uuid, long companyId,
1103                    OrderByComparator orderByComparator) throws SystemException {
1104                    List<MBThread> list = findByUuid_C(uuid, companyId, 0, 1,
1105                                    orderByComparator);
1106    
1107                    if (!list.isEmpty()) {
1108                            return list.get(0);
1109                    }
1110    
1111                    return null;
1112            }
1113    
1114            /**
1115             * Returns the last message boards thread in the ordered set where uuid = &#63; and companyId = &#63;.
1116             *
1117             * @param uuid the uuid
1118             * @param companyId the company ID
1119             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1120             * @return the last matching message boards thread
1121             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
1122             * @throws SystemException if a system exception occurred
1123             */
1124            public MBThread findByUuid_C_Last(String uuid, long companyId,
1125                    OrderByComparator orderByComparator)
1126                    throws NoSuchThreadException, SystemException {
1127                    MBThread mbThread = fetchByUuid_C_Last(uuid, companyId,
1128                                    orderByComparator);
1129    
1130                    if (mbThread != null) {
1131                            return mbThread;
1132                    }
1133    
1134                    StringBundler msg = new StringBundler(6);
1135    
1136                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1137    
1138                    msg.append("uuid=");
1139                    msg.append(uuid);
1140    
1141                    msg.append(", companyId=");
1142                    msg.append(companyId);
1143    
1144                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1145    
1146                    throw new NoSuchThreadException(msg.toString());
1147            }
1148    
1149            /**
1150             * Returns the last message boards thread in the ordered set where uuid = &#63; and companyId = &#63;.
1151             *
1152             * @param uuid the uuid
1153             * @param companyId the company ID
1154             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1155             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1156             * @throws SystemException if a system exception occurred
1157             */
1158            public MBThread fetchByUuid_C_Last(String uuid, long companyId,
1159                    OrderByComparator orderByComparator) throws SystemException {
1160                    int count = countByUuid_C(uuid, companyId);
1161    
1162                    List<MBThread> list = findByUuid_C(uuid, companyId, count - 1, count,
1163                                    orderByComparator);
1164    
1165                    if (!list.isEmpty()) {
1166                            return list.get(0);
1167                    }
1168    
1169                    return null;
1170            }
1171    
1172            /**
1173             * Returns the message boards threads before and after the current message boards thread in the ordered set where uuid = &#63; and companyId = &#63;.
1174             *
1175             * @param threadId the primary key of the current message boards thread
1176             * @param uuid the uuid
1177             * @param companyId the company ID
1178             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1179             * @return the previous, current, and next message boards thread
1180             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
1181             * @throws SystemException if a system exception occurred
1182             */
1183            public MBThread[] findByUuid_C_PrevAndNext(long threadId, String uuid,
1184                    long companyId, OrderByComparator orderByComparator)
1185                    throws NoSuchThreadException, SystemException {
1186                    MBThread mbThread = findByPrimaryKey(threadId);
1187    
1188                    Session session = null;
1189    
1190                    try {
1191                            session = openSession();
1192    
1193                            MBThread[] array = new MBThreadImpl[3];
1194    
1195                            array[0] = getByUuid_C_PrevAndNext(session, mbThread, uuid,
1196                                            companyId, orderByComparator, true);
1197    
1198                            array[1] = mbThread;
1199    
1200                            array[2] = getByUuid_C_PrevAndNext(session, mbThread, uuid,
1201                                            companyId, orderByComparator, false);
1202    
1203                            return array;
1204                    }
1205                    catch (Exception e) {
1206                            throw processException(e);
1207                    }
1208                    finally {
1209                            closeSession(session);
1210                    }
1211            }
1212    
1213            protected MBThread getByUuid_C_PrevAndNext(Session session,
1214                    MBThread mbThread, String uuid, long companyId,
1215                    OrderByComparator orderByComparator, boolean previous) {
1216                    StringBundler query = null;
1217    
1218                    if (orderByComparator != null) {
1219                            query = new StringBundler(6 +
1220                                            (orderByComparator.getOrderByFields().length * 6));
1221                    }
1222                    else {
1223                            query = new StringBundler(3);
1224                    }
1225    
1226                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1227    
1228                    boolean bindUuid = false;
1229    
1230                    if (uuid == null) {
1231                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1232                    }
1233                    else if (uuid.equals(StringPool.BLANK)) {
1234                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1235                    }
1236                    else {
1237                            bindUuid = true;
1238    
1239                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1240                    }
1241    
1242                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1243    
1244                    if (orderByComparator != null) {
1245                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1246    
1247                            if (orderByConditionFields.length > 0) {
1248                                    query.append(WHERE_AND);
1249                            }
1250    
1251                            for (int i = 0; i < orderByConditionFields.length; i++) {
1252                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1253                                    query.append(orderByConditionFields[i]);
1254    
1255                                    if ((i + 1) < orderByConditionFields.length) {
1256                                            if (orderByComparator.isAscending() ^ previous) {
1257                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1258                                            }
1259                                            else {
1260                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1261                                            }
1262                                    }
1263                                    else {
1264                                            if (orderByComparator.isAscending() ^ previous) {
1265                                                    query.append(WHERE_GREATER_THAN);
1266                                            }
1267                                            else {
1268                                                    query.append(WHERE_LESSER_THAN);
1269                                            }
1270                                    }
1271                            }
1272    
1273                            query.append(ORDER_BY_CLAUSE);
1274    
1275                            String[] orderByFields = orderByComparator.getOrderByFields();
1276    
1277                            for (int i = 0; i < orderByFields.length; i++) {
1278                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1279                                    query.append(orderByFields[i]);
1280    
1281                                    if ((i + 1) < orderByFields.length) {
1282                                            if (orderByComparator.isAscending() ^ previous) {
1283                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1284                                            }
1285                                            else {
1286                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1287                                            }
1288                                    }
1289                                    else {
1290                                            if (orderByComparator.isAscending() ^ previous) {
1291                                                    query.append(ORDER_BY_ASC);
1292                                            }
1293                                            else {
1294                                                    query.append(ORDER_BY_DESC);
1295                                            }
1296                                    }
1297                            }
1298                    }
1299                    else {
1300                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1301                    }
1302    
1303                    String sql = query.toString();
1304    
1305                    Query q = session.createQuery(sql);
1306    
1307                    q.setFirstResult(0);
1308                    q.setMaxResults(2);
1309    
1310                    QueryPos qPos = QueryPos.getInstance(q);
1311    
1312                    if (bindUuid) {
1313                            qPos.add(uuid);
1314                    }
1315    
1316                    qPos.add(companyId);
1317    
1318                    if (orderByComparator != null) {
1319                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1320    
1321                            for (Object value : values) {
1322                                    qPos.add(value);
1323                            }
1324                    }
1325    
1326                    List<MBThread> list = q.list();
1327    
1328                    if (list.size() == 2) {
1329                            return list.get(1);
1330                    }
1331                    else {
1332                            return null;
1333                    }
1334            }
1335    
1336            /**
1337             * Removes all the message boards threads where uuid = &#63; and companyId = &#63; from the database.
1338             *
1339             * @param uuid the uuid
1340             * @param companyId the company ID
1341             * @throws SystemException if a system exception occurred
1342             */
1343            public void removeByUuid_C(String uuid, long companyId)
1344                    throws SystemException {
1345                    for (MBThread mbThread : findByUuid_C(uuid, companyId,
1346                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1347                            remove(mbThread);
1348                    }
1349            }
1350    
1351            /**
1352             * Returns the number of message boards threads where uuid = &#63; and companyId = &#63;.
1353             *
1354             * @param uuid the uuid
1355             * @param companyId the company ID
1356             * @return the number of matching message boards threads
1357             * @throws SystemException if a system exception occurred
1358             */
1359            public int countByUuid_C(String uuid, long companyId)
1360                    throws SystemException {
1361                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1362    
1363                    Object[] finderArgs = new Object[] { uuid, companyId };
1364    
1365                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1366                                    this);
1367    
1368                    if (count == null) {
1369                            StringBundler query = new StringBundler(3);
1370    
1371                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
1372    
1373                            boolean bindUuid = false;
1374    
1375                            if (uuid == null) {
1376                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1377                            }
1378                            else if (uuid.equals(StringPool.BLANK)) {
1379                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1380                            }
1381                            else {
1382                                    bindUuid = true;
1383    
1384                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1385                            }
1386    
1387                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1388    
1389                            String sql = query.toString();
1390    
1391                            Session session = null;
1392    
1393                            try {
1394                                    session = openSession();
1395    
1396                                    Query q = session.createQuery(sql);
1397    
1398                                    QueryPos qPos = QueryPos.getInstance(q);
1399    
1400                                    if (bindUuid) {
1401                                            qPos.add(uuid);
1402                                    }
1403    
1404                                    qPos.add(companyId);
1405    
1406                                    count = (Long)q.uniqueResult();
1407    
1408                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1409                            }
1410                            catch (Exception e) {
1411                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1412    
1413                                    throw processException(e);
1414                            }
1415                            finally {
1416                                    closeSession(session);
1417                            }
1418                    }
1419    
1420                    return count.intValue();
1421            }
1422    
1423            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbThread.uuid IS NULL AND ";
1424            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbThread.uuid = ? AND ";
1425            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbThread.uuid IS NULL OR mbThread.uuid = '') AND ";
1426            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbThread.companyId = ?";
1427            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1428                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
1429                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1430                            new String[] {
1431                                    Long.class.getName(),
1432                                    
1433                            Integer.class.getName(), Integer.class.getName(),
1434                                    OrderByComparator.class.getName()
1435                            });
1436            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1437                    new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1438                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
1439                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1440                            new String[] { Long.class.getName() },
1441                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
1442                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
1443                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
1444            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1445                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
1446                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1447                            new String[] { Long.class.getName() });
1448    
1449            /**
1450             * Returns all the message boards threads where groupId = &#63;.
1451             *
1452             * @param groupId the group ID
1453             * @return the matching message boards threads
1454             * @throws SystemException if a system exception occurred
1455             */
1456            public List<MBThread> findByGroupId(long groupId) throws SystemException {
1457                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1458            }
1459    
1460            /**
1461             * Returns a range of all the message boards threads where groupId = &#63;.
1462             *
1463             * <p>
1464             * 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.
1465             * </p>
1466             *
1467             * @param groupId the group ID
1468             * @param start the lower bound of the range of message boards threads
1469             * @param end the upper bound of the range of message boards threads (not inclusive)
1470             * @return the range of matching message boards threads
1471             * @throws SystemException if a system exception occurred
1472             */
1473            public List<MBThread> findByGroupId(long groupId, int start, int end)
1474                    throws SystemException {
1475                    return findByGroupId(groupId, start, end, null);
1476            }
1477    
1478            /**
1479             * Returns an ordered range of all the message boards threads where groupId = &#63;.
1480             *
1481             * <p>
1482             * 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.
1483             * </p>
1484             *
1485             * @param groupId the group ID
1486             * @param start the lower bound of the range of message boards threads
1487             * @param end the upper bound of the range of message boards threads (not inclusive)
1488             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1489             * @return the ordered range of matching message boards threads
1490             * @throws SystemException if a system exception occurred
1491             */
1492            public List<MBThread> findByGroupId(long groupId, int start, int end,
1493                    OrderByComparator orderByComparator) throws SystemException {
1494                    boolean pagination = true;
1495                    FinderPath finderPath = null;
1496                    Object[] finderArgs = null;
1497    
1498                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1499                                    (orderByComparator == null)) {
1500                            pagination = false;
1501                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1502                            finderArgs = new Object[] { groupId };
1503                    }
1504                    else {
1505                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1506                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1507                    }
1508    
1509                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
1510                                    finderArgs, this);
1511    
1512                    if ((list != null) && !list.isEmpty()) {
1513                            for (MBThread mbThread : list) {
1514                                    if ((groupId != mbThread.getGroupId())) {
1515                                            list = null;
1516    
1517                                            break;
1518                                    }
1519                            }
1520                    }
1521    
1522                    if (list == null) {
1523                            StringBundler query = null;
1524    
1525                            if (orderByComparator != null) {
1526                                    query = new StringBundler(3 +
1527                                                    (orderByComparator.getOrderByFields().length * 3));
1528                            }
1529                            else {
1530                                    query = new StringBundler(3);
1531                            }
1532    
1533                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
1534    
1535                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1536    
1537                            if (orderByComparator != null) {
1538                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1539                                            orderByComparator);
1540                            }
1541                            else
1542                             if (pagination) {
1543                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1544                            }
1545    
1546                            String sql = query.toString();
1547    
1548                            Session session = null;
1549    
1550                            try {
1551                                    session = openSession();
1552    
1553                                    Query q = session.createQuery(sql);
1554    
1555                                    QueryPos qPos = QueryPos.getInstance(q);
1556    
1557                                    qPos.add(groupId);
1558    
1559                                    if (!pagination) {
1560                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1561                                                            start, end, false);
1562    
1563                                            Collections.sort(list);
1564    
1565                                            list = new UnmodifiableList<MBThread>(list);
1566                                    }
1567                                    else {
1568                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1569                                                            start, end);
1570                                    }
1571    
1572                                    cacheResult(list);
1573    
1574                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1575                            }
1576                            catch (Exception e) {
1577                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1578    
1579                                    throw processException(e);
1580                            }
1581                            finally {
1582                                    closeSession(session);
1583                            }
1584                    }
1585    
1586                    return list;
1587            }
1588    
1589            /**
1590             * Returns the first message boards thread in the ordered set where groupId = &#63;.
1591             *
1592             * @param groupId the group ID
1593             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1594             * @return the first matching message boards thread
1595             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
1596             * @throws SystemException if a system exception occurred
1597             */
1598            public MBThread findByGroupId_First(long groupId,
1599                    OrderByComparator orderByComparator)
1600                    throws NoSuchThreadException, SystemException {
1601                    MBThread mbThread = fetchByGroupId_First(groupId, orderByComparator);
1602    
1603                    if (mbThread != null) {
1604                            return mbThread;
1605                    }
1606    
1607                    StringBundler msg = new StringBundler(4);
1608    
1609                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1610    
1611                    msg.append("groupId=");
1612                    msg.append(groupId);
1613    
1614                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1615    
1616                    throw new NoSuchThreadException(msg.toString());
1617            }
1618    
1619            /**
1620             * Returns the first message boards thread in the ordered set where groupId = &#63;.
1621             *
1622             * @param groupId the group ID
1623             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1624             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1625             * @throws SystemException if a system exception occurred
1626             */
1627            public MBThread fetchByGroupId_First(long groupId,
1628                    OrderByComparator orderByComparator) throws SystemException {
1629                    List<MBThread> list = findByGroupId(groupId, 0, 1, orderByComparator);
1630    
1631                    if (!list.isEmpty()) {
1632                            return list.get(0);
1633                    }
1634    
1635                    return null;
1636            }
1637    
1638            /**
1639             * Returns the last message boards thread in the ordered set where groupId = &#63;.
1640             *
1641             * @param groupId the group ID
1642             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1643             * @return the last matching message boards thread
1644             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
1645             * @throws SystemException if a system exception occurred
1646             */
1647            public MBThread findByGroupId_Last(long groupId,
1648                    OrderByComparator orderByComparator)
1649                    throws NoSuchThreadException, SystemException {
1650                    MBThread mbThread = fetchByGroupId_Last(groupId, orderByComparator);
1651    
1652                    if (mbThread != null) {
1653                            return mbThread;
1654                    }
1655    
1656                    StringBundler msg = new StringBundler(4);
1657    
1658                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1659    
1660                    msg.append("groupId=");
1661                    msg.append(groupId);
1662    
1663                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1664    
1665                    throw new NoSuchThreadException(msg.toString());
1666            }
1667    
1668            /**
1669             * Returns the last message boards thread in the ordered set where groupId = &#63;.
1670             *
1671             * @param groupId the group ID
1672             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1673             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1674             * @throws SystemException if a system exception occurred
1675             */
1676            public MBThread fetchByGroupId_Last(long groupId,
1677                    OrderByComparator orderByComparator) throws SystemException {
1678                    int count = countByGroupId(groupId);
1679    
1680                    List<MBThread> list = findByGroupId(groupId, count - 1, count,
1681                                    orderByComparator);
1682    
1683                    if (!list.isEmpty()) {
1684                            return list.get(0);
1685                    }
1686    
1687                    return null;
1688            }
1689    
1690            /**
1691             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63;.
1692             *
1693             * @param threadId the primary key of the current message boards thread
1694             * @param groupId the group ID
1695             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1696             * @return the previous, current, and next message boards thread
1697             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
1698             * @throws SystemException if a system exception occurred
1699             */
1700            public MBThread[] findByGroupId_PrevAndNext(long threadId, long groupId,
1701                    OrderByComparator orderByComparator)
1702                    throws NoSuchThreadException, SystemException {
1703                    MBThread mbThread = findByPrimaryKey(threadId);
1704    
1705                    Session session = null;
1706    
1707                    try {
1708                            session = openSession();
1709    
1710                            MBThread[] array = new MBThreadImpl[3];
1711    
1712                            array[0] = getByGroupId_PrevAndNext(session, mbThread, groupId,
1713                                            orderByComparator, true);
1714    
1715                            array[1] = mbThread;
1716    
1717                            array[2] = getByGroupId_PrevAndNext(session, mbThread, groupId,
1718                                            orderByComparator, false);
1719    
1720                            return array;
1721                    }
1722                    catch (Exception e) {
1723                            throw processException(e);
1724                    }
1725                    finally {
1726                            closeSession(session);
1727                    }
1728            }
1729    
1730            protected MBThread getByGroupId_PrevAndNext(Session session,
1731                    MBThread mbThread, long groupId, OrderByComparator orderByComparator,
1732                    boolean previous) {
1733                    StringBundler query = null;
1734    
1735                    if (orderByComparator != null) {
1736                            query = new StringBundler(6 +
1737                                            (orderByComparator.getOrderByFields().length * 6));
1738                    }
1739                    else {
1740                            query = new StringBundler(3);
1741                    }
1742    
1743                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1744    
1745                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1746    
1747                    if (orderByComparator != null) {
1748                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1749    
1750                            if (orderByConditionFields.length > 0) {
1751                                    query.append(WHERE_AND);
1752                            }
1753    
1754                            for (int i = 0; i < orderByConditionFields.length; i++) {
1755                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1756                                    query.append(orderByConditionFields[i]);
1757    
1758                                    if ((i + 1) < orderByConditionFields.length) {
1759                                            if (orderByComparator.isAscending() ^ previous) {
1760                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1761                                            }
1762                                            else {
1763                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1764                                            }
1765                                    }
1766                                    else {
1767                                            if (orderByComparator.isAscending() ^ previous) {
1768                                                    query.append(WHERE_GREATER_THAN);
1769                                            }
1770                                            else {
1771                                                    query.append(WHERE_LESSER_THAN);
1772                                            }
1773                                    }
1774                            }
1775    
1776                            query.append(ORDER_BY_CLAUSE);
1777    
1778                            String[] orderByFields = orderByComparator.getOrderByFields();
1779    
1780                            for (int i = 0; i < orderByFields.length; i++) {
1781                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1782                                    query.append(orderByFields[i]);
1783    
1784                                    if ((i + 1) < orderByFields.length) {
1785                                            if (orderByComparator.isAscending() ^ previous) {
1786                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1787                                            }
1788                                            else {
1789                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1790                                            }
1791                                    }
1792                                    else {
1793                                            if (orderByComparator.isAscending() ^ previous) {
1794                                                    query.append(ORDER_BY_ASC);
1795                                            }
1796                                            else {
1797                                                    query.append(ORDER_BY_DESC);
1798                                            }
1799                                    }
1800                            }
1801                    }
1802                    else {
1803                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1804                    }
1805    
1806                    String sql = query.toString();
1807    
1808                    Query q = session.createQuery(sql);
1809    
1810                    q.setFirstResult(0);
1811                    q.setMaxResults(2);
1812    
1813                    QueryPos qPos = QueryPos.getInstance(q);
1814    
1815                    qPos.add(groupId);
1816    
1817                    if (orderByComparator != null) {
1818                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1819    
1820                            for (Object value : values) {
1821                                    qPos.add(value);
1822                            }
1823                    }
1824    
1825                    List<MBThread> list = q.list();
1826    
1827                    if (list.size() == 2) {
1828                            return list.get(1);
1829                    }
1830                    else {
1831                            return null;
1832                    }
1833            }
1834    
1835            /**
1836             * Returns all the message boards threads that the user has permission to view where groupId = &#63;.
1837             *
1838             * @param groupId the group ID
1839             * @return the matching message boards threads that the user has permission to view
1840             * @throws SystemException if a system exception occurred
1841             */
1842            public List<MBThread> filterFindByGroupId(long groupId)
1843                    throws SystemException {
1844                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1845                            QueryUtil.ALL_POS, null);
1846            }
1847    
1848            /**
1849             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63;.
1850             *
1851             * <p>
1852             * 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.
1853             * </p>
1854             *
1855             * @param groupId the group ID
1856             * @param start the lower bound of the range of message boards threads
1857             * @param end the upper bound of the range of message boards threads (not inclusive)
1858             * @return the range of matching message boards threads that the user has permission to view
1859             * @throws SystemException if a system exception occurred
1860             */
1861            public List<MBThread> filterFindByGroupId(long groupId, int start, int end)
1862                    throws SystemException {
1863                    return filterFindByGroupId(groupId, start, end, null);
1864            }
1865    
1866            /**
1867             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63;.
1868             *
1869             * <p>
1870             * 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.
1871             * </p>
1872             *
1873             * @param groupId the group ID
1874             * @param start the lower bound of the range of message boards threads
1875             * @param end the upper bound of the range of message boards threads (not inclusive)
1876             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1877             * @return the ordered range of matching message boards threads that the user has permission to view
1878             * @throws SystemException if a system exception occurred
1879             */
1880            public List<MBThread> filterFindByGroupId(long groupId, int start, int end,
1881                    OrderByComparator orderByComparator) throws SystemException {
1882                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1883                            return findByGroupId(groupId, start, end, orderByComparator);
1884                    }
1885    
1886                    StringBundler query = null;
1887    
1888                    if (orderByComparator != null) {
1889                            query = new StringBundler(3 +
1890                                            (orderByComparator.getOrderByFields().length * 3));
1891                    }
1892                    else {
1893                            query = new StringBundler(3);
1894                    }
1895    
1896                    if (getDB().isSupportsInlineDistinct()) {
1897                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
1898                    }
1899                    else {
1900                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
1901                    }
1902    
1903                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1904    
1905                    if (!getDB().isSupportsInlineDistinct()) {
1906                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
1907                    }
1908    
1909                    if (orderByComparator != null) {
1910                            if (getDB().isSupportsInlineDistinct()) {
1911                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1912                                            orderByComparator, true);
1913                            }
1914                            else {
1915                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1916                                            orderByComparator, true);
1917                            }
1918                    }
1919                    else {
1920                            if (getDB().isSupportsInlineDistinct()) {
1921                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1922                            }
1923                            else {
1924                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
1925                            }
1926                    }
1927    
1928                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1929                                    MBThread.class.getName(),
1930                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1931    
1932                    Session session = null;
1933    
1934                    try {
1935                            session = openSession();
1936    
1937                            SQLQuery q = session.createSQLQuery(sql);
1938    
1939                            if (getDB().isSupportsInlineDistinct()) {
1940                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
1941                            }
1942                            else {
1943                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
1944                            }
1945    
1946                            QueryPos qPos = QueryPos.getInstance(q);
1947    
1948                            qPos.add(groupId);
1949    
1950                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
1951                    }
1952                    catch (Exception e) {
1953                            throw processException(e);
1954                    }
1955                    finally {
1956                            closeSession(session);
1957                    }
1958            }
1959    
1960            /**
1961             * 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;.
1962             *
1963             * @param threadId the primary key of the current message boards thread
1964             * @param groupId the group ID
1965             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1966             * @return the previous, current, and next message boards thread
1967             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
1968             * @throws SystemException if a system exception occurred
1969             */
1970            public MBThread[] filterFindByGroupId_PrevAndNext(long threadId,
1971                    long groupId, OrderByComparator orderByComparator)
1972                    throws NoSuchThreadException, SystemException {
1973                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1974                            return findByGroupId_PrevAndNext(threadId, groupId,
1975                                    orderByComparator);
1976                    }
1977    
1978                    MBThread mbThread = findByPrimaryKey(threadId);
1979    
1980                    Session session = null;
1981    
1982                    try {
1983                            session = openSession();
1984    
1985                            MBThread[] array = new MBThreadImpl[3];
1986    
1987                            array[0] = filterGetByGroupId_PrevAndNext(session, mbThread,
1988                                            groupId, orderByComparator, true);
1989    
1990                            array[1] = mbThread;
1991    
1992                            array[2] = filterGetByGroupId_PrevAndNext(session, mbThread,
1993                                            groupId, orderByComparator, false);
1994    
1995                            return array;
1996                    }
1997                    catch (Exception e) {
1998                            throw processException(e);
1999                    }
2000                    finally {
2001                            closeSession(session);
2002                    }
2003            }
2004    
2005            protected MBThread filterGetByGroupId_PrevAndNext(Session session,
2006                    MBThread mbThread, long groupId, OrderByComparator orderByComparator,
2007                    boolean previous) {
2008                    StringBundler query = null;
2009    
2010                    if (orderByComparator != null) {
2011                            query = new StringBundler(6 +
2012                                            (orderByComparator.getOrderByFields().length * 6));
2013                    }
2014                    else {
2015                            query = new StringBundler(3);
2016                    }
2017    
2018                    if (getDB().isSupportsInlineDistinct()) {
2019                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2020                    }
2021                    else {
2022                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2023                    }
2024    
2025                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2026    
2027                    if (!getDB().isSupportsInlineDistinct()) {
2028                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
2029                    }
2030    
2031                    if (orderByComparator != null) {
2032                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2033    
2034                            if (orderByConditionFields.length > 0) {
2035                                    query.append(WHERE_AND);
2036                            }
2037    
2038                            for (int i = 0; i < orderByConditionFields.length; i++) {
2039                                    if (getDB().isSupportsInlineDistinct()) {
2040                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2041                                    }
2042                                    else {
2043                                            query.append(_ORDER_BY_ENTITY_TABLE);
2044                                    }
2045    
2046                                    query.append(orderByConditionFields[i]);
2047    
2048                                    if ((i + 1) < orderByConditionFields.length) {
2049                                            if (orderByComparator.isAscending() ^ previous) {
2050                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2051                                            }
2052                                            else {
2053                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2054                                            }
2055                                    }
2056                                    else {
2057                                            if (orderByComparator.isAscending() ^ previous) {
2058                                                    query.append(WHERE_GREATER_THAN);
2059                                            }
2060                                            else {
2061                                                    query.append(WHERE_LESSER_THAN);
2062                                            }
2063                                    }
2064                            }
2065    
2066                            query.append(ORDER_BY_CLAUSE);
2067    
2068                            String[] orderByFields = orderByComparator.getOrderByFields();
2069    
2070                            for (int i = 0; i < orderByFields.length; i++) {
2071                                    if (getDB().isSupportsInlineDistinct()) {
2072                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2073                                    }
2074                                    else {
2075                                            query.append(_ORDER_BY_ENTITY_TABLE);
2076                                    }
2077    
2078                                    query.append(orderByFields[i]);
2079    
2080                                    if ((i + 1) < orderByFields.length) {
2081                                            if (orderByComparator.isAscending() ^ previous) {
2082                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2083                                            }
2084                                            else {
2085                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2086                                            }
2087                                    }
2088                                    else {
2089                                            if (orderByComparator.isAscending() ^ previous) {
2090                                                    query.append(ORDER_BY_ASC);
2091                                            }
2092                                            else {
2093                                                    query.append(ORDER_BY_DESC);
2094                                            }
2095                                    }
2096                            }
2097                    }
2098                    else {
2099                            if (getDB().isSupportsInlineDistinct()) {
2100                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2101                            }
2102                            else {
2103                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
2104                            }
2105                    }
2106    
2107                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2108                                    MBThread.class.getName(),
2109                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2110    
2111                    SQLQuery q = session.createSQLQuery(sql);
2112    
2113                    q.setFirstResult(0);
2114                    q.setMaxResults(2);
2115    
2116                    if (getDB().isSupportsInlineDistinct()) {
2117                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
2118                    }
2119                    else {
2120                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
2121                    }
2122    
2123                    QueryPos qPos = QueryPos.getInstance(q);
2124    
2125                    qPos.add(groupId);
2126    
2127                    if (orderByComparator != null) {
2128                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
2129    
2130                            for (Object value : values) {
2131                                    qPos.add(value);
2132                            }
2133                    }
2134    
2135                    List<MBThread> list = q.list();
2136    
2137                    if (list.size() == 2) {
2138                            return list.get(1);
2139                    }
2140                    else {
2141                            return null;
2142                    }
2143            }
2144    
2145            /**
2146             * Removes all the message boards threads where groupId = &#63; from the database.
2147             *
2148             * @param groupId the group ID
2149             * @throws SystemException if a system exception occurred
2150             */
2151            public void removeByGroupId(long groupId) throws SystemException {
2152                    for (MBThread mbThread : findByGroupId(groupId, QueryUtil.ALL_POS,
2153                                    QueryUtil.ALL_POS, null)) {
2154                            remove(mbThread);
2155                    }
2156            }
2157    
2158            /**
2159             * Returns the number of message boards threads where groupId = &#63;.
2160             *
2161             * @param groupId the group ID
2162             * @return the number of matching message boards threads
2163             * @throws SystemException if a system exception occurred
2164             */
2165            public int countByGroupId(long groupId) throws SystemException {
2166                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2167    
2168                    Object[] finderArgs = new Object[] { groupId };
2169    
2170                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2171                                    this);
2172    
2173                    if (count == null) {
2174                            StringBundler query = new StringBundler(2);
2175    
2176                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
2177    
2178                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2179    
2180                            String sql = query.toString();
2181    
2182                            Session session = null;
2183    
2184                            try {
2185                                    session = openSession();
2186    
2187                                    Query q = session.createQuery(sql);
2188    
2189                                    QueryPos qPos = QueryPos.getInstance(q);
2190    
2191                                    qPos.add(groupId);
2192    
2193                                    count = (Long)q.uniqueResult();
2194    
2195                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2196                            }
2197                            catch (Exception e) {
2198                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2199    
2200                                    throw processException(e);
2201                            }
2202                            finally {
2203                                    closeSession(session);
2204                            }
2205                    }
2206    
2207                    return count.intValue();
2208            }
2209    
2210            /**
2211             * Returns the number of message boards threads that the user has permission to view where groupId = &#63;.
2212             *
2213             * @param groupId the group ID
2214             * @return the number of matching message boards threads that the user has permission to view
2215             * @throws SystemException if a system exception occurred
2216             */
2217            public int filterCountByGroupId(long groupId) throws SystemException {
2218                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2219                            return countByGroupId(groupId);
2220                    }
2221    
2222                    StringBundler query = new StringBundler(2);
2223    
2224                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
2225    
2226                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2227    
2228                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2229                                    MBThread.class.getName(),
2230                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2231    
2232                    Session session = null;
2233    
2234                    try {
2235                            session = openSession();
2236    
2237                            SQLQuery q = session.createSQLQuery(sql);
2238    
2239                            q.addScalar(COUNT_COLUMN_NAME,
2240                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2241    
2242                            QueryPos qPos = QueryPos.getInstance(q);
2243    
2244                            qPos.add(groupId);
2245    
2246                            Long count = (Long)q.uniqueResult();
2247    
2248                            return count.intValue();
2249                    }
2250                    catch (Exception e) {
2251                            throw processException(e);
2252                    }
2253                    finally {
2254                            closeSession(session);
2255                    }
2256            }
2257    
2258            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbThread.groupId = ? AND mbThread.categoryId != -1";
2259            public static final FinderPath FINDER_PATH_FETCH_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2260                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
2261                            FINDER_CLASS_NAME_ENTITY, "fetchByRootMessageId",
2262                            new String[] { Long.class.getName() },
2263                            MBThreadModelImpl.ROOTMESSAGEID_COLUMN_BITMASK);
2264            public static final FinderPath FINDER_PATH_COUNT_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2265                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
2266                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRootMessageId",
2267                            new String[] { Long.class.getName() });
2268    
2269            /**
2270             * Returns the message boards thread where rootMessageId = &#63; or throws a {@link com.liferay.portlet.messageboards.NoSuchThreadException} if it could not be found.
2271             *
2272             * @param rootMessageId the root message ID
2273             * @return the matching message boards thread
2274             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
2275             * @throws SystemException if a system exception occurred
2276             */
2277            public MBThread findByRootMessageId(long rootMessageId)
2278                    throws NoSuchThreadException, SystemException {
2279                    MBThread mbThread = fetchByRootMessageId(rootMessageId);
2280    
2281                    if (mbThread == null) {
2282                            StringBundler msg = new StringBundler(4);
2283    
2284                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2285    
2286                            msg.append("rootMessageId=");
2287                            msg.append(rootMessageId);
2288    
2289                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2290    
2291                            if (_log.isWarnEnabled()) {
2292                                    _log.warn(msg.toString());
2293                            }
2294    
2295                            throw new NoSuchThreadException(msg.toString());
2296                    }
2297    
2298                    return mbThread;
2299            }
2300    
2301            /**
2302             * Returns the message boards thread where rootMessageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2303             *
2304             * @param rootMessageId the root message ID
2305             * @return the matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
2306             * @throws SystemException if a system exception occurred
2307             */
2308            public MBThread fetchByRootMessageId(long rootMessageId)
2309                    throws SystemException {
2310                    return fetchByRootMessageId(rootMessageId, true);
2311            }
2312    
2313            /**
2314             * Returns the message boards thread where rootMessageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2315             *
2316             * @param rootMessageId the root message ID
2317             * @param retrieveFromCache whether to use the finder cache
2318             * @return the matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
2319             * @throws SystemException if a system exception occurred
2320             */
2321            public MBThread fetchByRootMessageId(long rootMessageId,
2322                    boolean retrieveFromCache) throws SystemException {
2323                    Object[] finderArgs = new Object[] { rootMessageId };
2324    
2325                    Object result = null;
2326    
2327                    if (retrieveFromCache) {
2328                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2329                                            finderArgs, this);
2330                    }
2331    
2332                    if (result instanceof MBThread) {
2333                            MBThread mbThread = (MBThread)result;
2334    
2335                            if ((rootMessageId != mbThread.getRootMessageId())) {
2336                                    result = null;
2337                            }
2338                    }
2339    
2340                    if (result == null) {
2341                            StringBundler query = new StringBundler(3);
2342    
2343                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
2344    
2345                            query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
2346    
2347                            String sql = query.toString();
2348    
2349                            Session session = null;
2350    
2351                            try {
2352                                    session = openSession();
2353    
2354                                    Query q = session.createQuery(sql);
2355    
2356                                    QueryPos qPos = QueryPos.getInstance(q);
2357    
2358                                    qPos.add(rootMessageId);
2359    
2360                                    List<MBThread> list = q.list();
2361    
2362                                    if (list.isEmpty()) {
2363                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2364                                                    finderArgs, list);
2365                                    }
2366                                    else {
2367                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
2368                                                    _log.warn(
2369                                                            "MBThreadPersistenceImpl.fetchByRootMessageId(long, boolean) with parameters (" +
2370                                                            StringUtil.merge(finderArgs) +
2371                                                            ") 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.");
2372                                            }
2373    
2374                                            MBThread mbThread = list.get(0);
2375    
2376                                            result = mbThread;
2377    
2378                                            cacheResult(mbThread);
2379    
2380                                            if ((mbThread.getRootMessageId() != rootMessageId)) {
2381                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2382                                                            finderArgs, mbThread);
2383                                            }
2384                                    }
2385                            }
2386                            catch (Exception e) {
2387                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2388                                            finderArgs);
2389    
2390                                    throw processException(e);
2391                            }
2392                            finally {
2393                                    closeSession(session);
2394                            }
2395                    }
2396    
2397                    if (result instanceof List<?>) {
2398                            return null;
2399                    }
2400                    else {
2401                            return (MBThread)result;
2402                    }
2403            }
2404    
2405            /**
2406             * Removes the message boards thread where rootMessageId = &#63; from the database.
2407             *
2408             * @param rootMessageId the root message ID
2409             * @return the message boards thread that was removed
2410             * @throws SystemException if a system exception occurred
2411             */
2412            public MBThread removeByRootMessageId(long rootMessageId)
2413                    throws NoSuchThreadException, SystemException {
2414                    MBThread mbThread = findByRootMessageId(rootMessageId);
2415    
2416                    return remove(mbThread);
2417            }
2418    
2419            /**
2420             * Returns the number of message boards threads where rootMessageId = &#63;.
2421             *
2422             * @param rootMessageId the root message ID
2423             * @return the number of matching message boards threads
2424             * @throws SystemException if a system exception occurred
2425             */
2426            public int countByRootMessageId(long rootMessageId)
2427                    throws SystemException {
2428                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ROOTMESSAGEID;
2429    
2430                    Object[] finderArgs = new Object[] { rootMessageId };
2431    
2432                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2433                                    this);
2434    
2435                    if (count == null) {
2436                            StringBundler query = new StringBundler(2);
2437    
2438                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
2439    
2440                            query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
2441    
2442                            String sql = query.toString();
2443    
2444                            Session session = null;
2445    
2446                            try {
2447                                    session = openSession();
2448    
2449                                    Query q = session.createQuery(sql);
2450    
2451                                    QueryPos qPos = QueryPos.getInstance(q);
2452    
2453                                    qPos.add(rootMessageId);
2454    
2455                                    count = (Long)q.uniqueResult();
2456    
2457                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2458                            }
2459                            catch (Exception e) {
2460                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2461    
2462                                    throw processException(e);
2463                            }
2464                            finally {
2465                                    closeSession(session);
2466                            }
2467                    }
2468    
2469                    return count.intValue();
2470            }
2471    
2472            private static final String _FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2 = "mbThread.rootMessageId = ?";
2473            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2474                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
2475                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
2476                            new String[] {
2477                                    Long.class.getName(), Long.class.getName(),
2478                                    
2479                            Integer.class.getName(), Integer.class.getName(),
2480                                    OrderByComparator.class.getName()
2481                            });
2482            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2483                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
2484                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
2485                            new String[] { Long.class.getName(), Long.class.getName() },
2486                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
2487                            MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
2488                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
2489                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
2490            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2491                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
2492                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
2493                            new String[] { Long.class.getName(), Long.class.getName() });
2494            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2495                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
2496                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C",
2497                            new String[] { Long.class.getName(), Long.class.getName() });
2498    
2499            /**
2500             * Returns all the message boards threads where groupId = &#63; and categoryId = &#63;.
2501             *
2502             * @param groupId the group ID
2503             * @param categoryId the category ID
2504             * @return the matching message boards threads
2505             * @throws SystemException if a system exception occurred
2506             */
2507            public List<MBThread> findByG_C(long groupId, long categoryId)
2508                    throws SystemException {
2509                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
2510                            QueryUtil.ALL_POS, null);
2511            }
2512    
2513            /**
2514             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = &#63;.
2515             *
2516             * <p>
2517             * 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.
2518             * </p>
2519             *
2520             * @param groupId the group ID
2521             * @param categoryId the category ID
2522             * @param start the lower bound of the range of message boards threads
2523             * @param end the upper bound of the range of message boards threads (not inclusive)
2524             * @return the range of matching message boards threads
2525             * @throws SystemException if a system exception occurred
2526             */
2527            public List<MBThread> findByG_C(long groupId, long categoryId, int start,
2528                    int end) throws SystemException {
2529                    return findByG_C(groupId, categoryId, start, end, null);
2530            }
2531    
2532            /**
2533             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63;.
2534             *
2535             * <p>
2536             * 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.
2537             * </p>
2538             *
2539             * @param groupId the group ID
2540             * @param categoryId the category ID
2541             * @param start the lower bound of the range of message boards threads
2542             * @param end the upper bound of the range of message boards threads (not inclusive)
2543             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2544             * @return the ordered range of matching message boards threads
2545             * @throws SystemException if a system exception occurred
2546             */
2547            public List<MBThread> findByG_C(long groupId, long categoryId, int start,
2548                    int end, OrderByComparator orderByComparator) throws SystemException {
2549                    boolean pagination = true;
2550                    FinderPath finderPath = null;
2551                    Object[] finderArgs = null;
2552    
2553                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2554                                    (orderByComparator == null)) {
2555                            pagination = false;
2556                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
2557                            finderArgs = new Object[] { groupId, categoryId };
2558                    }
2559                    else {
2560                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
2561                            finderArgs = new Object[] {
2562                                            groupId, categoryId,
2563                                            
2564                                            start, end, orderByComparator
2565                                    };
2566                    }
2567    
2568                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
2569                                    finderArgs, this);
2570    
2571                    if ((list != null) && !list.isEmpty()) {
2572                            for (MBThread mbThread : list) {
2573                                    if ((groupId != mbThread.getGroupId()) ||
2574                                                    (categoryId != mbThread.getCategoryId())) {
2575                                            list = null;
2576    
2577                                            break;
2578                                    }
2579                            }
2580                    }
2581    
2582                    if (list == null) {
2583                            StringBundler query = null;
2584    
2585                            if (orderByComparator != null) {
2586                                    query = new StringBundler(4 +
2587                                                    (orderByComparator.getOrderByFields().length * 3));
2588                            }
2589                            else {
2590                                    query = new StringBundler(4);
2591                            }
2592    
2593                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
2594    
2595                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2596    
2597                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2598    
2599                            if (orderByComparator != null) {
2600                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2601                                            orderByComparator);
2602                            }
2603                            else
2604                             if (pagination) {
2605                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2606                            }
2607    
2608                            String sql = query.toString();
2609    
2610                            Session session = null;
2611    
2612                            try {
2613                                    session = openSession();
2614    
2615                                    Query q = session.createQuery(sql);
2616    
2617                                    QueryPos qPos = QueryPos.getInstance(q);
2618    
2619                                    qPos.add(groupId);
2620    
2621                                    qPos.add(categoryId);
2622    
2623                                    if (!pagination) {
2624                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2625                                                            start, end, false);
2626    
2627                                            Collections.sort(list);
2628    
2629                                            list = new UnmodifiableList<MBThread>(list);
2630                                    }
2631                                    else {
2632                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2633                                                            start, end);
2634                                    }
2635    
2636                                    cacheResult(list);
2637    
2638                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2639                            }
2640                            catch (Exception e) {
2641                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2642    
2643                                    throw processException(e);
2644                            }
2645                            finally {
2646                                    closeSession(session);
2647                            }
2648                    }
2649    
2650                    return list;
2651            }
2652    
2653            /**
2654             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
2655             *
2656             * @param groupId the group ID
2657             * @param categoryId the category ID
2658             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2659             * @return the first matching message boards thread
2660             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
2661             * @throws SystemException if a system exception occurred
2662             */
2663            public MBThread findByG_C_First(long groupId, long categoryId,
2664                    OrderByComparator orderByComparator)
2665                    throws NoSuchThreadException, SystemException {
2666                    MBThread mbThread = fetchByG_C_First(groupId, categoryId,
2667                                    orderByComparator);
2668    
2669                    if (mbThread != null) {
2670                            return mbThread;
2671                    }
2672    
2673                    StringBundler msg = new StringBundler(6);
2674    
2675                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2676    
2677                    msg.append("groupId=");
2678                    msg.append(groupId);
2679    
2680                    msg.append(", categoryId=");
2681                    msg.append(categoryId);
2682    
2683                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2684    
2685                    throw new NoSuchThreadException(msg.toString());
2686            }
2687    
2688            /**
2689             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
2690             *
2691             * @param groupId the group ID
2692             * @param categoryId the category ID
2693             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2694             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
2695             * @throws SystemException if a system exception occurred
2696             */
2697            public MBThread fetchByG_C_First(long groupId, long categoryId,
2698                    OrderByComparator orderByComparator) throws SystemException {
2699                    List<MBThread> list = findByG_C(groupId, categoryId, 0, 1,
2700                                    orderByComparator);
2701    
2702                    if (!list.isEmpty()) {
2703                            return list.get(0);
2704                    }
2705    
2706                    return null;
2707            }
2708    
2709            /**
2710             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
2711             *
2712             * @param groupId the group ID
2713             * @param categoryId the category ID
2714             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2715             * @return the last matching message boards thread
2716             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
2717             * @throws SystemException if a system exception occurred
2718             */
2719            public MBThread findByG_C_Last(long groupId, long categoryId,
2720                    OrderByComparator orderByComparator)
2721                    throws NoSuchThreadException, SystemException {
2722                    MBThread mbThread = fetchByG_C_Last(groupId, categoryId,
2723                                    orderByComparator);
2724    
2725                    if (mbThread != null) {
2726                            return mbThread;
2727                    }
2728    
2729                    StringBundler msg = new StringBundler(6);
2730    
2731                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2732    
2733                    msg.append("groupId=");
2734                    msg.append(groupId);
2735    
2736                    msg.append(", categoryId=");
2737                    msg.append(categoryId);
2738    
2739                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2740    
2741                    throw new NoSuchThreadException(msg.toString());
2742            }
2743    
2744            /**
2745             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
2746             *
2747             * @param groupId the group ID
2748             * @param categoryId the category ID
2749             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2750             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
2751             * @throws SystemException if a system exception occurred
2752             */
2753            public MBThread fetchByG_C_Last(long groupId, long categoryId,
2754                    OrderByComparator orderByComparator) throws SystemException {
2755                    int count = countByG_C(groupId, categoryId);
2756    
2757                    List<MBThread> list = findByG_C(groupId, categoryId, count - 1, count,
2758                                    orderByComparator);
2759    
2760                    if (!list.isEmpty()) {
2761                            return list.get(0);
2762                    }
2763    
2764                    return null;
2765            }
2766    
2767            /**
2768             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
2769             *
2770             * @param threadId the primary key of the current message boards thread
2771             * @param groupId the group ID
2772             * @param categoryId the category ID
2773             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2774             * @return the previous, current, and next message boards thread
2775             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
2776             * @throws SystemException if a system exception occurred
2777             */
2778            public MBThread[] findByG_C_PrevAndNext(long threadId, long groupId,
2779                    long categoryId, OrderByComparator orderByComparator)
2780                    throws NoSuchThreadException, SystemException {
2781                    MBThread mbThread = findByPrimaryKey(threadId);
2782    
2783                    Session session = null;
2784    
2785                    try {
2786                            session = openSession();
2787    
2788                            MBThread[] array = new MBThreadImpl[3];
2789    
2790                            array[0] = getByG_C_PrevAndNext(session, mbThread, groupId,
2791                                            categoryId, orderByComparator, true);
2792    
2793                            array[1] = mbThread;
2794    
2795                            array[2] = getByG_C_PrevAndNext(session, mbThread, groupId,
2796                                            categoryId, orderByComparator, false);
2797    
2798                            return array;
2799                    }
2800                    catch (Exception e) {
2801                            throw processException(e);
2802                    }
2803                    finally {
2804                            closeSession(session);
2805                    }
2806            }
2807    
2808            protected MBThread getByG_C_PrevAndNext(Session session, MBThread mbThread,
2809                    long groupId, long categoryId, OrderByComparator orderByComparator,
2810                    boolean previous) {
2811                    StringBundler query = null;
2812    
2813                    if (orderByComparator != null) {
2814                            query = new StringBundler(6 +
2815                                            (orderByComparator.getOrderByFields().length * 6));
2816                    }
2817                    else {
2818                            query = new StringBundler(3);
2819                    }
2820    
2821                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
2822    
2823                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2824    
2825                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2826    
2827                    if (orderByComparator != null) {
2828                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2829    
2830                            if (orderByConditionFields.length > 0) {
2831                                    query.append(WHERE_AND);
2832                            }
2833    
2834                            for (int i = 0; i < orderByConditionFields.length; i++) {
2835                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2836                                    query.append(orderByConditionFields[i]);
2837    
2838                                    if ((i + 1) < orderByConditionFields.length) {
2839                                            if (orderByComparator.isAscending() ^ previous) {
2840                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2841                                            }
2842                                            else {
2843                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2844                                            }
2845                                    }
2846                                    else {
2847                                            if (orderByComparator.isAscending() ^ previous) {
2848                                                    query.append(WHERE_GREATER_THAN);
2849                                            }
2850                                            else {
2851                                                    query.append(WHERE_LESSER_THAN);
2852                                            }
2853                                    }
2854                            }
2855    
2856                            query.append(ORDER_BY_CLAUSE);
2857    
2858                            String[] orderByFields = orderByComparator.getOrderByFields();
2859    
2860                            for (int i = 0; i < orderByFields.length; i++) {
2861                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2862                                    query.append(orderByFields[i]);
2863    
2864                                    if ((i + 1) < orderByFields.length) {
2865                                            if (orderByComparator.isAscending() ^ previous) {
2866                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2867                                            }
2868                                            else {
2869                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2870                                            }
2871                                    }
2872                                    else {
2873                                            if (orderByComparator.isAscending() ^ previous) {
2874                                                    query.append(ORDER_BY_ASC);
2875                                            }
2876                                            else {
2877                                                    query.append(ORDER_BY_DESC);
2878                                            }
2879                                    }
2880                            }
2881                    }
2882                    else {
2883                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2884                    }
2885    
2886                    String sql = query.toString();
2887    
2888                    Query q = session.createQuery(sql);
2889    
2890                    q.setFirstResult(0);
2891                    q.setMaxResults(2);
2892    
2893                    QueryPos qPos = QueryPos.getInstance(q);
2894    
2895                    qPos.add(groupId);
2896    
2897                    qPos.add(categoryId);
2898    
2899                    if (orderByComparator != null) {
2900                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
2901    
2902                            for (Object value : values) {
2903                                    qPos.add(value);
2904                            }
2905                    }
2906    
2907                    List<MBThread> list = q.list();
2908    
2909                    if (list.size() == 2) {
2910                            return list.get(1);
2911                    }
2912                    else {
2913                            return null;
2914                    }
2915            }
2916    
2917            /**
2918             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63;.
2919             *
2920             * @param groupId the group ID
2921             * @param categoryId the category ID
2922             * @return the matching message boards threads that the user has permission to view
2923             * @throws SystemException if a system exception occurred
2924             */
2925            public List<MBThread> filterFindByG_C(long groupId, long categoryId)
2926                    throws SystemException {
2927                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
2928                            QueryUtil.ALL_POS, null);
2929            }
2930    
2931            /**
2932             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63;.
2933             *
2934             * <p>
2935             * 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.
2936             * </p>
2937             *
2938             * @param groupId the group ID
2939             * @param categoryId the category ID
2940             * @param start the lower bound of the range of message boards threads
2941             * @param end the upper bound of the range of message boards threads (not inclusive)
2942             * @return the range of matching message boards threads that the user has permission to view
2943             * @throws SystemException if a system exception occurred
2944             */
2945            public List<MBThread> filterFindByG_C(long groupId, long categoryId,
2946                    int start, int end) throws SystemException {
2947                    return filterFindByG_C(groupId, categoryId, start, end, null);
2948            }
2949    
2950            /**
2951             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
2952             *
2953             * <p>
2954             * 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.
2955             * </p>
2956             *
2957             * @param groupId the group ID
2958             * @param categoryId the category ID
2959             * @param start the lower bound of the range of message boards threads
2960             * @param end the upper bound of the range of message boards threads (not inclusive)
2961             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2962             * @return the ordered range of matching message boards threads that the user has permission to view
2963             * @throws SystemException if a system exception occurred
2964             */
2965            public List<MBThread> filterFindByG_C(long groupId, long categoryId,
2966                    int start, int end, OrderByComparator orderByComparator)
2967                    throws SystemException {
2968                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2969                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
2970                    }
2971    
2972                    StringBundler query = null;
2973    
2974                    if (orderByComparator != null) {
2975                            query = new StringBundler(4 +
2976                                            (orderByComparator.getOrderByFields().length * 3));
2977                    }
2978                    else {
2979                            query = new StringBundler(4);
2980                    }
2981    
2982                    if (getDB().isSupportsInlineDistinct()) {
2983                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2984                    }
2985                    else {
2986                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2987                    }
2988    
2989                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2990    
2991                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2992    
2993                    if (!getDB().isSupportsInlineDistinct()) {
2994                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
2995                    }
2996    
2997                    if (orderByComparator != null) {
2998                            if (getDB().isSupportsInlineDistinct()) {
2999                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3000                                            orderByComparator, true);
3001                            }
3002                            else {
3003                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3004                                            orderByComparator, true);
3005                            }
3006                    }
3007                    else {
3008                            if (getDB().isSupportsInlineDistinct()) {
3009                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3010                            }
3011                            else {
3012                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
3013                            }
3014                    }
3015    
3016                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3017                                    MBThread.class.getName(),
3018                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3019    
3020                    Session session = null;
3021    
3022                    try {
3023                            session = openSession();
3024    
3025                            SQLQuery q = session.createSQLQuery(sql);
3026    
3027                            if (getDB().isSupportsInlineDistinct()) {
3028                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3029                            }
3030                            else {
3031                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3032                            }
3033    
3034                            QueryPos qPos = QueryPos.getInstance(q);
3035    
3036                            qPos.add(groupId);
3037    
3038                            qPos.add(categoryId);
3039    
3040                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3041                    }
3042                    catch (Exception e) {
3043                            throw processException(e);
3044                    }
3045                    finally {
3046                            closeSession(session);
3047                    }
3048            }
3049    
3050            /**
3051             * 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;.
3052             *
3053             * @param threadId the primary key of the current message boards thread
3054             * @param groupId the group ID
3055             * @param categoryId the category ID
3056             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3057             * @return the previous, current, and next message boards thread
3058             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
3059             * @throws SystemException if a system exception occurred
3060             */
3061            public MBThread[] filterFindByG_C_PrevAndNext(long threadId, long groupId,
3062                    long categoryId, OrderByComparator orderByComparator)
3063                    throws NoSuchThreadException, SystemException {
3064                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3065                            return findByG_C_PrevAndNext(threadId, groupId, categoryId,
3066                                    orderByComparator);
3067                    }
3068    
3069                    MBThread mbThread = findByPrimaryKey(threadId);
3070    
3071                    Session session = null;
3072    
3073                    try {
3074                            session = openSession();
3075    
3076                            MBThread[] array = new MBThreadImpl[3];
3077    
3078                            array[0] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
3079                                            categoryId, orderByComparator, true);
3080    
3081                            array[1] = mbThread;
3082    
3083                            array[2] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
3084                                            categoryId, orderByComparator, false);
3085    
3086                            return array;
3087                    }
3088                    catch (Exception e) {
3089                            throw processException(e);
3090                    }
3091                    finally {
3092                            closeSession(session);
3093                    }
3094            }
3095    
3096            protected MBThread filterGetByG_C_PrevAndNext(Session session,
3097                    MBThread mbThread, long groupId, long categoryId,
3098                    OrderByComparator orderByComparator, boolean previous) {
3099                    StringBundler query = null;
3100    
3101                    if (orderByComparator != null) {
3102                            query = new StringBundler(6 +
3103                                            (orderByComparator.getOrderByFields().length * 6));
3104                    }
3105                    else {
3106                            query = new StringBundler(3);
3107                    }
3108    
3109                    if (getDB().isSupportsInlineDistinct()) {
3110                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3111                    }
3112                    else {
3113                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3114                    }
3115    
3116                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3117    
3118                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3119    
3120                    if (!getDB().isSupportsInlineDistinct()) {
3121                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3122                    }
3123    
3124                    if (orderByComparator != null) {
3125                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3126    
3127                            if (orderByConditionFields.length > 0) {
3128                                    query.append(WHERE_AND);
3129                            }
3130    
3131                            for (int i = 0; i < orderByConditionFields.length; i++) {
3132                                    if (getDB().isSupportsInlineDistinct()) {
3133                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3134                                    }
3135                                    else {
3136                                            query.append(_ORDER_BY_ENTITY_TABLE);
3137                                    }
3138    
3139                                    query.append(orderByConditionFields[i]);
3140    
3141                                    if ((i + 1) < orderByConditionFields.length) {
3142                                            if (orderByComparator.isAscending() ^ previous) {
3143                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3144                                            }
3145                                            else {
3146                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3147                                            }
3148                                    }
3149                                    else {
3150                                            if (orderByComparator.isAscending() ^ previous) {
3151                                                    query.append(WHERE_GREATER_THAN);
3152                                            }
3153                                            else {
3154                                                    query.append(WHERE_LESSER_THAN);
3155                                            }
3156                                    }
3157                            }
3158    
3159                            query.append(ORDER_BY_CLAUSE);
3160    
3161                            String[] orderByFields = orderByComparator.getOrderByFields();
3162    
3163                            for (int i = 0; i < orderByFields.length; i++) {
3164                                    if (getDB().isSupportsInlineDistinct()) {
3165                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3166                                    }
3167                                    else {
3168                                            query.append(_ORDER_BY_ENTITY_TABLE);
3169                                    }
3170    
3171                                    query.append(orderByFields[i]);
3172    
3173                                    if ((i + 1) < orderByFields.length) {
3174                                            if (orderByComparator.isAscending() ^ previous) {
3175                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3176                                            }
3177                                            else {
3178                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3179                                            }
3180                                    }
3181                                    else {
3182                                            if (orderByComparator.isAscending() ^ previous) {
3183                                                    query.append(ORDER_BY_ASC);
3184                                            }
3185                                            else {
3186                                                    query.append(ORDER_BY_DESC);
3187                                            }
3188                                    }
3189                            }
3190                    }
3191                    else {
3192                            if (getDB().isSupportsInlineDistinct()) {
3193                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3194                            }
3195                            else {
3196                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
3197                            }
3198                    }
3199    
3200                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3201                                    MBThread.class.getName(),
3202                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3203    
3204                    SQLQuery q = session.createSQLQuery(sql);
3205    
3206                    q.setFirstResult(0);
3207                    q.setMaxResults(2);
3208    
3209                    if (getDB().isSupportsInlineDistinct()) {
3210                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3211                    }
3212                    else {
3213                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3214                    }
3215    
3216                    QueryPos qPos = QueryPos.getInstance(q);
3217    
3218                    qPos.add(groupId);
3219    
3220                    qPos.add(categoryId);
3221    
3222                    if (orderByComparator != null) {
3223                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3224    
3225                            for (Object value : values) {
3226                                    qPos.add(value);
3227                            }
3228                    }
3229    
3230                    List<MBThread> list = q.list();
3231    
3232                    if (list.size() == 2) {
3233                            return list.get(1);
3234                    }
3235                    else {
3236                            return null;
3237                    }
3238            }
3239    
3240            /**
3241             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63;.
3242             *
3243             * @param groupId the group ID
3244             * @param categoryIds the category IDs
3245             * @return the matching message boards threads that the user has permission to view
3246             * @throws SystemException if a system exception occurred
3247             */
3248            public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds)
3249                    throws SystemException {
3250                    return filterFindByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
3251                            QueryUtil.ALL_POS, null);
3252            }
3253    
3254            /**
3255             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63;.
3256             *
3257             * <p>
3258             * 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.
3259             * </p>
3260             *
3261             * @param groupId the group ID
3262             * @param categoryIds the category IDs
3263             * @param start the lower bound of the range of message boards threads
3264             * @param end the upper bound of the range of message boards threads (not inclusive)
3265             * @return the range of matching message boards threads that the user has permission to view
3266             * @throws SystemException if a system exception occurred
3267             */
3268            public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
3269                    int start, int end) throws SystemException {
3270                    return filterFindByG_C(groupId, categoryIds, start, end, null);
3271            }
3272    
3273            /**
3274             * Returns an ordered range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63;.
3275             *
3276             * <p>
3277             * 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.
3278             * </p>
3279             *
3280             * @param groupId the group ID
3281             * @param categoryIds the category IDs
3282             * @param start the lower bound of the range of message boards threads
3283             * @param end the upper bound of the range of message boards threads (not inclusive)
3284             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3285             * @return the ordered range of matching message boards threads that the user has permission to view
3286             * @throws SystemException if a system exception occurred
3287             */
3288            public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
3289                    int start, int end, OrderByComparator orderByComparator)
3290                    throws SystemException {
3291                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3292                            return findByG_C(groupId, categoryIds, start, end, orderByComparator);
3293                    }
3294    
3295                    StringBundler query = new StringBundler();
3296    
3297                    if (getDB().isSupportsInlineDistinct()) {
3298                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3299                    }
3300                    else {
3301                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3302                    }
3303    
3304                    boolean conjunctionable = false;
3305    
3306                    if (conjunctionable) {
3307                            query.append(WHERE_AND);
3308                    }
3309    
3310                    query.append(_FINDER_COLUMN_G_C_GROUPID_5);
3311    
3312                    conjunctionable = true;
3313    
3314                    if ((categoryIds == null) || (categoryIds.length > 0)) {
3315                            if (conjunctionable) {
3316                                    query.append(WHERE_AND);
3317                            }
3318    
3319                            query.append(StringPool.OPEN_PARENTHESIS);
3320    
3321                            for (int i = 0; i < categoryIds.length; i++) {
3322                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
3323    
3324                                    if ((i + 1) < categoryIds.length) {
3325                                            query.append(WHERE_OR);
3326                                    }
3327                            }
3328    
3329                            query.append(StringPool.CLOSE_PARENTHESIS);
3330    
3331                            conjunctionable = true;
3332                    }
3333    
3334                    if (!getDB().isSupportsInlineDistinct()) {
3335                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3336                    }
3337    
3338                    if (orderByComparator != null) {
3339                            if (getDB().isSupportsInlineDistinct()) {
3340                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3341                                            orderByComparator, true);
3342                            }
3343                            else {
3344                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3345                                            orderByComparator, true);
3346                            }
3347                    }
3348                    else {
3349                            if (getDB().isSupportsInlineDistinct()) {
3350                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3351                            }
3352                            else {
3353                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
3354                            }
3355                    }
3356    
3357                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3358                                    MBThread.class.getName(),
3359                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3360    
3361                    Session session = null;
3362    
3363                    try {
3364                            session = openSession();
3365    
3366                            SQLQuery q = session.createSQLQuery(sql);
3367    
3368                            if (getDB().isSupportsInlineDistinct()) {
3369                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3370                            }
3371                            else {
3372                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3373                            }
3374    
3375                            QueryPos qPos = QueryPos.getInstance(q);
3376    
3377                            qPos.add(groupId);
3378    
3379                            if (categoryIds != null) {
3380                                    qPos.add(categoryIds);
3381                            }
3382    
3383                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3384                    }
3385                    catch (Exception e) {
3386                            throw processException(e);
3387                    }
3388                    finally {
3389                            closeSession(session);
3390                    }
3391            }
3392    
3393            /**
3394             * Returns all the message boards threads where groupId = &#63; and categoryId = any &#63;.
3395             *
3396             * <p>
3397             * 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.
3398             * </p>
3399             *
3400             * @param groupId the group ID
3401             * @param categoryIds the category IDs
3402             * @return the matching message boards threads
3403             * @throws SystemException if a system exception occurred
3404             */
3405            public List<MBThread> findByG_C(long groupId, long[] categoryIds)
3406                    throws SystemException {
3407                    return findByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
3408                            QueryUtil.ALL_POS, null);
3409            }
3410    
3411            /**
3412             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = any &#63;.
3413             *
3414             * <p>
3415             * 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.
3416             * </p>
3417             *
3418             * @param groupId the group ID
3419             * @param categoryIds the category IDs
3420             * @param start the lower bound of the range of message boards threads
3421             * @param end the upper bound of the range of message boards threads (not inclusive)
3422             * @return the range of matching message boards threads
3423             * @throws SystemException if a system exception occurred
3424             */
3425            public List<MBThread> findByG_C(long groupId, long[] categoryIds,
3426                    int start, int end) throws SystemException {
3427                    return findByG_C(groupId, categoryIds, start, end, null);
3428            }
3429    
3430            /**
3431             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = any &#63;.
3432             *
3433             * <p>
3434             * 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.
3435             * </p>
3436             *
3437             * @param groupId the group ID
3438             * @param categoryIds the category IDs
3439             * @param start the lower bound of the range of message boards threads
3440             * @param end the upper bound of the range of message boards threads (not inclusive)
3441             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3442             * @return the ordered range of matching message boards threads
3443             * @throws SystemException if a system exception occurred
3444             */
3445            public List<MBThread> findByG_C(long groupId, long[] categoryIds,
3446                    int start, int end, OrderByComparator orderByComparator)
3447                    throws SystemException {
3448                    if ((categoryIds != null) && (categoryIds.length == 1)) {
3449                            return findByG_C(groupId, categoryIds[0], start, end,
3450                                    orderByComparator);
3451                    }
3452    
3453                    boolean pagination = true;
3454                    Object[] finderArgs = null;
3455    
3456                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3457                                    (orderByComparator == null)) {
3458                            pagination = false;
3459                            finderArgs = new Object[] { groupId, StringUtil.merge(categoryIds) };
3460                    }
3461                    else {
3462                            finderArgs = new Object[] {
3463                                            groupId, StringUtil.merge(categoryIds),
3464                                            
3465                                            start, end, orderByComparator
3466                                    };
3467                    }
3468    
3469                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
3470                                    finderArgs, this);
3471    
3472                    if ((list != null) && !list.isEmpty()) {
3473                            for (MBThread mbThread : list) {
3474                                    if ((groupId != mbThread.getGroupId()) ||
3475                                                    !ArrayUtil.contains(categoryIds,
3476                                                            mbThread.getCategoryId())) {
3477                                            list = null;
3478    
3479                                            break;
3480                                    }
3481                            }
3482                    }
3483    
3484                    if (list == null) {
3485                            StringBundler query = new StringBundler();
3486    
3487                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
3488    
3489                            boolean conjunctionable = false;
3490    
3491                            if (conjunctionable) {
3492                                    query.append(WHERE_AND);
3493                            }
3494    
3495                            query.append(_FINDER_COLUMN_G_C_GROUPID_5);
3496    
3497                            conjunctionable = true;
3498    
3499                            if ((categoryIds == null) || (categoryIds.length > 0)) {
3500                                    if (conjunctionable) {
3501                                            query.append(WHERE_AND);
3502                                    }
3503    
3504                                    query.append(StringPool.OPEN_PARENTHESIS);
3505    
3506                                    for (int i = 0; i < categoryIds.length; i++) {
3507                                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
3508    
3509                                            if ((i + 1) < categoryIds.length) {
3510                                                    query.append(WHERE_OR);
3511                                            }
3512                                    }
3513    
3514                                    query.append(StringPool.CLOSE_PARENTHESIS);
3515    
3516                                    conjunctionable = true;
3517                            }
3518    
3519                            if (orderByComparator != null) {
3520                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3521                                            orderByComparator);
3522                            }
3523                            else
3524                             if (pagination) {
3525                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3526                            }
3527    
3528                            String sql = query.toString();
3529    
3530                            Session session = null;
3531    
3532                            try {
3533                                    session = openSession();
3534    
3535                                    Query q = session.createQuery(sql);
3536    
3537                                    QueryPos qPos = QueryPos.getInstance(q);
3538    
3539                                    qPos.add(groupId);
3540    
3541                                    if (categoryIds != null) {
3542                                            qPos.add(categoryIds);
3543                                    }
3544    
3545                                    if (!pagination) {
3546                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3547                                                            start, end, false);
3548    
3549                                            Collections.sort(list);
3550    
3551                                            list = new UnmodifiableList<MBThread>(list);
3552                                    }
3553                                    else {
3554                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3555                                                            start, end);
3556                                    }
3557    
3558                                    cacheResult(list);
3559    
3560                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
3561                                            finderArgs, list);
3562                            }
3563                            catch (Exception e) {
3564                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
3565                                            finderArgs);
3566    
3567                                    throw processException(e);
3568                            }
3569                            finally {
3570                                    closeSession(session);
3571                            }
3572                    }
3573    
3574                    return list;
3575            }
3576    
3577            /**
3578             * Removes all the message boards threads where groupId = &#63; and categoryId = &#63; from the database.
3579             *
3580             * @param groupId the group ID
3581             * @param categoryId the category ID
3582             * @throws SystemException if a system exception occurred
3583             */
3584            public void removeByG_C(long groupId, long categoryId)
3585                    throws SystemException {
3586                    for (MBThread mbThread : findByG_C(groupId, categoryId,
3587                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3588                            remove(mbThread);
3589                    }
3590            }
3591    
3592            /**
3593             * Returns the number of message boards threads where groupId = &#63; and categoryId = &#63;.
3594             *
3595             * @param groupId the group ID
3596             * @param categoryId the category ID
3597             * @return the number of matching message boards threads
3598             * @throws SystemException if a system exception occurred
3599             */
3600            public int countByG_C(long groupId, long categoryId)
3601                    throws SystemException {
3602                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
3603    
3604                    Object[] finderArgs = new Object[] { groupId, categoryId };
3605    
3606                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3607                                    this);
3608    
3609                    if (count == null) {
3610                            StringBundler query = new StringBundler(3);
3611    
3612                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
3613    
3614                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3615    
3616                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3617    
3618                            String sql = query.toString();
3619    
3620                            Session session = null;
3621    
3622                            try {
3623                                    session = openSession();
3624    
3625                                    Query q = session.createQuery(sql);
3626    
3627                                    QueryPos qPos = QueryPos.getInstance(q);
3628    
3629                                    qPos.add(groupId);
3630    
3631                                    qPos.add(categoryId);
3632    
3633                                    count = (Long)q.uniqueResult();
3634    
3635                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3636                            }
3637                            catch (Exception e) {
3638                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3639    
3640                                    throw processException(e);
3641                            }
3642                            finally {
3643                                    closeSession(session);
3644                            }
3645                    }
3646    
3647                    return count.intValue();
3648            }
3649    
3650            /**
3651             * Returns the number of message boards threads where groupId = &#63; and categoryId = any &#63;.
3652             *
3653             * @param groupId the group ID
3654             * @param categoryIds the category IDs
3655             * @return the number of matching message boards threads
3656             * @throws SystemException if a system exception occurred
3657             */
3658            public int countByG_C(long groupId, long[] categoryIds)
3659                    throws SystemException {
3660                    Object[] finderArgs = new Object[] {
3661                                    groupId, StringUtil.merge(categoryIds)
3662                            };
3663    
3664                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
3665                                    finderArgs, this);
3666    
3667                    if (count == null) {
3668                            StringBundler query = new StringBundler();
3669    
3670                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
3671    
3672                            boolean conjunctionable = false;
3673    
3674                            if (conjunctionable) {
3675                                    query.append(WHERE_AND);
3676                            }
3677    
3678                            query.append(_FINDER_COLUMN_G_C_GROUPID_5);
3679    
3680                            conjunctionable = true;
3681    
3682                            if ((categoryIds == null) || (categoryIds.length > 0)) {
3683                                    if (conjunctionable) {
3684                                            query.append(WHERE_AND);
3685                                    }
3686    
3687                                    query.append(StringPool.OPEN_PARENTHESIS);
3688    
3689                                    for (int i = 0; i < categoryIds.length; i++) {
3690                                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
3691    
3692                                            if ((i + 1) < categoryIds.length) {
3693                                                    query.append(WHERE_OR);
3694                                            }
3695                                    }
3696    
3697                                    query.append(StringPool.CLOSE_PARENTHESIS);
3698    
3699                                    conjunctionable = true;
3700                            }
3701    
3702                            String sql = query.toString();
3703    
3704                            Session session = null;
3705    
3706                            try {
3707                                    session = openSession();
3708    
3709                                    Query q = session.createQuery(sql);
3710    
3711                                    QueryPos qPos = QueryPos.getInstance(q);
3712    
3713                                    qPos.add(groupId);
3714    
3715                                    if (categoryIds != null) {
3716                                            qPos.add(categoryIds);
3717                                    }
3718    
3719                                    count = (Long)q.uniqueResult();
3720    
3721                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
3722                                            finderArgs, count);
3723                            }
3724                            catch (Exception e) {
3725                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
3726                                            finderArgs);
3727    
3728                                    throw processException(e);
3729                            }
3730                            finally {
3731                                    closeSession(session);
3732                            }
3733                    }
3734    
3735                    return count.intValue();
3736            }
3737    
3738            /**
3739             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63;.
3740             *
3741             * @param groupId the group ID
3742             * @param categoryId the category ID
3743             * @return the number of matching message boards threads that the user has permission to view
3744             * @throws SystemException if a system exception occurred
3745             */
3746            public int filterCountByG_C(long groupId, long categoryId)
3747                    throws SystemException {
3748                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3749                            return countByG_C(groupId, categoryId);
3750                    }
3751    
3752                    StringBundler query = new StringBundler(3);
3753    
3754                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
3755    
3756                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3757    
3758                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3759    
3760                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3761                                    MBThread.class.getName(),
3762                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3763    
3764                    Session session = null;
3765    
3766                    try {
3767                            session = openSession();
3768    
3769                            SQLQuery q = session.createSQLQuery(sql);
3770    
3771                            q.addScalar(COUNT_COLUMN_NAME,
3772                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3773    
3774                            QueryPos qPos = QueryPos.getInstance(q);
3775    
3776                            qPos.add(groupId);
3777    
3778                            qPos.add(categoryId);
3779    
3780                            Long count = (Long)q.uniqueResult();
3781    
3782                            return count.intValue();
3783                    }
3784                    catch (Exception e) {
3785                            throw processException(e);
3786                    }
3787                    finally {
3788                            closeSession(session);
3789                    }
3790            }
3791    
3792            /**
3793             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63;.
3794             *
3795             * @param groupId the group ID
3796             * @param categoryIds the category IDs
3797             * @return the number of matching message boards threads that the user has permission to view
3798             * @throws SystemException if a system exception occurred
3799             */
3800            public int filterCountByG_C(long groupId, long[] categoryIds)
3801                    throws SystemException {
3802                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3803                            return countByG_C(groupId, categoryIds);
3804                    }
3805    
3806                    StringBundler query = new StringBundler();
3807    
3808                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
3809    
3810                    boolean conjunctionable = false;
3811    
3812                    if (conjunctionable) {
3813                            query.append(WHERE_AND);
3814                    }
3815    
3816                    query.append(_FINDER_COLUMN_G_C_GROUPID_5);
3817    
3818                    conjunctionable = true;
3819    
3820                    if ((categoryIds == null) || (categoryIds.length > 0)) {
3821                            if (conjunctionable) {
3822                                    query.append(WHERE_AND);
3823                            }
3824    
3825                            query.append(StringPool.OPEN_PARENTHESIS);
3826    
3827                            for (int i = 0; i < categoryIds.length; i++) {
3828                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
3829    
3830                                    if ((i + 1) < categoryIds.length) {
3831                                            query.append(WHERE_OR);
3832                                    }
3833                            }
3834    
3835                            query.append(StringPool.CLOSE_PARENTHESIS);
3836    
3837                            conjunctionable = true;
3838                    }
3839    
3840                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3841                                    MBThread.class.getName(),
3842                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3843    
3844                    Session session = null;
3845    
3846                    try {
3847                            session = openSession();
3848    
3849                            SQLQuery q = session.createSQLQuery(sql);
3850    
3851                            q.addScalar(COUNT_COLUMN_NAME,
3852                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3853    
3854                            QueryPos qPos = QueryPos.getInstance(q);
3855    
3856                            qPos.add(groupId);
3857    
3858                            if (categoryIds != null) {
3859                                    qPos.add(categoryIds);
3860                            }
3861    
3862                            Long count = (Long)q.uniqueResult();
3863    
3864                            return count.intValue();
3865                    }
3866                    catch (Exception e) {
3867                            throw processException(e);
3868                    }
3869                    finally {
3870                            closeSession(session);
3871                    }
3872            }
3873    
3874            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbThread.groupId = ? AND ";
3875            private static final String _FINDER_COLUMN_G_C_GROUPID_5 = "(" +
3876                    removeConjunction(_FINDER_COLUMN_G_C_GROUPID_2) + ")";
3877            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbThread.categoryId = ?";
3878            private static final String _FINDER_COLUMN_G_C_CATEGORYID_5 = "(" +
3879                    removeConjunction(_FINDER_COLUMN_G_C_CATEGORYID_2) + ")";
3880            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
3881                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
3882                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC",
3883                            new String[] {
3884                                    Long.class.getName(), Long.class.getName(),
3885                                    
3886                            Integer.class.getName(), Integer.class.getName(),
3887                                    OrderByComparator.class.getName()
3888                            });
3889            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
3890                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
3891                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC",
3892                            new String[] { Long.class.getName(), Long.class.getName() });
3893    
3894            /**
3895             * Returns all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
3896             *
3897             * @param groupId the group ID
3898             * @param categoryId the category ID
3899             * @return the matching message boards threads
3900             * @throws SystemException if a system exception occurred
3901             */
3902            public List<MBThread> findByG_NotC(long groupId, long categoryId)
3903                    throws SystemException {
3904                    return findByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
3905                            QueryUtil.ALL_POS, null);
3906            }
3907    
3908            /**
3909             * Returns a range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
3910             *
3911             * <p>
3912             * 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.
3913             * </p>
3914             *
3915             * @param groupId the group ID
3916             * @param categoryId the category ID
3917             * @param start the lower bound of the range of message boards threads
3918             * @param end the upper bound of the range of message boards threads (not inclusive)
3919             * @return the range of matching message boards threads
3920             * @throws SystemException if a system exception occurred
3921             */
3922            public List<MBThread> findByG_NotC(long groupId, long categoryId,
3923                    int start, int end) throws SystemException {
3924                    return findByG_NotC(groupId, categoryId, start, end, null);
3925            }
3926    
3927            /**
3928             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
3929             *
3930             * <p>
3931             * 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.
3932             * </p>
3933             *
3934             * @param groupId the group ID
3935             * @param categoryId the category ID
3936             * @param start the lower bound of the range of message boards threads
3937             * @param end the upper bound of the range of message boards threads (not inclusive)
3938             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3939             * @return the ordered range of matching message boards threads
3940             * @throws SystemException if a system exception occurred
3941             */
3942            public List<MBThread> findByG_NotC(long groupId, long categoryId,
3943                    int start, int end, OrderByComparator orderByComparator)
3944                    throws SystemException {
3945                    boolean pagination = true;
3946                    FinderPath finderPath = null;
3947                    Object[] finderArgs = null;
3948    
3949                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC;
3950                    finderArgs = new Object[] {
3951                                    groupId, categoryId,
3952                                    
3953                                    start, end, orderByComparator
3954                            };
3955    
3956                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
3957                                    finderArgs, this);
3958    
3959                    if ((list != null) && !list.isEmpty()) {
3960                            for (MBThread mbThread : list) {
3961                                    if ((groupId != mbThread.getGroupId()) ||
3962                                                    (categoryId != mbThread.getCategoryId())) {
3963                                            list = null;
3964    
3965                                            break;
3966                                    }
3967                            }
3968                    }
3969    
3970                    if (list == null) {
3971                            StringBundler query = null;
3972    
3973                            if (orderByComparator != null) {
3974                                    query = new StringBundler(4 +
3975                                                    (orderByComparator.getOrderByFields().length * 3));
3976                            }
3977                            else {
3978                                    query = new StringBundler(4);
3979                            }
3980    
3981                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
3982    
3983                            query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
3984    
3985                            query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
3986    
3987                            if (orderByComparator != null) {
3988                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3989                                            orderByComparator);
3990                            }
3991                            else
3992                             if (pagination) {
3993                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3994                            }
3995    
3996                            String sql = query.toString();
3997    
3998                            Session session = null;
3999    
4000                            try {
4001                                    session = openSession();
4002    
4003                                    Query q = session.createQuery(sql);
4004    
4005                                    QueryPos qPos = QueryPos.getInstance(q);
4006    
4007                                    qPos.add(groupId);
4008    
4009                                    qPos.add(categoryId);
4010    
4011                                    if (!pagination) {
4012                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
4013                                                            start, end, false);
4014    
4015                                            Collections.sort(list);
4016    
4017                                            list = new UnmodifiableList<MBThread>(list);
4018                                    }
4019                                    else {
4020                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
4021                                                            start, end);
4022                                    }
4023    
4024                                    cacheResult(list);
4025    
4026                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4027                            }
4028                            catch (Exception e) {
4029                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4030    
4031                                    throw processException(e);
4032                            }
4033                            finally {
4034                                    closeSession(session);
4035                            }
4036                    }
4037    
4038                    return list;
4039            }
4040    
4041            /**
4042             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
4043             *
4044             * @param groupId the group ID
4045             * @param categoryId the category ID
4046             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4047             * @return the first matching message boards thread
4048             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
4049             * @throws SystemException if a system exception occurred
4050             */
4051            public MBThread findByG_NotC_First(long groupId, long categoryId,
4052                    OrderByComparator orderByComparator)
4053                    throws NoSuchThreadException, SystemException {
4054                    MBThread mbThread = fetchByG_NotC_First(groupId, categoryId,
4055                                    orderByComparator);
4056    
4057                    if (mbThread != null) {
4058                            return mbThread;
4059                    }
4060    
4061                    StringBundler msg = new StringBundler(6);
4062    
4063                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4064    
4065                    msg.append("groupId=");
4066                    msg.append(groupId);
4067    
4068                    msg.append(", categoryId=");
4069                    msg.append(categoryId);
4070    
4071                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4072    
4073                    throw new NoSuchThreadException(msg.toString());
4074            }
4075    
4076            /**
4077             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
4078             *
4079             * @param groupId the group ID
4080             * @param categoryId the category ID
4081             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4082             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
4083             * @throws SystemException if a system exception occurred
4084             */
4085            public MBThread fetchByG_NotC_First(long groupId, long categoryId,
4086                    OrderByComparator orderByComparator) throws SystemException {
4087                    List<MBThread> list = findByG_NotC(groupId, categoryId, 0, 1,
4088                                    orderByComparator);
4089    
4090                    if (!list.isEmpty()) {
4091                            return list.get(0);
4092                    }
4093    
4094                    return null;
4095            }
4096    
4097            /**
4098             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
4099             *
4100             * @param groupId the group ID
4101             * @param categoryId the category ID
4102             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4103             * @return the last matching message boards thread
4104             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
4105             * @throws SystemException if a system exception occurred
4106             */
4107            public MBThread findByG_NotC_Last(long groupId, long categoryId,
4108                    OrderByComparator orderByComparator)
4109                    throws NoSuchThreadException, SystemException {
4110                    MBThread mbThread = fetchByG_NotC_Last(groupId, categoryId,
4111                                    orderByComparator);
4112    
4113                    if (mbThread != null) {
4114                            return mbThread;
4115                    }
4116    
4117                    StringBundler msg = new StringBundler(6);
4118    
4119                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4120    
4121                    msg.append("groupId=");
4122                    msg.append(groupId);
4123    
4124                    msg.append(", categoryId=");
4125                    msg.append(categoryId);
4126    
4127                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4128    
4129                    throw new NoSuchThreadException(msg.toString());
4130            }
4131    
4132            /**
4133             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
4134             *
4135             * @param groupId the group ID
4136             * @param categoryId the category ID
4137             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4138             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
4139             * @throws SystemException if a system exception occurred
4140             */
4141            public MBThread fetchByG_NotC_Last(long groupId, long categoryId,
4142                    OrderByComparator orderByComparator) throws SystemException {
4143                    int count = countByG_NotC(groupId, categoryId);
4144    
4145                    List<MBThread> list = findByG_NotC(groupId, categoryId, count - 1,
4146                                    count, orderByComparator);
4147    
4148                    if (!list.isEmpty()) {
4149                            return list.get(0);
4150                    }
4151    
4152                    return null;
4153            }
4154    
4155            /**
4156             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
4157             *
4158             * @param threadId the primary key of the current message boards thread
4159             * @param groupId the group ID
4160             * @param categoryId the category ID
4161             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4162             * @return the previous, current, and next message boards thread
4163             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
4164             * @throws SystemException if a system exception occurred
4165             */
4166            public MBThread[] findByG_NotC_PrevAndNext(long threadId, long groupId,
4167                    long categoryId, OrderByComparator orderByComparator)
4168                    throws NoSuchThreadException, SystemException {
4169                    MBThread mbThread = findByPrimaryKey(threadId);
4170    
4171                    Session session = null;
4172    
4173                    try {
4174                            session = openSession();
4175    
4176                            MBThread[] array = new MBThreadImpl[3];
4177    
4178                            array[0] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
4179                                            categoryId, orderByComparator, true);
4180    
4181                            array[1] = mbThread;
4182    
4183                            array[2] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
4184                                            categoryId, orderByComparator, false);
4185    
4186                            return array;
4187                    }
4188                    catch (Exception e) {
4189                            throw processException(e);
4190                    }
4191                    finally {
4192                            closeSession(session);
4193                    }
4194            }
4195    
4196            protected MBThread getByG_NotC_PrevAndNext(Session session,
4197                    MBThread mbThread, long groupId, long categoryId,
4198                    OrderByComparator orderByComparator, boolean previous) {
4199                    StringBundler query = null;
4200    
4201                    if (orderByComparator != null) {
4202                            query = new StringBundler(6 +
4203                                            (orderByComparator.getOrderByFields().length * 6));
4204                    }
4205                    else {
4206                            query = new StringBundler(3);
4207                    }
4208    
4209                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
4210    
4211                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4212    
4213                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4214    
4215                    if (orderByComparator != null) {
4216                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4217    
4218                            if (orderByConditionFields.length > 0) {
4219                                    query.append(WHERE_AND);
4220                            }
4221    
4222                            for (int i = 0; i < orderByConditionFields.length; i++) {
4223                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4224                                    query.append(orderByConditionFields[i]);
4225    
4226                                    if ((i + 1) < orderByConditionFields.length) {
4227                                            if (orderByComparator.isAscending() ^ previous) {
4228                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4229                                            }
4230                                            else {
4231                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4232                                            }
4233                                    }
4234                                    else {
4235                                            if (orderByComparator.isAscending() ^ previous) {
4236                                                    query.append(WHERE_GREATER_THAN);
4237                                            }
4238                                            else {
4239                                                    query.append(WHERE_LESSER_THAN);
4240                                            }
4241                                    }
4242                            }
4243    
4244                            query.append(ORDER_BY_CLAUSE);
4245    
4246                            String[] orderByFields = orderByComparator.getOrderByFields();
4247    
4248                            for (int i = 0; i < orderByFields.length; i++) {
4249                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4250                                    query.append(orderByFields[i]);
4251    
4252                                    if ((i + 1) < orderByFields.length) {
4253                                            if (orderByComparator.isAscending() ^ previous) {
4254                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4255                                            }
4256                                            else {
4257                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4258                                            }
4259                                    }
4260                                    else {
4261                                            if (orderByComparator.isAscending() ^ previous) {
4262                                                    query.append(ORDER_BY_ASC);
4263                                            }
4264                                            else {
4265                                                    query.append(ORDER_BY_DESC);
4266                                            }
4267                                    }
4268                            }
4269                    }
4270                    else {
4271                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4272                    }
4273    
4274                    String sql = query.toString();
4275    
4276                    Query q = session.createQuery(sql);
4277    
4278                    q.setFirstResult(0);
4279                    q.setMaxResults(2);
4280    
4281                    QueryPos qPos = QueryPos.getInstance(q);
4282    
4283                    qPos.add(groupId);
4284    
4285                    qPos.add(categoryId);
4286    
4287                    if (orderByComparator != null) {
4288                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4289    
4290                            for (Object value : values) {
4291                                    qPos.add(value);
4292                            }
4293                    }
4294    
4295                    List<MBThread> list = q.list();
4296    
4297                    if (list.size() == 2) {
4298                            return list.get(1);
4299                    }
4300                    else {
4301                            return null;
4302                    }
4303            }
4304    
4305            /**
4306             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63;.
4307             *
4308             * @param groupId the group ID
4309             * @param categoryId the category ID
4310             * @return the matching message boards threads that the user has permission to view
4311             * @throws SystemException if a system exception occurred
4312             */
4313            public List<MBThread> filterFindByG_NotC(long groupId, long categoryId)
4314                    throws SystemException {
4315                    return filterFindByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
4316                            QueryUtil.ALL_POS, null);
4317            }
4318    
4319            /**
4320             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63;.
4321             *
4322             * <p>
4323             * 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.
4324             * </p>
4325             *
4326             * @param groupId the group ID
4327             * @param categoryId the category ID
4328             * @param start the lower bound of the range of message boards threads
4329             * @param end the upper bound of the range of message boards threads (not inclusive)
4330             * @return the range of matching message boards threads that the user has permission to view
4331             * @throws SystemException if a system exception occurred
4332             */
4333            public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
4334                    int start, int end) throws SystemException {
4335                    return filterFindByG_NotC(groupId, categoryId, start, end, null);
4336            }
4337    
4338            /**
4339             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and categoryId &ne; &#63;.
4340             *
4341             * <p>
4342             * 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.
4343             * </p>
4344             *
4345             * @param groupId the group ID
4346             * @param categoryId the category ID
4347             * @param start the lower bound of the range of message boards threads
4348             * @param end the upper bound of the range of message boards threads (not inclusive)
4349             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4350             * @return the ordered range of matching message boards threads that the user has permission to view
4351             * @throws SystemException if a system exception occurred
4352             */
4353            public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
4354                    int start, int end, OrderByComparator orderByComparator)
4355                    throws SystemException {
4356                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4357                            return findByG_NotC(groupId, categoryId, start, end,
4358                                    orderByComparator);
4359                    }
4360    
4361                    StringBundler query = null;
4362    
4363                    if (orderByComparator != null) {
4364                            query = new StringBundler(4 +
4365                                            (orderByComparator.getOrderByFields().length * 3));
4366                    }
4367                    else {
4368                            query = new StringBundler(4);
4369                    }
4370    
4371                    if (getDB().isSupportsInlineDistinct()) {
4372                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
4373                    }
4374                    else {
4375                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
4376                    }
4377    
4378                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4379    
4380                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4381    
4382                    if (!getDB().isSupportsInlineDistinct()) {
4383                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
4384                    }
4385    
4386                    if (orderByComparator != null) {
4387                            if (getDB().isSupportsInlineDistinct()) {
4388                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4389                                            orderByComparator, true);
4390                            }
4391                            else {
4392                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4393                                            orderByComparator, true);
4394                            }
4395                    }
4396                    else {
4397                            if (getDB().isSupportsInlineDistinct()) {
4398                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4399                            }
4400                            else {
4401                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
4402                            }
4403                    }
4404    
4405                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4406                                    MBThread.class.getName(),
4407                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4408    
4409                    Session session = null;
4410    
4411                    try {
4412                            session = openSession();
4413    
4414                            SQLQuery q = session.createSQLQuery(sql);
4415    
4416                            if (getDB().isSupportsInlineDistinct()) {
4417                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
4418                            }
4419                            else {
4420                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
4421                            }
4422    
4423                            QueryPos qPos = QueryPos.getInstance(q);
4424    
4425                            qPos.add(groupId);
4426    
4427                            qPos.add(categoryId);
4428    
4429                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
4430                    }
4431                    catch (Exception e) {
4432                            throw processException(e);
4433                    }
4434                    finally {
4435                            closeSession(session);
4436                    }
4437            }
4438    
4439            /**
4440             * 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;.
4441             *
4442             * @param threadId the primary key of the current message boards thread
4443             * @param groupId the group ID
4444             * @param categoryId the category ID
4445             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4446             * @return the previous, current, and next message boards thread
4447             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
4448             * @throws SystemException if a system exception occurred
4449             */
4450            public MBThread[] filterFindByG_NotC_PrevAndNext(long threadId,
4451                    long groupId, long categoryId, OrderByComparator orderByComparator)
4452                    throws NoSuchThreadException, SystemException {
4453                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4454                            return findByG_NotC_PrevAndNext(threadId, groupId, categoryId,
4455                                    orderByComparator);
4456                    }
4457    
4458                    MBThread mbThread = findByPrimaryKey(threadId);
4459    
4460                    Session session = null;
4461    
4462                    try {
4463                            session = openSession();
4464    
4465                            MBThread[] array = new MBThreadImpl[3];
4466    
4467                            array[0] = filterGetByG_NotC_PrevAndNext(session, mbThread,
4468                                            groupId, categoryId, orderByComparator, true);
4469    
4470                            array[1] = mbThread;
4471    
4472                            array[2] = filterGetByG_NotC_PrevAndNext(session, mbThread,
4473                                            groupId, categoryId, orderByComparator, false);
4474    
4475                            return array;
4476                    }
4477                    catch (Exception e) {
4478                            throw processException(e);
4479                    }
4480                    finally {
4481                            closeSession(session);
4482                    }
4483            }
4484    
4485            protected MBThread filterGetByG_NotC_PrevAndNext(Session session,
4486                    MBThread mbThread, long groupId, long categoryId,
4487                    OrderByComparator orderByComparator, boolean previous) {
4488                    StringBundler query = null;
4489    
4490                    if (orderByComparator != null) {
4491                            query = new StringBundler(6 +
4492                                            (orderByComparator.getOrderByFields().length * 6));
4493                    }
4494                    else {
4495                            query = new StringBundler(3);
4496                    }
4497    
4498                    if (getDB().isSupportsInlineDistinct()) {
4499                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
4500                    }
4501                    else {
4502                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
4503                    }
4504    
4505                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4506    
4507                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4508    
4509                    if (!getDB().isSupportsInlineDistinct()) {
4510                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
4511                    }
4512    
4513                    if (orderByComparator != null) {
4514                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4515    
4516                            if (orderByConditionFields.length > 0) {
4517                                    query.append(WHERE_AND);
4518                            }
4519    
4520                            for (int i = 0; i < orderByConditionFields.length; i++) {
4521                                    if (getDB().isSupportsInlineDistinct()) {
4522                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4523                                    }
4524                                    else {
4525                                            query.append(_ORDER_BY_ENTITY_TABLE);
4526                                    }
4527    
4528                                    query.append(orderByConditionFields[i]);
4529    
4530                                    if ((i + 1) < orderByConditionFields.length) {
4531                                            if (orderByComparator.isAscending() ^ previous) {
4532                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4533                                            }
4534                                            else {
4535                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4536                                            }
4537                                    }
4538                                    else {
4539                                            if (orderByComparator.isAscending() ^ previous) {
4540                                                    query.append(WHERE_GREATER_THAN);
4541                                            }
4542                                            else {
4543                                                    query.append(WHERE_LESSER_THAN);
4544                                            }
4545                                    }
4546                            }
4547    
4548                            query.append(ORDER_BY_CLAUSE);
4549    
4550                            String[] orderByFields = orderByComparator.getOrderByFields();
4551    
4552                            for (int i = 0; i < orderByFields.length; i++) {
4553                                    if (getDB().isSupportsInlineDistinct()) {
4554                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4555                                    }
4556                                    else {
4557                                            query.append(_ORDER_BY_ENTITY_TABLE);
4558                                    }
4559    
4560                                    query.append(orderByFields[i]);
4561    
4562                                    if ((i + 1) < orderByFields.length) {
4563                                            if (orderByComparator.isAscending() ^ previous) {
4564                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4565                                            }
4566                                            else {
4567                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4568                                            }
4569                                    }
4570                                    else {
4571                                            if (orderByComparator.isAscending() ^ previous) {
4572                                                    query.append(ORDER_BY_ASC);
4573                                            }
4574                                            else {
4575                                                    query.append(ORDER_BY_DESC);
4576                                            }
4577                                    }
4578                            }
4579                    }
4580                    else {
4581                            if (getDB().isSupportsInlineDistinct()) {
4582                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4583                            }
4584                            else {
4585                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
4586                            }
4587                    }
4588    
4589                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4590                                    MBThread.class.getName(),
4591                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4592    
4593                    SQLQuery q = session.createSQLQuery(sql);
4594    
4595                    q.setFirstResult(0);
4596                    q.setMaxResults(2);
4597    
4598                    if (getDB().isSupportsInlineDistinct()) {
4599                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
4600                    }
4601                    else {
4602                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
4603                    }
4604    
4605                    QueryPos qPos = QueryPos.getInstance(q);
4606    
4607                    qPos.add(groupId);
4608    
4609                    qPos.add(categoryId);
4610    
4611                    if (orderByComparator != null) {
4612                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4613    
4614                            for (Object value : values) {
4615                                    qPos.add(value);
4616                            }
4617                    }
4618    
4619                    List<MBThread> list = q.list();
4620    
4621                    if (list.size() == 2) {
4622                            return list.get(1);
4623                    }
4624                    else {
4625                            return null;
4626                    }
4627            }
4628    
4629            /**
4630             * Removes all the message boards threads where groupId = &#63; and categoryId &ne; &#63; from the database.
4631             *
4632             * @param groupId the group ID
4633             * @param categoryId the category ID
4634             * @throws SystemException if a system exception occurred
4635             */
4636            public void removeByG_NotC(long groupId, long categoryId)
4637                    throws SystemException {
4638                    for (MBThread mbThread : findByG_NotC(groupId, categoryId,
4639                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4640                            remove(mbThread);
4641                    }
4642            }
4643    
4644            /**
4645             * Returns the number of message boards threads where groupId = &#63; and categoryId &ne; &#63;.
4646             *
4647             * @param groupId the group ID
4648             * @param categoryId the category ID
4649             * @return the number of matching message boards threads
4650             * @throws SystemException if a system exception occurred
4651             */
4652            public int countByG_NotC(long groupId, long categoryId)
4653                    throws SystemException {
4654                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC;
4655    
4656                    Object[] finderArgs = new Object[] { groupId, categoryId };
4657    
4658                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4659                                    this);
4660    
4661                    if (count == null) {
4662                            StringBundler query = new StringBundler(3);
4663    
4664                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
4665    
4666                            query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4667    
4668                            query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4669    
4670                            String sql = query.toString();
4671    
4672                            Session session = null;
4673    
4674                            try {
4675                                    session = openSession();
4676    
4677                                    Query q = session.createQuery(sql);
4678    
4679                                    QueryPos qPos = QueryPos.getInstance(q);
4680    
4681                                    qPos.add(groupId);
4682    
4683                                    qPos.add(categoryId);
4684    
4685                                    count = (Long)q.uniqueResult();
4686    
4687                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4688                            }
4689                            catch (Exception e) {
4690                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4691    
4692                                    throw processException(e);
4693                            }
4694                            finally {
4695                                    closeSession(session);
4696                            }
4697                    }
4698    
4699                    return count.intValue();
4700            }
4701    
4702            /**
4703             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63;.
4704             *
4705             * @param groupId the group ID
4706             * @param categoryId the category ID
4707             * @return the number of matching message boards threads that the user has permission to view
4708             * @throws SystemException if a system exception occurred
4709             */
4710            public int filterCountByG_NotC(long groupId, long categoryId)
4711                    throws SystemException {
4712                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4713                            return countByG_NotC(groupId, categoryId);
4714                    }
4715    
4716                    StringBundler query = new StringBundler(3);
4717    
4718                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
4719    
4720                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4721    
4722                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4723    
4724                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4725                                    MBThread.class.getName(),
4726                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4727    
4728                    Session session = null;
4729    
4730                    try {
4731                            session = openSession();
4732    
4733                            SQLQuery q = session.createSQLQuery(sql);
4734    
4735                            q.addScalar(COUNT_COLUMN_NAME,
4736                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4737    
4738                            QueryPos qPos = QueryPos.getInstance(q);
4739    
4740                            qPos.add(groupId);
4741    
4742                            qPos.add(categoryId);
4743    
4744                            Long count = (Long)q.uniqueResult();
4745    
4746                            return count.intValue();
4747                    }
4748                    catch (Exception e) {
4749                            throw processException(e);
4750                    }
4751                    finally {
4752                            closeSession(session);
4753                    }
4754            }
4755    
4756            private static final String _FINDER_COLUMN_G_NOTC_GROUPID_2 = "mbThread.groupId = ? AND ";
4757            private static final String _FINDER_COLUMN_G_NOTC_CATEGORYID_2 = "mbThread.categoryId != ?";
4758            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4759                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
4760                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
4761                            new String[] {
4762                                    Long.class.getName(), Integer.class.getName(),
4763                                    
4764                            Integer.class.getName(), Integer.class.getName(),
4765                                    OrderByComparator.class.getName()
4766                            });
4767            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4768                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
4769                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
4770                            new String[] { Long.class.getName(), Integer.class.getName() },
4771                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
4772                            MBThreadModelImpl.STATUS_COLUMN_BITMASK |
4773                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
4774                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
4775            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4776                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
4777                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
4778                            new String[] { Long.class.getName(), Integer.class.getName() });
4779    
4780            /**
4781             * Returns all the message boards threads where groupId = &#63; and status = &#63;.
4782             *
4783             * @param groupId the group ID
4784             * @param status the status
4785             * @return the matching message boards threads
4786             * @throws SystemException if a system exception occurred
4787             */
4788            public List<MBThread> findByG_S(long groupId, int status)
4789                    throws SystemException {
4790                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4791                            null);
4792            }
4793    
4794            /**
4795             * Returns a range of all the message boards threads where groupId = &#63; and status = &#63;.
4796             *
4797             * <p>
4798             * 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.
4799             * </p>
4800             *
4801             * @param groupId the group ID
4802             * @param status the status
4803             * @param start the lower bound of the range of message boards threads
4804             * @param end the upper bound of the range of message boards threads (not inclusive)
4805             * @return the range of matching message boards threads
4806             * @throws SystemException if a system exception occurred
4807             */
4808            public List<MBThread> findByG_S(long groupId, int status, int start, int end)
4809                    throws SystemException {
4810                    return findByG_S(groupId, status, start, end, null);
4811            }
4812    
4813            /**
4814             * Returns an ordered range of all the message boards threads where groupId = &#63; and status = &#63;.
4815             *
4816             * <p>
4817             * 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.
4818             * </p>
4819             *
4820             * @param groupId the group ID
4821             * @param status the status
4822             * @param start the lower bound of the range of message boards threads
4823             * @param end the upper bound of the range of message boards threads (not inclusive)
4824             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4825             * @return the ordered range of matching message boards threads
4826             * @throws SystemException if a system exception occurred
4827             */
4828            public List<MBThread> findByG_S(long groupId, int status, int start,
4829                    int end, OrderByComparator orderByComparator) throws SystemException {
4830                    boolean pagination = true;
4831                    FinderPath finderPath = null;
4832                    Object[] finderArgs = null;
4833    
4834                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4835                                    (orderByComparator == null)) {
4836                            pagination = false;
4837                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
4838                            finderArgs = new Object[] { groupId, status };
4839                    }
4840                    else {
4841                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
4842                            finderArgs = new Object[] {
4843                                            groupId, status,
4844                                            
4845                                            start, end, orderByComparator
4846                                    };
4847                    }
4848    
4849                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
4850                                    finderArgs, this);
4851    
4852                    if ((list != null) && !list.isEmpty()) {
4853                            for (MBThread mbThread : list) {
4854                                    if ((groupId != mbThread.getGroupId()) ||
4855                                                    (status != mbThread.getStatus())) {
4856                                            list = null;
4857    
4858                                            break;
4859                                    }
4860                            }
4861                    }
4862    
4863                    if (list == null) {
4864                            StringBundler query = null;
4865    
4866                            if (orderByComparator != null) {
4867                                    query = new StringBundler(4 +
4868                                                    (orderByComparator.getOrderByFields().length * 3));
4869                            }
4870                            else {
4871                                    query = new StringBundler(4);
4872                            }
4873    
4874                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
4875    
4876                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4877    
4878                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
4879    
4880                            if (orderByComparator != null) {
4881                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4882                                            orderByComparator);
4883                            }
4884                            else
4885                             if (pagination) {
4886                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4887                            }
4888    
4889                            String sql = query.toString();
4890    
4891                            Session session = null;
4892    
4893                            try {
4894                                    session = openSession();
4895    
4896                                    Query q = session.createQuery(sql);
4897    
4898                                    QueryPos qPos = QueryPos.getInstance(q);
4899    
4900                                    qPos.add(groupId);
4901    
4902                                    qPos.add(status);
4903    
4904                                    if (!pagination) {
4905                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
4906                                                            start, end, false);
4907    
4908                                            Collections.sort(list);
4909    
4910                                            list = new UnmodifiableList<MBThread>(list);
4911                                    }
4912                                    else {
4913                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
4914                                                            start, end);
4915                                    }
4916    
4917                                    cacheResult(list);
4918    
4919                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4920                            }
4921                            catch (Exception e) {
4922                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4923    
4924                                    throw processException(e);
4925                            }
4926                            finally {
4927                                    closeSession(session);
4928                            }
4929                    }
4930    
4931                    return list;
4932            }
4933    
4934            /**
4935             * Returns the first message boards thread in the ordered set where groupId = &#63; and status = &#63;.
4936             *
4937             * @param groupId the group ID
4938             * @param status the status
4939             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4940             * @return the first matching message boards thread
4941             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
4942             * @throws SystemException if a system exception occurred
4943             */
4944            public MBThread findByG_S_First(long groupId, int status,
4945                    OrderByComparator orderByComparator)
4946                    throws NoSuchThreadException, SystemException {
4947                    MBThread mbThread = fetchByG_S_First(groupId, status, orderByComparator);
4948    
4949                    if (mbThread != null) {
4950                            return mbThread;
4951                    }
4952    
4953                    StringBundler msg = new StringBundler(6);
4954    
4955                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4956    
4957                    msg.append("groupId=");
4958                    msg.append(groupId);
4959    
4960                    msg.append(", status=");
4961                    msg.append(status);
4962    
4963                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4964    
4965                    throw new NoSuchThreadException(msg.toString());
4966            }
4967    
4968            /**
4969             * Returns the first message boards thread in the ordered set where groupId = &#63; and status = &#63;.
4970             *
4971             * @param groupId the group ID
4972             * @param status the status
4973             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4974             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
4975             * @throws SystemException if a system exception occurred
4976             */
4977            public MBThread fetchByG_S_First(long groupId, int status,
4978                    OrderByComparator orderByComparator) throws SystemException {
4979                    List<MBThread> list = findByG_S(groupId, status, 0, 1, orderByComparator);
4980    
4981                    if (!list.isEmpty()) {
4982                            return list.get(0);
4983                    }
4984    
4985                    return null;
4986            }
4987    
4988            /**
4989             * Returns the last message boards thread in the ordered set where groupId = &#63; and status = &#63;.
4990             *
4991             * @param groupId the group ID
4992             * @param status the status
4993             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4994             * @return the last matching message boards thread
4995             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
4996             * @throws SystemException if a system exception occurred
4997             */
4998            public MBThread findByG_S_Last(long groupId, int status,
4999                    OrderByComparator orderByComparator)
5000                    throws NoSuchThreadException, SystemException {
5001                    MBThread mbThread = fetchByG_S_Last(groupId, status, orderByComparator);
5002    
5003                    if (mbThread != null) {
5004                            return mbThread;
5005                    }
5006    
5007                    StringBundler msg = new StringBundler(6);
5008    
5009                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5010    
5011                    msg.append("groupId=");
5012                    msg.append(groupId);
5013    
5014                    msg.append(", status=");
5015                    msg.append(status);
5016    
5017                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5018    
5019                    throw new NoSuchThreadException(msg.toString());
5020            }
5021    
5022            /**
5023             * Returns the last message boards thread in the ordered set where groupId = &#63; and status = &#63;.
5024             *
5025             * @param groupId the group ID
5026             * @param status the status
5027             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5028             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
5029             * @throws SystemException if a system exception occurred
5030             */
5031            public MBThread fetchByG_S_Last(long groupId, int status,
5032                    OrderByComparator orderByComparator) throws SystemException {
5033                    int count = countByG_S(groupId, status);
5034    
5035                    List<MBThread> list = findByG_S(groupId, status, count - 1, count,
5036                                    orderByComparator);
5037    
5038                    if (!list.isEmpty()) {
5039                            return list.get(0);
5040                    }
5041    
5042                    return null;
5043            }
5044    
5045            /**
5046             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and status = &#63;.
5047             *
5048             * @param threadId the primary key of the current message boards thread
5049             * @param groupId the group ID
5050             * @param status the status
5051             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5052             * @return the previous, current, and next message boards thread
5053             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
5054             * @throws SystemException if a system exception occurred
5055             */
5056            public MBThread[] findByG_S_PrevAndNext(long threadId, long groupId,
5057                    int status, OrderByComparator orderByComparator)
5058                    throws NoSuchThreadException, SystemException {
5059                    MBThread mbThread = findByPrimaryKey(threadId);
5060    
5061                    Session session = null;
5062    
5063                    try {
5064                            session = openSession();
5065    
5066                            MBThread[] array = new MBThreadImpl[3];
5067    
5068                            array[0] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
5069                                            orderByComparator, true);
5070    
5071                            array[1] = mbThread;
5072    
5073                            array[2] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
5074                                            orderByComparator, false);
5075    
5076                            return array;
5077                    }
5078                    catch (Exception e) {
5079                            throw processException(e);
5080                    }
5081                    finally {
5082                            closeSession(session);
5083                    }
5084            }
5085    
5086            protected MBThread getByG_S_PrevAndNext(Session session, MBThread mbThread,
5087                    long groupId, int status, OrderByComparator orderByComparator,
5088                    boolean previous) {
5089                    StringBundler query = null;
5090    
5091                    if (orderByComparator != null) {
5092                            query = new StringBundler(6 +
5093                                            (orderByComparator.getOrderByFields().length * 6));
5094                    }
5095                    else {
5096                            query = new StringBundler(3);
5097                    }
5098    
5099                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
5100    
5101                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5102    
5103                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
5104    
5105                    if (orderByComparator != null) {
5106                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5107    
5108                            if (orderByConditionFields.length > 0) {
5109                                    query.append(WHERE_AND);
5110                            }
5111    
5112                            for (int i = 0; i < orderByConditionFields.length; i++) {
5113                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5114                                    query.append(orderByConditionFields[i]);
5115    
5116                                    if ((i + 1) < orderByConditionFields.length) {
5117                                            if (orderByComparator.isAscending() ^ previous) {
5118                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5119                                            }
5120                                            else {
5121                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5122                                            }
5123                                    }
5124                                    else {
5125                                            if (orderByComparator.isAscending() ^ previous) {
5126                                                    query.append(WHERE_GREATER_THAN);
5127                                            }
5128                                            else {
5129                                                    query.append(WHERE_LESSER_THAN);
5130                                            }
5131                                    }
5132                            }
5133    
5134                            query.append(ORDER_BY_CLAUSE);
5135    
5136                            String[] orderByFields = orderByComparator.getOrderByFields();
5137    
5138                            for (int i = 0; i < orderByFields.length; i++) {
5139                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5140                                    query.append(orderByFields[i]);
5141    
5142                                    if ((i + 1) < orderByFields.length) {
5143                                            if (orderByComparator.isAscending() ^ previous) {
5144                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5145                                            }
5146                                            else {
5147                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5148                                            }
5149                                    }
5150                                    else {
5151                                            if (orderByComparator.isAscending() ^ previous) {
5152                                                    query.append(ORDER_BY_ASC);
5153                                            }
5154                                            else {
5155                                                    query.append(ORDER_BY_DESC);
5156                                            }
5157                                    }
5158                            }
5159                    }
5160                    else {
5161                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5162                    }
5163    
5164                    String sql = query.toString();
5165    
5166                    Query q = session.createQuery(sql);
5167    
5168                    q.setFirstResult(0);
5169                    q.setMaxResults(2);
5170    
5171                    QueryPos qPos = QueryPos.getInstance(q);
5172    
5173                    qPos.add(groupId);
5174    
5175                    qPos.add(status);
5176    
5177                    if (orderByComparator != null) {
5178                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5179    
5180                            for (Object value : values) {
5181                                    qPos.add(value);
5182                            }
5183                    }
5184    
5185                    List<MBThread> list = q.list();
5186    
5187                    if (list.size() == 2) {
5188                            return list.get(1);
5189                    }
5190                    else {
5191                            return null;
5192                    }
5193            }
5194    
5195            /**
5196             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and status = &#63;.
5197             *
5198             * @param groupId the group ID
5199             * @param status the status
5200             * @return the matching message boards threads that the user has permission to view
5201             * @throws SystemException if a system exception occurred
5202             */
5203            public List<MBThread> filterFindByG_S(long groupId, int status)
5204                    throws SystemException {
5205                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
5206                            QueryUtil.ALL_POS, null);
5207            }
5208    
5209            /**
5210             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and status = &#63;.
5211             *
5212             * <p>
5213             * 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.
5214             * </p>
5215             *
5216             * @param groupId the group ID
5217             * @param status the status
5218             * @param start the lower bound of the range of message boards threads
5219             * @param end the upper bound of the range of message boards threads (not inclusive)
5220             * @return the range of matching message boards threads that the user has permission to view
5221             * @throws SystemException if a system exception occurred
5222             */
5223            public List<MBThread> filterFindByG_S(long groupId, int status, int start,
5224                    int end) throws SystemException {
5225                    return filterFindByG_S(groupId, status, start, end, null);
5226            }
5227    
5228            /**
5229             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and status = &#63;.
5230             *
5231             * <p>
5232             * 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.
5233             * </p>
5234             *
5235             * @param groupId the group ID
5236             * @param status the status
5237             * @param start the lower bound of the range of message boards threads
5238             * @param end the upper bound of the range of message boards threads (not inclusive)
5239             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5240             * @return the ordered range of matching message boards threads that the user has permission to view
5241             * @throws SystemException if a system exception occurred
5242             */
5243            public List<MBThread> filterFindByG_S(long groupId, int status, int start,
5244                    int end, OrderByComparator orderByComparator) throws SystemException {
5245                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5246                            return findByG_S(groupId, status, start, end, orderByComparator);
5247                    }
5248    
5249                    StringBundler query = null;
5250    
5251                    if (orderByComparator != null) {
5252                            query = new StringBundler(4 +
5253                                            (orderByComparator.getOrderByFields().length * 3));
5254                    }
5255                    else {
5256                            query = new StringBundler(4);
5257                    }
5258    
5259                    if (getDB().isSupportsInlineDistinct()) {
5260                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5261                    }
5262                    else {
5263                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5264                    }
5265    
5266                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5267    
5268                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
5269    
5270                    if (!getDB().isSupportsInlineDistinct()) {
5271                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5272                    }
5273    
5274                    if (orderByComparator != null) {
5275                            if (getDB().isSupportsInlineDistinct()) {
5276                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5277                                            orderByComparator, true);
5278                            }
5279                            else {
5280                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5281                                            orderByComparator, true);
5282                            }
5283                    }
5284                    else {
5285                            if (getDB().isSupportsInlineDistinct()) {
5286                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5287                            }
5288                            else {
5289                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
5290                            }
5291                    }
5292    
5293                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5294                                    MBThread.class.getName(),
5295                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5296    
5297                    Session session = null;
5298    
5299                    try {
5300                            session = openSession();
5301    
5302                            SQLQuery q = session.createSQLQuery(sql);
5303    
5304                            if (getDB().isSupportsInlineDistinct()) {
5305                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5306                            }
5307                            else {
5308                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5309                            }
5310    
5311                            QueryPos qPos = QueryPos.getInstance(q);
5312    
5313                            qPos.add(groupId);
5314    
5315                            qPos.add(status);
5316    
5317                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
5318                    }
5319                    catch (Exception e) {
5320                            throw processException(e);
5321                    }
5322                    finally {
5323                            closeSession(session);
5324                    }
5325            }
5326    
5327            /**
5328             * 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;.
5329             *
5330             * @param threadId the primary key of the current message boards thread
5331             * @param groupId the group ID
5332             * @param status the status
5333             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5334             * @return the previous, current, and next message boards thread
5335             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
5336             * @throws SystemException if a system exception occurred
5337             */
5338            public MBThread[] filterFindByG_S_PrevAndNext(long threadId, long groupId,
5339                    int status, OrderByComparator orderByComparator)
5340                    throws NoSuchThreadException, SystemException {
5341                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5342                            return findByG_S_PrevAndNext(threadId, groupId, status,
5343                                    orderByComparator);
5344                    }
5345    
5346                    MBThread mbThread = findByPrimaryKey(threadId);
5347    
5348                    Session session = null;
5349    
5350                    try {
5351                            session = openSession();
5352    
5353                            MBThread[] array = new MBThreadImpl[3];
5354    
5355                            array[0] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
5356                                            status, orderByComparator, true);
5357    
5358                            array[1] = mbThread;
5359    
5360                            array[2] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
5361                                            status, orderByComparator, false);
5362    
5363                            return array;
5364                    }
5365                    catch (Exception e) {
5366                            throw processException(e);
5367                    }
5368                    finally {
5369                            closeSession(session);
5370                    }
5371            }
5372    
5373            protected MBThread filterGetByG_S_PrevAndNext(Session session,
5374                    MBThread mbThread, long groupId, int status,
5375                    OrderByComparator orderByComparator, boolean previous) {
5376                    StringBundler query = null;
5377    
5378                    if (orderByComparator != null) {
5379                            query = new StringBundler(6 +
5380                                            (orderByComparator.getOrderByFields().length * 6));
5381                    }
5382                    else {
5383                            query = new StringBundler(3);
5384                    }
5385    
5386                    if (getDB().isSupportsInlineDistinct()) {
5387                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5388                    }
5389                    else {
5390                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5391                    }
5392    
5393                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5394    
5395                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
5396    
5397                    if (!getDB().isSupportsInlineDistinct()) {
5398                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5399                    }
5400    
5401                    if (orderByComparator != null) {
5402                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5403    
5404                            if (orderByConditionFields.length > 0) {
5405                                    query.append(WHERE_AND);
5406                            }
5407    
5408                            for (int i = 0; i < orderByConditionFields.length; i++) {
5409                                    if (getDB().isSupportsInlineDistinct()) {
5410                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5411                                    }
5412                                    else {
5413                                            query.append(_ORDER_BY_ENTITY_TABLE);
5414                                    }
5415    
5416                                    query.append(orderByConditionFields[i]);
5417    
5418                                    if ((i + 1) < orderByConditionFields.length) {
5419                                            if (orderByComparator.isAscending() ^ previous) {
5420                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5421                                            }
5422                                            else {
5423                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5424                                            }
5425                                    }
5426                                    else {
5427                                            if (orderByComparator.isAscending() ^ previous) {
5428                                                    query.append(WHERE_GREATER_THAN);
5429                                            }
5430                                            else {
5431                                                    query.append(WHERE_LESSER_THAN);
5432                                            }
5433                                    }
5434                            }
5435    
5436                            query.append(ORDER_BY_CLAUSE);
5437    
5438                            String[] orderByFields = orderByComparator.getOrderByFields();
5439    
5440                            for (int i = 0; i < orderByFields.length; i++) {
5441                                    if (getDB().isSupportsInlineDistinct()) {
5442                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5443                                    }
5444                                    else {
5445                                            query.append(_ORDER_BY_ENTITY_TABLE);
5446                                    }
5447    
5448                                    query.append(orderByFields[i]);
5449    
5450                                    if ((i + 1) < orderByFields.length) {
5451                                            if (orderByComparator.isAscending() ^ previous) {
5452                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5453                                            }
5454                                            else {
5455                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5456                                            }
5457                                    }
5458                                    else {
5459                                            if (orderByComparator.isAscending() ^ previous) {
5460                                                    query.append(ORDER_BY_ASC);
5461                                            }
5462                                            else {
5463                                                    query.append(ORDER_BY_DESC);
5464                                            }
5465                                    }
5466                            }
5467                    }
5468                    else {
5469                            if (getDB().isSupportsInlineDistinct()) {
5470                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5471                            }
5472                            else {
5473                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
5474                            }
5475                    }
5476    
5477                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5478                                    MBThread.class.getName(),
5479                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5480    
5481                    SQLQuery q = session.createSQLQuery(sql);
5482    
5483                    q.setFirstResult(0);
5484                    q.setMaxResults(2);
5485    
5486                    if (getDB().isSupportsInlineDistinct()) {
5487                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5488                    }
5489                    else {
5490                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5491                    }
5492    
5493                    QueryPos qPos = QueryPos.getInstance(q);
5494    
5495                    qPos.add(groupId);
5496    
5497                    qPos.add(status);
5498    
5499                    if (orderByComparator != null) {
5500                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5501    
5502                            for (Object value : values) {
5503                                    qPos.add(value);
5504                            }
5505                    }
5506    
5507                    List<MBThread> list = q.list();
5508    
5509                    if (list.size() == 2) {
5510                            return list.get(1);
5511                    }
5512                    else {
5513                            return null;
5514                    }
5515            }
5516    
5517            /**
5518             * Removes all the message boards threads where groupId = &#63; and status = &#63; from the database.
5519             *
5520             * @param groupId the group ID
5521             * @param status the status
5522             * @throws SystemException if a system exception occurred
5523             */
5524            public void removeByG_S(long groupId, int status) throws SystemException {
5525                    for (MBThread mbThread : findByG_S(groupId, status, QueryUtil.ALL_POS,
5526                                    QueryUtil.ALL_POS, null)) {
5527                            remove(mbThread);
5528                    }
5529            }
5530    
5531            /**
5532             * Returns the number of message boards threads where groupId = &#63; and status = &#63;.
5533             *
5534             * @param groupId the group ID
5535             * @param status the status
5536             * @return the number of matching message boards threads
5537             * @throws SystemException if a system exception occurred
5538             */
5539            public int countByG_S(long groupId, int status) throws SystemException {
5540                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
5541    
5542                    Object[] finderArgs = new Object[] { groupId, status };
5543    
5544                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5545                                    this);
5546    
5547                    if (count == null) {
5548                            StringBundler query = new StringBundler(3);
5549    
5550                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
5551    
5552                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5553    
5554                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
5555    
5556                            String sql = query.toString();
5557    
5558                            Session session = null;
5559    
5560                            try {
5561                                    session = openSession();
5562    
5563                                    Query q = session.createQuery(sql);
5564    
5565                                    QueryPos qPos = QueryPos.getInstance(q);
5566    
5567                                    qPos.add(groupId);
5568    
5569                                    qPos.add(status);
5570    
5571                                    count = (Long)q.uniqueResult();
5572    
5573                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5574                            }
5575                            catch (Exception e) {
5576                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5577    
5578                                    throw processException(e);
5579                            }
5580                            finally {
5581                                    closeSession(session);
5582                            }
5583                    }
5584    
5585                    return count.intValue();
5586            }
5587    
5588            /**
5589             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and status = &#63;.
5590             *
5591             * @param groupId the group ID
5592             * @param status the status
5593             * @return the number of matching message boards threads that the user has permission to view
5594             * @throws SystemException if a system exception occurred
5595             */
5596            public int filterCountByG_S(long groupId, int status)
5597                    throws SystemException {
5598                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5599                            return countByG_S(groupId, status);
5600                    }
5601    
5602                    StringBundler query = new StringBundler(3);
5603    
5604                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
5605    
5606                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5607    
5608                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
5609    
5610                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5611                                    MBThread.class.getName(),
5612                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5613    
5614                    Session session = null;
5615    
5616                    try {
5617                            session = openSession();
5618    
5619                            SQLQuery q = session.createSQLQuery(sql);
5620    
5621                            q.addScalar(COUNT_COLUMN_NAME,
5622                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5623    
5624                            QueryPos qPos = QueryPos.getInstance(q);
5625    
5626                            qPos.add(groupId);
5627    
5628                            qPos.add(status);
5629    
5630                            Long count = (Long)q.uniqueResult();
5631    
5632                            return count.intValue();
5633                    }
5634                    catch (Exception e) {
5635                            throw processException(e);
5636                    }
5637                    finally {
5638                            closeSession(session);
5639                    }
5640            }
5641    
5642            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbThread.groupId = ? AND ";
5643            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbThread.status = ? AND mbThread.categoryId != -1";
5644            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5645                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
5646                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
5647                            new String[] {
5648                                    Long.class.getName(), Double.class.getName(),
5649                                    
5650                            Integer.class.getName(), Integer.class.getName(),
5651                                    OrderByComparator.class.getName()
5652                            });
5653            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5654                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
5655                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
5656                            new String[] { Long.class.getName(), Double.class.getName() },
5657                            MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
5658                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
5659                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
5660            public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5661                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
5662                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
5663                            new String[] { Long.class.getName(), Double.class.getName() });
5664    
5665            /**
5666             * Returns all the message boards threads where categoryId = &#63; and priority = &#63;.
5667             *
5668             * @param categoryId the category ID
5669             * @param priority the priority
5670             * @return the matching message boards threads
5671             * @throws SystemException if a system exception occurred
5672             */
5673            public List<MBThread> findByC_P(long categoryId, double priority)
5674                    throws SystemException {
5675                    return findByC_P(categoryId, priority, QueryUtil.ALL_POS,
5676                            QueryUtil.ALL_POS, null);
5677            }
5678    
5679            /**
5680             * Returns a range of all the message boards threads where categoryId = &#63; and priority = &#63;.
5681             *
5682             * <p>
5683             * 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.
5684             * </p>
5685             *
5686             * @param categoryId the category ID
5687             * @param priority the priority
5688             * @param start the lower bound of the range of message boards threads
5689             * @param end the upper bound of the range of message boards threads (not inclusive)
5690             * @return the range of matching message boards threads
5691             * @throws SystemException if a system exception occurred
5692             */
5693            public List<MBThread> findByC_P(long categoryId, double priority,
5694                    int start, int end) throws SystemException {
5695                    return findByC_P(categoryId, priority, start, end, null);
5696            }
5697    
5698            /**
5699             * Returns an ordered range of all the message boards threads where categoryId = &#63; and priority = &#63;.
5700             *
5701             * <p>
5702             * 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.
5703             * </p>
5704             *
5705             * @param categoryId the category ID
5706             * @param priority the priority
5707             * @param start the lower bound of the range of message boards threads
5708             * @param end the upper bound of the range of message boards threads (not inclusive)
5709             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5710             * @return the ordered range of matching message boards threads
5711             * @throws SystemException if a system exception occurred
5712             */
5713            public List<MBThread> findByC_P(long categoryId, double priority,
5714                    int start, int end, OrderByComparator orderByComparator)
5715                    throws SystemException {
5716                    boolean pagination = true;
5717                    FinderPath finderPath = null;
5718                    Object[] finderArgs = null;
5719    
5720                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5721                                    (orderByComparator == null)) {
5722                            pagination = false;
5723                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
5724                            finderArgs = new Object[] { categoryId, priority };
5725                    }
5726                    else {
5727                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
5728                            finderArgs = new Object[] {
5729                                            categoryId, priority,
5730                                            
5731                                            start, end, orderByComparator
5732                                    };
5733                    }
5734    
5735                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
5736                                    finderArgs, this);
5737    
5738                    if ((list != null) && !list.isEmpty()) {
5739                            for (MBThread mbThread : list) {
5740                                    if ((categoryId != mbThread.getCategoryId()) ||
5741                                                    (priority != mbThread.getPriority())) {
5742                                            list = null;
5743    
5744                                            break;
5745                                    }
5746                            }
5747                    }
5748    
5749                    if (list == null) {
5750                            StringBundler query = null;
5751    
5752                            if (orderByComparator != null) {
5753                                    query = new StringBundler(4 +
5754                                                    (orderByComparator.getOrderByFields().length * 3));
5755                            }
5756                            else {
5757                                    query = new StringBundler(4);
5758                            }
5759    
5760                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
5761    
5762                            query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
5763    
5764                            query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
5765    
5766                            if (orderByComparator != null) {
5767                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5768                                            orderByComparator);
5769                            }
5770                            else
5771                             if (pagination) {
5772                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5773                            }
5774    
5775                            String sql = query.toString();
5776    
5777                            Session session = null;
5778    
5779                            try {
5780                                    session = openSession();
5781    
5782                                    Query q = session.createQuery(sql);
5783    
5784                                    QueryPos qPos = QueryPos.getInstance(q);
5785    
5786                                    qPos.add(categoryId);
5787    
5788                                    qPos.add(priority);
5789    
5790                                    if (!pagination) {
5791                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
5792                                                            start, end, false);
5793    
5794                                            Collections.sort(list);
5795    
5796                                            list = new UnmodifiableList<MBThread>(list);
5797                                    }
5798                                    else {
5799                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
5800                                                            start, end);
5801                                    }
5802    
5803                                    cacheResult(list);
5804    
5805                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5806                            }
5807                            catch (Exception e) {
5808                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5809    
5810                                    throw processException(e);
5811                            }
5812                            finally {
5813                                    closeSession(session);
5814                            }
5815                    }
5816    
5817                    return list;
5818            }
5819    
5820            /**
5821             * Returns the first message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
5822             *
5823             * @param categoryId the category ID
5824             * @param priority the priority
5825             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5826             * @return the first matching message boards thread
5827             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
5828             * @throws SystemException if a system exception occurred
5829             */
5830            public MBThread findByC_P_First(long categoryId, double priority,
5831                    OrderByComparator orderByComparator)
5832                    throws NoSuchThreadException, SystemException {
5833                    MBThread mbThread = fetchByC_P_First(categoryId, priority,
5834                                    orderByComparator);
5835    
5836                    if (mbThread != null) {
5837                            return mbThread;
5838                    }
5839    
5840                    StringBundler msg = new StringBundler(6);
5841    
5842                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5843    
5844                    msg.append("categoryId=");
5845                    msg.append(categoryId);
5846    
5847                    msg.append(", priority=");
5848                    msg.append(priority);
5849    
5850                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5851    
5852                    throw new NoSuchThreadException(msg.toString());
5853            }
5854    
5855            /**
5856             * Returns the first message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
5857             *
5858             * @param categoryId the category ID
5859             * @param priority the priority
5860             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5861             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
5862             * @throws SystemException if a system exception occurred
5863             */
5864            public MBThread fetchByC_P_First(long categoryId, double priority,
5865                    OrderByComparator orderByComparator) throws SystemException {
5866                    List<MBThread> list = findByC_P(categoryId, priority, 0, 1,
5867                                    orderByComparator);
5868    
5869                    if (!list.isEmpty()) {
5870                            return list.get(0);
5871                    }
5872    
5873                    return null;
5874            }
5875    
5876            /**
5877             * Returns the last message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
5878             *
5879             * @param categoryId the category ID
5880             * @param priority the priority
5881             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5882             * @return the last matching message boards thread
5883             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
5884             * @throws SystemException if a system exception occurred
5885             */
5886            public MBThread findByC_P_Last(long categoryId, double priority,
5887                    OrderByComparator orderByComparator)
5888                    throws NoSuchThreadException, SystemException {
5889                    MBThread mbThread = fetchByC_P_Last(categoryId, priority,
5890                                    orderByComparator);
5891    
5892                    if (mbThread != null) {
5893                            return mbThread;
5894                    }
5895    
5896                    StringBundler msg = new StringBundler(6);
5897    
5898                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5899    
5900                    msg.append("categoryId=");
5901                    msg.append(categoryId);
5902    
5903                    msg.append(", priority=");
5904                    msg.append(priority);
5905    
5906                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5907    
5908                    throw new NoSuchThreadException(msg.toString());
5909            }
5910    
5911            /**
5912             * Returns the last message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
5913             *
5914             * @param categoryId the category ID
5915             * @param priority the priority
5916             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5917             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
5918             * @throws SystemException if a system exception occurred
5919             */
5920            public MBThread fetchByC_P_Last(long categoryId, double priority,
5921                    OrderByComparator orderByComparator) throws SystemException {
5922                    int count = countByC_P(categoryId, priority);
5923    
5924                    List<MBThread> list = findByC_P(categoryId, priority, count - 1, count,
5925                                    orderByComparator);
5926    
5927                    if (!list.isEmpty()) {
5928                            return list.get(0);
5929                    }
5930    
5931                    return null;
5932            }
5933    
5934            /**
5935             * Returns the message boards threads before and after the current message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
5936             *
5937             * @param threadId the primary key of the current message boards thread
5938             * @param categoryId the category ID
5939             * @param priority the priority
5940             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5941             * @return the previous, current, and next message boards thread
5942             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
5943             * @throws SystemException if a system exception occurred
5944             */
5945            public MBThread[] findByC_P_PrevAndNext(long threadId, long categoryId,
5946                    double priority, OrderByComparator orderByComparator)
5947                    throws NoSuchThreadException, SystemException {
5948                    MBThread mbThread = findByPrimaryKey(threadId);
5949    
5950                    Session session = null;
5951    
5952                    try {
5953                            session = openSession();
5954    
5955                            MBThread[] array = new MBThreadImpl[3];
5956    
5957                            array[0] = getByC_P_PrevAndNext(session, mbThread, categoryId,
5958                                            priority, orderByComparator, true);
5959    
5960                            array[1] = mbThread;
5961    
5962                            array[2] = getByC_P_PrevAndNext(session, mbThread, categoryId,
5963                                            priority, orderByComparator, false);
5964    
5965                            return array;
5966                    }
5967                    catch (Exception e) {
5968                            throw processException(e);
5969                    }
5970                    finally {
5971                            closeSession(session);
5972                    }
5973            }
5974    
5975            protected MBThread getByC_P_PrevAndNext(Session session, MBThread mbThread,
5976                    long categoryId, double priority, OrderByComparator orderByComparator,
5977                    boolean previous) {
5978                    StringBundler query = null;
5979    
5980                    if (orderByComparator != null) {
5981                            query = new StringBundler(6 +
5982                                            (orderByComparator.getOrderByFields().length * 6));
5983                    }
5984                    else {
5985                            query = new StringBundler(3);
5986                    }
5987    
5988                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
5989    
5990                    query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
5991    
5992                    query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
5993    
5994                    if (orderByComparator != null) {
5995                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5996    
5997                            if (orderByConditionFields.length > 0) {
5998                                    query.append(WHERE_AND);
5999                            }
6000    
6001                            for (int i = 0; i < orderByConditionFields.length; i++) {
6002                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6003                                    query.append(orderByConditionFields[i]);
6004    
6005                                    if ((i + 1) < orderByConditionFields.length) {
6006                                            if (orderByComparator.isAscending() ^ previous) {
6007                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6008                                            }
6009                                            else {
6010                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6011                                            }
6012                                    }
6013                                    else {
6014                                            if (orderByComparator.isAscending() ^ previous) {
6015                                                    query.append(WHERE_GREATER_THAN);
6016                                            }
6017                                            else {
6018                                                    query.append(WHERE_LESSER_THAN);
6019                                            }
6020                                    }
6021                            }
6022    
6023                            query.append(ORDER_BY_CLAUSE);
6024    
6025                            String[] orderByFields = orderByComparator.getOrderByFields();
6026    
6027                            for (int i = 0; i < orderByFields.length; i++) {
6028                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6029                                    query.append(orderByFields[i]);
6030    
6031                                    if ((i + 1) < orderByFields.length) {
6032                                            if (orderByComparator.isAscending() ^ previous) {
6033                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6034                                            }
6035                                            else {
6036                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6037                                            }
6038                                    }
6039                                    else {
6040                                            if (orderByComparator.isAscending() ^ previous) {
6041                                                    query.append(ORDER_BY_ASC);
6042                                            }
6043                                            else {
6044                                                    query.append(ORDER_BY_DESC);
6045                                            }
6046                                    }
6047                            }
6048                    }
6049                    else {
6050                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6051                    }
6052    
6053                    String sql = query.toString();
6054    
6055                    Query q = session.createQuery(sql);
6056    
6057                    q.setFirstResult(0);
6058                    q.setMaxResults(2);
6059    
6060                    QueryPos qPos = QueryPos.getInstance(q);
6061    
6062                    qPos.add(categoryId);
6063    
6064                    qPos.add(priority);
6065    
6066                    if (orderByComparator != null) {
6067                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
6068    
6069                            for (Object value : values) {
6070                                    qPos.add(value);
6071                            }
6072                    }
6073    
6074                    List<MBThread> list = q.list();
6075    
6076                    if (list.size() == 2) {
6077                            return list.get(1);
6078                    }
6079                    else {
6080                            return null;
6081                    }
6082            }
6083    
6084            /**
6085             * Removes all the message boards threads where categoryId = &#63; and priority = &#63; from the database.
6086             *
6087             * @param categoryId the category ID
6088             * @param priority the priority
6089             * @throws SystemException if a system exception occurred
6090             */
6091            public void removeByC_P(long categoryId, double priority)
6092                    throws SystemException {
6093                    for (MBThread mbThread : findByC_P(categoryId, priority,
6094                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6095                            remove(mbThread);
6096                    }
6097            }
6098    
6099            /**
6100             * Returns the number of message boards threads where categoryId = &#63; and priority = &#63;.
6101             *
6102             * @param categoryId the category ID
6103             * @param priority the priority
6104             * @return the number of matching message boards threads
6105             * @throws SystemException if a system exception occurred
6106             */
6107            public int countByC_P(long categoryId, double priority)
6108                    throws SystemException {
6109                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_P;
6110    
6111                    Object[] finderArgs = new Object[] { categoryId, priority };
6112    
6113                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6114                                    this);
6115    
6116                    if (count == null) {
6117                            StringBundler query = new StringBundler(3);
6118    
6119                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
6120    
6121                            query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
6122    
6123                            query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
6124    
6125                            String sql = query.toString();
6126    
6127                            Session session = null;
6128    
6129                            try {
6130                                    session = openSession();
6131    
6132                                    Query q = session.createQuery(sql);
6133    
6134                                    QueryPos qPos = QueryPos.getInstance(q);
6135    
6136                                    qPos.add(categoryId);
6137    
6138                                    qPos.add(priority);
6139    
6140                                    count = (Long)q.uniqueResult();
6141    
6142                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6143                            }
6144                            catch (Exception e) {
6145                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6146    
6147                                    throw processException(e);
6148                            }
6149                            finally {
6150                                    closeSession(session);
6151                            }
6152                    }
6153    
6154                    return count.intValue();
6155            }
6156    
6157            private static final String _FINDER_COLUMN_C_P_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
6158            private static final String _FINDER_COLUMN_C_P_PRIORITY_2 = "mbThread.priority = ?";
6159            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6160                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6161                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByL_P",
6162                            new String[] {
6163                                    Date.class.getName(), Double.class.getName(),
6164                                    
6165                            Integer.class.getName(), Integer.class.getName(),
6166                                    OrderByComparator.class.getName()
6167                            });
6168            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6169                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6170                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByL_P",
6171                            new String[] { Date.class.getName(), Double.class.getName() },
6172                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK |
6173                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
6174            public static final FinderPath FINDER_PATH_COUNT_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6175                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
6176                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByL_P",
6177                            new String[] { Date.class.getName(), Double.class.getName() });
6178    
6179            /**
6180             * Returns all the message boards threads where lastPostDate = &#63; and priority = &#63;.
6181             *
6182             * @param lastPostDate the last post date
6183             * @param priority the priority
6184             * @return the matching message boards threads
6185             * @throws SystemException if a system exception occurred
6186             */
6187            public List<MBThread> findByL_P(Date lastPostDate, double priority)
6188                    throws SystemException {
6189                    return findByL_P(lastPostDate, priority, QueryUtil.ALL_POS,
6190                            QueryUtil.ALL_POS, null);
6191            }
6192    
6193            /**
6194             * Returns a range of all the message boards threads where lastPostDate = &#63; and priority = &#63;.
6195             *
6196             * <p>
6197             * 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.
6198             * </p>
6199             *
6200             * @param lastPostDate the last post date
6201             * @param priority the priority
6202             * @param start the lower bound of the range of message boards threads
6203             * @param end the upper bound of the range of message boards threads (not inclusive)
6204             * @return the range of matching message boards threads
6205             * @throws SystemException if a system exception occurred
6206             */
6207            public List<MBThread> findByL_P(Date lastPostDate, double priority,
6208                    int start, int end) throws SystemException {
6209                    return findByL_P(lastPostDate, priority, start, end, null);
6210            }
6211    
6212            /**
6213             * Returns an ordered range of all the message boards threads where lastPostDate = &#63; and priority = &#63;.
6214             *
6215             * <p>
6216             * 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.
6217             * </p>
6218             *
6219             * @param lastPostDate the last post date
6220             * @param priority the priority
6221             * @param start the lower bound of the range of message boards threads
6222             * @param end the upper bound of the range of message boards threads (not inclusive)
6223             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6224             * @return the ordered range of matching message boards threads
6225             * @throws SystemException if a system exception occurred
6226             */
6227            public List<MBThread> findByL_P(Date lastPostDate, double priority,
6228                    int start, int end, OrderByComparator orderByComparator)
6229                    throws SystemException {
6230                    boolean pagination = true;
6231                    FinderPath finderPath = null;
6232                    Object[] finderArgs = null;
6233    
6234                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6235                                    (orderByComparator == null)) {
6236                            pagination = false;
6237                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P;
6238                            finderArgs = new Object[] { lastPostDate, priority };
6239                    }
6240                    else {
6241                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P;
6242                            finderArgs = new Object[] {
6243                                            lastPostDate, priority,
6244                                            
6245                                            start, end, orderByComparator
6246                                    };
6247                    }
6248    
6249                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
6250                                    finderArgs, this);
6251    
6252                    if ((list != null) && !list.isEmpty()) {
6253                            for (MBThread mbThread : list) {
6254                                    if (!Validator.equals(lastPostDate, mbThread.getLastPostDate()) ||
6255                                                    (priority != mbThread.getPriority())) {
6256                                            list = null;
6257    
6258                                            break;
6259                                    }
6260                            }
6261                    }
6262    
6263                    if (list == null) {
6264                            StringBundler query = null;
6265    
6266                            if (orderByComparator != null) {
6267                                    query = new StringBundler(4 +
6268                                                    (orderByComparator.getOrderByFields().length * 3));
6269                            }
6270                            else {
6271                                    query = new StringBundler(4);
6272                            }
6273    
6274                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
6275    
6276                            boolean bindLastPostDate = false;
6277    
6278                            if (lastPostDate == null) {
6279                                    query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
6280                            }
6281                            else {
6282                                    bindLastPostDate = true;
6283    
6284                                    query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
6285                            }
6286    
6287                            query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
6288    
6289                            if (orderByComparator != null) {
6290                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6291                                            orderByComparator);
6292                            }
6293                            else
6294                             if (pagination) {
6295                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6296                            }
6297    
6298                            String sql = query.toString();
6299    
6300                            Session session = null;
6301    
6302                            try {
6303                                    session = openSession();
6304    
6305                                    Query q = session.createQuery(sql);
6306    
6307                                    QueryPos qPos = QueryPos.getInstance(q);
6308    
6309                                    if (bindLastPostDate) {
6310                                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
6311                                    }
6312    
6313                                    qPos.add(priority);
6314    
6315                                    if (!pagination) {
6316                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
6317                                                            start, end, false);
6318    
6319                                            Collections.sort(list);
6320    
6321                                            list = new UnmodifiableList<MBThread>(list);
6322                                    }
6323                                    else {
6324                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
6325                                                            start, end);
6326                                    }
6327    
6328                                    cacheResult(list);
6329    
6330                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6331                            }
6332                            catch (Exception e) {
6333                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6334    
6335                                    throw processException(e);
6336                            }
6337                            finally {
6338                                    closeSession(session);
6339                            }
6340                    }
6341    
6342                    return list;
6343            }
6344    
6345            /**
6346             * Returns the first message boards thread in the ordered set where lastPostDate = &#63; and priority = &#63;.
6347             *
6348             * @param lastPostDate the last post date
6349             * @param priority the priority
6350             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6351             * @return the first matching message boards thread
6352             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
6353             * @throws SystemException if a system exception occurred
6354             */
6355            public MBThread findByL_P_First(Date lastPostDate, double priority,
6356                    OrderByComparator orderByComparator)
6357                    throws NoSuchThreadException, SystemException {
6358                    MBThread mbThread = fetchByL_P_First(lastPostDate, priority,
6359                                    orderByComparator);
6360    
6361                    if (mbThread != null) {
6362                            return mbThread;
6363                    }
6364    
6365                    StringBundler msg = new StringBundler(6);
6366    
6367                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6368    
6369                    msg.append("lastPostDate=");
6370                    msg.append(lastPostDate);
6371    
6372                    msg.append(", priority=");
6373                    msg.append(priority);
6374    
6375                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6376    
6377                    throw new NoSuchThreadException(msg.toString());
6378            }
6379    
6380            /**
6381             * Returns the first message boards thread in the ordered set where lastPostDate = &#63; and priority = &#63;.
6382             *
6383             * @param lastPostDate the last post date
6384             * @param priority the priority
6385             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6386             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
6387             * @throws SystemException if a system exception occurred
6388             */
6389            public MBThread fetchByL_P_First(Date lastPostDate, double priority,
6390                    OrderByComparator orderByComparator) throws SystemException {
6391                    List<MBThread> list = findByL_P(lastPostDate, priority, 0, 1,
6392                                    orderByComparator);
6393    
6394                    if (!list.isEmpty()) {
6395                            return list.get(0);
6396                    }
6397    
6398                    return null;
6399            }
6400    
6401            /**
6402             * Returns the last message boards thread in the ordered set where lastPostDate = &#63; and priority = &#63;.
6403             *
6404             * @param lastPostDate the last post date
6405             * @param priority the priority
6406             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6407             * @return the last matching message boards thread
6408             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
6409             * @throws SystemException if a system exception occurred
6410             */
6411            public MBThread findByL_P_Last(Date lastPostDate, double priority,
6412                    OrderByComparator orderByComparator)
6413                    throws NoSuchThreadException, SystemException {
6414                    MBThread mbThread = fetchByL_P_Last(lastPostDate, priority,
6415                                    orderByComparator);
6416    
6417                    if (mbThread != null) {
6418                            return mbThread;
6419                    }
6420    
6421                    StringBundler msg = new StringBundler(6);
6422    
6423                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6424    
6425                    msg.append("lastPostDate=");
6426                    msg.append(lastPostDate);
6427    
6428                    msg.append(", priority=");
6429                    msg.append(priority);
6430    
6431                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6432    
6433                    throw new NoSuchThreadException(msg.toString());
6434            }
6435    
6436            /**
6437             * Returns the last message boards thread in the ordered set where lastPostDate = &#63; and priority = &#63;.
6438             *
6439             * @param lastPostDate the last post date
6440             * @param priority the priority
6441             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6442             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
6443             * @throws SystemException if a system exception occurred
6444             */
6445            public MBThread fetchByL_P_Last(Date lastPostDate, double priority,
6446                    OrderByComparator orderByComparator) throws SystemException {
6447                    int count = countByL_P(lastPostDate, priority);
6448    
6449                    List<MBThread> list = findByL_P(lastPostDate, priority, count - 1,
6450                                    count, orderByComparator);
6451    
6452                    if (!list.isEmpty()) {
6453                            return list.get(0);
6454                    }
6455    
6456                    return null;
6457            }
6458    
6459            /**
6460             * Returns the message boards threads before and after the current message boards thread in the ordered set where lastPostDate = &#63; and priority = &#63;.
6461             *
6462             * @param threadId the primary key of the current message boards thread
6463             * @param lastPostDate the last post date
6464             * @param priority the priority
6465             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6466             * @return the previous, current, and next message boards thread
6467             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
6468             * @throws SystemException if a system exception occurred
6469             */
6470            public MBThread[] findByL_P_PrevAndNext(long threadId, Date lastPostDate,
6471                    double priority, OrderByComparator orderByComparator)
6472                    throws NoSuchThreadException, SystemException {
6473                    MBThread mbThread = findByPrimaryKey(threadId);
6474    
6475                    Session session = null;
6476    
6477                    try {
6478                            session = openSession();
6479    
6480                            MBThread[] array = new MBThreadImpl[3];
6481    
6482                            array[0] = getByL_P_PrevAndNext(session, mbThread, lastPostDate,
6483                                            priority, orderByComparator, true);
6484    
6485                            array[1] = mbThread;
6486    
6487                            array[2] = getByL_P_PrevAndNext(session, mbThread, lastPostDate,
6488                                            priority, orderByComparator, false);
6489    
6490                            return array;
6491                    }
6492                    catch (Exception e) {
6493                            throw processException(e);
6494                    }
6495                    finally {
6496                            closeSession(session);
6497                    }
6498            }
6499    
6500            protected MBThread getByL_P_PrevAndNext(Session session, MBThread mbThread,
6501                    Date lastPostDate, double priority,
6502                    OrderByComparator orderByComparator, boolean previous) {
6503                    StringBundler query = null;
6504    
6505                    if (orderByComparator != null) {
6506                            query = new StringBundler(6 +
6507                                            (orderByComparator.getOrderByFields().length * 6));
6508                    }
6509                    else {
6510                            query = new StringBundler(3);
6511                    }
6512    
6513                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
6514    
6515                    boolean bindLastPostDate = false;
6516    
6517                    if (lastPostDate == null) {
6518                            query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
6519                    }
6520                    else {
6521                            bindLastPostDate = true;
6522    
6523                            query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
6524                    }
6525    
6526                    query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
6527    
6528                    if (orderByComparator != null) {
6529                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6530    
6531                            if (orderByConditionFields.length > 0) {
6532                                    query.append(WHERE_AND);
6533                            }
6534    
6535                            for (int i = 0; i < orderByConditionFields.length; i++) {
6536                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6537                                    query.append(orderByConditionFields[i]);
6538    
6539                                    if ((i + 1) < orderByConditionFields.length) {
6540                                            if (orderByComparator.isAscending() ^ previous) {
6541                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6542                                            }
6543                                            else {
6544                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6545                                            }
6546                                    }
6547                                    else {
6548                                            if (orderByComparator.isAscending() ^ previous) {
6549                                                    query.append(WHERE_GREATER_THAN);
6550                                            }
6551                                            else {
6552                                                    query.append(WHERE_LESSER_THAN);
6553                                            }
6554                                    }
6555                            }
6556    
6557                            query.append(ORDER_BY_CLAUSE);
6558    
6559                            String[] orderByFields = orderByComparator.getOrderByFields();
6560    
6561                            for (int i = 0; i < orderByFields.length; i++) {
6562                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6563                                    query.append(orderByFields[i]);
6564    
6565                                    if ((i + 1) < orderByFields.length) {
6566                                            if (orderByComparator.isAscending() ^ previous) {
6567                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6568                                            }
6569                                            else {
6570                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6571                                            }
6572                                    }
6573                                    else {
6574                                            if (orderByComparator.isAscending() ^ previous) {
6575                                                    query.append(ORDER_BY_ASC);
6576                                            }
6577                                            else {
6578                                                    query.append(ORDER_BY_DESC);
6579                                            }
6580                                    }
6581                            }
6582                    }
6583                    else {
6584                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6585                    }
6586    
6587                    String sql = query.toString();
6588    
6589                    Query q = session.createQuery(sql);
6590    
6591                    q.setFirstResult(0);
6592                    q.setMaxResults(2);
6593    
6594                    QueryPos qPos = QueryPos.getInstance(q);
6595    
6596                    if (bindLastPostDate) {
6597                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
6598                    }
6599    
6600                    qPos.add(priority);
6601    
6602                    if (orderByComparator != null) {
6603                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
6604    
6605                            for (Object value : values) {
6606                                    qPos.add(value);
6607                            }
6608                    }
6609    
6610                    List<MBThread> list = q.list();
6611    
6612                    if (list.size() == 2) {
6613                            return list.get(1);
6614                    }
6615                    else {
6616                            return null;
6617                    }
6618            }
6619    
6620            /**
6621             * Removes all the message boards threads where lastPostDate = &#63; and priority = &#63; from the database.
6622             *
6623             * @param lastPostDate the last post date
6624             * @param priority the priority
6625             * @throws SystemException if a system exception occurred
6626             */
6627            public void removeByL_P(Date lastPostDate, double priority)
6628                    throws SystemException {
6629                    for (MBThread mbThread : findByL_P(lastPostDate, priority,
6630                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6631                            remove(mbThread);
6632                    }
6633            }
6634    
6635            /**
6636             * Returns the number of message boards threads where lastPostDate = &#63; and priority = &#63;.
6637             *
6638             * @param lastPostDate the last post date
6639             * @param priority the priority
6640             * @return the number of matching message boards threads
6641             * @throws SystemException if a system exception occurred
6642             */
6643            public int countByL_P(Date lastPostDate, double priority)
6644                    throws SystemException {
6645                    FinderPath finderPath = FINDER_PATH_COUNT_BY_L_P;
6646    
6647                    Object[] finderArgs = new Object[] { lastPostDate, priority };
6648    
6649                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6650                                    this);
6651    
6652                    if (count == null) {
6653                            StringBundler query = new StringBundler(3);
6654    
6655                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
6656    
6657                            boolean bindLastPostDate = false;
6658    
6659                            if (lastPostDate == null) {
6660                                    query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
6661                            }
6662                            else {
6663                                    bindLastPostDate = true;
6664    
6665                                    query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
6666                            }
6667    
6668                            query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
6669    
6670                            String sql = query.toString();
6671    
6672                            Session session = null;
6673    
6674                            try {
6675                                    session = openSession();
6676    
6677                                    Query q = session.createQuery(sql);
6678    
6679                                    QueryPos qPos = QueryPos.getInstance(q);
6680    
6681                                    if (bindLastPostDate) {
6682                                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
6683                                    }
6684    
6685                                    qPos.add(priority);
6686    
6687                                    count = (Long)q.uniqueResult();
6688    
6689                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6690                            }
6691                            catch (Exception e) {
6692                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6693    
6694                                    throw processException(e);
6695                            }
6696                            finally {
6697                                    closeSession(session);
6698                            }
6699                    }
6700    
6701                    return count.intValue();
6702            }
6703    
6704            private static final String _FINDER_COLUMN_L_P_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL AND ";
6705            private static final String _FINDER_COLUMN_L_P_LASTPOSTDATE_2 = "mbThread.lastPostDate = ? AND ";
6706            private static final String _FINDER_COLUMN_L_P_PRIORITY_2 = "mbThread.priority = ? AND mbThread.categoryId != -1";
6707            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6708                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6709                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_L",
6710                            new String[] {
6711                                    Long.class.getName(), Long.class.getName(), Date.class.getName(),
6712                                    
6713                            Integer.class.getName(), Integer.class.getName(),
6714                                    OrderByComparator.class.getName()
6715                            });
6716            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6717                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6718                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_L",
6719                            new String[] {
6720                                    Long.class.getName(), Long.class.getName(), Date.class.getName()
6721                            },
6722                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
6723                            MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
6724                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK |
6725                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
6726            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6727                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
6728                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_L",
6729                            new String[] {
6730                                    Long.class.getName(), Long.class.getName(), Date.class.getName()
6731                            });
6732    
6733            /**
6734             * Returns all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
6735             *
6736             * @param groupId the group ID
6737             * @param categoryId the category ID
6738             * @param lastPostDate the last post date
6739             * @return the matching message boards threads
6740             * @throws SystemException if a system exception occurred
6741             */
6742            public List<MBThread> findByG_C_L(long groupId, long categoryId,
6743                    Date lastPostDate) throws SystemException {
6744                    return findByG_C_L(groupId, categoryId, lastPostDate,
6745                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6746            }
6747    
6748            /**
6749             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
6750             *
6751             * <p>
6752             * 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.
6753             * </p>
6754             *
6755             * @param groupId the group ID
6756             * @param categoryId the category ID
6757             * @param lastPostDate the last post date
6758             * @param start the lower bound of the range of message boards threads
6759             * @param end the upper bound of the range of message boards threads (not inclusive)
6760             * @return the range of matching message boards threads
6761             * @throws SystemException if a system exception occurred
6762             */
6763            public List<MBThread> findByG_C_L(long groupId, long categoryId,
6764                    Date lastPostDate, int start, int end) throws SystemException {
6765                    return findByG_C_L(groupId, categoryId, lastPostDate, start, end, null);
6766            }
6767    
6768            /**
6769             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
6770             *
6771             * <p>
6772             * 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.
6773             * </p>
6774             *
6775             * @param groupId the group ID
6776             * @param categoryId the category ID
6777             * @param lastPostDate the last post date
6778             * @param start the lower bound of the range of message boards threads
6779             * @param end the upper bound of the range of message boards threads (not inclusive)
6780             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6781             * @return the ordered range of matching message boards threads
6782             * @throws SystemException if a system exception occurred
6783             */
6784            public List<MBThread> findByG_C_L(long groupId, long categoryId,
6785                    Date lastPostDate, int start, int end,
6786                    OrderByComparator orderByComparator) throws SystemException {
6787                    boolean pagination = true;
6788                    FinderPath finderPath = null;
6789                    Object[] finderArgs = null;
6790    
6791                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6792                                    (orderByComparator == null)) {
6793                            pagination = false;
6794                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L;
6795                            finderArgs = new Object[] { groupId, categoryId, lastPostDate };
6796                    }
6797                    else {
6798                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L;
6799                            finderArgs = new Object[] {
6800                                            groupId, categoryId, lastPostDate,
6801                                            
6802                                            start, end, orderByComparator
6803                                    };
6804                    }
6805    
6806                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
6807                                    finderArgs, this);
6808    
6809                    if ((list != null) && !list.isEmpty()) {
6810                            for (MBThread mbThread : list) {
6811                                    if ((groupId != mbThread.getGroupId()) ||
6812                                                    (categoryId != mbThread.getCategoryId()) ||
6813                                                    !Validator.equals(lastPostDate,
6814                                                            mbThread.getLastPostDate())) {
6815                                            list = null;
6816    
6817                                            break;
6818                                    }
6819                            }
6820                    }
6821    
6822                    if (list == null) {
6823                            StringBundler query = null;
6824    
6825                            if (orderByComparator != null) {
6826                                    query = new StringBundler(5 +
6827                                                    (orderByComparator.getOrderByFields().length * 3));
6828                            }
6829                            else {
6830                                    query = new StringBundler(5);
6831                            }
6832    
6833                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
6834    
6835                            query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
6836    
6837                            query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
6838    
6839                            boolean bindLastPostDate = false;
6840    
6841                            if (lastPostDate == null) {
6842                                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
6843                            }
6844                            else {
6845                                    bindLastPostDate = true;
6846    
6847                                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
6848                            }
6849    
6850                            if (orderByComparator != null) {
6851                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6852                                            orderByComparator);
6853                            }
6854                            else
6855                             if (pagination) {
6856                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6857                            }
6858    
6859                            String sql = query.toString();
6860    
6861                            Session session = null;
6862    
6863                            try {
6864                                    session = openSession();
6865    
6866                                    Query q = session.createQuery(sql);
6867    
6868                                    QueryPos qPos = QueryPos.getInstance(q);
6869    
6870                                    qPos.add(groupId);
6871    
6872                                    qPos.add(categoryId);
6873    
6874                                    if (bindLastPostDate) {
6875                                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
6876                                    }
6877    
6878                                    if (!pagination) {
6879                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
6880                                                            start, end, false);
6881    
6882                                            Collections.sort(list);
6883    
6884                                            list = new UnmodifiableList<MBThread>(list);
6885                                    }
6886                                    else {
6887                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
6888                                                            start, end);
6889                                    }
6890    
6891                                    cacheResult(list);
6892    
6893                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6894                            }
6895                            catch (Exception e) {
6896                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6897    
6898                                    throw processException(e);
6899                            }
6900                            finally {
6901                                    closeSession(session);
6902                            }
6903                    }
6904    
6905                    return list;
6906            }
6907    
6908            /**
6909             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
6910             *
6911             * @param groupId the group ID
6912             * @param categoryId the category ID
6913             * @param lastPostDate the last post date
6914             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6915             * @return the first matching message boards thread
6916             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
6917             * @throws SystemException if a system exception occurred
6918             */
6919            public MBThread findByG_C_L_First(long groupId, long categoryId,
6920                    Date lastPostDate, OrderByComparator orderByComparator)
6921                    throws NoSuchThreadException, SystemException {
6922                    MBThread mbThread = fetchByG_C_L_First(groupId, categoryId,
6923                                    lastPostDate, orderByComparator);
6924    
6925                    if (mbThread != null) {
6926                            return mbThread;
6927                    }
6928    
6929                    StringBundler msg = new StringBundler(8);
6930    
6931                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6932    
6933                    msg.append("groupId=");
6934                    msg.append(groupId);
6935    
6936                    msg.append(", categoryId=");
6937                    msg.append(categoryId);
6938    
6939                    msg.append(", lastPostDate=");
6940                    msg.append(lastPostDate);
6941    
6942                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6943    
6944                    throw new NoSuchThreadException(msg.toString());
6945            }
6946    
6947            /**
6948             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
6949             *
6950             * @param groupId the group ID
6951             * @param categoryId the category ID
6952             * @param lastPostDate the last post date
6953             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6954             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
6955             * @throws SystemException if a system exception occurred
6956             */
6957            public MBThread fetchByG_C_L_First(long groupId, long categoryId,
6958                    Date lastPostDate, OrderByComparator orderByComparator)
6959                    throws SystemException {
6960                    List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate, 0,
6961                                    1, orderByComparator);
6962    
6963                    if (!list.isEmpty()) {
6964                            return list.get(0);
6965                    }
6966    
6967                    return null;
6968            }
6969    
6970            /**
6971             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
6972             *
6973             * @param groupId the group ID
6974             * @param categoryId the category ID
6975             * @param lastPostDate the last post date
6976             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6977             * @return the last matching message boards thread
6978             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
6979             * @throws SystemException if a system exception occurred
6980             */
6981            public MBThread findByG_C_L_Last(long groupId, long categoryId,
6982                    Date lastPostDate, OrderByComparator orderByComparator)
6983                    throws NoSuchThreadException, SystemException {
6984                    MBThread mbThread = fetchByG_C_L_Last(groupId, categoryId,
6985                                    lastPostDate, orderByComparator);
6986    
6987                    if (mbThread != null) {
6988                            return mbThread;
6989                    }
6990    
6991                    StringBundler msg = new StringBundler(8);
6992    
6993                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6994    
6995                    msg.append("groupId=");
6996                    msg.append(groupId);
6997    
6998                    msg.append(", categoryId=");
6999                    msg.append(categoryId);
7000    
7001                    msg.append(", lastPostDate=");
7002                    msg.append(lastPostDate);
7003    
7004                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7005    
7006                    throw new NoSuchThreadException(msg.toString());
7007            }
7008    
7009            /**
7010             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
7011             *
7012             * @param groupId the group ID
7013             * @param categoryId the category ID
7014             * @param lastPostDate the last post date
7015             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7016             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
7017             * @throws SystemException if a system exception occurred
7018             */
7019            public MBThread fetchByG_C_L_Last(long groupId, long categoryId,
7020                    Date lastPostDate, OrderByComparator orderByComparator)
7021                    throws SystemException {
7022                    int count = countByG_C_L(groupId, categoryId, lastPostDate);
7023    
7024                    List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate,
7025                                    count - 1, count, orderByComparator);
7026    
7027                    if (!list.isEmpty()) {
7028                            return list.get(0);
7029                    }
7030    
7031                    return null;
7032            }
7033    
7034            /**
7035             * 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;.
7036             *
7037             * @param threadId the primary key of the current message boards thread
7038             * @param groupId the group ID
7039             * @param categoryId the category ID
7040             * @param lastPostDate the last post date
7041             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7042             * @return the previous, current, and next message boards thread
7043             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
7044             * @throws SystemException if a system exception occurred
7045             */
7046            public MBThread[] findByG_C_L_PrevAndNext(long threadId, long groupId,
7047                    long categoryId, Date lastPostDate, OrderByComparator orderByComparator)
7048                    throws NoSuchThreadException, SystemException {
7049                    MBThread mbThread = findByPrimaryKey(threadId);
7050    
7051                    Session session = null;
7052    
7053                    try {
7054                            session = openSession();
7055    
7056                            MBThread[] array = new MBThreadImpl[3];
7057    
7058                            array[0] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
7059                                            categoryId, lastPostDate, orderByComparator, true);
7060    
7061                            array[1] = mbThread;
7062    
7063                            array[2] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
7064                                            categoryId, lastPostDate, orderByComparator, false);
7065    
7066                            return array;
7067                    }
7068                    catch (Exception e) {
7069                            throw processException(e);
7070                    }
7071                    finally {
7072                            closeSession(session);
7073                    }
7074            }
7075    
7076            protected MBThread getByG_C_L_PrevAndNext(Session session,
7077                    MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
7078                    OrderByComparator orderByComparator, boolean previous) {
7079                    StringBundler query = null;
7080    
7081                    if (orderByComparator != null) {
7082                            query = new StringBundler(6 +
7083                                            (orderByComparator.getOrderByFields().length * 6));
7084                    }
7085                    else {
7086                            query = new StringBundler(3);
7087                    }
7088    
7089                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
7090    
7091                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7092    
7093                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7094    
7095                    boolean bindLastPostDate = false;
7096    
7097                    if (lastPostDate == null) {
7098                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7099                    }
7100                    else {
7101                            bindLastPostDate = true;
7102    
7103                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7104                    }
7105    
7106                    if (orderByComparator != null) {
7107                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7108    
7109                            if (orderByConditionFields.length > 0) {
7110                                    query.append(WHERE_AND);
7111                            }
7112    
7113                            for (int i = 0; i < orderByConditionFields.length; i++) {
7114                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7115                                    query.append(orderByConditionFields[i]);
7116    
7117                                    if ((i + 1) < orderByConditionFields.length) {
7118                                            if (orderByComparator.isAscending() ^ previous) {
7119                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7120                                            }
7121                                            else {
7122                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7123                                            }
7124                                    }
7125                                    else {
7126                                            if (orderByComparator.isAscending() ^ previous) {
7127                                                    query.append(WHERE_GREATER_THAN);
7128                                            }
7129                                            else {
7130                                                    query.append(WHERE_LESSER_THAN);
7131                                            }
7132                                    }
7133                            }
7134    
7135                            query.append(ORDER_BY_CLAUSE);
7136    
7137                            String[] orderByFields = orderByComparator.getOrderByFields();
7138    
7139                            for (int i = 0; i < orderByFields.length; i++) {
7140                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7141                                    query.append(orderByFields[i]);
7142    
7143                                    if ((i + 1) < orderByFields.length) {
7144                                            if (orderByComparator.isAscending() ^ previous) {
7145                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7146                                            }
7147                                            else {
7148                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7149                                            }
7150                                    }
7151                                    else {
7152                                            if (orderByComparator.isAscending() ^ previous) {
7153                                                    query.append(ORDER_BY_ASC);
7154                                            }
7155                                            else {
7156                                                    query.append(ORDER_BY_DESC);
7157                                            }
7158                                    }
7159                            }
7160                    }
7161                    else {
7162                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7163                    }
7164    
7165                    String sql = query.toString();
7166    
7167                    Query q = session.createQuery(sql);
7168    
7169                    q.setFirstResult(0);
7170                    q.setMaxResults(2);
7171    
7172                    QueryPos qPos = QueryPos.getInstance(q);
7173    
7174                    qPos.add(groupId);
7175    
7176                    qPos.add(categoryId);
7177    
7178                    if (bindLastPostDate) {
7179                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
7180                    }
7181    
7182                    if (orderByComparator != null) {
7183                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
7184    
7185                            for (Object value : values) {
7186                                    qPos.add(value);
7187                            }
7188                    }
7189    
7190                    List<MBThread> list = q.list();
7191    
7192                    if (list.size() == 2) {
7193                            return list.get(1);
7194                    }
7195                    else {
7196                            return null;
7197                    }
7198            }
7199    
7200            /**
7201             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
7202             *
7203             * @param groupId the group ID
7204             * @param categoryId the category ID
7205             * @param lastPostDate the last post date
7206             * @return the matching message boards threads that the user has permission to view
7207             * @throws SystemException if a system exception occurred
7208             */
7209            public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
7210                    Date lastPostDate) throws SystemException {
7211                    return filterFindByG_C_L(groupId, categoryId, lastPostDate,
7212                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7213            }
7214    
7215            /**
7216             * 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;.
7217             *
7218             * <p>
7219             * 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.
7220             * </p>
7221             *
7222             * @param groupId the group ID
7223             * @param categoryId the category ID
7224             * @param lastPostDate the last post date
7225             * @param start the lower bound of the range of message boards threads
7226             * @param end the upper bound of the range of message boards threads (not inclusive)
7227             * @return the range of matching message boards threads that the user has permission to view
7228             * @throws SystemException if a system exception occurred
7229             */
7230            public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
7231                    Date lastPostDate, int start, int end) throws SystemException {
7232                    return filterFindByG_C_L(groupId, categoryId, lastPostDate, start, end,
7233                            null);
7234            }
7235    
7236            /**
7237             * 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;.
7238             *
7239             * <p>
7240             * 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.
7241             * </p>
7242             *
7243             * @param groupId the group ID
7244             * @param categoryId the category ID
7245             * @param lastPostDate the last post date
7246             * @param start the lower bound of the range of message boards threads
7247             * @param end the upper bound of the range of message boards threads (not inclusive)
7248             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7249             * @return the ordered range of matching message boards threads that the user has permission to view
7250             * @throws SystemException if a system exception occurred
7251             */
7252            public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
7253                    Date lastPostDate, int start, int end,
7254                    OrderByComparator orderByComparator) throws SystemException {
7255                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7256                            return findByG_C_L(groupId, categoryId, lastPostDate, start, end,
7257                                    orderByComparator);
7258                    }
7259    
7260                    StringBundler query = null;
7261    
7262                    if (orderByComparator != null) {
7263                            query = new StringBundler(5 +
7264                                            (orderByComparator.getOrderByFields().length * 3));
7265                    }
7266                    else {
7267                            query = new StringBundler(5);
7268                    }
7269    
7270                    if (getDB().isSupportsInlineDistinct()) {
7271                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
7272                    }
7273                    else {
7274                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
7275                    }
7276    
7277                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7278    
7279                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7280    
7281                    boolean bindLastPostDate = false;
7282    
7283                    if (lastPostDate == null) {
7284                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7285                    }
7286                    else {
7287                            bindLastPostDate = true;
7288    
7289                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7290                    }
7291    
7292                    if (!getDB().isSupportsInlineDistinct()) {
7293                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
7294                    }
7295    
7296                    if (orderByComparator != null) {
7297                            if (getDB().isSupportsInlineDistinct()) {
7298                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7299                                            orderByComparator, true);
7300                            }
7301                            else {
7302                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7303                                            orderByComparator, true);
7304                            }
7305                    }
7306                    else {
7307                            if (getDB().isSupportsInlineDistinct()) {
7308                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7309                            }
7310                            else {
7311                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
7312                            }
7313                    }
7314    
7315                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7316                                    MBThread.class.getName(),
7317                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7318    
7319                    Session session = null;
7320    
7321                    try {
7322                            session = openSession();
7323    
7324                            SQLQuery q = session.createSQLQuery(sql);
7325    
7326                            if (getDB().isSupportsInlineDistinct()) {
7327                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
7328                            }
7329                            else {
7330                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
7331                            }
7332    
7333                            QueryPos qPos = QueryPos.getInstance(q);
7334    
7335                            qPos.add(groupId);
7336    
7337                            qPos.add(categoryId);
7338    
7339                            if (bindLastPostDate) {
7340                                    qPos.add(CalendarUtil.getTimestamp(lastPostDate));
7341                            }
7342    
7343                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
7344                    }
7345                    catch (Exception e) {
7346                            throw processException(e);
7347                    }
7348                    finally {
7349                            closeSession(session);
7350                    }
7351            }
7352    
7353            /**
7354             * 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;.
7355             *
7356             * @param threadId the primary key of the current message boards thread
7357             * @param groupId the group ID
7358             * @param categoryId the category ID
7359             * @param lastPostDate the last post date
7360             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7361             * @return the previous, current, and next message boards thread
7362             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
7363             * @throws SystemException if a system exception occurred
7364             */
7365            public MBThread[] filterFindByG_C_L_PrevAndNext(long threadId,
7366                    long groupId, long categoryId, Date lastPostDate,
7367                    OrderByComparator orderByComparator)
7368                    throws NoSuchThreadException, SystemException {
7369                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7370                            return findByG_C_L_PrevAndNext(threadId, groupId, categoryId,
7371                                    lastPostDate, orderByComparator);
7372                    }
7373    
7374                    MBThread mbThread = findByPrimaryKey(threadId);
7375    
7376                    Session session = null;
7377    
7378                    try {
7379                            session = openSession();
7380    
7381                            MBThread[] array = new MBThreadImpl[3];
7382    
7383                            array[0] = filterGetByG_C_L_PrevAndNext(session, mbThread, groupId,
7384                                            categoryId, lastPostDate, orderByComparator, true);
7385    
7386                            array[1] = mbThread;
7387    
7388                            array[2] = filterGetByG_C_L_PrevAndNext(session, mbThread, groupId,
7389                                            categoryId, lastPostDate, orderByComparator, false);
7390    
7391                            return array;
7392                    }
7393                    catch (Exception e) {
7394                            throw processException(e);
7395                    }
7396                    finally {
7397                            closeSession(session);
7398                    }
7399            }
7400    
7401            protected MBThread filterGetByG_C_L_PrevAndNext(Session session,
7402                    MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
7403                    OrderByComparator orderByComparator, boolean previous) {
7404                    StringBundler query = null;
7405    
7406                    if (orderByComparator != null) {
7407                            query = new StringBundler(6 +
7408                                            (orderByComparator.getOrderByFields().length * 6));
7409                    }
7410                    else {
7411                            query = new StringBundler(3);
7412                    }
7413    
7414                    if (getDB().isSupportsInlineDistinct()) {
7415                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
7416                    }
7417                    else {
7418                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
7419                    }
7420    
7421                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7422    
7423                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7424    
7425                    boolean bindLastPostDate = false;
7426    
7427                    if (lastPostDate == null) {
7428                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7429                    }
7430                    else {
7431                            bindLastPostDate = true;
7432    
7433                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7434                    }
7435    
7436                    if (!getDB().isSupportsInlineDistinct()) {
7437                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
7438                    }
7439    
7440                    if (orderByComparator != null) {
7441                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7442    
7443                            if (orderByConditionFields.length > 0) {
7444                                    query.append(WHERE_AND);
7445                            }
7446    
7447                            for (int i = 0; i < orderByConditionFields.length; i++) {
7448                                    if (getDB().isSupportsInlineDistinct()) {
7449                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7450                                    }
7451                                    else {
7452                                            query.append(_ORDER_BY_ENTITY_TABLE);
7453                                    }
7454    
7455                                    query.append(orderByConditionFields[i]);
7456    
7457                                    if ((i + 1) < orderByConditionFields.length) {
7458                                            if (orderByComparator.isAscending() ^ previous) {
7459                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7460                                            }
7461                                            else {
7462                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7463                                            }
7464                                    }
7465                                    else {
7466                                            if (orderByComparator.isAscending() ^ previous) {
7467                                                    query.append(WHERE_GREATER_THAN);
7468                                            }
7469                                            else {
7470                                                    query.append(WHERE_LESSER_THAN);
7471                                            }
7472                                    }
7473                            }
7474    
7475                            query.append(ORDER_BY_CLAUSE);
7476    
7477                            String[] orderByFields = orderByComparator.getOrderByFields();
7478    
7479                            for (int i = 0; i < orderByFields.length; i++) {
7480                                    if (getDB().isSupportsInlineDistinct()) {
7481                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7482                                    }
7483                                    else {
7484                                            query.append(_ORDER_BY_ENTITY_TABLE);
7485                                    }
7486    
7487                                    query.append(orderByFields[i]);
7488    
7489                                    if ((i + 1) < orderByFields.length) {
7490                                            if (orderByComparator.isAscending() ^ previous) {
7491                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7492                                            }
7493                                            else {
7494                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7495                                            }
7496                                    }
7497                                    else {
7498                                            if (orderByComparator.isAscending() ^ previous) {
7499                                                    query.append(ORDER_BY_ASC);
7500                                            }
7501                                            else {
7502                                                    query.append(ORDER_BY_DESC);
7503                                            }
7504                                    }
7505                            }
7506                    }
7507                    else {
7508                            if (getDB().isSupportsInlineDistinct()) {
7509                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7510                            }
7511                            else {
7512                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
7513                            }
7514                    }
7515    
7516                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7517                                    MBThread.class.getName(),
7518                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7519    
7520                    SQLQuery q = session.createSQLQuery(sql);
7521    
7522                    q.setFirstResult(0);
7523                    q.setMaxResults(2);
7524    
7525                    if (getDB().isSupportsInlineDistinct()) {
7526                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
7527                    }
7528                    else {
7529                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
7530                    }
7531    
7532                    QueryPos qPos = QueryPos.getInstance(q);
7533    
7534                    qPos.add(groupId);
7535    
7536                    qPos.add(categoryId);
7537    
7538                    if (bindLastPostDate) {
7539                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
7540                    }
7541    
7542                    if (orderByComparator != null) {
7543                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
7544    
7545                            for (Object value : values) {
7546                                    qPos.add(value);
7547                            }
7548                    }
7549    
7550                    List<MBThread> list = q.list();
7551    
7552                    if (list.size() == 2) {
7553                            return list.get(1);
7554                    }
7555                    else {
7556                            return null;
7557                    }
7558            }
7559    
7560            /**
7561             * Removes all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63; from the database.
7562             *
7563             * @param groupId the group ID
7564             * @param categoryId the category ID
7565             * @param lastPostDate the last post date
7566             * @throws SystemException if a system exception occurred
7567             */
7568            public void removeByG_C_L(long groupId, long categoryId, Date lastPostDate)
7569                    throws SystemException {
7570                    for (MBThread mbThread : findByG_C_L(groupId, categoryId, lastPostDate,
7571                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7572                            remove(mbThread);
7573                    }
7574            }
7575    
7576            /**
7577             * Returns the number of message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
7578             *
7579             * @param groupId the group ID
7580             * @param categoryId the category ID
7581             * @param lastPostDate the last post date
7582             * @return the number of matching message boards threads
7583             * @throws SystemException if a system exception occurred
7584             */
7585            public int countByG_C_L(long groupId, long categoryId, Date lastPostDate)
7586                    throws SystemException {
7587                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_L;
7588    
7589                    Object[] finderArgs = new Object[] { groupId, categoryId, lastPostDate };
7590    
7591                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7592                                    this);
7593    
7594                    if (count == null) {
7595                            StringBundler query = new StringBundler(4);
7596    
7597                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
7598    
7599                            query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7600    
7601                            query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7602    
7603                            boolean bindLastPostDate = false;
7604    
7605                            if (lastPostDate == null) {
7606                                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7607                            }
7608                            else {
7609                                    bindLastPostDate = true;
7610    
7611                                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7612                            }
7613    
7614                            String sql = query.toString();
7615    
7616                            Session session = null;
7617    
7618                            try {
7619                                    session = openSession();
7620    
7621                                    Query q = session.createQuery(sql);
7622    
7623                                    QueryPos qPos = QueryPos.getInstance(q);
7624    
7625                                    qPos.add(groupId);
7626    
7627                                    qPos.add(categoryId);
7628    
7629                                    if (bindLastPostDate) {
7630                                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
7631                                    }
7632    
7633                                    count = (Long)q.uniqueResult();
7634    
7635                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7636                            }
7637                            catch (Exception e) {
7638                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7639    
7640                                    throw processException(e);
7641                            }
7642                            finally {
7643                                    closeSession(session);
7644                            }
7645                    }
7646    
7647                    return count.intValue();
7648            }
7649    
7650            /**
7651             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
7652             *
7653             * @param groupId the group ID
7654             * @param categoryId the category ID
7655             * @param lastPostDate the last post date
7656             * @return the number of matching message boards threads that the user has permission to view
7657             * @throws SystemException if a system exception occurred
7658             */
7659            public int filterCountByG_C_L(long groupId, long categoryId,
7660                    Date lastPostDate) throws SystemException {
7661                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7662                            return countByG_C_L(groupId, categoryId, lastPostDate);
7663                    }
7664    
7665                    StringBundler query = new StringBundler(4);
7666    
7667                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
7668    
7669                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7670    
7671                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7672    
7673                    boolean bindLastPostDate = false;
7674    
7675                    if (lastPostDate == null) {
7676                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7677                    }
7678                    else {
7679                            bindLastPostDate = true;
7680    
7681                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7682                    }
7683    
7684                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7685                                    MBThread.class.getName(),
7686                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7687    
7688                    Session session = null;
7689    
7690                    try {
7691                            session = openSession();
7692    
7693                            SQLQuery q = session.createSQLQuery(sql);
7694    
7695                            q.addScalar(COUNT_COLUMN_NAME,
7696                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7697    
7698                            QueryPos qPos = QueryPos.getInstance(q);
7699    
7700                            qPos.add(groupId);
7701    
7702                            qPos.add(categoryId);
7703    
7704                            if (bindLastPostDate) {
7705                                    qPos.add(CalendarUtil.getTimestamp(lastPostDate));
7706                            }
7707    
7708                            Long count = (Long)q.uniqueResult();
7709    
7710                            return count.intValue();
7711                    }
7712                    catch (Exception e) {
7713                            throw processException(e);
7714                    }
7715                    finally {
7716                            closeSession(session);
7717                    }
7718            }
7719    
7720            private static final String _FINDER_COLUMN_G_C_L_GROUPID_2 = "mbThread.groupId = ? AND ";
7721            private static final String _FINDER_COLUMN_G_C_L_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
7722            private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL";
7723            private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_2 = "mbThread.lastPostDate = ?";
7724            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7725                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
7726                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
7727                            new String[] {
7728                                    Long.class.getName(), Long.class.getName(),
7729                                    Integer.class.getName(),
7730                                    
7731                            Integer.class.getName(), Integer.class.getName(),
7732                                    OrderByComparator.class.getName()
7733                            });
7734            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7735                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
7736                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
7737                            new String[] {
7738                                    Long.class.getName(), Long.class.getName(),
7739                                    Integer.class.getName()
7740                            },
7741                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
7742                            MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
7743                            MBThreadModelImpl.STATUS_COLUMN_BITMASK |
7744                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
7745                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
7746            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7747                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
7748                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
7749                            new String[] {
7750                                    Long.class.getName(), Long.class.getName(),
7751                                    Integer.class.getName()
7752                            });
7753            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7754                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
7755                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C_S",
7756                            new String[] {
7757                                    Long.class.getName(), Long.class.getName(),
7758                                    Integer.class.getName()
7759                            });
7760    
7761            /**
7762             * Returns all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63;.
7763             *
7764             * @param groupId the group ID
7765             * @param categoryId the category ID
7766             * @param status the status
7767             * @return the matching message boards threads
7768             * @throws SystemException if a system exception occurred
7769             */
7770            public List<MBThread> findByG_C_S(long groupId, long categoryId, int status)
7771                    throws SystemException {
7772                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
7773                            QueryUtil.ALL_POS, null);
7774            }
7775    
7776            /**
7777             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63;.
7778             *
7779             * <p>
7780             * 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.
7781             * </p>
7782             *
7783             * @param groupId the group ID
7784             * @param categoryId the category ID
7785             * @param status the status
7786             * @param start the lower bound of the range of message boards threads
7787             * @param end the upper bound of the range of message boards threads (not inclusive)
7788             * @return the range of matching message boards threads
7789             * @throws SystemException if a system exception occurred
7790             */
7791            public List<MBThread> findByG_C_S(long groupId, long categoryId,
7792                    int status, int start, int end) throws SystemException {
7793                    return findByG_C_S(groupId, categoryId, status, start, end, null);
7794            }
7795    
7796            /**
7797             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63;.
7798             *
7799             * <p>
7800             * 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.
7801             * </p>
7802             *
7803             * @param groupId the group ID
7804             * @param categoryId the category ID
7805             * @param status the status
7806             * @param start the lower bound of the range of message boards threads
7807             * @param end the upper bound of the range of message boards threads (not inclusive)
7808             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7809             * @return the ordered range of matching message boards threads
7810             * @throws SystemException if a system exception occurred
7811             */
7812            public List<MBThread> findByG_C_S(long groupId, long categoryId,
7813                    int status, int start, int end, OrderByComparator orderByComparator)
7814                    throws SystemException {
7815                    boolean pagination = true;
7816                    FinderPath finderPath = null;
7817                    Object[] finderArgs = null;
7818    
7819                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7820                                    (orderByComparator == null)) {
7821                            pagination = false;
7822                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
7823                            finderArgs = new Object[] { groupId, categoryId, status };
7824                    }
7825                    else {
7826                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
7827                            finderArgs = new Object[] {
7828                                            groupId, categoryId, status,
7829                                            
7830                                            start, end, orderByComparator
7831                                    };
7832                    }
7833    
7834                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
7835                                    finderArgs, this);
7836    
7837                    if ((list != null) && !list.isEmpty()) {
7838                            for (MBThread mbThread : list) {
7839                                    if ((groupId != mbThread.getGroupId()) ||
7840                                                    (categoryId != mbThread.getCategoryId()) ||
7841                                                    (status != mbThread.getStatus())) {
7842                                            list = null;
7843    
7844                                            break;
7845                                    }
7846                            }
7847                    }
7848    
7849                    if (list == null) {
7850                            StringBundler query = null;
7851    
7852                            if (orderByComparator != null) {
7853                                    query = new StringBundler(5 +
7854                                                    (orderByComparator.getOrderByFields().length * 3));
7855                            }
7856                            else {
7857                                    query = new StringBundler(5);
7858                            }
7859    
7860                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
7861    
7862                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
7863    
7864                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
7865    
7866                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
7867    
7868                            if (orderByComparator != null) {
7869                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7870                                            orderByComparator);
7871                            }
7872                            else
7873                             if (pagination) {
7874                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7875                            }
7876    
7877                            String sql = query.toString();
7878    
7879                            Session session = null;
7880    
7881                            try {
7882                                    session = openSession();
7883    
7884                                    Query q = session.createQuery(sql);
7885    
7886                                    QueryPos qPos = QueryPos.getInstance(q);
7887    
7888                                    qPos.add(groupId);
7889    
7890                                    qPos.add(categoryId);
7891    
7892                                    qPos.add(status);
7893    
7894                                    if (!pagination) {
7895                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
7896                                                            start, end, false);
7897    
7898                                            Collections.sort(list);
7899    
7900                                            list = new UnmodifiableList<MBThread>(list);
7901                                    }
7902                                    else {
7903                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
7904                                                            start, end);
7905                                    }
7906    
7907                                    cacheResult(list);
7908    
7909                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7910                            }
7911                            catch (Exception e) {
7912                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7913    
7914                                    throw processException(e);
7915                            }
7916                            finally {
7917                                    closeSession(session);
7918                            }
7919                    }
7920    
7921                    return list;
7922            }
7923    
7924            /**
7925             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
7926             *
7927             * @param groupId the group ID
7928             * @param categoryId the category ID
7929             * @param status the status
7930             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7931             * @return the first matching message boards thread
7932             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
7933             * @throws SystemException if a system exception occurred
7934             */
7935            public MBThread findByG_C_S_First(long groupId, long categoryId,
7936                    int status, OrderByComparator orderByComparator)
7937                    throws NoSuchThreadException, SystemException {
7938                    MBThread mbThread = fetchByG_C_S_First(groupId, categoryId, status,
7939                                    orderByComparator);
7940    
7941                    if (mbThread != null) {
7942                            return mbThread;
7943                    }
7944    
7945                    StringBundler msg = new StringBundler(8);
7946    
7947                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7948    
7949                    msg.append("groupId=");
7950                    msg.append(groupId);
7951    
7952                    msg.append(", categoryId=");
7953                    msg.append(categoryId);
7954    
7955                    msg.append(", status=");
7956                    msg.append(status);
7957    
7958                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7959    
7960                    throw new NoSuchThreadException(msg.toString());
7961            }
7962    
7963            /**
7964             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
7965             *
7966             * @param groupId the group ID
7967             * @param categoryId the category ID
7968             * @param status the status
7969             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7970             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
7971             * @throws SystemException if a system exception occurred
7972             */
7973            public MBThread fetchByG_C_S_First(long groupId, long categoryId,
7974                    int status, OrderByComparator orderByComparator)
7975                    throws SystemException {
7976                    List<MBThread> list = findByG_C_S(groupId, categoryId, status, 0, 1,
7977                                    orderByComparator);
7978    
7979                    if (!list.isEmpty()) {
7980                            return list.get(0);
7981                    }
7982    
7983                    return null;
7984            }
7985    
7986            /**
7987             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
7988             *
7989             * @param groupId the group ID
7990             * @param categoryId the category ID
7991             * @param status the status
7992             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7993             * @return the last matching message boards thread
7994             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
7995             * @throws SystemException if a system exception occurred
7996             */
7997            public MBThread findByG_C_S_Last(long groupId, long categoryId, int status,
7998                    OrderByComparator orderByComparator)
7999                    throws NoSuchThreadException, SystemException {
8000                    MBThread mbThread = fetchByG_C_S_Last(groupId, categoryId, status,
8001                                    orderByComparator);
8002    
8003                    if (mbThread != null) {
8004                            return mbThread;
8005                    }
8006    
8007                    StringBundler msg = new StringBundler(8);
8008    
8009                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8010    
8011                    msg.append("groupId=");
8012                    msg.append(groupId);
8013    
8014                    msg.append(", categoryId=");
8015                    msg.append(categoryId);
8016    
8017                    msg.append(", status=");
8018                    msg.append(status);
8019    
8020                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8021    
8022                    throw new NoSuchThreadException(msg.toString());
8023            }
8024    
8025            /**
8026             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
8027             *
8028             * @param groupId the group ID
8029             * @param categoryId the category ID
8030             * @param status the status
8031             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8032             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
8033             * @throws SystemException if a system exception occurred
8034             */
8035            public MBThread fetchByG_C_S_Last(long groupId, long categoryId,
8036                    int status, OrderByComparator orderByComparator)
8037                    throws SystemException {
8038                    int count = countByG_C_S(groupId, categoryId, status);
8039    
8040                    List<MBThread> list = findByG_C_S(groupId, categoryId, status,
8041                                    count - 1, count, orderByComparator);
8042    
8043                    if (!list.isEmpty()) {
8044                            return list.get(0);
8045                    }
8046    
8047                    return null;
8048            }
8049    
8050            /**
8051             * 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;.
8052             *
8053             * @param threadId the primary key of the current message boards thread
8054             * @param groupId the group ID
8055             * @param categoryId the category ID
8056             * @param status the status
8057             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8058             * @return the previous, current, and next message boards thread
8059             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
8060             * @throws SystemException if a system exception occurred
8061             */
8062            public MBThread[] findByG_C_S_PrevAndNext(long threadId, long groupId,
8063                    long categoryId, int status, OrderByComparator orderByComparator)
8064                    throws NoSuchThreadException, SystemException {
8065                    MBThread mbThread = findByPrimaryKey(threadId);
8066    
8067                    Session session = null;
8068    
8069                    try {
8070                            session = openSession();
8071    
8072                            MBThread[] array = new MBThreadImpl[3];
8073    
8074                            array[0] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
8075                                            categoryId, status, orderByComparator, true);
8076    
8077                            array[1] = mbThread;
8078    
8079                            array[2] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
8080                                            categoryId, status, orderByComparator, false);
8081    
8082                            return array;
8083                    }
8084                    catch (Exception e) {
8085                            throw processException(e);
8086                    }
8087                    finally {
8088                            closeSession(session);
8089                    }
8090            }
8091    
8092            protected MBThread getByG_C_S_PrevAndNext(Session session,
8093                    MBThread mbThread, long groupId, long categoryId, int status,
8094                    OrderByComparator orderByComparator, boolean previous) {
8095                    StringBundler query = null;
8096    
8097                    if (orderByComparator != null) {
8098                            query = new StringBundler(6 +
8099                                            (orderByComparator.getOrderByFields().length * 6));
8100                    }
8101                    else {
8102                            query = new StringBundler(3);
8103                    }
8104    
8105                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
8106    
8107                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8108    
8109                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8110    
8111                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8112    
8113                    if (orderByComparator != null) {
8114                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8115    
8116                            if (orderByConditionFields.length > 0) {
8117                                    query.append(WHERE_AND);
8118                            }
8119    
8120                            for (int i = 0; i < orderByConditionFields.length; i++) {
8121                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8122                                    query.append(orderByConditionFields[i]);
8123    
8124                                    if ((i + 1) < orderByConditionFields.length) {
8125                                            if (orderByComparator.isAscending() ^ previous) {
8126                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8127                                            }
8128                                            else {
8129                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8130                                            }
8131                                    }
8132                                    else {
8133                                            if (orderByComparator.isAscending() ^ previous) {
8134                                                    query.append(WHERE_GREATER_THAN);
8135                                            }
8136                                            else {
8137                                                    query.append(WHERE_LESSER_THAN);
8138                                            }
8139                                    }
8140                            }
8141    
8142                            query.append(ORDER_BY_CLAUSE);
8143    
8144                            String[] orderByFields = orderByComparator.getOrderByFields();
8145    
8146                            for (int i = 0; i < orderByFields.length; i++) {
8147                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8148                                    query.append(orderByFields[i]);
8149    
8150                                    if ((i + 1) < orderByFields.length) {
8151                                            if (orderByComparator.isAscending() ^ previous) {
8152                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8153                                            }
8154                                            else {
8155                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8156                                            }
8157                                    }
8158                                    else {
8159                                            if (orderByComparator.isAscending() ^ previous) {
8160                                                    query.append(ORDER_BY_ASC);
8161                                            }
8162                                            else {
8163                                                    query.append(ORDER_BY_DESC);
8164                                            }
8165                                    }
8166                            }
8167                    }
8168                    else {
8169                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8170                    }
8171    
8172                    String sql = query.toString();
8173    
8174                    Query q = session.createQuery(sql);
8175    
8176                    q.setFirstResult(0);
8177                    q.setMaxResults(2);
8178    
8179                    QueryPos qPos = QueryPos.getInstance(q);
8180    
8181                    qPos.add(groupId);
8182    
8183                    qPos.add(categoryId);
8184    
8185                    qPos.add(status);
8186    
8187                    if (orderByComparator != null) {
8188                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
8189    
8190                            for (Object value : values) {
8191                                    qPos.add(value);
8192                            }
8193                    }
8194    
8195                    List<MBThread> list = q.list();
8196    
8197                    if (list.size() == 2) {
8198                            return list.get(1);
8199                    }
8200                    else {
8201                            return null;
8202                    }
8203            }
8204    
8205            /**
8206             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
8207             *
8208             * @param groupId the group ID
8209             * @param categoryId the category ID
8210             * @param status the status
8211             * @return the matching message boards threads that the user has permission to view
8212             * @throws SystemException if a system exception occurred
8213             */
8214            public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
8215                    int status) throws SystemException {
8216                    return filterFindByG_C_S(groupId, categoryId, status,
8217                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8218            }
8219    
8220            /**
8221             * 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;.
8222             *
8223             * <p>
8224             * 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.
8225             * </p>
8226             *
8227             * @param groupId the group ID
8228             * @param categoryId the category ID
8229             * @param status the status
8230             * @param start the lower bound of the range of message boards threads
8231             * @param end the upper bound of the range of message boards threads (not inclusive)
8232             * @return the range of matching message boards threads that the user has permission to view
8233             * @throws SystemException if a system exception occurred
8234             */
8235            public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
8236                    int status, int start, int end) throws SystemException {
8237                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
8238            }
8239    
8240            /**
8241             * 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;.
8242             *
8243             * <p>
8244             * 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.
8245             * </p>
8246             *
8247             * @param groupId the group ID
8248             * @param categoryId the category ID
8249             * @param status the status
8250             * @param start the lower bound of the range of message boards threads
8251             * @param end the upper bound of the range of message boards threads (not inclusive)
8252             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8253             * @return the ordered range of matching message boards threads that the user has permission to view
8254             * @throws SystemException if a system exception occurred
8255             */
8256            public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
8257                    int status, int start, int end, OrderByComparator orderByComparator)
8258                    throws SystemException {
8259                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8260                            return findByG_C_S(groupId, categoryId, status, start, end,
8261                                    orderByComparator);
8262                    }
8263    
8264                    StringBundler query = null;
8265    
8266                    if (orderByComparator != null) {
8267                            query = new StringBundler(5 +
8268                                            (orderByComparator.getOrderByFields().length * 3));
8269                    }
8270                    else {
8271                            query = new StringBundler(5);
8272                    }
8273    
8274                    if (getDB().isSupportsInlineDistinct()) {
8275                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
8276                    }
8277                    else {
8278                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
8279                    }
8280    
8281                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8282    
8283                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8284    
8285                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8286    
8287                    if (!getDB().isSupportsInlineDistinct()) {
8288                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
8289                    }
8290    
8291                    if (orderByComparator != null) {
8292                            if (getDB().isSupportsInlineDistinct()) {
8293                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8294                                            orderByComparator, true);
8295                            }
8296                            else {
8297                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8298                                            orderByComparator, true);
8299                            }
8300                    }
8301                    else {
8302                            if (getDB().isSupportsInlineDistinct()) {
8303                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8304                            }
8305                            else {
8306                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
8307                            }
8308                    }
8309    
8310                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8311                                    MBThread.class.getName(),
8312                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8313    
8314                    Session session = null;
8315    
8316                    try {
8317                            session = openSession();
8318    
8319                            SQLQuery q = session.createSQLQuery(sql);
8320    
8321                            if (getDB().isSupportsInlineDistinct()) {
8322                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
8323                            }
8324                            else {
8325                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
8326                            }
8327    
8328                            QueryPos qPos = QueryPos.getInstance(q);
8329    
8330                            qPos.add(groupId);
8331    
8332                            qPos.add(categoryId);
8333    
8334                            qPos.add(status);
8335    
8336                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
8337                    }
8338                    catch (Exception e) {
8339                            throw processException(e);
8340                    }
8341                    finally {
8342                            closeSession(session);
8343                    }
8344            }
8345    
8346            /**
8347             * 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;.
8348             *
8349             * @param threadId the primary key of the current message boards thread
8350             * @param groupId the group ID
8351             * @param categoryId the category ID
8352             * @param status the status
8353             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8354             * @return the previous, current, and next message boards thread
8355             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
8356             * @throws SystemException if a system exception occurred
8357             */
8358            public MBThread[] filterFindByG_C_S_PrevAndNext(long threadId,
8359                    long groupId, long categoryId, int status,
8360                    OrderByComparator orderByComparator)
8361                    throws NoSuchThreadException, SystemException {
8362                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8363                            return findByG_C_S_PrevAndNext(threadId, groupId, categoryId,
8364                                    status, orderByComparator);
8365                    }
8366    
8367                    MBThread mbThread = findByPrimaryKey(threadId);
8368    
8369                    Session session = null;
8370    
8371                    try {
8372                            session = openSession();
8373    
8374                            MBThread[] array = new MBThreadImpl[3];
8375    
8376                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbThread, groupId,
8377                                            categoryId, status, orderByComparator, true);
8378    
8379                            array[1] = mbThread;
8380    
8381                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbThread, groupId,
8382                                            categoryId, status, orderByComparator, false);
8383    
8384                            return array;
8385                    }
8386                    catch (Exception e) {
8387                            throw processException(e);
8388                    }
8389                    finally {
8390                            closeSession(session);
8391                    }
8392            }
8393    
8394            protected MBThread filterGetByG_C_S_PrevAndNext(Session session,
8395                    MBThread mbThread, long groupId, long categoryId, int status,
8396                    OrderByComparator orderByComparator, boolean previous) {
8397                    StringBundler query = null;
8398    
8399                    if (orderByComparator != null) {
8400                            query = new StringBundler(6 +
8401                                            (orderByComparator.getOrderByFields().length * 6));
8402                    }
8403                    else {
8404                            query = new StringBundler(3);
8405                    }
8406    
8407                    if (getDB().isSupportsInlineDistinct()) {
8408                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
8409                    }
8410                    else {
8411                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
8412                    }
8413    
8414                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8415    
8416                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8417    
8418                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8419    
8420                    if (!getDB().isSupportsInlineDistinct()) {
8421                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
8422                    }
8423    
8424                    if (orderByComparator != null) {
8425                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8426    
8427                            if (orderByConditionFields.length > 0) {
8428                                    query.append(WHERE_AND);
8429                            }
8430    
8431                            for (int i = 0; i < orderByConditionFields.length; i++) {
8432                                    if (getDB().isSupportsInlineDistinct()) {
8433                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8434                                    }
8435                                    else {
8436                                            query.append(_ORDER_BY_ENTITY_TABLE);
8437                                    }
8438    
8439                                    query.append(orderByConditionFields[i]);
8440    
8441                                    if ((i + 1) < orderByConditionFields.length) {
8442                                            if (orderByComparator.isAscending() ^ previous) {
8443                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8444                                            }
8445                                            else {
8446                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8447                                            }
8448                                    }
8449                                    else {
8450                                            if (orderByComparator.isAscending() ^ previous) {
8451                                                    query.append(WHERE_GREATER_THAN);
8452                                            }
8453                                            else {
8454                                                    query.append(WHERE_LESSER_THAN);
8455                                            }
8456                                    }
8457                            }
8458    
8459                            query.append(ORDER_BY_CLAUSE);
8460    
8461                            String[] orderByFields = orderByComparator.getOrderByFields();
8462    
8463                            for (int i = 0; i < orderByFields.length; i++) {
8464                                    if (getDB().isSupportsInlineDistinct()) {
8465                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8466                                    }
8467                                    else {
8468                                            query.append(_ORDER_BY_ENTITY_TABLE);
8469                                    }
8470    
8471                                    query.append(orderByFields[i]);
8472    
8473                                    if ((i + 1) < orderByFields.length) {
8474                                            if (orderByComparator.isAscending() ^ previous) {
8475                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8476                                            }
8477                                            else {
8478                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8479                                            }
8480                                    }
8481                                    else {
8482                                            if (orderByComparator.isAscending() ^ previous) {
8483                                                    query.append(ORDER_BY_ASC);
8484                                            }
8485                                            else {
8486                                                    query.append(ORDER_BY_DESC);
8487                                            }
8488                                    }
8489                            }
8490                    }
8491                    else {
8492                            if (getDB().isSupportsInlineDistinct()) {
8493                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8494                            }
8495                            else {
8496                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
8497                            }
8498                    }
8499    
8500                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8501                                    MBThread.class.getName(),
8502                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8503    
8504                    SQLQuery q = session.createSQLQuery(sql);
8505    
8506                    q.setFirstResult(0);
8507                    q.setMaxResults(2);
8508    
8509                    if (getDB().isSupportsInlineDistinct()) {
8510                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
8511                    }
8512                    else {
8513                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
8514                    }
8515    
8516                    QueryPos qPos = QueryPos.getInstance(q);
8517    
8518                    qPos.add(groupId);
8519    
8520                    qPos.add(categoryId);
8521    
8522                    qPos.add(status);
8523    
8524                    if (orderByComparator != null) {
8525                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
8526    
8527                            for (Object value : values) {
8528                                    qPos.add(value);
8529                            }
8530                    }
8531    
8532                    List<MBThread> list = q.list();
8533    
8534                    if (list.size() == 2) {
8535                            return list.get(1);
8536                    }
8537                    else {
8538                            return null;
8539                    }
8540            }
8541    
8542            /**
8543             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63; and status = &#63;.
8544             *
8545             * @param groupId the group ID
8546             * @param categoryIds the category IDs
8547             * @param status the status
8548             * @return the matching message boards threads that the user has permission to view
8549             * @throws SystemException if a system exception occurred
8550             */
8551            public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
8552                    int status) throws SystemException {
8553                    return filterFindByG_C_S(groupId, categoryIds, status,
8554                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8555            }
8556    
8557            /**
8558             * 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;.
8559             *
8560             * <p>
8561             * 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.
8562             * </p>
8563             *
8564             * @param groupId the group ID
8565             * @param categoryIds the category IDs
8566             * @param status the status
8567             * @param start the lower bound of the range of message boards threads
8568             * @param end the upper bound of the range of message boards threads (not inclusive)
8569             * @return the range of matching message boards threads that the user has permission to view
8570             * @throws SystemException if a system exception occurred
8571             */
8572            public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
8573                    int status, int start, int end) throws SystemException {
8574                    return filterFindByG_C_S(groupId, categoryIds, status, start, end, null);
8575            }
8576    
8577            /**
8578             * 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;.
8579             *
8580             * <p>
8581             * 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.
8582             * </p>
8583             *
8584             * @param groupId the group ID
8585             * @param categoryIds the category IDs
8586             * @param status the status
8587             * @param start the lower bound of the range of message boards threads
8588             * @param end the upper bound of the range of message boards threads (not inclusive)
8589             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8590             * @return the ordered range of matching message boards threads that the user has permission to view
8591             * @throws SystemException if a system exception occurred
8592             */
8593            public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
8594                    int status, int start, int end, OrderByComparator orderByComparator)
8595                    throws SystemException {
8596                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8597                            return findByG_C_S(groupId, categoryIds, status, start, end,
8598                                    orderByComparator);
8599                    }
8600    
8601                    StringBundler query = new StringBundler();
8602    
8603                    if (getDB().isSupportsInlineDistinct()) {
8604                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
8605                    }
8606                    else {
8607                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
8608                    }
8609    
8610                    boolean conjunctionable = false;
8611    
8612                    if (conjunctionable) {
8613                            query.append(WHERE_AND);
8614                    }
8615    
8616                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
8617    
8618                    conjunctionable = true;
8619    
8620                    if ((categoryIds == null) || (categoryIds.length > 0)) {
8621                            if (conjunctionable) {
8622                                    query.append(WHERE_AND);
8623                            }
8624    
8625                            query.append(StringPool.OPEN_PARENTHESIS);
8626    
8627                            for (int i = 0; i < categoryIds.length; i++) {
8628                                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
8629    
8630                                    if ((i + 1) < categoryIds.length) {
8631                                            query.append(WHERE_OR);
8632                                    }
8633                            }
8634    
8635                            query.append(StringPool.CLOSE_PARENTHESIS);
8636    
8637                            conjunctionable = true;
8638                    }
8639    
8640                    if (conjunctionable) {
8641                            query.append(WHERE_AND);
8642                    }
8643    
8644                    query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
8645    
8646                    conjunctionable = true;
8647    
8648                    if (!getDB().isSupportsInlineDistinct()) {
8649                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
8650                    }
8651    
8652                    if (orderByComparator != null) {
8653                            if (getDB().isSupportsInlineDistinct()) {
8654                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8655                                            orderByComparator, true);
8656                            }
8657                            else {
8658                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8659                                            orderByComparator, true);
8660                            }
8661                    }
8662                    else {
8663                            if (getDB().isSupportsInlineDistinct()) {
8664                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8665                            }
8666                            else {
8667                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
8668                            }
8669                    }
8670    
8671                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8672                                    MBThread.class.getName(),
8673                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8674    
8675                    Session session = null;
8676    
8677                    try {
8678                            session = openSession();
8679    
8680                            SQLQuery q = session.createSQLQuery(sql);
8681    
8682                            if (getDB().isSupportsInlineDistinct()) {
8683                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
8684                            }
8685                            else {
8686                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
8687                            }
8688    
8689                            QueryPos qPos = QueryPos.getInstance(q);
8690    
8691                            qPos.add(groupId);
8692    
8693                            if (categoryIds != null) {
8694                                    qPos.add(categoryIds);
8695                            }
8696    
8697                            qPos.add(status);
8698    
8699                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
8700                    }
8701                    catch (Exception e) {
8702                            throw processException(e);
8703                    }
8704                    finally {
8705                            closeSession(session);
8706                    }
8707            }
8708    
8709            /**
8710             * Returns all the message boards threads where groupId = &#63; and categoryId = any &#63; and status = &#63;.
8711             *
8712             * <p>
8713             * 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.
8714             * </p>
8715             *
8716             * @param groupId the group ID
8717             * @param categoryIds the category IDs
8718             * @param status the status
8719             * @return the matching message boards threads
8720             * @throws SystemException if a system exception occurred
8721             */
8722            public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
8723                    int status) throws SystemException {
8724                    return findByG_C_S(groupId, categoryIds, status, QueryUtil.ALL_POS,
8725                            QueryUtil.ALL_POS, null);
8726            }
8727    
8728            /**
8729             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = any &#63; and status = &#63;.
8730             *
8731             * <p>
8732             * 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.
8733             * </p>
8734             *
8735             * @param groupId the group ID
8736             * @param categoryIds the category IDs
8737             * @param status the status
8738             * @param start the lower bound of the range of message boards threads
8739             * @param end the upper bound of the range of message boards threads (not inclusive)
8740             * @return the range of matching message boards threads
8741             * @throws SystemException if a system exception occurred
8742             */
8743            public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
8744                    int status, int start, int end) throws SystemException {
8745                    return findByG_C_S(groupId, categoryIds, status, start, end, null);
8746            }
8747    
8748            /**
8749             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = any &#63; and status = &#63;.
8750             *
8751             * <p>
8752             * 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.
8753             * </p>
8754             *
8755             * @param groupId the group ID
8756             * @param categoryIds the category IDs
8757             * @param status the status
8758             * @param start the lower bound of the range of message boards threads
8759             * @param end the upper bound of the range of message boards threads (not inclusive)
8760             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8761             * @return the ordered range of matching message boards threads
8762             * @throws SystemException if a system exception occurred
8763             */
8764            public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
8765                    int status, int start, int end, OrderByComparator orderByComparator)
8766                    throws SystemException {
8767                    if ((categoryIds != null) && (categoryIds.length == 1)) {
8768                            return findByG_C_S(groupId, categoryIds[0], status, start, end,
8769                                    orderByComparator);
8770                    }
8771    
8772                    boolean pagination = true;
8773                    Object[] finderArgs = null;
8774    
8775                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8776                                    (orderByComparator == null)) {
8777                            pagination = false;
8778                            finderArgs = new Object[] {
8779                                            groupId, StringUtil.merge(categoryIds), status
8780                                    };
8781                    }
8782                    else {
8783                            finderArgs = new Object[] {
8784                                            groupId, StringUtil.merge(categoryIds), status,
8785                                            
8786                                            start, end, orderByComparator
8787                                    };
8788                    }
8789    
8790                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S,
8791                                    finderArgs, this);
8792    
8793                    if ((list != null) && !list.isEmpty()) {
8794                            for (MBThread mbThread : list) {
8795                                    if ((groupId != mbThread.getGroupId()) ||
8796                                                    !ArrayUtil.contains(categoryIds,
8797                                                            mbThread.getCategoryId()) ||
8798                                                    (status != mbThread.getStatus())) {
8799                                            list = null;
8800    
8801                                            break;
8802                                    }
8803                            }
8804                    }
8805    
8806                    if (list == null) {
8807                            StringBundler query = new StringBundler();
8808    
8809                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
8810    
8811                            boolean conjunctionable = false;
8812    
8813                            if (conjunctionable) {
8814                                    query.append(WHERE_AND);
8815                            }
8816    
8817                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
8818    
8819                            conjunctionable = true;
8820    
8821                            if ((categoryIds == null) || (categoryIds.length > 0)) {
8822                                    if (conjunctionable) {
8823                                            query.append(WHERE_AND);
8824                                    }
8825    
8826                                    query.append(StringPool.OPEN_PARENTHESIS);
8827    
8828                                    for (int i = 0; i < categoryIds.length; i++) {
8829                                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
8830    
8831                                            if ((i + 1) < categoryIds.length) {
8832                                                    query.append(WHERE_OR);
8833                                            }
8834                                    }
8835    
8836                                    query.append(StringPool.CLOSE_PARENTHESIS);
8837    
8838                                    conjunctionable = true;
8839                            }
8840    
8841                            if (conjunctionable) {
8842                                    query.append(WHERE_AND);
8843                            }
8844    
8845                            query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
8846    
8847                            conjunctionable = true;
8848    
8849                            if (orderByComparator != null) {
8850                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8851                                            orderByComparator);
8852                            }
8853                            else
8854                             if (pagination) {
8855                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8856                            }
8857    
8858                            String sql = query.toString();
8859    
8860                            Session session = null;
8861    
8862                            try {
8863                                    session = openSession();
8864    
8865                                    Query q = session.createQuery(sql);
8866    
8867                                    QueryPos qPos = QueryPos.getInstance(q);
8868    
8869                                    qPos.add(groupId);
8870    
8871                                    if (categoryIds != null) {
8872                                            qPos.add(categoryIds);
8873                                    }
8874    
8875                                    qPos.add(status);
8876    
8877                                    if (!pagination) {
8878                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
8879                                                            start, end, false);
8880    
8881                                            Collections.sort(list);
8882    
8883                                            list = new UnmodifiableList<MBThread>(list);
8884                                    }
8885                                    else {
8886                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
8887                                                            start, end);
8888                                    }
8889    
8890                                    cacheResult(list);
8891    
8892                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S,
8893                                            finderArgs, list);
8894                            }
8895                            catch (Exception e) {
8896                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S,
8897                                            finderArgs);
8898    
8899                                    throw processException(e);
8900                            }
8901                            finally {
8902                                    closeSession(session);
8903                            }
8904                    }
8905    
8906                    return list;
8907            }
8908    
8909            /**
8910             * Removes all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
8911             *
8912             * @param groupId the group ID
8913             * @param categoryId the category ID
8914             * @param status the status
8915             * @throws SystemException if a system exception occurred
8916             */
8917            public void removeByG_C_S(long groupId, long categoryId, int status)
8918                    throws SystemException {
8919                    for (MBThread mbThread : findByG_C_S(groupId, categoryId, status,
8920                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8921                            remove(mbThread);
8922                    }
8923            }
8924    
8925            /**
8926             * Returns the number of message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63;.
8927             *
8928             * @param groupId the group ID
8929             * @param categoryId the category ID
8930             * @param status the status
8931             * @return the number of matching message boards threads
8932             * @throws SystemException if a system exception occurred
8933             */
8934            public int countByG_C_S(long groupId, long categoryId, int status)
8935                    throws SystemException {
8936                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
8937    
8938                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
8939    
8940                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8941                                    this);
8942    
8943                    if (count == null) {
8944                            StringBundler query = new StringBundler(4);
8945    
8946                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
8947    
8948                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8949    
8950                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8951    
8952                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8953    
8954                            String sql = query.toString();
8955    
8956                            Session session = null;
8957    
8958                            try {
8959                                    session = openSession();
8960    
8961                                    Query q = session.createQuery(sql);
8962    
8963                                    QueryPos qPos = QueryPos.getInstance(q);
8964    
8965                                    qPos.add(groupId);
8966    
8967                                    qPos.add(categoryId);
8968    
8969                                    qPos.add(status);
8970    
8971                                    count = (Long)q.uniqueResult();
8972    
8973                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8974                            }
8975                            catch (Exception e) {
8976                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8977    
8978                                    throw processException(e);
8979                            }
8980                            finally {
8981                                    closeSession(session);
8982                            }
8983                    }
8984    
8985                    return count.intValue();
8986            }
8987    
8988            /**
8989             * Returns the number of message boards threads where groupId = &#63; and categoryId = any &#63; and status = &#63;.
8990             *
8991             * @param groupId the group ID
8992             * @param categoryIds the category IDs
8993             * @param status the status
8994             * @return the number of matching message boards threads
8995             * @throws SystemException if a system exception occurred
8996             */
8997            public int countByG_C_S(long groupId, long[] categoryIds, int status)
8998                    throws SystemException {
8999                    Object[] finderArgs = new Object[] {
9000                                    groupId, StringUtil.merge(categoryIds), status
9001                            };
9002    
9003                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
9004                                    finderArgs, this);
9005    
9006                    if (count == null) {
9007                            StringBundler query = new StringBundler();
9008    
9009                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
9010    
9011                            boolean conjunctionable = false;
9012    
9013                            if (conjunctionable) {
9014                                    query.append(WHERE_AND);
9015                            }
9016    
9017                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
9018    
9019                            conjunctionable = true;
9020    
9021                            if ((categoryIds == null) || (categoryIds.length > 0)) {
9022                                    if (conjunctionable) {
9023                                            query.append(WHERE_AND);
9024                                    }
9025    
9026                                    query.append(StringPool.OPEN_PARENTHESIS);
9027    
9028                                    for (int i = 0; i < categoryIds.length; i++) {
9029                                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
9030    
9031                                            if ((i + 1) < categoryIds.length) {
9032                                                    query.append(WHERE_OR);
9033                                            }
9034                                    }
9035    
9036                                    query.append(StringPool.CLOSE_PARENTHESIS);
9037    
9038                                    conjunctionable = true;
9039                            }
9040    
9041                            if (conjunctionable) {
9042                                    query.append(WHERE_AND);
9043                            }
9044    
9045                            query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
9046    
9047                            conjunctionable = true;
9048    
9049                            String sql = query.toString();
9050    
9051                            Session session = null;
9052    
9053                            try {
9054                                    session = openSession();
9055    
9056                                    Query q = session.createQuery(sql);
9057    
9058                                    QueryPos qPos = QueryPos.getInstance(q);
9059    
9060                                    qPos.add(groupId);
9061    
9062                                    if (categoryIds != null) {
9063                                            qPos.add(categoryIds);
9064                                    }
9065    
9066                                    qPos.add(status);
9067    
9068                                    count = (Long)q.uniqueResult();
9069    
9070                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
9071                                            finderArgs, count);
9072                            }
9073                            catch (Exception e) {
9074                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
9075                                            finderArgs);
9076    
9077                                    throw processException(e);
9078                            }
9079                            finally {
9080                                    closeSession(session);
9081                            }
9082                    }
9083    
9084                    return count.intValue();
9085            }
9086    
9087            /**
9088             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
9089             *
9090             * @param groupId the group ID
9091             * @param categoryId the category ID
9092             * @param status the status
9093             * @return the number of matching message boards threads that the user has permission to view
9094             * @throws SystemException if a system exception occurred
9095             */
9096            public int filterCountByG_C_S(long groupId, long categoryId, int status)
9097                    throws SystemException {
9098                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9099                            return countByG_C_S(groupId, categoryId, status);
9100                    }
9101    
9102                    StringBundler query = new StringBundler(4);
9103    
9104                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
9105    
9106                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
9107    
9108                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
9109    
9110                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
9111    
9112                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9113                                    MBThread.class.getName(),
9114                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9115    
9116                    Session session = null;
9117    
9118                    try {
9119                            session = openSession();
9120    
9121                            SQLQuery q = session.createSQLQuery(sql);
9122    
9123                            q.addScalar(COUNT_COLUMN_NAME,
9124                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9125    
9126                            QueryPos qPos = QueryPos.getInstance(q);
9127    
9128                            qPos.add(groupId);
9129    
9130                            qPos.add(categoryId);
9131    
9132                            qPos.add(status);
9133    
9134                            Long count = (Long)q.uniqueResult();
9135    
9136                            return count.intValue();
9137                    }
9138                    catch (Exception e) {
9139                            throw processException(e);
9140                    }
9141                    finally {
9142                            closeSession(session);
9143                    }
9144            }
9145    
9146            /**
9147             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63; and status = &#63;.
9148             *
9149             * @param groupId the group ID
9150             * @param categoryIds the category IDs
9151             * @param status the status
9152             * @return the number of matching message boards threads that the user has permission to view
9153             * @throws SystemException if a system exception occurred
9154             */
9155            public int filterCountByG_C_S(long groupId, long[] categoryIds, int status)
9156                    throws SystemException {
9157                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9158                            return countByG_C_S(groupId, categoryIds, status);
9159                    }
9160    
9161                    StringBundler query = new StringBundler();
9162    
9163                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
9164    
9165                    boolean conjunctionable = false;
9166    
9167                    if (conjunctionable) {
9168                            query.append(WHERE_AND);
9169                    }
9170    
9171                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
9172    
9173                    conjunctionable = true;
9174    
9175                    if ((categoryIds == null) || (categoryIds.length > 0)) {
9176                            if (conjunctionable) {
9177                                    query.append(WHERE_AND);
9178                            }
9179    
9180                            query.append(StringPool.OPEN_PARENTHESIS);
9181    
9182                            for (int i = 0; i < categoryIds.length; i++) {
9183                                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
9184    
9185                                    if ((i + 1) < categoryIds.length) {
9186                                            query.append(WHERE_OR);
9187                                    }
9188                            }
9189    
9190                            query.append(StringPool.CLOSE_PARENTHESIS);
9191    
9192                            conjunctionable = true;
9193                    }
9194    
9195                    if (conjunctionable) {
9196                            query.append(WHERE_AND);
9197                    }
9198    
9199                    query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
9200    
9201                    conjunctionable = true;
9202    
9203                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9204                                    MBThread.class.getName(),
9205                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9206    
9207                    Session session = null;
9208    
9209                    try {
9210                            session = openSession();
9211    
9212                            SQLQuery q = session.createSQLQuery(sql);
9213    
9214                            q.addScalar(COUNT_COLUMN_NAME,
9215                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9216    
9217                            QueryPos qPos = QueryPos.getInstance(q);
9218    
9219                            qPos.add(groupId);
9220    
9221                            if (categoryIds != null) {
9222                                    qPos.add(categoryIds);
9223                            }
9224    
9225                            qPos.add(status);
9226    
9227                            Long count = (Long)q.uniqueResult();
9228    
9229                            return count.intValue();
9230                    }
9231                    catch (Exception e) {
9232                            throw processException(e);
9233                    }
9234                    finally {
9235                            closeSession(session);
9236                    }
9237            }
9238    
9239            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbThread.groupId = ? AND ";
9240            private static final String _FINDER_COLUMN_G_C_S_GROUPID_5 = "(" +
9241                    removeConjunction(_FINDER_COLUMN_G_C_S_GROUPID_2) + ")";
9242            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
9243            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_5 = "(" +
9244                    removeConjunction(_FINDER_COLUMN_G_C_S_CATEGORYID_2) + ")";
9245            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbThread.status = ?";
9246            private static final String _FINDER_COLUMN_G_C_S_STATUS_5 = "(" +
9247                    removeConjunction(_FINDER_COLUMN_G_C_S_STATUS_2) + ")";
9248            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
9249                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
9250                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_NotS",
9251                            new String[] {
9252                                    Long.class.getName(), Long.class.getName(),
9253                                    Integer.class.getName(),
9254                                    
9255                            Integer.class.getName(), Integer.class.getName(),
9256                                    OrderByComparator.class.getName()
9257                            });
9258            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS =
9259                    new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
9260                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
9261                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C_NotS",
9262                            new String[] {
9263                                    Long.class.getName(), Long.class.getName(),
9264                                    Integer.class.getName()
9265                            });
9266    
9267            /**
9268             * Returns all the message boards threads where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9269             *
9270             * @param groupId the group ID
9271             * @param categoryId the category ID
9272             * @param status the status
9273             * @return the matching message boards threads
9274             * @throws SystemException if a system exception occurred
9275             */
9276            public List<MBThread> findByG_C_NotS(long groupId, long categoryId,
9277                    int status) throws SystemException {
9278                    return findByG_C_NotS(groupId, categoryId, status, QueryUtil.ALL_POS,
9279                            QueryUtil.ALL_POS, null);
9280            }
9281    
9282            /**
9283             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9284             *
9285             * <p>
9286             * 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.
9287             * </p>
9288             *
9289             * @param groupId the group ID
9290             * @param categoryId the category ID
9291             * @param status the status
9292             * @param start the lower bound of the range of message boards threads
9293             * @param end the upper bound of the range of message boards threads (not inclusive)
9294             * @return the range of matching message boards threads
9295             * @throws SystemException if a system exception occurred
9296             */
9297            public List<MBThread> findByG_C_NotS(long groupId, long categoryId,
9298                    int status, int start, int end) throws SystemException {
9299                    return findByG_C_NotS(groupId, categoryId, status, start, end, null);
9300            }
9301    
9302            /**
9303             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9304             *
9305             * <p>
9306             * 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.
9307             * </p>
9308             *
9309             * @param groupId the group ID
9310             * @param categoryId the category ID
9311             * @param status the status
9312             * @param start the lower bound of the range of message boards threads
9313             * @param end the upper bound of the range of message boards threads (not inclusive)
9314             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9315             * @return the ordered range of matching message boards threads
9316             * @throws SystemException if a system exception occurred
9317             */
9318            public List<MBThread> findByG_C_NotS(long groupId, long categoryId,
9319                    int status, int start, int end, OrderByComparator orderByComparator)
9320                    throws SystemException {
9321                    boolean pagination = true;
9322                    FinderPath finderPath = null;
9323                    Object[] finderArgs = null;
9324    
9325                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS;
9326                    finderArgs = new Object[] {
9327                                    groupId, categoryId, status,
9328                                    
9329                                    start, end, orderByComparator
9330                            };
9331    
9332                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
9333                                    finderArgs, this);
9334    
9335                    if ((list != null) && !list.isEmpty()) {
9336                            for (MBThread mbThread : list) {
9337                                    if ((groupId != mbThread.getGroupId()) ||
9338                                                    (categoryId != mbThread.getCategoryId()) ||
9339                                                    (status != mbThread.getStatus())) {
9340                                            list = null;
9341    
9342                                            break;
9343                                    }
9344                            }
9345                    }
9346    
9347                    if (list == null) {
9348                            StringBundler query = null;
9349    
9350                            if (orderByComparator != null) {
9351                                    query = new StringBundler(5 +
9352                                                    (orderByComparator.getOrderByFields().length * 3));
9353                            }
9354                            else {
9355                                    query = new StringBundler(5);
9356                            }
9357    
9358                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
9359    
9360                            query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9361    
9362                            query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9363    
9364                            query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9365    
9366                            if (orderByComparator != null) {
9367                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9368                                            orderByComparator);
9369                            }
9370                            else
9371                             if (pagination) {
9372                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9373                            }
9374    
9375                            String sql = query.toString();
9376    
9377                            Session session = null;
9378    
9379                            try {
9380                                    session = openSession();
9381    
9382                                    Query q = session.createQuery(sql);
9383    
9384                                    QueryPos qPos = QueryPos.getInstance(q);
9385    
9386                                    qPos.add(groupId);
9387    
9388                                    qPos.add(categoryId);
9389    
9390                                    qPos.add(status);
9391    
9392                                    if (!pagination) {
9393                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
9394                                                            start, end, false);
9395    
9396                                            Collections.sort(list);
9397    
9398                                            list = new UnmodifiableList<MBThread>(list);
9399                                    }
9400                                    else {
9401                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
9402                                                            start, end);
9403                                    }
9404    
9405                                    cacheResult(list);
9406    
9407                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9408                            }
9409                            catch (Exception e) {
9410                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9411    
9412                                    throw processException(e);
9413                            }
9414                            finally {
9415                                    closeSession(session);
9416                            }
9417                    }
9418    
9419                    return list;
9420            }
9421    
9422            /**
9423             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9424             *
9425             * @param groupId the group ID
9426             * @param categoryId the category ID
9427             * @param status the status
9428             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9429             * @return the first matching message boards thread
9430             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
9431             * @throws SystemException if a system exception occurred
9432             */
9433            public MBThread findByG_C_NotS_First(long groupId, long categoryId,
9434                    int status, OrderByComparator orderByComparator)
9435                    throws NoSuchThreadException, SystemException {
9436                    MBThread mbThread = fetchByG_C_NotS_First(groupId, categoryId, status,
9437                                    orderByComparator);
9438    
9439                    if (mbThread != null) {
9440                            return mbThread;
9441                    }
9442    
9443                    StringBundler msg = new StringBundler(8);
9444    
9445                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9446    
9447                    msg.append("groupId=");
9448                    msg.append(groupId);
9449    
9450                    msg.append(", categoryId=");
9451                    msg.append(categoryId);
9452    
9453                    msg.append(", status=");
9454                    msg.append(status);
9455    
9456                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9457    
9458                    throw new NoSuchThreadException(msg.toString());
9459            }
9460    
9461            /**
9462             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9463             *
9464             * @param groupId the group ID
9465             * @param categoryId the category ID
9466             * @param status the status
9467             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9468             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
9469             * @throws SystemException if a system exception occurred
9470             */
9471            public MBThread fetchByG_C_NotS_First(long groupId, long categoryId,
9472                    int status, OrderByComparator orderByComparator)
9473                    throws SystemException {
9474                    List<MBThread> list = findByG_C_NotS(groupId, categoryId, status, 0, 1,
9475                                    orderByComparator);
9476    
9477                    if (!list.isEmpty()) {
9478                            return list.get(0);
9479                    }
9480    
9481                    return null;
9482            }
9483    
9484            /**
9485             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9486             *
9487             * @param groupId the group ID
9488             * @param categoryId the category ID
9489             * @param status the status
9490             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9491             * @return the last matching message boards thread
9492             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
9493             * @throws SystemException if a system exception occurred
9494             */
9495            public MBThread findByG_C_NotS_Last(long groupId, long categoryId,
9496                    int status, OrderByComparator orderByComparator)
9497                    throws NoSuchThreadException, SystemException {
9498                    MBThread mbThread = fetchByG_C_NotS_Last(groupId, categoryId, status,
9499                                    orderByComparator);
9500    
9501                    if (mbThread != null) {
9502                            return mbThread;
9503                    }
9504    
9505                    StringBundler msg = new StringBundler(8);
9506    
9507                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9508    
9509                    msg.append("groupId=");
9510                    msg.append(groupId);
9511    
9512                    msg.append(", categoryId=");
9513                    msg.append(categoryId);
9514    
9515                    msg.append(", status=");
9516                    msg.append(status);
9517    
9518                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9519    
9520                    throw new NoSuchThreadException(msg.toString());
9521            }
9522    
9523            /**
9524             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9525             *
9526             * @param groupId the group ID
9527             * @param categoryId the category ID
9528             * @param status the status
9529             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9530             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
9531             * @throws SystemException if a system exception occurred
9532             */
9533            public MBThread fetchByG_C_NotS_Last(long groupId, long categoryId,
9534                    int status, OrderByComparator orderByComparator)
9535                    throws SystemException {
9536                    int count = countByG_C_NotS(groupId, categoryId, status);
9537    
9538                    List<MBThread> list = findByG_C_NotS(groupId, categoryId, status,
9539                                    count - 1, count, orderByComparator);
9540    
9541                    if (!list.isEmpty()) {
9542                            return list.get(0);
9543                    }
9544    
9545                    return null;
9546            }
9547    
9548            /**
9549             * 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;.
9550             *
9551             * @param threadId the primary key of the current message boards thread
9552             * @param groupId the group ID
9553             * @param categoryId the category ID
9554             * @param status the status
9555             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9556             * @return the previous, current, and next message boards thread
9557             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
9558             * @throws SystemException if a system exception occurred
9559             */
9560            public MBThread[] findByG_C_NotS_PrevAndNext(long threadId, long groupId,
9561                    long categoryId, int status, OrderByComparator orderByComparator)
9562                    throws NoSuchThreadException, SystemException {
9563                    MBThread mbThread = findByPrimaryKey(threadId);
9564    
9565                    Session session = null;
9566    
9567                    try {
9568                            session = openSession();
9569    
9570                            MBThread[] array = new MBThreadImpl[3];
9571    
9572                            array[0] = getByG_C_NotS_PrevAndNext(session, mbThread, groupId,
9573                                            categoryId, status, orderByComparator, true);
9574    
9575                            array[1] = mbThread;
9576    
9577                            array[2] = getByG_C_NotS_PrevAndNext(session, mbThread, groupId,
9578                                            categoryId, status, orderByComparator, false);
9579    
9580                            return array;
9581                    }
9582                    catch (Exception e) {
9583                            throw processException(e);
9584                    }
9585                    finally {
9586                            closeSession(session);
9587                    }
9588            }
9589    
9590            protected MBThread getByG_C_NotS_PrevAndNext(Session session,
9591                    MBThread mbThread, long groupId, long categoryId, int status,
9592                    OrderByComparator orderByComparator, boolean previous) {
9593                    StringBundler query = null;
9594    
9595                    if (orderByComparator != null) {
9596                            query = new StringBundler(6 +
9597                                            (orderByComparator.getOrderByFields().length * 6));
9598                    }
9599                    else {
9600                            query = new StringBundler(3);
9601                    }
9602    
9603                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
9604    
9605                    query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9606    
9607                    query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9608    
9609                    query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9610    
9611                    if (orderByComparator != null) {
9612                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9613    
9614                            if (orderByConditionFields.length > 0) {
9615                                    query.append(WHERE_AND);
9616                            }
9617    
9618                            for (int i = 0; i < orderByConditionFields.length; i++) {
9619                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9620                                    query.append(orderByConditionFields[i]);
9621    
9622                                    if ((i + 1) < orderByConditionFields.length) {
9623                                            if (orderByComparator.isAscending() ^ previous) {
9624                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9625                                            }
9626                                            else {
9627                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9628                                            }
9629                                    }
9630                                    else {
9631                                            if (orderByComparator.isAscending() ^ previous) {
9632                                                    query.append(WHERE_GREATER_THAN);
9633                                            }
9634                                            else {
9635                                                    query.append(WHERE_LESSER_THAN);
9636                                            }
9637                                    }
9638                            }
9639    
9640                            query.append(ORDER_BY_CLAUSE);
9641    
9642                            String[] orderByFields = orderByComparator.getOrderByFields();
9643    
9644                            for (int i = 0; i < orderByFields.length; i++) {
9645                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9646                                    query.append(orderByFields[i]);
9647    
9648                                    if ((i + 1) < orderByFields.length) {
9649                                            if (orderByComparator.isAscending() ^ previous) {
9650                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9651                                            }
9652                                            else {
9653                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9654                                            }
9655                                    }
9656                                    else {
9657                                            if (orderByComparator.isAscending() ^ previous) {
9658                                                    query.append(ORDER_BY_ASC);
9659                                            }
9660                                            else {
9661                                                    query.append(ORDER_BY_DESC);
9662                                            }
9663                                    }
9664                            }
9665                    }
9666                    else {
9667                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9668                    }
9669    
9670                    String sql = query.toString();
9671    
9672                    Query q = session.createQuery(sql);
9673    
9674                    q.setFirstResult(0);
9675                    q.setMaxResults(2);
9676    
9677                    QueryPos qPos = QueryPos.getInstance(q);
9678    
9679                    qPos.add(groupId);
9680    
9681                    qPos.add(categoryId);
9682    
9683                    qPos.add(status);
9684    
9685                    if (orderByComparator != null) {
9686                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
9687    
9688                            for (Object value : values) {
9689                                    qPos.add(value);
9690                            }
9691                    }
9692    
9693                    List<MBThread> list = q.list();
9694    
9695                    if (list.size() == 2) {
9696                            return list.get(1);
9697                    }
9698                    else {
9699                            return null;
9700                    }
9701            }
9702    
9703            /**
9704             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
9705             *
9706             * @param groupId the group ID
9707             * @param categoryId the category ID
9708             * @param status the status
9709             * @return the matching message boards threads that the user has permission to view
9710             * @throws SystemException if a system exception occurred
9711             */
9712            public List<MBThread> filterFindByG_C_NotS(long groupId, long categoryId,
9713                    int status) throws SystemException {
9714                    return filterFindByG_C_NotS(groupId, categoryId, status,
9715                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9716            }
9717    
9718            /**
9719             * 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;.
9720             *
9721             * <p>
9722             * 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.
9723             * </p>
9724             *
9725             * @param groupId the group ID
9726             * @param categoryId the category ID
9727             * @param status the status
9728             * @param start the lower bound of the range of message boards threads
9729             * @param end the upper bound of the range of message boards threads (not inclusive)
9730             * @return the range of matching message boards threads that the user has permission to view
9731             * @throws SystemException if a system exception occurred
9732             */
9733            public List<MBThread> filterFindByG_C_NotS(long groupId, long categoryId,
9734                    int status, int start, int end) throws SystemException {
9735                    return filterFindByG_C_NotS(groupId, categoryId, status, start, end,
9736                            null);
9737            }
9738    
9739            /**
9740             * 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;.
9741             *
9742             * <p>
9743             * 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.
9744             * </p>
9745             *
9746             * @param groupId the group ID
9747             * @param categoryId the category ID
9748             * @param status the status
9749             * @param start the lower bound of the range of message boards threads
9750             * @param end the upper bound of the range of message boards threads (not inclusive)
9751             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9752             * @return the ordered range of matching message boards threads that the user has permission to view
9753             * @throws SystemException if a system exception occurred
9754             */
9755            public List<MBThread> filterFindByG_C_NotS(long groupId, long categoryId,
9756                    int status, int start, int end, OrderByComparator orderByComparator)
9757                    throws SystemException {
9758                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9759                            return findByG_C_NotS(groupId, categoryId, status, start, end,
9760                                    orderByComparator);
9761                    }
9762    
9763                    StringBundler query = null;
9764    
9765                    if (orderByComparator != null) {
9766                            query = new StringBundler(5 +
9767                                            (orderByComparator.getOrderByFields().length * 3));
9768                    }
9769                    else {
9770                            query = new StringBundler(5);
9771                    }
9772    
9773                    if (getDB().isSupportsInlineDistinct()) {
9774                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
9775                    }
9776                    else {
9777                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
9778                    }
9779    
9780                    query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9781    
9782                    query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9783    
9784                    query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9785    
9786                    if (!getDB().isSupportsInlineDistinct()) {
9787                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
9788                    }
9789    
9790                    if (orderByComparator != null) {
9791                            if (getDB().isSupportsInlineDistinct()) {
9792                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9793                                            orderByComparator, true);
9794                            }
9795                            else {
9796                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
9797                                            orderByComparator, true);
9798                            }
9799                    }
9800                    else {
9801                            if (getDB().isSupportsInlineDistinct()) {
9802                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9803                            }
9804                            else {
9805                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
9806                            }
9807                    }
9808    
9809                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9810                                    MBThread.class.getName(),
9811                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9812    
9813                    Session session = null;
9814    
9815                    try {
9816                            session = openSession();
9817    
9818                            SQLQuery q = session.createSQLQuery(sql);
9819    
9820                            if (getDB().isSupportsInlineDistinct()) {
9821                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
9822                            }
9823                            else {
9824                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
9825                            }
9826    
9827                            QueryPos qPos = QueryPos.getInstance(q);
9828    
9829                            qPos.add(groupId);
9830    
9831                            qPos.add(categoryId);
9832    
9833                            qPos.add(status);
9834    
9835                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
9836                    }
9837                    catch (Exception e) {
9838                            throw processException(e);
9839                    }
9840                    finally {
9841                            closeSession(session);
9842                    }
9843            }
9844    
9845            /**
9846             * 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;.
9847             *
9848             * @param threadId the primary key of the current message boards thread
9849             * @param groupId the group ID
9850             * @param categoryId the category ID
9851             * @param status the status
9852             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9853             * @return the previous, current, and next message boards thread
9854             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
9855             * @throws SystemException if a system exception occurred
9856             */
9857            public MBThread[] filterFindByG_C_NotS_PrevAndNext(long threadId,
9858                    long groupId, long categoryId, int status,
9859                    OrderByComparator orderByComparator)
9860                    throws NoSuchThreadException, SystemException {
9861                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9862                            return findByG_C_NotS_PrevAndNext(threadId, groupId, categoryId,
9863                                    status, orderByComparator);
9864                    }
9865    
9866                    MBThread mbThread = findByPrimaryKey(threadId);
9867    
9868                    Session session = null;
9869    
9870                    try {
9871                            session = openSession();
9872    
9873                            MBThread[] array = new MBThreadImpl[3];
9874    
9875                            array[0] = filterGetByG_C_NotS_PrevAndNext(session, mbThread,
9876                                            groupId, categoryId, status, orderByComparator, true);
9877    
9878                            array[1] = mbThread;
9879    
9880                            array[2] = filterGetByG_C_NotS_PrevAndNext(session, mbThread,
9881                                            groupId, categoryId, status, orderByComparator, false);
9882    
9883                            return array;
9884                    }
9885                    catch (Exception e) {
9886                            throw processException(e);
9887                    }
9888                    finally {
9889                            closeSession(session);
9890                    }
9891            }
9892    
9893            protected MBThread filterGetByG_C_NotS_PrevAndNext(Session session,
9894                    MBThread mbThread, long groupId, long categoryId, int status,
9895                    OrderByComparator orderByComparator, boolean previous) {
9896                    StringBundler query = null;
9897    
9898                    if (orderByComparator != null) {
9899                            query = new StringBundler(6 +
9900                                            (orderByComparator.getOrderByFields().length * 6));
9901                    }
9902                    else {
9903                            query = new StringBundler(3);
9904                    }
9905    
9906                    if (getDB().isSupportsInlineDistinct()) {
9907                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
9908                    }
9909                    else {
9910                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
9911                    }
9912    
9913                    query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9914    
9915                    query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9916    
9917                    query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9918    
9919                    if (!getDB().isSupportsInlineDistinct()) {
9920                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
9921                    }
9922    
9923                    if (orderByComparator != null) {
9924                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9925    
9926                            if (orderByConditionFields.length > 0) {
9927                                    query.append(WHERE_AND);
9928                            }
9929    
9930                            for (int i = 0; i < orderByConditionFields.length; i++) {
9931                                    if (getDB().isSupportsInlineDistinct()) {
9932                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9933                                    }
9934                                    else {
9935                                            query.append(_ORDER_BY_ENTITY_TABLE);
9936                                    }
9937    
9938                                    query.append(orderByConditionFields[i]);
9939    
9940                                    if ((i + 1) < orderByConditionFields.length) {
9941                                            if (orderByComparator.isAscending() ^ previous) {
9942                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9943                                            }
9944                                            else {
9945                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9946                                            }
9947                                    }
9948                                    else {
9949                                            if (orderByComparator.isAscending() ^ previous) {
9950                                                    query.append(WHERE_GREATER_THAN);
9951                                            }
9952                                            else {
9953                                                    query.append(WHERE_LESSER_THAN);
9954                                            }
9955                                    }
9956                            }
9957    
9958                            query.append(ORDER_BY_CLAUSE);
9959    
9960                            String[] orderByFields = orderByComparator.getOrderByFields();
9961    
9962                            for (int i = 0; i < orderByFields.length; i++) {
9963                                    if (getDB().isSupportsInlineDistinct()) {
9964                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9965                                    }
9966                                    else {
9967                                            query.append(_ORDER_BY_ENTITY_TABLE);
9968                                    }
9969    
9970                                    query.append(orderByFields[i]);
9971    
9972                                    if ((i + 1) < orderByFields.length) {
9973                                            if (orderByComparator.isAscending() ^ previous) {
9974                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9975                                            }
9976                                            else {
9977                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9978                                            }
9979                                    }
9980                                    else {
9981                                            if (orderByComparator.isAscending() ^ previous) {
9982                                                    query.append(ORDER_BY_ASC);
9983                                            }
9984                                            else {
9985                                                    query.append(ORDER_BY_DESC);
9986                                            }
9987                                    }
9988                            }
9989                    }
9990                    else {
9991                            if (getDB().isSupportsInlineDistinct()) {
9992                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9993                            }
9994                            else {
9995                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
9996                            }
9997                    }
9998    
9999                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10000                                    MBThread.class.getName(),
10001                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10002    
10003                    SQLQuery q = session.createSQLQuery(sql);
10004    
10005                    q.setFirstResult(0);
10006                    q.setMaxResults(2);
10007    
10008                    if (getDB().isSupportsInlineDistinct()) {
10009                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
10010                    }
10011                    else {
10012                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
10013                    }
10014    
10015                    QueryPos qPos = QueryPos.getInstance(q);
10016    
10017                    qPos.add(groupId);
10018    
10019                    qPos.add(categoryId);
10020    
10021                    qPos.add(status);
10022    
10023                    if (orderByComparator != null) {
10024                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
10025    
10026                            for (Object value : values) {
10027                                    qPos.add(value);
10028                            }
10029                    }
10030    
10031                    List<MBThread> list = q.list();
10032    
10033                    if (list.size() == 2) {
10034                            return list.get(1);
10035                    }
10036                    else {
10037                            return null;
10038                    }
10039            }
10040    
10041            /**
10042             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63; and status &ne; &#63;.
10043             *
10044             * @param groupId the group ID
10045             * @param categoryIds the category IDs
10046             * @param status the status
10047             * @return the matching message boards threads that the user has permission to view
10048             * @throws SystemException if a system exception occurred
10049             */
10050            public List<MBThread> filterFindByG_C_NotS(long groupId,
10051                    long[] categoryIds, int status) throws SystemException {
10052                    return filterFindByG_C_NotS(groupId, categoryIds, status,
10053                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10054            }
10055    
10056            /**
10057             * 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;.
10058             *
10059             * <p>
10060             * 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.
10061             * </p>
10062             *
10063             * @param groupId the group ID
10064             * @param categoryIds the category IDs
10065             * @param status the status
10066             * @param start the lower bound of the range of message boards threads
10067             * @param end the upper bound of the range of message boards threads (not inclusive)
10068             * @return the range of matching message boards threads that the user has permission to view
10069             * @throws SystemException if a system exception occurred
10070             */
10071            public List<MBThread> filterFindByG_C_NotS(long groupId,
10072                    long[] categoryIds, int status, int start, int end)
10073                    throws SystemException {
10074                    return filterFindByG_C_NotS(groupId, categoryIds, status, start, end,
10075                            null);
10076            }
10077    
10078            /**
10079             * 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;.
10080             *
10081             * <p>
10082             * 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.
10083             * </p>
10084             *
10085             * @param groupId the group ID
10086             * @param categoryIds the category IDs
10087             * @param status the status
10088             * @param start the lower bound of the range of message boards threads
10089             * @param end the upper bound of the range of message boards threads (not inclusive)
10090             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10091             * @return the ordered range of matching message boards threads that the user has permission to view
10092             * @throws SystemException if a system exception occurred
10093             */
10094            public List<MBThread> filterFindByG_C_NotS(long groupId,
10095                    long[] categoryIds, int status, int start, int end,
10096                    OrderByComparator orderByComparator) throws SystemException {
10097                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10098                            return findByG_C_NotS(groupId, categoryIds, status, start, end,
10099                                    orderByComparator);
10100                    }
10101    
10102                    StringBundler query = new StringBundler();
10103    
10104                    if (getDB().isSupportsInlineDistinct()) {
10105                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
10106                    }
10107                    else {
10108                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
10109                    }
10110    
10111                    boolean conjunctionable = false;
10112    
10113                    if (conjunctionable) {
10114                            query.append(WHERE_AND);
10115                    }
10116    
10117                    query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_5);
10118    
10119                    conjunctionable = true;
10120    
10121                    if ((categoryIds == null) || (categoryIds.length > 0)) {
10122                            if (conjunctionable) {
10123                                    query.append(WHERE_AND);
10124                            }
10125    
10126                            query.append(StringPool.OPEN_PARENTHESIS);
10127    
10128                            for (int i = 0; i < categoryIds.length; i++) {
10129                                    query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_5);
10130    
10131                                    if ((i + 1) < categoryIds.length) {
10132                                            query.append(WHERE_OR);
10133                                    }
10134                            }
10135    
10136                            query.append(StringPool.CLOSE_PARENTHESIS);
10137    
10138                            conjunctionable = true;
10139                    }
10140    
10141                    if (conjunctionable) {
10142                            query.append(WHERE_AND);
10143                    }
10144    
10145                    query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_5);
10146    
10147                    conjunctionable = true;
10148    
10149                    if (!getDB().isSupportsInlineDistinct()) {
10150                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
10151                    }
10152    
10153                    if (orderByComparator != null) {
10154                            if (getDB().isSupportsInlineDistinct()) {
10155                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10156                                            orderByComparator, true);
10157                            }
10158                            else {
10159                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10160                                            orderByComparator, true);
10161                            }
10162                    }
10163                    else {
10164                            if (getDB().isSupportsInlineDistinct()) {
10165                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10166                            }
10167                            else {
10168                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
10169                            }
10170                    }
10171    
10172                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10173                                    MBThread.class.getName(),
10174                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10175    
10176                    Session session = null;
10177    
10178                    try {
10179                            session = openSession();
10180    
10181                            SQLQuery q = session.createSQLQuery(sql);
10182    
10183                            if (getDB().isSupportsInlineDistinct()) {
10184                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
10185                            }
10186                            else {
10187                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
10188                            }
10189    
10190                            QueryPos qPos = QueryPos.getInstance(q);
10191    
10192                            qPos.add(groupId);
10193    
10194                            if (categoryIds != null) {
10195                                    qPos.add(categoryIds);
10196                            }
10197    
10198                            qPos.add(status);
10199    
10200                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
10201                    }
10202                    catch (Exception e) {
10203                            throw processException(e);
10204                    }
10205                    finally {
10206                            closeSession(session);
10207                    }
10208            }
10209    
10210            /**
10211             * Returns all the message boards threads where groupId = &#63; and categoryId = any &#63; and status &ne; &#63;.
10212             *
10213             * <p>
10214             * 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.
10215             * </p>
10216             *
10217             * @param groupId the group ID
10218             * @param categoryIds the category IDs
10219             * @param status the status
10220             * @return the matching message boards threads
10221             * @throws SystemException if a system exception occurred
10222             */
10223            public List<MBThread> findByG_C_NotS(long groupId, long[] categoryIds,
10224                    int status) throws SystemException {
10225                    return findByG_C_NotS(groupId, categoryIds, status, QueryUtil.ALL_POS,
10226                            QueryUtil.ALL_POS, null);
10227            }
10228    
10229            /**
10230             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = any &#63; and status &ne; &#63;.
10231             *
10232             * <p>
10233             * 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.
10234             * </p>
10235             *
10236             * @param groupId the group ID
10237             * @param categoryIds the category IDs
10238             * @param status the status
10239             * @param start the lower bound of the range of message boards threads
10240             * @param end the upper bound of the range of message boards threads (not inclusive)
10241             * @return the range of matching message boards threads
10242             * @throws SystemException if a system exception occurred
10243             */
10244            public List<MBThread> findByG_C_NotS(long groupId, long[] categoryIds,
10245                    int status, int start, int end) throws SystemException {
10246                    return findByG_C_NotS(groupId, categoryIds, status, start, end, null);
10247            }
10248    
10249            /**
10250             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = any &#63; and status &ne; &#63;.
10251             *
10252             * <p>
10253             * 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.
10254             * </p>
10255             *
10256             * @param groupId the group ID
10257             * @param categoryIds the category IDs
10258             * @param status the status
10259             * @param start the lower bound of the range of message boards threads
10260             * @param end the upper bound of the range of message boards threads (not inclusive)
10261             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10262             * @return the ordered range of matching message boards threads
10263             * @throws SystemException if a system exception occurred
10264             */
10265            public List<MBThread> findByG_C_NotS(long groupId, long[] categoryIds,
10266                    int status, int start, int end, OrderByComparator orderByComparator)
10267                    throws SystemException {
10268                    if ((categoryIds != null) && (categoryIds.length == 1)) {
10269                            return findByG_C_NotS(groupId, categoryIds[0], status, start, end,
10270                                    orderByComparator);
10271                    }
10272    
10273                    boolean pagination = true;
10274                    Object[] finderArgs = null;
10275    
10276                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10277                                    (orderByComparator == null)) {
10278                            pagination = false;
10279                            finderArgs = new Object[] {
10280                                            groupId, StringUtil.merge(categoryIds), status
10281                                    };
10282                    }
10283                    else {
10284                            finderArgs = new Object[] {
10285                                            groupId, StringUtil.merge(categoryIds), status,
10286                                            
10287                                            start, end, orderByComparator
10288                                    };
10289                    }
10290    
10291                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS,
10292                                    finderArgs, this);
10293    
10294                    if ((list != null) && !list.isEmpty()) {
10295                            for (MBThread mbThread : list) {
10296                                    if ((groupId != mbThread.getGroupId()) ||
10297                                                    !ArrayUtil.contains(categoryIds,
10298                                                            mbThread.getCategoryId()) ||
10299                                                    (status != mbThread.getStatus())) {
10300                                            list = null;
10301    
10302                                            break;
10303                                    }
10304                            }
10305                    }
10306    
10307                    if (list == null) {
10308                            StringBundler query = new StringBundler();
10309    
10310                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
10311    
10312                            boolean conjunctionable = false;
10313    
10314                            if (conjunctionable) {
10315                                    query.append(WHERE_AND);
10316                            }
10317    
10318                            query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_5);
10319    
10320                            conjunctionable = true;
10321    
10322                            if ((categoryIds == null) || (categoryIds.length > 0)) {
10323                                    if (conjunctionable) {
10324                                            query.append(WHERE_AND);
10325                                    }
10326    
10327                                    query.append(StringPool.OPEN_PARENTHESIS);
10328    
10329                                    for (int i = 0; i < categoryIds.length; i++) {
10330                                            query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_5);
10331    
10332                                            if ((i + 1) < categoryIds.length) {
10333                                                    query.append(WHERE_OR);
10334                                            }
10335                                    }
10336    
10337                                    query.append(StringPool.CLOSE_PARENTHESIS);
10338    
10339                                    conjunctionable = true;
10340                            }
10341    
10342                            if (conjunctionable) {
10343                                    query.append(WHERE_AND);
10344                            }
10345    
10346                            query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_5);
10347    
10348                            conjunctionable = true;
10349    
10350                            if (orderByComparator != null) {
10351                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10352                                            orderByComparator);
10353                            }
10354                            else
10355                             if (pagination) {
10356                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10357                            }
10358    
10359                            String sql = query.toString();
10360    
10361                            Session session = null;
10362    
10363                            try {
10364                                    session = openSession();
10365    
10366                                    Query q = session.createQuery(sql);
10367    
10368                                    QueryPos qPos = QueryPos.getInstance(q);
10369    
10370                                    qPos.add(groupId);
10371    
10372                                    if (categoryIds != null) {
10373                                            qPos.add(categoryIds);
10374                                    }
10375    
10376                                    qPos.add(status);
10377    
10378                                    if (!pagination) {
10379                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
10380                                                            start, end, false);
10381    
10382                                            Collections.sort(list);
10383    
10384                                            list = new UnmodifiableList<MBThread>(list);
10385                                    }
10386                                    else {
10387                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
10388                                                            start, end);
10389                                    }
10390    
10391                                    cacheResult(list);
10392    
10393                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS,
10394                                            finderArgs, list);
10395                            }
10396                            catch (Exception e) {
10397                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS,
10398                                            finderArgs);
10399    
10400                                    throw processException(e);
10401                            }
10402                            finally {
10403                                    closeSession(session);
10404                            }
10405                    }
10406    
10407                    return list;
10408            }
10409    
10410            /**
10411             * Removes all the message boards threads where groupId = &#63; and categoryId = &#63; and status &ne; &#63; from the database.
10412             *
10413             * @param groupId the group ID
10414             * @param categoryId the category ID
10415             * @param status the status
10416             * @throws SystemException if a system exception occurred
10417             */
10418            public void removeByG_C_NotS(long groupId, long categoryId, int status)
10419                    throws SystemException {
10420                    for (MBThread mbThread : findByG_C_NotS(groupId, categoryId, status,
10421                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10422                            remove(mbThread);
10423                    }
10424            }
10425    
10426            /**
10427             * Returns the number of message boards threads where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
10428             *
10429             * @param groupId the group ID
10430             * @param categoryId the category ID
10431             * @param status the status
10432             * @return the number of matching message boards threads
10433             * @throws SystemException if a system exception occurred
10434             */
10435            public int countByG_C_NotS(long groupId, long categoryId, int status)
10436                    throws SystemException {
10437                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS;
10438    
10439                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
10440    
10441                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10442                                    this);
10443    
10444                    if (count == null) {
10445                            StringBundler query = new StringBundler(4);
10446    
10447                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
10448    
10449                            query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10450    
10451                            query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
10452    
10453                            query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10454    
10455                            String sql = query.toString();
10456    
10457                            Session session = null;
10458    
10459                            try {
10460                                    session = openSession();
10461    
10462                                    Query q = session.createQuery(sql);
10463    
10464                                    QueryPos qPos = QueryPos.getInstance(q);
10465    
10466                                    qPos.add(groupId);
10467    
10468                                    qPos.add(categoryId);
10469    
10470                                    qPos.add(status);
10471    
10472                                    count = (Long)q.uniqueResult();
10473    
10474                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10475                            }
10476                            catch (Exception e) {
10477                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10478    
10479                                    throw processException(e);
10480                            }
10481                            finally {
10482                                    closeSession(session);
10483                            }
10484                    }
10485    
10486                    return count.intValue();
10487            }
10488    
10489            /**
10490             * Returns the number of message boards threads where groupId = &#63; and categoryId = any &#63; and status &ne; &#63;.
10491             *
10492             * @param groupId the group ID
10493             * @param categoryIds the category IDs
10494             * @param status the status
10495             * @return the number of matching message boards threads
10496             * @throws SystemException if a system exception occurred
10497             */
10498            public int countByG_C_NotS(long groupId, long[] categoryIds, int status)
10499                    throws SystemException {
10500                    Object[] finderArgs = new Object[] {
10501                                    groupId, StringUtil.merge(categoryIds), status
10502                            };
10503    
10504                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS,
10505                                    finderArgs, this);
10506    
10507                    if (count == null) {
10508                            StringBundler query = new StringBundler();
10509    
10510                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
10511    
10512                            boolean conjunctionable = false;
10513    
10514                            if (conjunctionable) {
10515                                    query.append(WHERE_AND);
10516                            }
10517    
10518                            query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_5);
10519    
10520                            conjunctionable = true;
10521    
10522                            if ((categoryIds == null) || (categoryIds.length > 0)) {
10523                                    if (conjunctionable) {
10524                                            query.append(WHERE_AND);
10525                                    }
10526    
10527                                    query.append(StringPool.OPEN_PARENTHESIS);
10528    
10529                                    for (int i = 0; i < categoryIds.length; i++) {
10530                                            query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_5);
10531    
10532                                            if ((i + 1) < categoryIds.length) {
10533                                                    query.append(WHERE_OR);
10534                                            }
10535                                    }
10536    
10537                                    query.append(StringPool.CLOSE_PARENTHESIS);
10538    
10539                                    conjunctionable = true;
10540                            }
10541    
10542                            if (conjunctionable) {
10543                                    query.append(WHERE_AND);
10544                            }
10545    
10546                            query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_5);
10547    
10548                            conjunctionable = true;
10549    
10550                            String sql = query.toString();
10551    
10552                            Session session = null;
10553    
10554                            try {
10555                                    session = openSession();
10556    
10557                                    Query q = session.createQuery(sql);
10558    
10559                                    QueryPos qPos = QueryPos.getInstance(q);
10560    
10561                                    qPos.add(groupId);
10562    
10563                                    if (categoryIds != null) {
10564                                            qPos.add(categoryIds);
10565                                    }
10566    
10567                                    qPos.add(status);
10568    
10569                                    count = (Long)q.uniqueResult();
10570    
10571                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS,
10572                                            finderArgs, count);
10573                            }
10574                            catch (Exception e) {
10575                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS,
10576                                            finderArgs);
10577    
10578                                    throw processException(e);
10579                            }
10580                            finally {
10581                                    closeSession(session);
10582                            }
10583                    }
10584    
10585                    return count.intValue();
10586            }
10587    
10588            /**
10589             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and status &ne; &#63;.
10590             *
10591             * @param groupId the group ID
10592             * @param categoryId the category ID
10593             * @param status the status
10594             * @return the number of matching message boards threads that the user has permission to view
10595             * @throws SystemException if a system exception occurred
10596             */
10597            public int filterCountByG_C_NotS(long groupId, long categoryId, int status)
10598                    throws SystemException {
10599                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10600                            return countByG_C_NotS(groupId, categoryId, status);
10601                    }
10602    
10603                    StringBundler query = new StringBundler(4);
10604    
10605                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
10606    
10607                    query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10608    
10609                    query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
10610    
10611                    query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10612    
10613                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10614                                    MBThread.class.getName(),
10615                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10616    
10617                    Session session = null;
10618    
10619                    try {
10620                            session = openSession();
10621    
10622                            SQLQuery q = session.createSQLQuery(sql);
10623    
10624                            q.addScalar(COUNT_COLUMN_NAME,
10625                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
10626    
10627                            QueryPos qPos = QueryPos.getInstance(q);
10628    
10629                            qPos.add(groupId);
10630    
10631                            qPos.add(categoryId);
10632    
10633                            qPos.add(status);
10634    
10635                            Long count = (Long)q.uniqueResult();
10636    
10637                            return count.intValue();
10638                    }
10639                    catch (Exception e) {
10640                            throw processException(e);
10641                    }
10642                    finally {
10643                            closeSession(session);
10644                    }
10645            }
10646    
10647            /**
10648             * 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;.
10649             *
10650             * @param groupId the group ID
10651             * @param categoryIds the category IDs
10652             * @param status the status
10653             * @return the number of matching message boards threads that the user has permission to view
10654             * @throws SystemException if a system exception occurred
10655             */
10656            public int filterCountByG_C_NotS(long groupId, long[] categoryIds,
10657                    int status) throws SystemException {
10658                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10659                            return countByG_C_NotS(groupId, categoryIds, status);
10660                    }
10661    
10662                    StringBundler query = new StringBundler();
10663    
10664                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
10665    
10666                    boolean conjunctionable = false;
10667    
10668                    if (conjunctionable) {
10669                            query.append(WHERE_AND);
10670                    }
10671    
10672                    query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_5);
10673    
10674                    conjunctionable = true;
10675    
10676                    if ((categoryIds == null) || (categoryIds.length > 0)) {
10677                            if (conjunctionable) {
10678                                    query.append(WHERE_AND);
10679                            }
10680    
10681                            query.append(StringPool.OPEN_PARENTHESIS);
10682    
10683                            for (int i = 0; i < categoryIds.length; i++) {
10684                                    query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_5);
10685    
10686                                    if ((i + 1) < categoryIds.length) {
10687                                            query.append(WHERE_OR);
10688                                    }
10689                            }
10690    
10691                            query.append(StringPool.CLOSE_PARENTHESIS);
10692    
10693                            conjunctionable = true;
10694                    }
10695    
10696                    if (conjunctionable) {
10697                            query.append(WHERE_AND);
10698                    }
10699    
10700                    query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_5);
10701    
10702                    conjunctionable = true;
10703    
10704                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10705                                    MBThread.class.getName(),
10706                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10707    
10708                    Session session = null;
10709    
10710                    try {
10711                            session = openSession();
10712    
10713                            SQLQuery q = session.createSQLQuery(sql);
10714    
10715                            q.addScalar(COUNT_COLUMN_NAME,
10716                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
10717    
10718                            QueryPos qPos = QueryPos.getInstance(q);
10719    
10720                            qPos.add(groupId);
10721    
10722                            if (categoryIds != null) {
10723                                    qPos.add(categoryIds);
10724                            }
10725    
10726                            qPos.add(status);
10727    
10728                            Long count = (Long)q.uniqueResult();
10729    
10730                            return count.intValue();
10731                    }
10732                    catch (Exception e) {
10733                            throw processException(e);
10734                    }
10735                    finally {
10736                            closeSession(session);
10737                    }
10738            }
10739    
10740            private static final String _FINDER_COLUMN_G_C_NOTS_GROUPID_2 = "mbThread.groupId = ? AND ";
10741            private static final String _FINDER_COLUMN_G_C_NOTS_GROUPID_5 = "(" +
10742                    removeConjunction(_FINDER_COLUMN_G_C_NOTS_GROUPID_2) + ")";
10743            private static final String _FINDER_COLUMN_G_C_NOTS_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
10744            private static final String _FINDER_COLUMN_G_C_NOTS_CATEGORYID_5 = "(" +
10745                    removeConjunction(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2) + ")";
10746            private static final String _FINDER_COLUMN_G_C_NOTS_STATUS_2 = "mbThread.status != ?";
10747            private static final String _FINDER_COLUMN_G_C_NOTS_STATUS_5 = "(" +
10748                    removeConjunction(_FINDER_COLUMN_G_C_NOTS_STATUS_2) + ")";
10749            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
10750                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
10751                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC_S",
10752                            new String[] {
10753                                    Long.class.getName(), Long.class.getName(),
10754                                    Integer.class.getName(),
10755                                    
10756                            Integer.class.getName(), Integer.class.getName(),
10757                                    OrderByComparator.class.getName()
10758                            });
10759            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_S =
10760                    new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
10761                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
10762                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC_S",
10763                            new String[] {
10764                                    Long.class.getName(), Long.class.getName(),
10765                                    Integer.class.getName()
10766                            });
10767    
10768            /**
10769             * Returns all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
10770             *
10771             * @param groupId the group ID
10772             * @param categoryId the category ID
10773             * @param status the status
10774             * @return the matching message boards threads
10775             * @throws SystemException if a system exception occurred
10776             */
10777            public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
10778                    int status) throws SystemException {
10779                    return findByG_NotC_S(groupId, categoryId, status, QueryUtil.ALL_POS,
10780                            QueryUtil.ALL_POS, null);
10781            }
10782    
10783            /**
10784             * Returns a range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
10785             *
10786             * <p>
10787             * 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.
10788             * </p>
10789             *
10790             * @param groupId the group ID
10791             * @param categoryId the category ID
10792             * @param status the status
10793             * @param start the lower bound of the range of message boards threads
10794             * @param end the upper bound of the range of message boards threads (not inclusive)
10795             * @return the range of matching message boards threads
10796             * @throws SystemException if a system exception occurred
10797             */
10798            public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
10799                    int status, int start, int end) throws SystemException {
10800                    return findByG_NotC_S(groupId, categoryId, status, start, end, null);
10801            }
10802    
10803            /**
10804             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
10805             *
10806             * <p>
10807             * 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.
10808             * </p>
10809             *
10810             * @param groupId the group ID
10811             * @param categoryId the category ID
10812             * @param status the status
10813             * @param start the lower bound of the range of message boards threads
10814             * @param end the upper bound of the range of message boards threads (not inclusive)
10815             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10816             * @return the ordered range of matching message boards threads
10817             * @throws SystemException if a system exception occurred
10818             */
10819            public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
10820                    int status, int start, int end, OrderByComparator orderByComparator)
10821                    throws SystemException {
10822                    boolean pagination = true;
10823                    FinderPath finderPath = null;
10824                    Object[] finderArgs = null;
10825    
10826                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_S;
10827                    finderArgs = new Object[] {
10828                                    groupId, categoryId, status,
10829                                    
10830                                    start, end, orderByComparator
10831                            };
10832    
10833                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
10834                                    finderArgs, this);
10835    
10836                    if ((list != null) && !list.isEmpty()) {
10837                            for (MBThread mbThread : list) {
10838                                    if ((groupId != mbThread.getGroupId()) ||
10839                                                    (categoryId != mbThread.getCategoryId()) ||
10840                                                    (status != mbThread.getStatus())) {
10841                                            list = null;
10842    
10843                                            break;
10844                                    }
10845                            }
10846                    }
10847    
10848                    if (list == null) {
10849                            StringBundler query = null;
10850    
10851                            if (orderByComparator != null) {
10852                                    query = new StringBundler(5 +
10853                                                    (orderByComparator.getOrderByFields().length * 3));
10854                            }
10855                            else {
10856                                    query = new StringBundler(5);
10857                            }
10858    
10859                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
10860    
10861                            query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
10862    
10863                            query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
10864    
10865                            query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
10866    
10867                            if (orderByComparator != null) {
10868                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10869                                            orderByComparator);
10870                            }
10871                            else
10872                             if (pagination) {
10873                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10874                            }
10875    
10876                            String sql = query.toString();
10877    
10878                            Session session = null;
10879    
10880                            try {
10881                                    session = openSession();
10882    
10883                                    Query q = session.createQuery(sql);
10884    
10885                                    QueryPos qPos = QueryPos.getInstance(q);
10886    
10887                                    qPos.add(groupId);
10888    
10889                                    qPos.add(categoryId);
10890    
10891                                    qPos.add(status);
10892    
10893                                    if (!pagination) {
10894                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
10895                                                            start, end, false);
10896    
10897                                            Collections.sort(list);
10898    
10899                                            list = new UnmodifiableList<MBThread>(list);
10900                                    }
10901                                    else {
10902                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
10903                                                            start, end);
10904                                    }
10905    
10906                                    cacheResult(list);
10907    
10908                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10909                            }
10910                            catch (Exception e) {
10911                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10912    
10913                                    throw processException(e);
10914                            }
10915                            finally {
10916                                    closeSession(session);
10917                            }
10918                    }
10919    
10920                    return list;
10921            }
10922    
10923            /**
10924             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
10925             *
10926             * @param groupId the group ID
10927             * @param categoryId the category ID
10928             * @param status the status
10929             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10930             * @return the first matching message boards thread
10931             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
10932             * @throws SystemException if a system exception occurred
10933             */
10934            public MBThread findByG_NotC_S_First(long groupId, long categoryId,
10935                    int status, OrderByComparator orderByComparator)
10936                    throws NoSuchThreadException, SystemException {
10937                    MBThread mbThread = fetchByG_NotC_S_First(groupId, categoryId, status,
10938                                    orderByComparator);
10939    
10940                    if (mbThread != null) {
10941                            return mbThread;
10942                    }
10943    
10944                    StringBundler msg = new StringBundler(8);
10945    
10946                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10947    
10948                    msg.append("groupId=");
10949                    msg.append(groupId);
10950    
10951                    msg.append(", categoryId=");
10952                    msg.append(categoryId);
10953    
10954                    msg.append(", status=");
10955                    msg.append(status);
10956    
10957                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10958    
10959                    throw new NoSuchThreadException(msg.toString());
10960            }
10961    
10962            /**
10963             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
10964             *
10965             * @param groupId the group ID
10966             * @param categoryId the category ID
10967             * @param status the status
10968             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10969             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
10970             * @throws SystemException if a system exception occurred
10971             */
10972            public MBThread fetchByG_NotC_S_First(long groupId, long categoryId,
10973                    int status, OrderByComparator orderByComparator)
10974                    throws SystemException {
10975                    List<MBThread> list = findByG_NotC_S(groupId, categoryId, status, 0, 1,
10976                                    orderByComparator);
10977    
10978                    if (!list.isEmpty()) {
10979                            return list.get(0);
10980                    }
10981    
10982                    return null;
10983            }
10984    
10985            /**
10986             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
10987             *
10988             * @param groupId the group ID
10989             * @param categoryId the category ID
10990             * @param status the status
10991             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10992             * @return the last matching message boards thread
10993             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
10994             * @throws SystemException if a system exception occurred
10995             */
10996            public MBThread findByG_NotC_S_Last(long groupId, long categoryId,
10997                    int status, OrderByComparator orderByComparator)
10998                    throws NoSuchThreadException, SystemException {
10999                    MBThread mbThread = fetchByG_NotC_S_Last(groupId, categoryId, status,
11000                                    orderByComparator);
11001    
11002                    if (mbThread != null) {
11003                            return mbThread;
11004                    }
11005    
11006                    StringBundler msg = new StringBundler(8);
11007    
11008                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11009    
11010                    msg.append("groupId=");
11011                    msg.append(groupId);
11012    
11013                    msg.append(", categoryId=");
11014                    msg.append(categoryId);
11015    
11016                    msg.append(", status=");
11017                    msg.append(status);
11018    
11019                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11020    
11021                    throw new NoSuchThreadException(msg.toString());
11022            }
11023    
11024            /**
11025             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
11026             *
11027             * @param groupId the group ID
11028             * @param categoryId the category ID
11029             * @param status the status
11030             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11031             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
11032             * @throws SystemException if a system exception occurred
11033             */
11034            public MBThread fetchByG_NotC_S_Last(long groupId, long categoryId,
11035                    int status, OrderByComparator orderByComparator)
11036                    throws SystemException {
11037                    int count = countByG_NotC_S(groupId, categoryId, status);
11038    
11039                    List<MBThread> list = findByG_NotC_S(groupId, categoryId, status,
11040                                    count - 1, count, orderByComparator);
11041    
11042                    if (!list.isEmpty()) {
11043                            return list.get(0);
11044                    }
11045    
11046                    return null;
11047            }
11048    
11049            /**
11050             * 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;.
11051             *
11052             * @param threadId the primary key of the current message boards thread
11053             * @param groupId the group ID
11054             * @param categoryId the category ID
11055             * @param status the status
11056             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11057             * @return the previous, current, and next message boards thread
11058             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
11059             * @throws SystemException if a system exception occurred
11060             */
11061            public MBThread[] findByG_NotC_S_PrevAndNext(long threadId, long groupId,
11062                    long categoryId, int status, OrderByComparator orderByComparator)
11063                    throws NoSuchThreadException, SystemException {
11064                    MBThread mbThread = findByPrimaryKey(threadId);
11065    
11066                    Session session = null;
11067    
11068                    try {
11069                            session = openSession();
11070    
11071                            MBThread[] array = new MBThreadImpl[3];
11072    
11073                            array[0] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
11074                                            categoryId, status, orderByComparator, true);
11075    
11076                            array[1] = mbThread;
11077    
11078                            array[2] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
11079                                            categoryId, status, orderByComparator, false);
11080    
11081                            return array;
11082                    }
11083                    catch (Exception e) {
11084                            throw processException(e);
11085                    }
11086                    finally {
11087                            closeSession(session);
11088                    }
11089            }
11090    
11091            protected MBThread getByG_NotC_S_PrevAndNext(Session session,
11092                    MBThread mbThread, long groupId, long categoryId, int status,
11093                    OrderByComparator orderByComparator, boolean previous) {
11094                    StringBundler query = null;
11095    
11096                    if (orderByComparator != null) {
11097                            query = new StringBundler(6 +
11098                                            (orderByComparator.getOrderByFields().length * 6));
11099                    }
11100                    else {
11101                            query = new StringBundler(3);
11102                    }
11103    
11104                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
11105    
11106                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11107    
11108                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11109    
11110                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11111    
11112                    if (orderByComparator != null) {
11113                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11114    
11115                            if (orderByConditionFields.length > 0) {
11116                                    query.append(WHERE_AND);
11117                            }
11118    
11119                            for (int i = 0; i < orderByConditionFields.length; i++) {
11120                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11121                                    query.append(orderByConditionFields[i]);
11122    
11123                                    if ((i + 1) < orderByConditionFields.length) {
11124                                            if (orderByComparator.isAscending() ^ previous) {
11125                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11126                                            }
11127                                            else {
11128                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11129                                            }
11130                                    }
11131                                    else {
11132                                            if (orderByComparator.isAscending() ^ previous) {
11133                                                    query.append(WHERE_GREATER_THAN);
11134                                            }
11135                                            else {
11136                                                    query.append(WHERE_LESSER_THAN);
11137                                            }
11138                                    }
11139                            }
11140    
11141                            query.append(ORDER_BY_CLAUSE);
11142    
11143                            String[] orderByFields = orderByComparator.getOrderByFields();
11144    
11145                            for (int i = 0; i < orderByFields.length; i++) {
11146                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11147                                    query.append(orderByFields[i]);
11148    
11149                                    if ((i + 1) < orderByFields.length) {
11150                                            if (orderByComparator.isAscending() ^ previous) {
11151                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11152                                            }
11153                                            else {
11154                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11155                                            }
11156                                    }
11157                                    else {
11158                                            if (orderByComparator.isAscending() ^ previous) {
11159                                                    query.append(ORDER_BY_ASC);
11160                                            }
11161                                            else {
11162                                                    query.append(ORDER_BY_DESC);
11163                                            }
11164                                    }
11165                            }
11166                    }
11167                    else {
11168                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11169                    }
11170    
11171                    String sql = query.toString();
11172    
11173                    Query q = session.createQuery(sql);
11174    
11175                    q.setFirstResult(0);
11176                    q.setMaxResults(2);
11177    
11178                    QueryPos qPos = QueryPos.getInstance(q);
11179    
11180                    qPos.add(groupId);
11181    
11182                    qPos.add(categoryId);
11183    
11184                    qPos.add(status);
11185    
11186                    if (orderByComparator != null) {
11187                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
11188    
11189                            for (Object value : values) {
11190                                    qPos.add(value);
11191                            }
11192                    }
11193    
11194                    List<MBThread> list = q.list();
11195    
11196                    if (list.size() == 2) {
11197                            return list.get(1);
11198                    }
11199                    else {
11200                            return null;
11201                    }
11202            }
11203    
11204            /**
11205             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
11206             *
11207             * @param groupId the group ID
11208             * @param categoryId the category ID
11209             * @param status the status
11210             * @return the matching message boards threads that the user has permission to view
11211             * @throws SystemException if a system exception occurred
11212             */
11213            public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
11214                    int status) throws SystemException {
11215                    return filterFindByG_NotC_S(groupId, categoryId, status,
11216                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11217            }
11218    
11219            /**
11220             * 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;.
11221             *
11222             * <p>
11223             * 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.
11224             * </p>
11225             *
11226             * @param groupId the group ID
11227             * @param categoryId the category ID
11228             * @param status the status
11229             * @param start the lower bound of the range of message boards threads
11230             * @param end the upper bound of the range of message boards threads (not inclusive)
11231             * @return the range of matching message boards threads that the user has permission to view
11232             * @throws SystemException if a system exception occurred
11233             */
11234            public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
11235                    int status, int start, int end) throws SystemException {
11236                    return filterFindByG_NotC_S(groupId, categoryId, status, start, end,
11237                            null);
11238            }
11239    
11240            /**
11241             * 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;.
11242             *
11243             * <p>
11244             * 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.
11245             * </p>
11246             *
11247             * @param groupId the group ID
11248             * @param categoryId the category ID
11249             * @param status the status
11250             * @param start the lower bound of the range of message boards threads
11251             * @param end the upper bound of the range of message boards threads (not inclusive)
11252             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11253             * @return the ordered range of matching message boards threads that the user has permission to view
11254             * @throws SystemException if a system exception occurred
11255             */
11256            public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
11257                    int status, int start, int end, OrderByComparator orderByComparator)
11258                    throws SystemException {
11259                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11260                            return findByG_NotC_S(groupId, categoryId, status, start, end,
11261                                    orderByComparator);
11262                    }
11263    
11264                    StringBundler query = null;
11265    
11266                    if (orderByComparator != null) {
11267                            query = new StringBundler(5 +
11268                                            (orderByComparator.getOrderByFields().length * 3));
11269                    }
11270                    else {
11271                            query = new StringBundler(5);
11272                    }
11273    
11274                    if (getDB().isSupportsInlineDistinct()) {
11275                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
11276                    }
11277                    else {
11278                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
11279                    }
11280    
11281                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11282    
11283                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11284    
11285                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11286    
11287                    if (!getDB().isSupportsInlineDistinct()) {
11288                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
11289                    }
11290    
11291                    if (orderByComparator != null) {
11292                            if (getDB().isSupportsInlineDistinct()) {
11293                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11294                                            orderByComparator, true);
11295                            }
11296                            else {
11297                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11298                                            orderByComparator, true);
11299                            }
11300                    }
11301                    else {
11302                            if (getDB().isSupportsInlineDistinct()) {
11303                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11304                            }
11305                            else {
11306                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
11307                            }
11308                    }
11309    
11310                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11311                                    MBThread.class.getName(),
11312                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11313    
11314                    Session session = null;
11315    
11316                    try {
11317                            session = openSession();
11318    
11319                            SQLQuery q = session.createSQLQuery(sql);
11320    
11321                            if (getDB().isSupportsInlineDistinct()) {
11322                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
11323                            }
11324                            else {
11325                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
11326                            }
11327    
11328                            QueryPos qPos = QueryPos.getInstance(q);
11329    
11330                            qPos.add(groupId);
11331    
11332                            qPos.add(categoryId);
11333    
11334                            qPos.add(status);
11335    
11336                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
11337                    }
11338                    catch (Exception e) {
11339                            throw processException(e);
11340                    }
11341                    finally {
11342                            closeSession(session);
11343                    }
11344            }
11345    
11346            /**
11347             * 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;.
11348             *
11349             * @param threadId the primary key of the current message boards thread
11350             * @param groupId the group ID
11351             * @param categoryId the category ID
11352             * @param status the status
11353             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11354             * @return the previous, current, and next message boards thread
11355             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
11356             * @throws SystemException if a system exception occurred
11357             */
11358            public MBThread[] filterFindByG_NotC_S_PrevAndNext(long threadId,
11359                    long groupId, long categoryId, int status,
11360                    OrderByComparator orderByComparator)
11361                    throws NoSuchThreadException, SystemException {
11362                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11363                            return findByG_NotC_S_PrevAndNext(threadId, groupId, categoryId,
11364                                    status, orderByComparator);
11365                    }
11366    
11367                    MBThread mbThread = findByPrimaryKey(threadId);
11368    
11369                    Session session = null;
11370    
11371                    try {
11372                            session = openSession();
11373    
11374                            MBThread[] array = new MBThreadImpl[3];
11375    
11376                            array[0] = filterGetByG_NotC_S_PrevAndNext(session, mbThread,
11377                                            groupId, categoryId, status, orderByComparator, true);
11378    
11379                            array[1] = mbThread;
11380    
11381                            array[2] = filterGetByG_NotC_S_PrevAndNext(session, mbThread,
11382                                            groupId, categoryId, status, orderByComparator, false);
11383    
11384                            return array;
11385                    }
11386                    catch (Exception e) {
11387                            throw processException(e);
11388                    }
11389                    finally {
11390                            closeSession(session);
11391                    }
11392            }
11393    
11394            protected MBThread filterGetByG_NotC_S_PrevAndNext(Session session,
11395                    MBThread mbThread, long groupId, long categoryId, int status,
11396                    OrderByComparator orderByComparator, boolean previous) {
11397                    StringBundler query = null;
11398    
11399                    if (orderByComparator != null) {
11400                            query = new StringBundler(6 +
11401                                            (orderByComparator.getOrderByFields().length * 6));
11402                    }
11403                    else {
11404                            query = new StringBundler(3);
11405                    }
11406    
11407                    if (getDB().isSupportsInlineDistinct()) {
11408                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
11409                    }
11410                    else {
11411                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
11412                    }
11413    
11414                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11415    
11416                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11417    
11418                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11419    
11420                    if (!getDB().isSupportsInlineDistinct()) {
11421                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
11422                    }
11423    
11424                    if (orderByComparator != null) {
11425                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11426    
11427                            if (orderByConditionFields.length > 0) {
11428                                    query.append(WHERE_AND);
11429                            }
11430    
11431                            for (int i = 0; i < orderByConditionFields.length; i++) {
11432                                    if (getDB().isSupportsInlineDistinct()) {
11433                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11434                                    }
11435                                    else {
11436                                            query.append(_ORDER_BY_ENTITY_TABLE);
11437                                    }
11438    
11439                                    query.append(orderByConditionFields[i]);
11440    
11441                                    if ((i + 1) < orderByConditionFields.length) {
11442                                            if (orderByComparator.isAscending() ^ previous) {
11443                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11444                                            }
11445                                            else {
11446                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11447                                            }
11448                                    }
11449                                    else {
11450                                            if (orderByComparator.isAscending() ^ previous) {
11451                                                    query.append(WHERE_GREATER_THAN);
11452                                            }
11453                                            else {
11454                                                    query.append(WHERE_LESSER_THAN);
11455                                            }
11456                                    }
11457                            }
11458    
11459                            query.append(ORDER_BY_CLAUSE);
11460    
11461                            String[] orderByFields = orderByComparator.getOrderByFields();
11462    
11463                            for (int i = 0; i < orderByFields.length; i++) {
11464                                    if (getDB().isSupportsInlineDistinct()) {
11465                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11466                                    }
11467                                    else {
11468                                            query.append(_ORDER_BY_ENTITY_TABLE);
11469                                    }
11470    
11471                                    query.append(orderByFields[i]);
11472    
11473                                    if ((i + 1) < orderByFields.length) {
11474                                            if (orderByComparator.isAscending() ^ previous) {
11475                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11476                                            }
11477                                            else {
11478                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11479                                            }
11480                                    }
11481                                    else {
11482                                            if (orderByComparator.isAscending() ^ previous) {
11483                                                    query.append(ORDER_BY_ASC);
11484                                            }
11485                                            else {
11486                                                    query.append(ORDER_BY_DESC);
11487                                            }
11488                                    }
11489                            }
11490                    }
11491                    else {
11492                            if (getDB().isSupportsInlineDistinct()) {
11493                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11494                            }
11495                            else {
11496                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
11497                            }
11498                    }
11499    
11500                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11501                                    MBThread.class.getName(),
11502                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11503    
11504                    SQLQuery q = session.createSQLQuery(sql);
11505    
11506                    q.setFirstResult(0);
11507                    q.setMaxResults(2);
11508    
11509                    if (getDB().isSupportsInlineDistinct()) {
11510                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
11511                    }
11512                    else {
11513                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
11514                    }
11515    
11516                    QueryPos qPos = QueryPos.getInstance(q);
11517    
11518                    qPos.add(groupId);
11519    
11520                    qPos.add(categoryId);
11521    
11522                    qPos.add(status);
11523    
11524                    if (orderByComparator != null) {
11525                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
11526    
11527                            for (Object value : values) {
11528                                    qPos.add(value);
11529                            }
11530                    }
11531    
11532                    List<MBThread> list = q.list();
11533    
11534                    if (list.size() == 2) {
11535                            return list.get(1);
11536                    }
11537                    else {
11538                            return null;
11539                    }
11540            }
11541    
11542            /**
11543             * Removes all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63; from the database.
11544             *
11545             * @param groupId the group ID
11546             * @param categoryId the category ID
11547             * @param status the status
11548             * @throws SystemException if a system exception occurred
11549             */
11550            public void removeByG_NotC_S(long groupId, long categoryId, int status)
11551                    throws SystemException {
11552                    for (MBThread mbThread : findByG_NotC_S(groupId, categoryId, status,
11553                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11554                            remove(mbThread);
11555                    }
11556            }
11557    
11558            /**
11559             * Returns the number of message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
11560             *
11561             * @param groupId the group ID
11562             * @param categoryId the category ID
11563             * @param status the status
11564             * @return the number of matching message boards threads
11565             * @throws SystemException if a system exception occurred
11566             */
11567            public int countByG_NotC_S(long groupId, long categoryId, int status)
11568                    throws SystemException {
11569                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_S;
11570    
11571                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
11572    
11573                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11574                                    this);
11575    
11576                    if (count == null) {
11577                            StringBundler query = new StringBundler(4);
11578    
11579                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
11580    
11581                            query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11582    
11583                            query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11584    
11585                            query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11586    
11587                            String sql = query.toString();
11588    
11589                            Session session = null;
11590    
11591                            try {
11592                                    session = openSession();
11593    
11594                                    Query q = session.createQuery(sql);
11595    
11596                                    QueryPos qPos = QueryPos.getInstance(q);
11597    
11598                                    qPos.add(groupId);
11599    
11600                                    qPos.add(categoryId);
11601    
11602                                    qPos.add(status);
11603    
11604                                    count = (Long)q.uniqueResult();
11605    
11606                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
11607                            }
11608                            catch (Exception e) {
11609                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11610    
11611                                    throw processException(e);
11612                            }
11613                            finally {
11614                                    closeSession(session);
11615                            }
11616                    }
11617    
11618                    return count.intValue();
11619            }
11620    
11621            /**
11622             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
11623             *
11624             * @param groupId the group ID
11625             * @param categoryId the category ID
11626             * @param status the status
11627             * @return the number of matching message boards threads that the user has permission to view
11628             * @throws SystemException if a system exception occurred
11629             */
11630            public int filterCountByG_NotC_S(long groupId, long categoryId, int status)
11631                    throws SystemException {
11632                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11633                            return countByG_NotC_S(groupId, categoryId, status);
11634                    }
11635    
11636                    StringBundler query = new StringBundler(4);
11637    
11638                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
11639    
11640                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11641    
11642                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11643    
11644                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11645    
11646                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11647                                    MBThread.class.getName(),
11648                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11649    
11650                    Session session = null;
11651    
11652                    try {
11653                            session = openSession();
11654    
11655                            SQLQuery q = session.createSQLQuery(sql);
11656    
11657                            q.addScalar(COUNT_COLUMN_NAME,
11658                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
11659    
11660                            QueryPos qPos = QueryPos.getInstance(q);
11661    
11662                            qPos.add(groupId);
11663    
11664                            qPos.add(categoryId);
11665    
11666                            qPos.add(status);
11667    
11668                            Long count = (Long)q.uniqueResult();
11669    
11670                            return count.intValue();
11671                    }
11672                    catch (Exception e) {
11673                            throw processException(e);
11674                    }
11675                    finally {
11676                            closeSession(session);
11677                    }
11678            }
11679    
11680            private static final String _FINDER_COLUMN_G_NOTC_S_GROUPID_2 = "mbThread.groupId = ? AND ";
11681            private static final String _FINDER_COLUMN_G_NOTC_S_CATEGORYID_2 = "mbThread.categoryId != ? AND ";
11682            private static final String _FINDER_COLUMN_G_NOTC_S_STATUS_2 = "mbThread.status = ?";
11683            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_NOTS =
11684                    new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
11685                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
11686                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC_NotS",
11687                            new String[] {
11688                                    Long.class.getName(), Long.class.getName(),
11689                                    Integer.class.getName(),
11690                                    
11691                            Integer.class.getName(), Integer.class.getName(),
11692                                    OrderByComparator.class.getName()
11693                            });
11694            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_NOTS =
11695                    new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
11696                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
11697                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC_NotS",
11698                            new String[] {
11699                                    Long.class.getName(), Long.class.getName(),
11700                                    Integer.class.getName()
11701                            });
11702    
11703            /**
11704             * Returns all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11705             *
11706             * @param groupId the group ID
11707             * @param categoryId the category ID
11708             * @param status the status
11709             * @return the matching message boards threads
11710             * @throws SystemException if a system exception occurred
11711             */
11712            public List<MBThread> findByG_NotC_NotS(long groupId, long categoryId,
11713                    int status) throws SystemException {
11714                    return findByG_NotC_NotS(groupId, categoryId, status,
11715                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11716            }
11717    
11718            /**
11719             * Returns a range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11720             *
11721             * <p>
11722             * 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.
11723             * </p>
11724             *
11725             * @param groupId the group ID
11726             * @param categoryId the category ID
11727             * @param status the status
11728             * @param start the lower bound of the range of message boards threads
11729             * @param end the upper bound of the range of message boards threads (not inclusive)
11730             * @return the range of matching message boards threads
11731             * @throws SystemException if a system exception occurred
11732             */
11733            public List<MBThread> findByG_NotC_NotS(long groupId, long categoryId,
11734                    int status, int start, int end) throws SystemException {
11735                    return findByG_NotC_NotS(groupId, categoryId, status, start, end, null);
11736            }
11737    
11738            /**
11739             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11740             *
11741             * <p>
11742             * 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.
11743             * </p>
11744             *
11745             * @param groupId the group ID
11746             * @param categoryId the category ID
11747             * @param status the status
11748             * @param start the lower bound of the range of message boards threads
11749             * @param end the upper bound of the range of message boards threads (not inclusive)
11750             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11751             * @return the ordered range of matching message boards threads
11752             * @throws SystemException if a system exception occurred
11753             */
11754            public List<MBThread> findByG_NotC_NotS(long groupId, long categoryId,
11755                    int status, int start, int end, OrderByComparator orderByComparator)
11756                    throws SystemException {
11757                    boolean pagination = true;
11758                    FinderPath finderPath = null;
11759                    Object[] finderArgs = null;
11760    
11761                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_NOTS;
11762                    finderArgs = new Object[] {
11763                                    groupId, categoryId, status,
11764                                    
11765                                    start, end, orderByComparator
11766                            };
11767    
11768                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
11769                                    finderArgs, this);
11770    
11771                    if ((list != null) && !list.isEmpty()) {
11772                            for (MBThread mbThread : list) {
11773                                    if ((groupId != mbThread.getGroupId()) ||
11774                                                    (categoryId != mbThread.getCategoryId()) ||
11775                                                    (status != mbThread.getStatus())) {
11776                                            list = null;
11777    
11778                                            break;
11779                                    }
11780                            }
11781                    }
11782    
11783                    if (list == null) {
11784                            StringBundler query = null;
11785    
11786                            if (orderByComparator != null) {
11787                                    query = new StringBundler(5 +
11788                                                    (orderByComparator.getOrderByFields().length * 3));
11789                            }
11790                            else {
11791                                    query = new StringBundler(5);
11792                            }
11793    
11794                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
11795    
11796                            query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
11797    
11798                            query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
11799    
11800                            query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
11801    
11802                            if (orderByComparator != null) {
11803                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11804                                            orderByComparator);
11805                            }
11806                            else
11807                             if (pagination) {
11808                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11809                            }
11810    
11811                            String sql = query.toString();
11812    
11813                            Session session = null;
11814    
11815                            try {
11816                                    session = openSession();
11817    
11818                                    Query q = session.createQuery(sql);
11819    
11820                                    QueryPos qPos = QueryPos.getInstance(q);
11821    
11822                                    qPos.add(groupId);
11823    
11824                                    qPos.add(categoryId);
11825    
11826                                    qPos.add(status);
11827    
11828                                    if (!pagination) {
11829                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
11830                                                            start, end, false);
11831    
11832                                            Collections.sort(list);
11833    
11834                                            list = new UnmodifiableList<MBThread>(list);
11835                                    }
11836                                    else {
11837                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
11838                                                            start, end);
11839                                    }
11840    
11841                                    cacheResult(list);
11842    
11843                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11844                            }
11845                            catch (Exception e) {
11846                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11847    
11848                                    throw processException(e);
11849                            }
11850                            finally {
11851                                    closeSession(session);
11852                            }
11853                    }
11854    
11855                    return list;
11856            }
11857    
11858            /**
11859             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11860             *
11861             * @param groupId the group ID
11862             * @param categoryId the category ID
11863             * @param status the status
11864             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11865             * @return the first matching message boards thread
11866             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
11867             * @throws SystemException if a system exception occurred
11868             */
11869            public MBThread findByG_NotC_NotS_First(long groupId, long categoryId,
11870                    int status, OrderByComparator orderByComparator)
11871                    throws NoSuchThreadException, SystemException {
11872                    MBThread mbThread = fetchByG_NotC_NotS_First(groupId, categoryId,
11873                                    status, orderByComparator);
11874    
11875                    if (mbThread != null) {
11876                            return mbThread;
11877                    }
11878    
11879                    StringBundler msg = new StringBundler(8);
11880    
11881                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11882    
11883                    msg.append("groupId=");
11884                    msg.append(groupId);
11885    
11886                    msg.append(", categoryId=");
11887                    msg.append(categoryId);
11888    
11889                    msg.append(", status=");
11890                    msg.append(status);
11891    
11892                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11893    
11894                    throw new NoSuchThreadException(msg.toString());
11895            }
11896    
11897            /**
11898             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11899             *
11900             * @param groupId the group ID
11901             * @param categoryId the category ID
11902             * @param status the status
11903             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11904             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
11905             * @throws SystemException if a system exception occurred
11906             */
11907            public MBThread fetchByG_NotC_NotS_First(long groupId, long categoryId,
11908                    int status, OrderByComparator orderByComparator)
11909                    throws SystemException {
11910                    List<MBThread> list = findByG_NotC_NotS(groupId, categoryId, status, 0,
11911                                    1, orderByComparator);
11912    
11913                    if (!list.isEmpty()) {
11914                            return list.get(0);
11915                    }
11916    
11917                    return null;
11918            }
11919    
11920            /**
11921             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11922             *
11923             * @param groupId the group ID
11924             * @param categoryId the category ID
11925             * @param status the status
11926             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11927             * @return the last matching message boards thread
11928             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
11929             * @throws SystemException if a system exception occurred
11930             */
11931            public MBThread findByG_NotC_NotS_Last(long groupId, long categoryId,
11932                    int status, OrderByComparator orderByComparator)
11933                    throws NoSuchThreadException, SystemException {
11934                    MBThread mbThread = fetchByG_NotC_NotS_Last(groupId, categoryId,
11935                                    status, orderByComparator);
11936    
11937                    if (mbThread != null) {
11938                            return mbThread;
11939                    }
11940    
11941                    StringBundler msg = new StringBundler(8);
11942    
11943                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11944    
11945                    msg.append("groupId=");
11946                    msg.append(groupId);
11947    
11948                    msg.append(", categoryId=");
11949                    msg.append(categoryId);
11950    
11951                    msg.append(", status=");
11952                    msg.append(status);
11953    
11954                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11955    
11956                    throw new NoSuchThreadException(msg.toString());
11957            }
11958    
11959            /**
11960             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
11961             *
11962             * @param groupId the group ID
11963             * @param categoryId the category ID
11964             * @param status the status
11965             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11966             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
11967             * @throws SystemException if a system exception occurred
11968             */
11969            public MBThread fetchByG_NotC_NotS_Last(long groupId, long categoryId,
11970                    int status, OrderByComparator orderByComparator)
11971                    throws SystemException {
11972                    int count = countByG_NotC_NotS(groupId, categoryId, status);
11973    
11974                    List<MBThread> list = findByG_NotC_NotS(groupId, categoryId, status,
11975                                    count - 1, count, orderByComparator);
11976    
11977                    if (!list.isEmpty()) {
11978                            return list.get(0);
11979                    }
11980    
11981                    return null;
11982            }
11983    
11984            /**
11985             * 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;.
11986             *
11987             * @param threadId the primary key of the current message boards thread
11988             * @param groupId the group ID
11989             * @param categoryId the category ID
11990             * @param status the status
11991             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11992             * @return the previous, current, and next message boards thread
11993             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
11994             * @throws SystemException if a system exception occurred
11995             */
11996            public MBThread[] findByG_NotC_NotS_PrevAndNext(long threadId,
11997                    long groupId, long categoryId, int status,
11998                    OrderByComparator orderByComparator)
11999                    throws NoSuchThreadException, SystemException {
12000                    MBThread mbThread = findByPrimaryKey(threadId);
12001    
12002                    Session session = null;
12003    
12004                    try {
12005                            session = openSession();
12006    
12007                            MBThread[] array = new MBThreadImpl[3];
12008    
12009                            array[0] = getByG_NotC_NotS_PrevAndNext(session, mbThread, groupId,
12010                                            categoryId, status, orderByComparator, true);
12011    
12012                            array[1] = mbThread;
12013    
12014                            array[2] = getByG_NotC_NotS_PrevAndNext(session, mbThread, groupId,
12015                                            categoryId, status, orderByComparator, false);
12016    
12017                            return array;
12018                    }
12019                    catch (Exception e) {
12020                            throw processException(e);
12021                    }
12022                    finally {
12023                            closeSession(session);
12024                    }
12025            }
12026    
12027            protected MBThread getByG_NotC_NotS_PrevAndNext(Session session,
12028                    MBThread mbThread, long groupId, long categoryId, int status,
12029                    OrderByComparator orderByComparator, boolean previous) {
12030                    StringBundler query = null;
12031    
12032                    if (orderByComparator != null) {
12033                            query = new StringBundler(6 +
12034                                            (orderByComparator.getOrderByFields().length * 6));
12035                    }
12036                    else {
12037                            query = new StringBundler(3);
12038                    }
12039    
12040                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
12041    
12042                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12043    
12044                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12045    
12046                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12047    
12048                    if (orderByComparator != null) {
12049                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12050    
12051                            if (orderByConditionFields.length > 0) {
12052                                    query.append(WHERE_AND);
12053                            }
12054    
12055                            for (int i = 0; i < orderByConditionFields.length; i++) {
12056                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12057                                    query.append(orderByConditionFields[i]);
12058    
12059                                    if ((i + 1) < orderByConditionFields.length) {
12060                                            if (orderByComparator.isAscending() ^ previous) {
12061                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12062                                            }
12063                                            else {
12064                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12065                                            }
12066                                    }
12067                                    else {
12068                                            if (orderByComparator.isAscending() ^ previous) {
12069                                                    query.append(WHERE_GREATER_THAN);
12070                                            }
12071                                            else {
12072                                                    query.append(WHERE_LESSER_THAN);
12073                                            }
12074                                    }
12075                            }
12076    
12077                            query.append(ORDER_BY_CLAUSE);
12078    
12079                            String[] orderByFields = orderByComparator.getOrderByFields();
12080    
12081                            for (int i = 0; i < orderByFields.length; i++) {
12082                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12083                                    query.append(orderByFields[i]);
12084    
12085                                    if ((i + 1) < orderByFields.length) {
12086                                            if (orderByComparator.isAscending() ^ previous) {
12087                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12088                                            }
12089                                            else {
12090                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12091                                            }
12092                                    }
12093                                    else {
12094                                            if (orderByComparator.isAscending() ^ previous) {
12095                                                    query.append(ORDER_BY_ASC);
12096                                            }
12097                                            else {
12098                                                    query.append(ORDER_BY_DESC);
12099                                            }
12100                                    }
12101                            }
12102                    }
12103                    else {
12104                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
12105                    }
12106    
12107                    String sql = query.toString();
12108    
12109                    Query q = session.createQuery(sql);
12110    
12111                    q.setFirstResult(0);
12112                    q.setMaxResults(2);
12113    
12114                    QueryPos qPos = QueryPos.getInstance(q);
12115    
12116                    qPos.add(groupId);
12117    
12118                    qPos.add(categoryId);
12119    
12120                    qPos.add(status);
12121    
12122                    if (orderByComparator != null) {
12123                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
12124    
12125                            for (Object value : values) {
12126                                    qPos.add(value);
12127                            }
12128                    }
12129    
12130                    List<MBThread> list = q.list();
12131    
12132                    if (list.size() == 2) {
12133                            return list.get(1);
12134                    }
12135                    else {
12136                            return null;
12137                    }
12138            }
12139    
12140            /**
12141             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
12142             *
12143             * @param groupId the group ID
12144             * @param categoryId the category ID
12145             * @param status the status
12146             * @return the matching message boards threads that the user has permission to view
12147             * @throws SystemException if a system exception occurred
12148             */
12149            public List<MBThread> filterFindByG_NotC_NotS(long groupId,
12150                    long categoryId, int status) throws SystemException {
12151                    return filterFindByG_NotC_NotS(groupId, categoryId, status,
12152                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12153            }
12154    
12155            /**
12156             * 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;.
12157             *
12158             * <p>
12159             * 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.
12160             * </p>
12161             *
12162             * @param groupId the group ID
12163             * @param categoryId the category ID
12164             * @param status the status
12165             * @param start the lower bound of the range of message boards threads
12166             * @param end the upper bound of the range of message boards threads (not inclusive)
12167             * @return the range of matching message boards threads that the user has permission to view
12168             * @throws SystemException if a system exception occurred
12169             */
12170            public List<MBThread> filterFindByG_NotC_NotS(long groupId,
12171                    long categoryId, int status, int start, int end)
12172                    throws SystemException {
12173                    return filterFindByG_NotC_NotS(groupId, categoryId, status, start, end,
12174                            null);
12175            }
12176    
12177            /**
12178             * 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;.
12179             *
12180             * <p>
12181             * 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.
12182             * </p>
12183             *
12184             * @param groupId the group ID
12185             * @param categoryId the category ID
12186             * @param status the status
12187             * @param start the lower bound of the range of message boards threads
12188             * @param end the upper bound of the range of message boards threads (not inclusive)
12189             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12190             * @return the ordered range of matching message boards threads that the user has permission to view
12191             * @throws SystemException if a system exception occurred
12192             */
12193            public List<MBThread> filterFindByG_NotC_NotS(long groupId,
12194                    long categoryId, int status, int start, int end,
12195                    OrderByComparator orderByComparator) throws SystemException {
12196                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12197                            return findByG_NotC_NotS(groupId, categoryId, status, start, end,
12198                                    orderByComparator);
12199                    }
12200    
12201                    StringBundler query = null;
12202    
12203                    if (orderByComparator != null) {
12204                            query = new StringBundler(5 +
12205                                            (orderByComparator.getOrderByFields().length * 3));
12206                    }
12207                    else {
12208                            query = new StringBundler(5);
12209                    }
12210    
12211                    if (getDB().isSupportsInlineDistinct()) {
12212                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
12213                    }
12214                    else {
12215                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
12216                    }
12217    
12218                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12219    
12220                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12221    
12222                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12223    
12224                    if (!getDB().isSupportsInlineDistinct()) {
12225                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
12226                    }
12227    
12228                    if (orderByComparator != null) {
12229                            if (getDB().isSupportsInlineDistinct()) {
12230                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12231                                            orderByComparator, true);
12232                            }
12233                            else {
12234                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12235                                            orderByComparator, true);
12236                            }
12237                    }
12238                    else {
12239                            if (getDB().isSupportsInlineDistinct()) {
12240                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
12241                            }
12242                            else {
12243                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
12244                            }
12245                    }
12246    
12247                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12248                                    MBThread.class.getName(),
12249                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12250    
12251                    Session session = null;
12252    
12253                    try {
12254                            session = openSession();
12255    
12256                            SQLQuery q = session.createSQLQuery(sql);
12257    
12258                            if (getDB().isSupportsInlineDistinct()) {
12259                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
12260                            }
12261                            else {
12262                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
12263                            }
12264    
12265                            QueryPos qPos = QueryPos.getInstance(q);
12266    
12267                            qPos.add(groupId);
12268    
12269                            qPos.add(categoryId);
12270    
12271                            qPos.add(status);
12272    
12273                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
12274                    }
12275                    catch (Exception e) {
12276                            throw processException(e);
12277                    }
12278                    finally {
12279                            closeSession(session);
12280                    }
12281            }
12282    
12283            /**
12284             * 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;.
12285             *
12286             * @param threadId the primary key of the current message boards thread
12287             * @param groupId the group ID
12288             * @param categoryId the category ID
12289             * @param status the status
12290             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12291             * @return the previous, current, and next message boards thread
12292             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
12293             * @throws SystemException if a system exception occurred
12294             */
12295            public MBThread[] filterFindByG_NotC_NotS_PrevAndNext(long threadId,
12296                    long groupId, long categoryId, int status,
12297                    OrderByComparator orderByComparator)
12298                    throws NoSuchThreadException, SystemException {
12299                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12300                            return findByG_NotC_NotS_PrevAndNext(threadId, groupId, categoryId,
12301                                    status, orderByComparator);
12302                    }
12303    
12304                    MBThread mbThread = findByPrimaryKey(threadId);
12305    
12306                    Session session = null;
12307    
12308                    try {
12309                            session = openSession();
12310    
12311                            MBThread[] array = new MBThreadImpl[3];
12312    
12313                            array[0] = filterGetByG_NotC_NotS_PrevAndNext(session, mbThread,
12314                                            groupId, categoryId, status, orderByComparator, true);
12315    
12316                            array[1] = mbThread;
12317    
12318                            array[2] = filterGetByG_NotC_NotS_PrevAndNext(session, mbThread,
12319                                            groupId, categoryId, status, orderByComparator, false);
12320    
12321                            return array;
12322                    }
12323                    catch (Exception e) {
12324                            throw processException(e);
12325                    }
12326                    finally {
12327                            closeSession(session);
12328                    }
12329            }
12330    
12331            protected MBThread filterGetByG_NotC_NotS_PrevAndNext(Session session,
12332                    MBThread mbThread, long groupId, long categoryId, int status,
12333                    OrderByComparator orderByComparator, boolean previous) {
12334                    StringBundler query = null;
12335    
12336                    if (orderByComparator != null) {
12337                            query = new StringBundler(6 +
12338                                            (orderByComparator.getOrderByFields().length * 6));
12339                    }
12340                    else {
12341                            query = new StringBundler(3);
12342                    }
12343    
12344                    if (getDB().isSupportsInlineDistinct()) {
12345                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
12346                    }
12347                    else {
12348                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
12349                    }
12350    
12351                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12352    
12353                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12354    
12355                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12356    
12357                    if (!getDB().isSupportsInlineDistinct()) {
12358                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
12359                    }
12360    
12361                    if (orderByComparator != null) {
12362                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12363    
12364                            if (orderByConditionFields.length > 0) {
12365                                    query.append(WHERE_AND);
12366                            }
12367    
12368                            for (int i = 0; i < orderByConditionFields.length; i++) {
12369                                    if (getDB().isSupportsInlineDistinct()) {
12370                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12371                                    }
12372                                    else {
12373                                            query.append(_ORDER_BY_ENTITY_TABLE);
12374                                    }
12375    
12376                                    query.append(orderByConditionFields[i]);
12377    
12378                                    if ((i + 1) < orderByConditionFields.length) {
12379                                            if (orderByComparator.isAscending() ^ previous) {
12380                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12381                                            }
12382                                            else {
12383                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12384                                            }
12385                                    }
12386                                    else {
12387                                            if (orderByComparator.isAscending() ^ previous) {
12388                                                    query.append(WHERE_GREATER_THAN);
12389                                            }
12390                                            else {
12391                                                    query.append(WHERE_LESSER_THAN);
12392                                            }
12393                                    }
12394                            }
12395    
12396                            query.append(ORDER_BY_CLAUSE);
12397    
12398                            String[] orderByFields = orderByComparator.getOrderByFields();
12399    
12400                            for (int i = 0; i < orderByFields.length; i++) {
12401                                    if (getDB().isSupportsInlineDistinct()) {
12402                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12403                                    }
12404                                    else {
12405                                            query.append(_ORDER_BY_ENTITY_TABLE);
12406                                    }
12407    
12408                                    query.append(orderByFields[i]);
12409    
12410                                    if ((i + 1) < orderByFields.length) {
12411                                            if (orderByComparator.isAscending() ^ previous) {
12412                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12413                                            }
12414                                            else {
12415                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12416                                            }
12417                                    }
12418                                    else {
12419                                            if (orderByComparator.isAscending() ^ previous) {
12420                                                    query.append(ORDER_BY_ASC);
12421                                            }
12422                                            else {
12423                                                    query.append(ORDER_BY_DESC);
12424                                            }
12425                                    }
12426                            }
12427                    }
12428                    else {
12429                            if (getDB().isSupportsInlineDistinct()) {
12430                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
12431                            }
12432                            else {
12433                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
12434                            }
12435                    }
12436    
12437                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12438                                    MBThread.class.getName(),
12439                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12440    
12441                    SQLQuery q = session.createSQLQuery(sql);
12442    
12443                    q.setFirstResult(0);
12444                    q.setMaxResults(2);
12445    
12446                    if (getDB().isSupportsInlineDistinct()) {
12447                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
12448                    }
12449                    else {
12450                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
12451                    }
12452    
12453                    QueryPos qPos = QueryPos.getInstance(q);
12454    
12455                    qPos.add(groupId);
12456    
12457                    qPos.add(categoryId);
12458    
12459                    qPos.add(status);
12460    
12461                    if (orderByComparator != null) {
12462                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
12463    
12464                            for (Object value : values) {
12465                                    qPos.add(value);
12466                            }
12467                    }
12468    
12469                    List<MBThread> list = q.list();
12470    
12471                    if (list.size() == 2) {
12472                            return list.get(1);
12473                    }
12474                    else {
12475                            return null;
12476                    }
12477            }
12478    
12479            /**
12480             * Removes all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63; from the database.
12481             *
12482             * @param groupId the group ID
12483             * @param categoryId the category ID
12484             * @param status the status
12485             * @throws SystemException if a system exception occurred
12486             */
12487            public void removeByG_NotC_NotS(long groupId, long categoryId, int status)
12488                    throws SystemException {
12489                    for (MBThread mbThread : findByG_NotC_NotS(groupId, categoryId, status,
12490                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12491                            remove(mbThread);
12492                    }
12493            }
12494    
12495            /**
12496             * Returns the number of message boards threads where groupId = &#63; and categoryId &ne; &#63; and status &ne; &#63;.
12497             *
12498             * @param groupId the group ID
12499             * @param categoryId the category ID
12500             * @param status the status
12501             * @return the number of matching message boards threads
12502             * @throws SystemException if a system exception occurred
12503             */
12504            public int countByG_NotC_NotS(long groupId, long categoryId, int status)
12505                    throws SystemException {
12506                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_NOTS;
12507    
12508                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
12509    
12510                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12511                                    this);
12512    
12513                    if (count == null) {
12514                            StringBundler query = new StringBundler(4);
12515    
12516                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
12517    
12518                            query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12519    
12520                            query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12521    
12522                            query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12523    
12524                            String sql = query.toString();
12525    
12526                            Session session = null;
12527    
12528                            try {
12529                                    session = openSession();
12530    
12531                                    Query q = session.createQuery(sql);
12532    
12533                                    QueryPos qPos = QueryPos.getInstance(q);
12534    
12535                                    qPos.add(groupId);
12536    
12537                                    qPos.add(categoryId);
12538    
12539                                    qPos.add(status);
12540    
12541                                    count = (Long)q.uniqueResult();
12542    
12543                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
12544                            }
12545                            catch (Exception e) {
12546                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12547    
12548                                    throw processException(e);
12549                            }
12550                            finally {
12551                                    closeSession(session);
12552                            }
12553                    }
12554    
12555                    return count.intValue();
12556            }
12557    
12558            /**
12559             * 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;.
12560             *
12561             * @param groupId the group ID
12562             * @param categoryId the category ID
12563             * @param status the status
12564             * @return the number of matching message boards threads that the user has permission to view
12565             * @throws SystemException if a system exception occurred
12566             */
12567            public int filterCountByG_NotC_NotS(long groupId, long categoryId,
12568                    int status) throws SystemException {
12569                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12570                            return countByG_NotC_NotS(groupId, categoryId, status);
12571                    }
12572    
12573                    StringBundler query = new StringBundler(4);
12574    
12575                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
12576    
12577                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12578    
12579                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12580    
12581                    query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12582    
12583                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12584                                    MBThread.class.getName(),
12585                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12586    
12587                    Session session = null;
12588    
12589                    try {
12590                            session = openSession();
12591    
12592                            SQLQuery q = session.createSQLQuery(sql);
12593    
12594                            q.addScalar(COUNT_COLUMN_NAME,
12595                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12596    
12597                            QueryPos qPos = QueryPos.getInstance(q);
12598    
12599                            qPos.add(groupId);
12600    
12601                            qPos.add(categoryId);
12602    
12603                            qPos.add(status);
12604    
12605                            Long count = (Long)q.uniqueResult();
12606    
12607                            return count.intValue();
12608                    }
12609                    catch (Exception e) {
12610                            throw processException(e);
12611                    }
12612                    finally {
12613                            closeSession(session);
12614                    }
12615            }
12616    
12617            private static final String _FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2 = "mbThread.groupId = ? AND ";
12618            private static final String _FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2 = "mbThread.categoryId != ? AND ";
12619            private static final String _FINDER_COLUMN_G_NOTC_NOTS_STATUS_2 = "mbThread.status != ?";
12620    
12621            /**
12622             * Caches the message boards thread in the entity cache if it is enabled.
12623             *
12624             * @param mbThread the message boards thread
12625             */
12626            public void cacheResult(MBThread mbThread) {
12627                    EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12628                            MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
12629    
12630                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
12631                            new Object[] { mbThread.getUuid(), mbThread.getGroupId() }, mbThread);
12632    
12633                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
12634                            new Object[] { mbThread.getRootMessageId() }, mbThread);
12635    
12636                    mbThread.resetOriginalValues();
12637            }
12638    
12639            /**
12640             * Caches the message boards threads in the entity cache if it is enabled.
12641             *
12642             * @param mbThreads the message boards threads
12643             */
12644            public void cacheResult(List<MBThread> mbThreads) {
12645                    for (MBThread mbThread : mbThreads) {
12646                            if (EntityCacheUtil.getResult(
12647                                                    MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12648                                                    MBThreadImpl.class, mbThread.getPrimaryKey()) == null) {
12649                                    cacheResult(mbThread);
12650                            }
12651                            else {
12652                                    mbThread.resetOriginalValues();
12653                            }
12654                    }
12655            }
12656    
12657            /**
12658             * Clears the cache for all message boards threads.
12659             *
12660             * <p>
12661             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
12662             * </p>
12663             */
12664            @Override
12665            public void clearCache() {
12666                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
12667                            CacheRegistryUtil.clear(MBThreadImpl.class.getName());
12668                    }
12669    
12670                    EntityCacheUtil.clearCache(MBThreadImpl.class.getName());
12671    
12672                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
12673                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12674                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12675            }
12676    
12677            /**
12678             * Clears the cache for the message boards thread.
12679             *
12680             * <p>
12681             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
12682             * </p>
12683             */
12684            @Override
12685            public void clearCache(MBThread mbThread) {
12686                    EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12687                            MBThreadImpl.class, mbThread.getPrimaryKey());
12688    
12689                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12690                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12691    
12692                    clearUniqueFindersCache(mbThread);
12693            }
12694    
12695            @Override
12696            public void clearCache(List<MBThread> mbThreads) {
12697                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12698                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12699    
12700                    for (MBThread mbThread : mbThreads) {
12701                            EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12702                                    MBThreadImpl.class, mbThread.getPrimaryKey());
12703    
12704                            clearUniqueFindersCache(mbThread);
12705                    }
12706            }
12707    
12708            protected void cacheUniqueFindersCache(MBThread mbThread) {
12709                    if (mbThread.isNew()) {
12710                            Object[] args = new Object[] {
12711                                            mbThread.getUuid(), mbThread.getGroupId()
12712                                    };
12713    
12714                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
12715                                    Long.valueOf(1));
12716                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
12717                                    mbThread);
12718    
12719                            args = new Object[] { mbThread.getRootMessageId() };
12720    
12721                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID, args,
12722                                    Long.valueOf(1));
12723                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID, args,
12724                                    mbThread);
12725                    }
12726                    else {
12727                            MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
12728    
12729                            if ((mbThreadModelImpl.getColumnBitmask() &
12730                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
12731                                    Object[] args = new Object[] {
12732                                                    mbThread.getUuid(), mbThread.getGroupId()
12733                                            };
12734    
12735                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
12736                                            Long.valueOf(1));
12737                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
12738                                            mbThread);
12739                            }
12740    
12741                            if ((mbThreadModelImpl.getColumnBitmask() &
12742                                            FINDER_PATH_FETCH_BY_ROOTMESSAGEID.getColumnBitmask()) != 0) {
12743                                    Object[] args = new Object[] { mbThread.getRootMessageId() };
12744    
12745                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
12746                                            args, Long.valueOf(1));
12747                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
12748                                            args, mbThread);
12749                            }
12750                    }
12751            }
12752    
12753            protected void clearUniqueFindersCache(MBThread mbThread) {
12754                    MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
12755    
12756                    Object[] args = new Object[] { mbThread.getUuid(), mbThread.getGroupId() };
12757    
12758                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
12759                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
12760    
12761                    if ((mbThreadModelImpl.getColumnBitmask() &
12762                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
12763                            args = new Object[] {
12764                                            mbThreadModelImpl.getOriginalUuid(),
12765                                            mbThreadModelImpl.getOriginalGroupId()
12766                                    };
12767    
12768                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
12769                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
12770                    }
12771    
12772                    args = new Object[] { mbThread.getRootMessageId() };
12773    
12774                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID, args);
12775                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID, args);
12776    
12777                    if ((mbThreadModelImpl.getColumnBitmask() &
12778                                    FINDER_PATH_FETCH_BY_ROOTMESSAGEID.getColumnBitmask()) != 0) {
12779                            args = new Object[] { mbThreadModelImpl.getOriginalRootMessageId() };
12780    
12781                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
12782                                    args);
12783                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
12784                                    args);
12785                    }
12786            }
12787    
12788            /**
12789             * Creates a new message boards thread with the primary key. Does not add the message boards thread to the database.
12790             *
12791             * @param threadId the primary key for the new message boards thread
12792             * @return the new message boards thread
12793             */
12794            public MBThread create(long threadId) {
12795                    MBThread mbThread = new MBThreadImpl();
12796    
12797                    mbThread.setNew(true);
12798                    mbThread.setPrimaryKey(threadId);
12799    
12800                    String uuid = PortalUUIDUtil.generate();
12801    
12802                    mbThread.setUuid(uuid);
12803    
12804                    return mbThread;
12805            }
12806    
12807            /**
12808             * Removes the message boards thread with the primary key from the database. Also notifies the appropriate model listeners.
12809             *
12810             * @param threadId the primary key of the message boards thread
12811             * @return the message boards thread that was removed
12812             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
12813             * @throws SystemException if a system exception occurred
12814             */
12815            public MBThread remove(long threadId)
12816                    throws NoSuchThreadException, SystemException {
12817                    return remove((Serializable)threadId);
12818            }
12819    
12820            /**
12821             * Removes the message boards thread with the primary key from the database. Also notifies the appropriate model listeners.
12822             *
12823             * @param primaryKey the primary key of the message boards thread
12824             * @return the message boards thread that was removed
12825             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
12826             * @throws SystemException if a system exception occurred
12827             */
12828            @Override
12829            public MBThread remove(Serializable primaryKey)
12830                    throws NoSuchThreadException, SystemException {
12831                    Session session = null;
12832    
12833                    try {
12834                            session = openSession();
12835    
12836                            MBThread mbThread = (MBThread)session.get(MBThreadImpl.class,
12837                                            primaryKey);
12838    
12839                            if (mbThread == null) {
12840                                    if (_log.isWarnEnabled()) {
12841                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
12842                                    }
12843    
12844                                    throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
12845                                            primaryKey);
12846                            }
12847    
12848                            return remove(mbThread);
12849                    }
12850                    catch (NoSuchThreadException nsee) {
12851                            throw nsee;
12852                    }
12853                    catch (Exception e) {
12854                            throw processException(e);
12855                    }
12856                    finally {
12857                            closeSession(session);
12858                    }
12859            }
12860    
12861            @Override
12862            protected MBThread removeImpl(MBThread mbThread) throws SystemException {
12863                    mbThread = toUnwrappedModel(mbThread);
12864    
12865                    Session session = null;
12866    
12867                    try {
12868                            session = openSession();
12869    
12870                            if (!session.contains(mbThread)) {
12871                                    mbThread = (MBThread)session.get(MBThreadImpl.class,
12872                                                    mbThread.getPrimaryKeyObj());
12873                            }
12874    
12875                            if (mbThread != null) {
12876                                    session.delete(mbThread);
12877                            }
12878                    }
12879                    catch (Exception e) {
12880                            throw processException(e);
12881                    }
12882                    finally {
12883                            closeSession(session);
12884                    }
12885    
12886                    if (mbThread != null) {
12887                            clearCache(mbThread);
12888                    }
12889    
12890                    return mbThread;
12891            }
12892    
12893            @Override
12894            public MBThread updateImpl(
12895                    com.liferay.portlet.messageboards.model.MBThread mbThread)
12896                    throws SystemException {
12897                    mbThread = toUnwrappedModel(mbThread);
12898    
12899                    boolean isNew = mbThread.isNew();
12900    
12901                    MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
12902    
12903                    if (Validator.isNull(mbThread.getUuid())) {
12904                            String uuid = PortalUUIDUtil.generate();
12905    
12906                            mbThread.setUuid(uuid);
12907                    }
12908    
12909                    Session session = null;
12910    
12911                    try {
12912                            session = openSession();
12913    
12914                            if (mbThread.isNew()) {
12915                                    session.save(mbThread);
12916    
12917                                    mbThread.setNew(false);
12918                            }
12919                            else {
12920                                    session.merge(mbThread);
12921                            }
12922                    }
12923                    catch (Exception e) {
12924                            throw processException(e);
12925                    }
12926                    finally {
12927                            closeSession(session);
12928                    }
12929    
12930                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12931    
12932                    if (isNew || !MBThreadModelImpl.COLUMN_BITMASK_ENABLED) {
12933                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12934                    }
12935    
12936                    else {
12937                            if ((mbThreadModelImpl.getColumnBitmask() &
12938                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
12939                                    Object[] args = new Object[] { mbThreadModelImpl.getOriginalUuid() };
12940    
12941                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
12942                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
12943                                            args);
12944    
12945                                    args = new Object[] { mbThreadModelImpl.getUuid() };
12946    
12947                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
12948                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
12949                                            args);
12950                            }
12951    
12952                            if ((mbThreadModelImpl.getColumnBitmask() &
12953                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
12954                                    Object[] args = new Object[] {
12955                                                    mbThreadModelImpl.getOriginalUuid(),
12956                                                    mbThreadModelImpl.getOriginalCompanyId()
12957                                            };
12958    
12959                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
12960                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
12961                                            args);
12962    
12963                                    args = new Object[] {
12964                                                    mbThreadModelImpl.getUuid(),
12965                                                    mbThreadModelImpl.getCompanyId()
12966                                            };
12967    
12968                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
12969                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
12970                                            args);
12971                            }
12972    
12973                            if ((mbThreadModelImpl.getColumnBitmask() &
12974                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
12975                                    Object[] args = new Object[] {
12976                                                    mbThreadModelImpl.getOriginalGroupId()
12977                                            };
12978    
12979                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
12980                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
12981                                            args);
12982    
12983                                    args = new Object[] { mbThreadModelImpl.getGroupId() };
12984    
12985                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
12986                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
12987                                            args);
12988                            }
12989    
12990                            if ((mbThreadModelImpl.getColumnBitmask() &
12991                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
12992                                    Object[] args = new Object[] {
12993                                                    mbThreadModelImpl.getOriginalGroupId(),
12994                                                    mbThreadModelImpl.getOriginalCategoryId()
12995                                            };
12996    
12997                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
12998                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
12999                                            args);
13000    
13001                                    args = new Object[] {
13002                                                    mbThreadModelImpl.getGroupId(),
13003                                                    mbThreadModelImpl.getCategoryId()
13004                                            };
13005    
13006                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
13007                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
13008                                            args);
13009                            }
13010    
13011                            if ((mbThreadModelImpl.getColumnBitmask() &
13012                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
13013                                    Object[] args = new Object[] {
13014                                                    mbThreadModelImpl.getOriginalGroupId(),
13015                                                    mbThreadModelImpl.getOriginalStatus()
13016                                            };
13017    
13018                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
13019                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
13020                                            args);
13021    
13022                                    args = new Object[] {
13023                                                    mbThreadModelImpl.getGroupId(),
13024                                                    mbThreadModelImpl.getStatus()
13025                                            };
13026    
13027                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
13028                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
13029                                            args);
13030                            }
13031    
13032                            if ((mbThreadModelImpl.getColumnBitmask() &
13033                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
13034                                    Object[] args = new Object[] {
13035                                                    mbThreadModelImpl.getOriginalCategoryId(),
13036                                                    mbThreadModelImpl.getOriginalPriority()
13037                                            };
13038    
13039                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
13040                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
13041                                            args);
13042    
13043                                    args = new Object[] {
13044                                                    mbThreadModelImpl.getCategoryId(),
13045                                                    mbThreadModelImpl.getPriority()
13046                                            };
13047    
13048                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
13049                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
13050                                            args);
13051                            }
13052    
13053                            if ((mbThreadModelImpl.getColumnBitmask() &
13054                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P.getColumnBitmask()) != 0) {
13055                                    Object[] args = new Object[] {
13056                                                    mbThreadModelImpl.getOriginalLastPostDate(),
13057                                                    mbThreadModelImpl.getOriginalPriority()
13058                                            };
13059    
13060                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
13061                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
13062                                            args);
13063    
13064                                    args = new Object[] {
13065                                                    mbThreadModelImpl.getLastPostDate(),
13066                                                    mbThreadModelImpl.getPriority()
13067                                            };
13068    
13069                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
13070                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
13071                                            args);
13072                            }
13073    
13074                            if ((mbThreadModelImpl.getColumnBitmask() &
13075                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L.getColumnBitmask()) != 0) {
13076                                    Object[] args = new Object[] {
13077                                                    mbThreadModelImpl.getOriginalGroupId(),
13078                                                    mbThreadModelImpl.getOriginalCategoryId(),
13079                                                    mbThreadModelImpl.getOriginalLastPostDate()
13080                                            };
13081    
13082                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
13083                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
13084                                            args);
13085    
13086                                    args = new Object[] {
13087                                                    mbThreadModelImpl.getGroupId(),
13088                                                    mbThreadModelImpl.getCategoryId(),
13089                                                    mbThreadModelImpl.getLastPostDate()
13090                                            };
13091    
13092                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
13093                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
13094                                            args);
13095                            }
13096    
13097                            if ((mbThreadModelImpl.getColumnBitmask() &
13098                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
13099                                    Object[] args = new Object[] {
13100                                                    mbThreadModelImpl.getOriginalGroupId(),
13101                                                    mbThreadModelImpl.getOriginalCategoryId(),
13102                                                    mbThreadModelImpl.getOriginalStatus()
13103                                            };
13104    
13105                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
13106                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
13107                                            args);
13108    
13109                                    args = new Object[] {
13110                                                    mbThreadModelImpl.getGroupId(),
13111                                                    mbThreadModelImpl.getCategoryId(),
13112                                                    mbThreadModelImpl.getStatus()
13113                                            };
13114    
13115                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
13116                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
13117                                            args);
13118                            }
13119                    }
13120    
13121                    EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13122                            MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
13123    
13124                    clearUniqueFindersCache(mbThread);
13125                    cacheUniqueFindersCache(mbThread);
13126    
13127                    return mbThread;
13128            }
13129    
13130            protected MBThread toUnwrappedModel(MBThread mbThread) {
13131                    if (mbThread instanceof MBThreadImpl) {
13132                            return mbThread;
13133                    }
13134    
13135                    MBThreadImpl mbThreadImpl = new MBThreadImpl();
13136    
13137                    mbThreadImpl.setNew(mbThread.isNew());
13138                    mbThreadImpl.setPrimaryKey(mbThread.getPrimaryKey());
13139    
13140                    mbThreadImpl.setUuid(mbThread.getUuid());
13141                    mbThreadImpl.setThreadId(mbThread.getThreadId());
13142                    mbThreadImpl.setGroupId(mbThread.getGroupId());
13143                    mbThreadImpl.setCompanyId(mbThread.getCompanyId());
13144                    mbThreadImpl.setUserId(mbThread.getUserId());
13145                    mbThreadImpl.setUserName(mbThread.getUserName());
13146                    mbThreadImpl.setCreateDate(mbThread.getCreateDate());
13147                    mbThreadImpl.setModifiedDate(mbThread.getModifiedDate());
13148                    mbThreadImpl.setCategoryId(mbThread.getCategoryId());
13149                    mbThreadImpl.setRootMessageId(mbThread.getRootMessageId());
13150                    mbThreadImpl.setRootMessageUserId(mbThread.getRootMessageUserId());
13151                    mbThreadImpl.setMessageCount(mbThread.getMessageCount());
13152                    mbThreadImpl.setViewCount(mbThread.getViewCount());
13153                    mbThreadImpl.setLastPostByUserId(mbThread.getLastPostByUserId());
13154                    mbThreadImpl.setLastPostDate(mbThread.getLastPostDate());
13155                    mbThreadImpl.setPriority(mbThread.getPriority());
13156                    mbThreadImpl.setQuestion(mbThread.isQuestion());
13157                    mbThreadImpl.setStatus(mbThread.getStatus());
13158                    mbThreadImpl.setStatusByUserId(mbThread.getStatusByUserId());
13159                    mbThreadImpl.setStatusByUserName(mbThread.getStatusByUserName());
13160                    mbThreadImpl.setStatusDate(mbThread.getStatusDate());
13161    
13162                    return mbThreadImpl;
13163            }
13164    
13165            /**
13166             * Returns the message boards thread with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
13167             *
13168             * @param primaryKey the primary key of the message boards thread
13169             * @return the message boards thread
13170             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
13171             * @throws SystemException if a system exception occurred
13172             */
13173            @Override
13174            public MBThread findByPrimaryKey(Serializable primaryKey)
13175                    throws NoSuchThreadException, SystemException {
13176                    MBThread mbThread = fetchByPrimaryKey(primaryKey);
13177    
13178                    if (mbThread == null) {
13179                            if (_log.isWarnEnabled()) {
13180                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
13181                            }
13182    
13183                            throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
13184                                    primaryKey);
13185                    }
13186    
13187                    return mbThread;
13188            }
13189    
13190            /**
13191             * Returns the message boards thread with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchThreadException} if it could not be found.
13192             *
13193             * @param threadId the primary key of the message boards thread
13194             * @return the message boards thread
13195             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
13196             * @throws SystemException if a system exception occurred
13197             */
13198            public MBThread findByPrimaryKey(long threadId)
13199                    throws NoSuchThreadException, SystemException {
13200                    return findByPrimaryKey((Serializable)threadId);
13201            }
13202    
13203            /**
13204             * Returns the message boards thread with the primary key or returns <code>null</code> if it could not be found.
13205             *
13206             * @param primaryKey the primary key of the message boards thread
13207             * @return the message boards thread, or <code>null</code> if a message boards thread with the primary key could not be found
13208             * @throws SystemException if a system exception occurred
13209             */
13210            @Override
13211            public MBThread fetchByPrimaryKey(Serializable primaryKey)
13212                    throws SystemException {
13213                    MBThread mbThread = (MBThread)EntityCacheUtil.getResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13214                                    MBThreadImpl.class, primaryKey);
13215    
13216                    if (mbThread == _nullMBThread) {
13217                            return null;
13218                    }
13219    
13220                    if (mbThread == null) {
13221                            Session session = null;
13222    
13223                            try {
13224                                    session = openSession();
13225    
13226                                    mbThread = (MBThread)session.get(MBThreadImpl.class, primaryKey);
13227    
13228                                    if (mbThread != null) {
13229                                            cacheResult(mbThread);
13230                                    }
13231                                    else {
13232                                            EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13233                                                    MBThreadImpl.class, primaryKey, _nullMBThread);
13234                                    }
13235                            }
13236                            catch (Exception e) {
13237                                    EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13238                                            MBThreadImpl.class, primaryKey);
13239    
13240                                    throw processException(e);
13241                            }
13242                            finally {
13243                                    closeSession(session);
13244                            }
13245                    }
13246    
13247                    return mbThread;
13248            }
13249    
13250            /**
13251             * Returns the message boards thread with the primary key or returns <code>null</code> if it could not be found.
13252             *
13253             * @param threadId the primary key of the message boards thread
13254             * @return the message boards thread, or <code>null</code> if a message boards thread with the primary key could not be found
13255             * @throws SystemException if a system exception occurred
13256             */
13257            public MBThread fetchByPrimaryKey(long threadId) throws SystemException {
13258                    return fetchByPrimaryKey((Serializable)threadId);
13259            }
13260    
13261            /**
13262             * Returns all the message boards threads.
13263             *
13264             * @return the message boards threads
13265             * @throws SystemException if a system exception occurred
13266             */
13267            public List<MBThread> findAll() throws SystemException {
13268                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13269            }
13270    
13271            /**
13272             * Returns a range of all the message boards threads.
13273             *
13274             * <p>
13275             * 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.
13276             * </p>
13277             *
13278             * @param start the lower bound of the range of message boards threads
13279             * @param end the upper bound of the range of message boards threads (not inclusive)
13280             * @return the range of message boards threads
13281             * @throws SystemException if a system exception occurred
13282             */
13283            public List<MBThread> findAll(int start, int end) throws SystemException {
13284                    return findAll(start, end, null);
13285            }
13286    
13287            /**
13288             * Returns an ordered range of all the message boards threads.
13289             *
13290             * <p>
13291             * 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.
13292             * </p>
13293             *
13294             * @param start the lower bound of the range of message boards threads
13295             * @param end the upper bound of the range of message boards threads (not inclusive)
13296             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13297             * @return the ordered range of message boards threads
13298             * @throws SystemException if a system exception occurred
13299             */
13300            public List<MBThread> findAll(int start, int end,
13301                    OrderByComparator orderByComparator) throws SystemException {
13302                    boolean pagination = true;
13303                    FinderPath finderPath = null;
13304                    Object[] finderArgs = null;
13305    
13306                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13307                                    (orderByComparator == null)) {
13308                            pagination = false;
13309                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
13310                            finderArgs = FINDER_ARGS_EMPTY;
13311                    }
13312                    else {
13313                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
13314                            finderArgs = new Object[] { start, end, orderByComparator };
13315                    }
13316    
13317                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
13318                                    finderArgs, this);
13319    
13320                    if (list == null) {
13321                            StringBundler query = null;
13322                            String sql = null;
13323    
13324                            if (orderByComparator != null) {
13325                                    query = new StringBundler(2 +
13326                                                    (orderByComparator.getOrderByFields().length * 3));
13327    
13328                                    query.append(_SQL_SELECT_MBTHREAD);
13329    
13330                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13331                                            orderByComparator);
13332    
13333                                    sql = query.toString();
13334                            }
13335                            else {
13336                                    sql = _SQL_SELECT_MBTHREAD;
13337    
13338                                    if (pagination) {
13339                                            sql = sql.concat(MBThreadModelImpl.ORDER_BY_JPQL);
13340                                    }
13341                            }
13342    
13343                            Session session = null;
13344    
13345                            try {
13346                                    session = openSession();
13347    
13348                                    Query q = session.createQuery(sql);
13349    
13350                                    if (!pagination) {
13351                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
13352                                                            start, end, false);
13353    
13354                                            Collections.sort(list);
13355    
13356                                            list = new UnmodifiableList<MBThread>(list);
13357                                    }
13358                                    else {
13359                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
13360                                                            start, end);
13361                                    }
13362    
13363                                    cacheResult(list);
13364    
13365                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13366                            }
13367                            catch (Exception e) {
13368                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13369    
13370                                    throw processException(e);
13371                            }
13372                            finally {
13373                                    closeSession(session);
13374                            }
13375                    }
13376    
13377                    return list;
13378            }
13379    
13380            /**
13381             * Removes all the message boards threads from the database.
13382             *
13383             * @throws SystemException if a system exception occurred
13384             */
13385            public void removeAll() throws SystemException {
13386                    for (MBThread mbThread : findAll()) {
13387                            remove(mbThread);
13388                    }
13389            }
13390    
13391            /**
13392             * Returns the number of message boards threads.
13393             *
13394             * @return the number of message boards threads
13395             * @throws SystemException if a system exception occurred
13396             */
13397            public int countAll() throws SystemException {
13398                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
13399                                    FINDER_ARGS_EMPTY, this);
13400    
13401                    if (count == null) {
13402                            Session session = null;
13403    
13404                            try {
13405                                    session = openSession();
13406    
13407                                    Query q = session.createQuery(_SQL_COUNT_MBTHREAD);
13408    
13409                                    count = (Long)q.uniqueResult();
13410    
13411                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
13412                                            FINDER_ARGS_EMPTY, count);
13413                            }
13414                            catch (Exception e) {
13415                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
13416                                            FINDER_ARGS_EMPTY);
13417    
13418                                    throw processException(e);
13419                            }
13420                            finally {
13421                                    closeSession(session);
13422                            }
13423                    }
13424    
13425                    return count.intValue();
13426            }
13427    
13428            @Override
13429            protected Set<String> getBadColumnNames() {
13430                    return _badColumnNames;
13431            }
13432    
13433            /**
13434             * Initializes the message boards thread persistence.
13435             */
13436            public void afterPropertiesSet() {
13437                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
13438                                            com.liferay.portal.util.PropsUtil.get(
13439                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBThread")));
13440    
13441                    if (listenerClassNames.length > 0) {
13442                            try {
13443                                    List<ModelListener<MBThread>> listenersList = new ArrayList<ModelListener<MBThread>>();
13444    
13445                                    for (String listenerClassName : listenerClassNames) {
13446                                            listenersList.add((ModelListener<MBThread>)InstanceFactory.newInstance(
13447                                                            getClassLoader(), listenerClassName));
13448                                    }
13449    
13450                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
13451                            }
13452                            catch (Exception e) {
13453                                    _log.error(e);
13454                            }
13455                    }
13456            }
13457    
13458            public void destroy() {
13459                    EntityCacheUtil.removeCache(MBThreadImpl.class.getName());
13460                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
13461                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
13462                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
13463            }
13464    
13465            private static final String _SQL_SELECT_MBTHREAD = "SELECT mbThread FROM MBThread mbThread";
13466            private static final String _SQL_SELECT_MBTHREAD_WHERE = "SELECT mbThread FROM MBThread mbThread WHERE ";
13467            private static final String _SQL_COUNT_MBTHREAD = "SELECT COUNT(mbThread) FROM MBThread mbThread";
13468            private static final String _SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(mbThread) FROM MBThread mbThread WHERE ";
13469            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbThread.threadId";
13470            private static final String _FILTER_SQL_SELECT_MBTHREAD_WHERE = "SELECT DISTINCT {mbThread.*} FROM MBThread mbThread WHERE ";
13471            private static final String _FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1 =
13472                    "SELECT {MBThread.*} FROM (SELECT DISTINCT mbThread.threadId FROM MBThread mbThread WHERE ";
13473            private static final String _FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2 =
13474                    ") TEMP_TABLE INNER JOIN MBThread ON TEMP_TABLE.threadId = MBThread.threadId";
13475            private static final String _FILTER_SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(DISTINCT mbThread.threadId) AS COUNT_VALUE FROM MBThread mbThread WHERE ";
13476            private static final String _FILTER_ENTITY_ALIAS = "mbThread";
13477            private static final String _FILTER_ENTITY_TABLE = "MBThread";
13478            private static final String _ORDER_BY_ENTITY_ALIAS = "mbThread.";
13479            private static final String _ORDER_BY_ENTITY_TABLE = "MBThread.";
13480            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBThread exists with the primary key ";
13481            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBThread exists with the key {";
13482            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
13483            private static Log _log = LogFactoryUtil.getLog(MBThreadPersistenceImpl.class);
13484            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
13485                                    "uuid"
13486                            });
13487            private static MBThread _nullMBThread = new MBThreadImpl() {
13488                            @Override
13489                            public Object clone() {
13490                                    return this;
13491                            }
13492    
13493                            @Override
13494                            public CacheModel<MBThread> toCacheModel() {
13495                                    return _nullMBThreadCacheModel;
13496                            }
13497                    };
13498    
13499            private static CacheModel<MBThread> _nullMBThreadCacheModel = new CacheModel<MBThread>() {
13500                            public MBThread toEntityModel() {
13501                                    return _nullMBThread;
13502                            }
13503                    };
13504    }