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