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