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