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.Set;
068    
069    /**
070     * The persistence implementation for the message boards thread service.
071     *
072     * <p>
073     * Caching information and settings can be found in <code>portal.properties</code>
074     * </p>
075     *
076     * @author Brian Wing Shun Chan
077     * @see MBThreadPersistence
078     * @see com.liferay.message.boards.kernel.service.persistence.MBThreadUtil
079     * @generated
080     */
081    @ProviderType
082    public class MBThreadPersistenceImpl extends BasePersistenceImpl<MBThread>
083            implements MBThreadPersistence {
084            /*
085             * NOTE FOR DEVELOPERS:
086             *
087             * 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.
088             */
089            public static final String FINDER_CLASS_NAME_ENTITY = MBThreadImpl.class.getName();
090            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
091                    ".List1";
092            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
093                    ".List2";
094            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
095                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
097            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
098                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
100            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
101                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
103            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
104                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
105                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
106                            new String[] {
107                                    String.class.getName(),
108                                    
109                            Integer.class.getName(), Integer.class.getName(),
110                                    OrderByComparator.class.getName()
111                            });
112            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
113                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
114                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
115                            new String[] { String.class.getName() },
116                            MBThreadModelImpl.UUID_COLUMN_BITMASK |
117                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
118                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
119            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
120                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
121                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
122                            new String[] { String.class.getName() });
123    
124            /**
125             * Returns all the message boards threads where uuid = &#63;.
126             *
127             * @param uuid the uuid
128             * @return the matching message boards threads
129             */
130            @Override
131            public List<MBThread> findByUuid(String uuid) {
132                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
133            }
134    
135            /**
136             * Returns a range of all the message boards threads where uuid = &#63;.
137             *
138             * <p>
139             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
140             * </p>
141             *
142             * @param uuid the uuid
143             * @param start the lower bound of the range of message boards threads
144             * @param end the upper bound of the range of message boards threads (not inclusive)
145             * @return the range of matching message boards threads
146             */
147            @Override
148            public List<MBThread> findByUuid(String uuid, int start, int end) {
149                    return findByUuid(uuid, start, end, null);
150            }
151    
152            /**
153             * Returns an ordered range of all the message boards threads where uuid = &#63;.
154             *
155             * <p>
156             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
157             * </p>
158             *
159             * @param uuid the uuid
160             * @param start the lower bound of the range of message boards threads
161             * @param end the upper bound of the range of message boards threads (not inclusive)
162             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
163             * @return the ordered range of matching message boards threads
164             */
165            @Override
166            public List<MBThread> findByUuid(String uuid, int start, int end,
167                    OrderByComparator<MBThread> orderByComparator) {
168                    return findByUuid(uuid, start, end, orderByComparator, true);
169            }
170    
171            /**
172             * Returns an ordered range of all the message boards threads where uuid = &#63;.
173             *
174             * <p>
175             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
176             * </p>
177             *
178             * @param uuid the uuid
179             * @param start the lower bound of the range of message boards threads
180             * @param end the upper bound of the range of message boards threads (not inclusive)
181             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
182             * @param retrieveFromCache whether to retrieve from the finder cache
183             * @return the ordered range of matching message boards threads
184             */
185            @Override
186            public List<MBThread> findByUuid(String uuid, int start, int end,
187                    OrderByComparator<MBThread> orderByComparator, boolean retrieveFromCache) {
188                    boolean pagination = true;
189                    FinderPath finderPath = null;
190                    Object[] finderArgs = null;
191    
192                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
193                                    (orderByComparator == null)) {
194                            pagination = false;
195                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
196                            finderArgs = new Object[] { uuid };
197                    }
198                    else {
199                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
200                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
201                    }
202    
203                    List<MBThread> list = null;
204    
205                    if (retrieveFromCache) {
206                            list = (List<MBThread>)finderCache.getResult(finderPath,
207                                            finderArgs, this);
208    
209                            if ((list != null) && !list.isEmpty()) {
210                                    for (MBThread mbThread : list) {
211                                            if (!Validator.equals(uuid, mbThread.getUuid())) {
212                                                    list = null;
213    
214                                                    break;
215                                            }
216                                    }
217                            }
218                    }
219    
220                    if (list == null) {
221                            StringBundler query = null;
222    
223                            if (orderByComparator != null) {
224                                    query = new StringBundler(3 +
225                                                    (orderByComparator.getOrderByFields().length * 2));
226                            }
227                            else {
228                                    query = new StringBundler(3);
229                            }
230    
231                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
232    
233                            boolean bindUuid = false;
234    
235                            if (uuid == null) {
236                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
237                            }
238                            else if (uuid.equals(StringPool.BLANK)) {
239                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
240                            }
241                            else {
242                                    bindUuid = true;
243    
244                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
245                            }
246    
247                            if (orderByComparator != null) {
248                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
249                                            orderByComparator);
250                            }
251                            else
252                             if (pagination) {
253                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
254                            }
255    
256                            String sql = query.toString();
257    
258                            Session session = null;
259    
260                            try {
261                                    session = openSession();
262    
263                                    Query q = session.createQuery(sql);
264    
265                                    QueryPos qPos = QueryPos.getInstance(q);
266    
267                                    if (bindUuid) {
268                                            qPos.add(uuid);
269                                    }
270    
271                                    if (!pagination) {
272                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
273                                                            start, end, false);
274    
275                                            Collections.sort(list);
276    
277                                            list = Collections.unmodifiableList(list);
278                                    }
279                                    else {
280                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
281                                                            start, end);
282                                    }
283    
284                                    cacheResult(list);
285    
286                                    finderCache.putResult(finderPath, finderArgs, list);
287                            }
288                            catch (Exception e) {
289                                    finderCache.removeResult(finderPath, finderArgs);
290    
291                                    throw processException(e);
292                            }
293                            finally {
294                                    closeSession(session);
295                            }
296                    }
297    
298                    return list;
299            }
300    
301            /**
302             * Returns the first message boards thread in the ordered set where uuid = &#63;.
303             *
304             * @param uuid the uuid
305             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
306             * @return the first matching message boards thread
307             * @throws NoSuchThreadException if a matching message boards thread could not be found
308             */
309            @Override
310            public MBThread findByUuid_First(String uuid,
311                    OrderByComparator<MBThread> orderByComparator)
312                    throws NoSuchThreadException {
313                    MBThread mbThread = fetchByUuid_First(uuid, orderByComparator);
314    
315                    if (mbThread != null) {
316                            return mbThread;
317                    }
318    
319                    StringBundler msg = new StringBundler(4);
320    
321                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
322    
323                    msg.append("uuid=");
324                    msg.append(uuid);
325    
326                    msg.append(StringPool.CLOSE_CURLY_BRACE);
327    
328                    throw new NoSuchThreadException(msg.toString());
329            }
330    
331            /**
332             * Returns the first message boards thread in the ordered set where uuid = &#63;.
333             *
334             * @param uuid the uuid
335             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
336             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
337             */
338            @Override
339            public MBThread fetchByUuid_First(String uuid,
340                    OrderByComparator<MBThread> orderByComparator) {
341                    List<MBThread> list = findByUuid(uuid, 0, 1, orderByComparator);
342    
343                    if (!list.isEmpty()) {
344                            return list.get(0);
345                    }
346    
347                    return null;
348            }
349    
350            /**
351             * Returns the last message boards thread in the ordered set where uuid = &#63;.
352             *
353             * @param uuid the uuid
354             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
355             * @return the last matching message boards thread
356             * @throws NoSuchThreadException if a matching message boards thread could not be found
357             */
358            @Override
359            public MBThread findByUuid_Last(String uuid,
360                    OrderByComparator<MBThread> orderByComparator)
361                    throws NoSuchThreadException {
362                    MBThread mbThread = fetchByUuid_Last(uuid, orderByComparator);
363    
364                    if (mbThread != null) {
365                            return mbThread;
366                    }
367    
368                    StringBundler msg = new StringBundler(4);
369    
370                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
371    
372                    msg.append("uuid=");
373                    msg.append(uuid);
374    
375                    msg.append(StringPool.CLOSE_CURLY_BRACE);
376    
377                    throw new NoSuchThreadException(msg.toString());
378            }
379    
380            /**
381             * Returns the last message boards thread in the ordered set where uuid = &#63;.
382             *
383             * @param uuid the uuid
384             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
385             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
386             */
387            @Override
388            public MBThread fetchByUuid_Last(String uuid,
389                    OrderByComparator<MBThread> orderByComparator) {
390                    int count = countByUuid(uuid);
391    
392                    if (count == 0) {
393                            return null;
394                    }
395    
396                    List<MBThread> list = findByUuid(uuid, count - 1, count,
397                                    orderByComparator);
398    
399                    if (!list.isEmpty()) {
400                            return list.get(0);
401                    }
402    
403                    return null;
404            }
405    
406            /**
407             * Returns the message boards threads before and after the current message boards thread in the ordered set where uuid = &#63;.
408             *
409             * @param threadId the primary key of the current message boards thread
410             * @param uuid the uuid
411             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
412             * @return the previous, current, and next message boards thread
413             * @throws NoSuchThreadException if a message boards thread with the primary key could not be found
414             */
415            @Override
416            public MBThread[] findByUuid_PrevAndNext(long threadId, String uuid,
417                    OrderByComparator<MBThread> orderByComparator)
418                    throws NoSuchThreadException {
419                    MBThread mbThread = findByPrimaryKey(threadId);
420    
421                    Session session = null;
422    
423                    try {
424                            session = openSession();
425    
426                            MBThread[] array = new MBThreadImpl[3];
427    
428                            array[0] = getByUuid_PrevAndNext(session, mbThread, uuid,
429                                            orderByComparator, true);
430    
431                            array[1] = mbThread;
432    
433                            array[2] = getByUuid_PrevAndNext(session, mbThread, uuid,
434                                            orderByComparator, false);
435    
436                            return array;
437                    }
438                    catch (Exception e) {
439                            throw processException(e);
440                    }
441                    finally {
442                            closeSession(session);
443                    }
444            }
445    
446            protected MBThread getByUuid_PrevAndNext(Session session,
447                    MBThread mbThread, String uuid,
448                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
449                    StringBundler query = null;
450    
451                    if (orderByComparator != null) {
452                            query = new StringBundler(4 +
453                                            (orderByComparator.getOrderByConditionFields().length * 3) +
454                                            (orderByComparator.getOrderByFields().length * 3));
455                    }
456                    else {
457                            query = new StringBundler(3);
458                    }
459    
460                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
461    
462                    boolean bindUuid = false;
463    
464                    if (uuid == null) {
465                            query.append(_FINDER_COLUMN_UUID_UUID_1);
466                    }
467                    else if (uuid.equals(StringPool.BLANK)) {
468                            query.append(_FINDER_COLUMN_UUID_UUID_3);
469                    }
470                    else {
471                            bindUuid = true;
472    
473                            query.append(_FINDER_COLUMN_UUID_UUID_2);
474                    }
475    
476                    if (orderByComparator != null) {
477                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
478    
479                            if (orderByConditionFields.length > 0) {
480                                    query.append(WHERE_AND);
481                            }
482    
483                            for (int i = 0; i < orderByConditionFields.length; i++) {
484                                    query.append(_ORDER_BY_ENTITY_ALIAS);
485                                    query.append(orderByConditionFields[i]);
486    
487                                    if ((i + 1) < orderByConditionFields.length) {
488                                            if (orderByComparator.isAscending() ^ previous) {
489                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
490                                            }
491                                            else {
492                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
493                                            }
494                                    }
495                                    else {
496                                            if (orderByComparator.isAscending() ^ previous) {
497                                                    query.append(WHERE_GREATER_THAN);
498                                            }
499                                            else {
500                                                    query.append(WHERE_LESSER_THAN);
501                                            }
502                                    }
503                            }
504    
505                            query.append(ORDER_BY_CLAUSE);
506    
507                            String[] orderByFields = orderByComparator.getOrderByFields();
508    
509                            for (int i = 0; i < orderByFields.length; i++) {
510                                    query.append(_ORDER_BY_ENTITY_ALIAS);
511                                    query.append(orderByFields[i]);
512    
513                                    if ((i + 1) < orderByFields.length) {
514                                            if (orderByComparator.isAscending() ^ previous) {
515                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
516                                            }
517                                            else {
518                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
519                                            }
520                                    }
521                                    else {
522                                            if (orderByComparator.isAscending() ^ previous) {
523                                                    query.append(ORDER_BY_ASC);
524                                            }
525                                            else {
526                                                    query.append(ORDER_BY_DESC);
527                                            }
528                                    }
529                            }
530                    }
531                    else {
532                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
533                    }
534    
535                    String sql = query.toString();
536    
537                    Query q = session.createQuery(sql);
538    
539                    q.setFirstResult(0);
540                    q.setMaxResults(2);
541    
542                    QueryPos qPos = QueryPos.getInstance(q);
543    
544                    if (bindUuid) {
545                            qPos.add(uuid);
546                    }
547    
548                    if (orderByComparator != null) {
549                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
550    
551                            for (Object value : values) {
552                                    qPos.add(value);
553                            }
554                    }
555    
556                    List<MBThread> list = q.list();
557    
558                    if (list.size() == 2) {
559                            return list.get(1);
560                    }
561                    else {
562                            return null;
563                    }
564            }
565    
566            /**
567             * Removes all the message boards threads where uuid = &#63; from the database.
568             *
569             * @param uuid the uuid
570             */
571            @Override
572            public void removeByUuid(String uuid) {
573                    for (MBThread mbThread : findByUuid(uuid, QueryUtil.ALL_POS,
574                                    QueryUtil.ALL_POS, null)) {
575                            remove(mbThread);
576                    }
577            }
578    
579            /**
580             * Returns the number of message boards threads where uuid = &#63;.
581             *
582             * @param uuid the uuid
583             * @return the number of matching message boards threads
584             */
585            @Override
586            public int countByUuid(String uuid) {
587                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
588    
589                    Object[] finderArgs = new Object[] { uuid };
590    
591                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
592    
593                    if (count == null) {
594                            StringBundler query = new StringBundler(2);
595    
596                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
597    
598                            boolean bindUuid = false;
599    
600                            if (uuid == null) {
601                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
602                            }
603                            else if (uuid.equals(StringPool.BLANK)) {
604                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
605                            }
606                            else {
607                                    bindUuid = true;
608    
609                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
610                            }
611    
612                            String sql = query.toString();
613    
614                            Session session = null;
615    
616                            try {
617                                    session = openSession();
618    
619                                    Query q = session.createQuery(sql);
620    
621                                    QueryPos qPos = QueryPos.getInstance(q);
622    
623                                    if (bindUuid) {
624                                            qPos.add(uuid);
625                                    }
626    
627                                    count = (Long)q.uniqueResult();
628    
629                                    finderCache.putResult(finderPath, finderArgs, count);
630                            }
631                            catch (Exception e) {
632                                    finderCache.removeResult(finderPath, finderArgs);
633    
634                                    throw processException(e);
635                            }
636                            finally {
637                                    closeSession(session);
638                            }
639                    }
640    
641                    return count.intValue();
642            }
643    
644            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbThread.uuid IS NULL";
645            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbThread.uuid = ?";
646            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbThread.uuid IS NULL OR mbThread.uuid = '')";
647            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
648                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
649                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
650                            new String[] { String.class.getName(), Long.class.getName() },
651                            MBThreadModelImpl.UUID_COLUMN_BITMASK |
652                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK);
653            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
654                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
655                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
656                            new String[] { String.class.getName(), Long.class.getName() });
657    
658            /**
659             * Returns the message boards thread where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchThreadException} if it could not be found.
660             *
661             * @param uuid the uuid
662             * @param groupId the group ID
663             * @return the matching message boards thread
664             * @throws NoSuchThreadException if a matching message boards thread could not be found
665             */
666            @Override
667            public MBThread findByUUID_G(String uuid, long groupId)
668                    throws NoSuchThreadException {
669                    MBThread mbThread = fetchByUUID_G(uuid, groupId);
670    
671                    if (mbThread == null) {
672                            StringBundler msg = new StringBundler(6);
673    
674                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
675    
676                            msg.append("uuid=");
677                            msg.append(uuid);
678    
679                            msg.append(", groupId=");
680                            msg.append(groupId);
681    
682                            msg.append(StringPool.CLOSE_CURLY_BRACE);
683    
684                            if (_log.isWarnEnabled()) {
685                                    _log.warn(msg.toString());
686                            }
687    
688                            throw new NoSuchThreadException(msg.toString());
689                    }
690    
691                    return mbThread;
692            }
693    
694            /**
695             * 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.
696             *
697             * @param uuid the uuid
698             * @param groupId the group ID
699             * @return the matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
700             */
701            @Override
702            public MBThread fetchByUUID_G(String uuid, long groupId) {
703                    return fetchByUUID_G(uuid, groupId, true);
704            }
705    
706            /**
707             * 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.
708             *
709             * @param uuid the uuid
710             * @param groupId the group ID
711             * @param retrieveFromCache whether to retrieve from the finder cache
712             * @return the matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
713             */
714            @Override
715            public MBThread fetchByUUID_G(String uuid, long groupId,
716                    boolean retrieveFromCache) {
717                    Object[] finderArgs = new Object[] { uuid, groupId };
718    
719                    Object result = null;
720    
721                    if (retrieveFromCache) {
722                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
723                                            finderArgs, this);
724                    }
725    
726                    if (result instanceof MBThread) {
727                            MBThread mbThread = (MBThread)result;
728    
729                            if (!Validator.equals(uuid, mbThread.getUuid()) ||
730                                            (groupId != mbThread.getGroupId())) {
731                                    result = null;
732                            }
733                    }
734    
735                    if (result == null) {
736                            StringBundler query = new StringBundler(4);
737    
738                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
739    
740                            boolean bindUuid = false;
741    
742                            if (uuid == null) {
743                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
744                            }
745                            else if (uuid.equals(StringPool.BLANK)) {
746                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
747                            }
748                            else {
749                                    bindUuid = true;
750    
751                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
752                            }
753    
754                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
755    
756                            String sql = query.toString();
757    
758                            Session session = null;
759    
760                            try {
761                                    session = openSession();
762    
763                                    Query q = session.createQuery(sql);
764    
765                                    QueryPos qPos = QueryPos.getInstance(q);
766    
767                                    if (bindUuid) {
768                                            qPos.add(uuid);
769                                    }
770    
771                                    qPos.add(groupId);
772    
773                                    List<MBThread> list = q.list();
774    
775                                    if (list.isEmpty()) {
776                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
777                                                    finderArgs, list);
778                                    }
779                                    else {
780                                            MBThread mbThread = list.get(0);
781    
782                                            result = mbThread;
783    
784                                            cacheResult(mbThread);
785    
786                                            if ((mbThread.getUuid() == null) ||
787                                                            !mbThread.getUuid().equals(uuid) ||
788                                                            (mbThread.getGroupId() != groupId)) {
789                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
790                                                            finderArgs, mbThread);
791                                            }
792                                    }
793                            }
794                            catch (Exception e) {
795                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
796    
797                                    throw processException(e);
798                            }
799                            finally {
800                                    closeSession(session);
801                            }
802                    }
803    
804                    if (result instanceof List<?>) {
805                            return null;
806                    }
807                    else {
808                            return (MBThread)result;
809                    }
810            }
811    
812            /**
813             * Removes the message boards thread where uuid = &#63; and groupId = &#63; from the database.
814             *
815             * @param uuid the uuid
816             * @param groupId the group ID
817             * @return the message boards thread that was removed
818             */
819            @Override
820            public MBThread removeByUUID_G(String uuid, long groupId)
821                    throws NoSuchThreadException {
822                    MBThread mbThread = findByUUID_G(uuid, groupId);
823    
824                    return remove(mbThread);
825            }
826    
827            /**
828             * Returns the number of message boards threads where uuid = &#63; and groupId = &#63;.
829             *
830             * @param uuid the uuid
831             * @param groupId the group ID
832             * @return the number of matching message boards threads
833             */
834            @Override
835            public int countByUUID_G(String uuid, long groupId) {
836                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
837    
838                    Object[] finderArgs = new Object[] { uuid, groupId };
839    
840                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
841    
842                    if (count == null) {
843                            StringBundler query = new StringBundler(3);
844    
845                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
846    
847                            boolean bindUuid = false;
848    
849                            if (uuid == null) {
850                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
851                            }
852                            else if (uuid.equals(StringPool.BLANK)) {
853                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
854                            }
855                            else {
856                                    bindUuid = true;
857    
858                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
859                            }
860    
861                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
862    
863                            String sql = query.toString();
864    
865                            Session session = null;
866    
867                            try {
868                                    session = openSession();
869    
870                                    Query q = session.createQuery(sql);
871    
872                                    QueryPos qPos = QueryPos.getInstance(q);
873    
874                                    if (bindUuid) {
875                                            qPos.add(uuid);
876                                    }
877    
878                                    qPos.add(groupId);
879    
880                                    count = (Long)q.uniqueResult();
881    
882                                    finderCache.putResult(finderPath, finderArgs, count);
883                            }
884                            catch (Exception e) {
885                                    finderCache.removeResult(finderPath, finderArgs);
886    
887                                    throw processException(e);
888                            }
889                            finally {
890                                    closeSession(session);
891                            }
892                    }
893    
894                    return count.intValue();
895            }
896    
897            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbThread.uuid IS NULL AND ";
898            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbThread.uuid = ? AND ";
899            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbThread.uuid IS NULL OR mbThread.uuid = '') AND ";
900            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbThread.groupId = ?";
901            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
902                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
903                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
904                            new String[] {
905                                    String.class.getName(), Long.class.getName(),
906                                    
907                            Integer.class.getName(), Integer.class.getName(),
908                                    OrderByComparator.class.getName()
909                            });
910            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
911                    new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
912                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
913                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
914                            new String[] { String.class.getName(), Long.class.getName() },
915                            MBThreadModelImpl.UUID_COLUMN_BITMASK |
916                            MBThreadModelImpl.COMPANYID_COLUMN_BITMASK |
917                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
918                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
919            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
920                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
921                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
922                            new String[] { String.class.getName(), Long.class.getName() });
923    
924            /**
925             * Returns all the message boards threads where uuid = &#63; and companyId = &#63;.
926             *
927             * @param uuid the uuid
928             * @param companyId the company ID
929             * @return the matching message boards threads
930             */
931            @Override
932            public List<MBThread> findByUuid_C(String uuid, long companyId) {
933                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
934                            QueryUtil.ALL_POS, null);
935            }
936    
937            /**
938             * Returns a range of all the message boards threads where uuid = &#63; and companyId = &#63;.
939             *
940             * <p>
941             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
942             * </p>
943             *
944             * @param uuid the uuid
945             * @param companyId the company ID
946             * @param start the lower bound of the range of message boards threads
947             * @param end the upper bound of the range of message boards threads (not inclusive)
948             * @return the range of matching message boards threads
949             */
950            @Override
951            public List<MBThread> findByUuid_C(String uuid, long companyId, int start,
952                    int end) {
953                    return findByUuid_C(uuid, companyId, start, end, null);
954            }
955    
956            /**
957             * Returns an ordered range of all the message boards threads where uuid = &#63; and companyId = &#63;.
958             *
959             * <p>
960             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
961             * </p>
962             *
963             * @param uuid the uuid
964             * @param companyId the company ID
965             * @param start the lower bound of the range of message boards threads
966             * @param end the upper bound of the range of message boards threads (not inclusive)
967             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
968             * @return the ordered range of matching message boards threads
969             */
970            @Override
971            public List<MBThread> findByUuid_C(String uuid, long companyId, int start,
972                    int end, OrderByComparator<MBThread> orderByComparator) {
973                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
974            }
975    
976            /**
977             * Returns an ordered range of all the message boards threads where uuid = &#63; and companyId = &#63;.
978             *
979             * <p>
980             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
981             * </p>
982             *
983             * @param uuid the uuid
984             * @param companyId the company ID
985             * @param start the lower bound of the range of message boards threads
986             * @param end the upper bound of the range of message boards threads (not inclusive)
987             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
988             * @param retrieveFromCache whether to retrieve from the finder cache
989             * @return the ordered range of matching message boards threads
990             */
991            @Override
992            public List<MBThread> findByUuid_C(String uuid, long companyId, int start,
993                    int end, OrderByComparator<MBThread> orderByComparator,
994                    boolean retrieveFromCache) {
995                    boolean pagination = true;
996                    FinderPath finderPath = null;
997                    Object[] finderArgs = null;
998    
999                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1000                                    (orderByComparator == null)) {
1001                            pagination = false;
1002                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1003                            finderArgs = new Object[] { uuid, companyId };
1004                    }
1005                    else {
1006                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1007                            finderArgs = new Object[] {
1008                                            uuid, companyId,
1009                                            
1010                                            start, end, orderByComparator
1011                                    };
1012                    }
1013    
1014                    List<MBThread> list = null;
1015    
1016                    if (retrieveFromCache) {
1017                            list = (List<MBThread>)finderCache.getResult(finderPath,
1018                                            finderArgs, this);
1019    
1020                            if ((list != null) && !list.isEmpty()) {
1021                                    for (MBThread mbThread : list) {
1022                                            if (!Validator.equals(uuid, mbThread.getUuid()) ||
1023                                                            (companyId != mbThread.getCompanyId())) {
1024                                                    list = null;
1025    
1026                                                    break;
1027                                            }
1028                                    }
1029                            }
1030                    }
1031    
1032                    if (list == null) {
1033                            StringBundler query = null;
1034    
1035                            if (orderByComparator != null) {
1036                                    query = new StringBundler(4 +
1037                                                    (orderByComparator.getOrderByFields().length * 2));
1038                            }
1039                            else {
1040                                    query = new StringBundler(4);
1041                            }
1042    
1043                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
1044    
1045                            boolean bindUuid = false;
1046    
1047                            if (uuid == null) {
1048                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1049                            }
1050                            else if (uuid.equals(StringPool.BLANK)) {
1051                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1052                            }
1053                            else {
1054                                    bindUuid = true;
1055    
1056                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1057                            }
1058    
1059                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1060    
1061                            if (orderByComparator != null) {
1062                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1063                                            orderByComparator);
1064                            }
1065                            else
1066                             if (pagination) {
1067                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1068                            }
1069    
1070                            String sql = query.toString();
1071    
1072                            Session session = null;
1073    
1074                            try {
1075                                    session = openSession();
1076    
1077                                    Query q = session.createQuery(sql);
1078    
1079                                    QueryPos qPos = QueryPos.getInstance(q);
1080    
1081                                    if (bindUuid) {
1082                                            qPos.add(uuid);
1083                                    }
1084    
1085                                    qPos.add(companyId);
1086    
1087                                    if (!pagination) {
1088                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1089                                                            start, end, false);
1090    
1091                                            Collections.sort(list);
1092    
1093                                            list = Collections.unmodifiableList(list);
1094                                    }
1095                                    else {
1096                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1097                                                            start, end);
1098                                    }
1099    
1100                                    cacheResult(list);
1101    
1102                                    finderCache.putResult(finderPath, finderArgs, list);
1103                            }
1104                            catch (Exception e) {
1105                                    finderCache.removeResult(finderPath, finderArgs);
1106    
1107                                    throw processException(e);
1108                            }
1109                            finally {
1110                                    closeSession(session);
1111                            }
1112                    }
1113    
1114                    return list;
1115            }
1116    
1117            /**
1118             * Returns the first message boards thread in the ordered set where uuid = &#63; and companyId = &#63;.
1119             *
1120             * @param uuid the uuid
1121             * @param companyId the company ID
1122             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1123             * @return the first matching message boards thread
1124             * @throws NoSuchThreadException if a matching message boards thread could not be found
1125             */
1126            @Override
1127            public MBThread findByUuid_C_First(String uuid, long companyId,
1128                    OrderByComparator<MBThread> orderByComparator)
1129                    throws NoSuchThreadException {
1130                    MBThread mbThread = fetchByUuid_C_First(uuid, companyId,
1131                                    orderByComparator);
1132    
1133                    if (mbThread != null) {
1134                            return mbThread;
1135                    }
1136    
1137                    StringBundler msg = new StringBundler(6);
1138    
1139                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1140    
1141                    msg.append("uuid=");
1142                    msg.append(uuid);
1143    
1144                    msg.append(", companyId=");
1145                    msg.append(companyId);
1146    
1147                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1148    
1149                    throw new NoSuchThreadException(msg.toString());
1150            }
1151    
1152            /**
1153             * Returns the first message boards thread in the ordered set where uuid = &#63; and companyId = &#63;.
1154             *
1155             * @param uuid the uuid
1156             * @param companyId the company ID
1157             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1158             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1159             */
1160            @Override
1161            public MBThread fetchByUuid_C_First(String uuid, long companyId,
1162                    OrderByComparator<MBThread> orderByComparator) {
1163                    List<MBThread> list = findByUuid_C(uuid, companyId, 0, 1,
1164                                    orderByComparator);
1165    
1166                    if (!list.isEmpty()) {
1167                            return list.get(0);
1168                    }
1169    
1170                    return null;
1171            }
1172    
1173            /**
1174             * Returns the last message boards thread in the ordered set where uuid = &#63; and companyId = &#63;.
1175             *
1176             * @param uuid the uuid
1177             * @param companyId the company ID
1178             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1179             * @return the last matching message boards thread
1180             * @throws NoSuchThreadException if a matching message boards thread could not be found
1181             */
1182            @Override
1183            public MBThread findByUuid_C_Last(String uuid, long companyId,
1184                    OrderByComparator<MBThread> orderByComparator)
1185                    throws NoSuchThreadException {
1186                    MBThread mbThread = fetchByUuid_C_Last(uuid, companyId,
1187                                    orderByComparator);
1188    
1189                    if (mbThread != null) {
1190                            return mbThread;
1191                    }
1192    
1193                    StringBundler msg = new StringBundler(6);
1194    
1195                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1196    
1197                    msg.append("uuid=");
1198                    msg.append(uuid);
1199    
1200                    msg.append(", companyId=");
1201                    msg.append(companyId);
1202    
1203                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1204    
1205                    throw new NoSuchThreadException(msg.toString());
1206            }
1207    
1208            /**
1209             * Returns the last message boards thread in the ordered set where uuid = &#63; and companyId = &#63;.
1210             *
1211             * @param uuid the uuid
1212             * @param companyId the company ID
1213             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1214             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1215             */
1216            @Override
1217            public MBThread fetchByUuid_C_Last(String uuid, long companyId,
1218                    OrderByComparator<MBThread> orderByComparator) {
1219                    int count = countByUuid_C(uuid, companyId);
1220    
1221                    if (count == 0) {
1222                            return null;
1223                    }
1224    
1225                    List<MBThread> list = findByUuid_C(uuid, companyId, count - 1, count,
1226                                    orderByComparator);
1227    
1228                    if (!list.isEmpty()) {
1229                            return list.get(0);
1230                    }
1231    
1232                    return null;
1233            }
1234    
1235            /**
1236             * Returns the message boards threads before and after the current message boards thread in the ordered set where uuid = &#63; and companyId = &#63;.
1237             *
1238             * @param threadId the primary key of the current message boards thread
1239             * @param uuid the uuid
1240             * @param companyId the company ID
1241             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1242             * @return the previous, current, and next message boards thread
1243             * @throws NoSuchThreadException if a message boards thread with the primary key could not be found
1244             */
1245            @Override
1246            public MBThread[] findByUuid_C_PrevAndNext(long threadId, String uuid,
1247                    long companyId, OrderByComparator<MBThread> orderByComparator)
1248                    throws NoSuchThreadException {
1249                    MBThread mbThread = findByPrimaryKey(threadId);
1250    
1251                    Session session = null;
1252    
1253                    try {
1254                            session = openSession();
1255    
1256                            MBThread[] array = new MBThreadImpl[3];
1257    
1258                            array[0] = getByUuid_C_PrevAndNext(session, mbThread, uuid,
1259                                            companyId, orderByComparator, true);
1260    
1261                            array[1] = mbThread;
1262    
1263                            array[2] = getByUuid_C_PrevAndNext(session, mbThread, uuid,
1264                                            companyId, orderByComparator, false);
1265    
1266                            return array;
1267                    }
1268                    catch (Exception e) {
1269                            throw processException(e);
1270                    }
1271                    finally {
1272                            closeSession(session);
1273                    }
1274            }
1275    
1276            protected MBThread getByUuid_C_PrevAndNext(Session session,
1277                    MBThread mbThread, String uuid, long companyId,
1278                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
1279                    StringBundler query = null;
1280    
1281                    if (orderByComparator != null) {
1282                            query = new StringBundler(5 +
1283                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1284                                            (orderByComparator.getOrderByFields().length * 3));
1285                    }
1286                    else {
1287                            query = new StringBundler(4);
1288                    }
1289    
1290                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1291    
1292                    boolean bindUuid = false;
1293    
1294                    if (uuid == null) {
1295                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1296                    }
1297                    else if (uuid.equals(StringPool.BLANK)) {
1298                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1299                    }
1300                    else {
1301                            bindUuid = true;
1302    
1303                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1304                    }
1305    
1306                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1307    
1308                    if (orderByComparator != null) {
1309                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1310    
1311                            if (orderByConditionFields.length > 0) {
1312                                    query.append(WHERE_AND);
1313                            }
1314    
1315                            for (int i = 0; i < orderByConditionFields.length; i++) {
1316                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1317                                    query.append(orderByConditionFields[i]);
1318    
1319                                    if ((i + 1) < orderByConditionFields.length) {
1320                                            if (orderByComparator.isAscending() ^ previous) {
1321                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1322                                            }
1323                                            else {
1324                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1325                                            }
1326                                    }
1327                                    else {
1328                                            if (orderByComparator.isAscending() ^ previous) {
1329                                                    query.append(WHERE_GREATER_THAN);
1330                                            }
1331                                            else {
1332                                                    query.append(WHERE_LESSER_THAN);
1333                                            }
1334                                    }
1335                            }
1336    
1337                            query.append(ORDER_BY_CLAUSE);
1338    
1339                            String[] orderByFields = orderByComparator.getOrderByFields();
1340    
1341                            for (int i = 0; i < orderByFields.length; i++) {
1342                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1343                                    query.append(orderByFields[i]);
1344    
1345                                    if ((i + 1) < orderByFields.length) {
1346                                            if (orderByComparator.isAscending() ^ previous) {
1347                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1348                                            }
1349                                            else {
1350                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1351                                            }
1352                                    }
1353                                    else {
1354                                            if (orderByComparator.isAscending() ^ previous) {
1355                                                    query.append(ORDER_BY_ASC);
1356                                            }
1357                                            else {
1358                                                    query.append(ORDER_BY_DESC);
1359                                            }
1360                                    }
1361                            }
1362                    }
1363                    else {
1364                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1365                    }
1366    
1367                    String sql = query.toString();
1368    
1369                    Query q = session.createQuery(sql);
1370    
1371                    q.setFirstResult(0);
1372                    q.setMaxResults(2);
1373    
1374                    QueryPos qPos = QueryPos.getInstance(q);
1375    
1376                    if (bindUuid) {
1377                            qPos.add(uuid);
1378                    }
1379    
1380                    qPos.add(companyId);
1381    
1382                    if (orderByComparator != null) {
1383                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1384    
1385                            for (Object value : values) {
1386                                    qPos.add(value);
1387                            }
1388                    }
1389    
1390                    List<MBThread> list = q.list();
1391    
1392                    if (list.size() == 2) {
1393                            return list.get(1);
1394                    }
1395                    else {
1396                            return null;
1397                    }
1398            }
1399    
1400            /**
1401             * Removes all the message boards threads where uuid = &#63; and companyId = &#63; from the database.
1402             *
1403             * @param uuid the uuid
1404             * @param companyId the company ID
1405             */
1406            @Override
1407            public void removeByUuid_C(String uuid, long companyId) {
1408                    for (MBThread mbThread : findByUuid_C(uuid, companyId,
1409                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1410                            remove(mbThread);
1411                    }
1412            }
1413    
1414            /**
1415             * Returns the number of message boards threads where uuid = &#63; and companyId = &#63;.
1416             *
1417             * @param uuid the uuid
1418             * @param companyId the company ID
1419             * @return the number of matching message boards threads
1420             */
1421            @Override
1422            public int countByUuid_C(String uuid, long companyId) {
1423                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1424    
1425                    Object[] finderArgs = new Object[] { uuid, companyId };
1426    
1427                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1428    
1429                    if (count == null) {
1430                            StringBundler query = new StringBundler(3);
1431    
1432                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
1433    
1434                            boolean bindUuid = false;
1435    
1436                            if (uuid == null) {
1437                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1438                            }
1439                            else if (uuid.equals(StringPool.BLANK)) {
1440                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1441                            }
1442                            else {
1443                                    bindUuid = true;
1444    
1445                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1446                            }
1447    
1448                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1449    
1450                            String sql = query.toString();
1451    
1452                            Session session = null;
1453    
1454                            try {
1455                                    session = openSession();
1456    
1457                                    Query q = session.createQuery(sql);
1458    
1459                                    QueryPos qPos = QueryPos.getInstance(q);
1460    
1461                                    if (bindUuid) {
1462                                            qPos.add(uuid);
1463                                    }
1464    
1465                                    qPos.add(companyId);
1466    
1467                                    count = (Long)q.uniqueResult();
1468    
1469                                    finderCache.putResult(finderPath, finderArgs, count);
1470                            }
1471                            catch (Exception e) {
1472                                    finderCache.removeResult(finderPath, finderArgs);
1473    
1474                                    throw processException(e);
1475                            }
1476                            finally {
1477                                    closeSession(session);
1478                            }
1479                    }
1480    
1481                    return count.intValue();
1482            }
1483    
1484            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbThread.uuid IS NULL AND ";
1485            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbThread.uuid = ? AND ";
1486            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbThread.uuid IS NULL OR mbThread.uuid = '') AND ";
1487            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbThread.companyId = ?";
1488            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1489                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
1490                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1491                            new String[] {
1492                                    Long.class.getName(),
1493                                    
1494                            Integer.class.getName(), Integer.class.getName(),
1495                                    OrderByComparator.class.getName()
1496                            });
1497            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1498                    new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1499                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
1500                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1501                            new String[] { Long.class.getName() },
1502                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
1503                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
1504                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
1505            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1506                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
1507                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1508                            new String[] { Long.class.getName() });
1509    
1510            /**
1511             * Returns all the message boards threads where groupId = &#63;.
1512             *
1513             * @param groupId the group ID
1514             * @return the matching message boards threads
1515             */
1516            @Override
1517            public List<MBThread> findByGroupId(long groupId) {
1518                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1519            }
1520    
1521            /**
1522             * Returns a range of all the message boards threads where groupId = &#63;.
1523             *
1524             * <p>
1525             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1526             * </p>
1527             *
1528             * @param groupId the group ID
1529             * @param start the lower bound of the range of message boards threads
1530             * @param end the upper bound of the range of message boards threads (not inclusive)
1531             * @return the range of matching message boards threads
1532             */
1533            @Override
1534            public List<MBThread> findByGroupId(long groupId, int start, int end) {
1535                    return findByGroupId(groupId, start, end, null);
1536            }
1537    
1538            /**
1539             * Returns an ordered range of all the message boards threads where groupId = &#63;.
1540             *
1541             * <p>
1542             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1543             * </p>
1544             *
1545             * @param groupId the group ID
1546             * @param start the lower bound of the range of message boards threads
1547             * @param end the upper bound of the range of message boards threads (not inclusive)
1548             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1549             * @return the ordered range of matching message boards threads
1550             */
1551            @Override
1552            public List<MBThread> findByGroupId(long groupId, int start, int end,
1553                    OrderByComparator<MBThread> orderByComparator) {
1554                    return findByGroupId(groupId, start, end, orderByComparator, true);
1555            }
1556    
1557            /**
1558             * Returns an ordered range of all the message boards threads where groupId = &#63;.
1559             *
1560             * <p>
1561             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1562             * </p>
1563             *
1564             * @param groupId the group ID
1565             * @param start the lower bound of the range of message boards threads
1566             * @param end the upper bound of the range of message boards threads (not inclusive)
1567             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1568             * @param retrieveFromCache whether to retrieve from the finder cache
1569             * @return the ordered range of matching message boards threads
1570             */
1571            @Override
1572            public List<MBThread> findByGroupId(long groupId, int start, int end,
1573                    OrderByComparator<MBThread> orderByComparator, boolean retrieveFromCache) {
1574                    boolean pagination = true;
1575                    FinderPath finderPath = null;
1576                    Object[] finderArgs = null;
1577    
1578                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1579                                    (orderByComparator == null)) {
1580                            pagination = false;
1581                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1582                            finderArgs = new Object[] { groupId };
1583                    }
1584                    else {
1585                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1586                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1587                    }
1588    
1589                    List<MBThread> list = null;
1590    
1591                    if (retrieveFromCache) {
1592                            list = (List<MBThread>)finderCache.getResult(finderPath,
1593                                            finderArgs, this);
1594    
1595                            if ((list != null) && !list.isEmpty()) {
1596                                    for (MBThread mbThread : list) {
1597                                            if ((groupId != mbThread.getGroupId())) {
1598                                                    list = null;
1599    
1600                                                    break;
1601                                            }
1602                                    }
1603                            }
1604                    }
1605    
1606                    if (list == null) {
1607                            StringBundler query = null;
1608    
1609                            if (orderByComparator != null) {
1610                                    query = new StringBundler(3 +
1611                                                    (orderByComparator.getOrderByFields().length * 2));
1612                            }
1613                            else {
1614                                    query = new StringBundler(3);
1615                            }
1616    
1617                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
1618    
1619                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1620    
1621                            if (orderByComparator != null) {
1622                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1623                                            orderByComparator);
1624                            }
1625                            else
1626                             if (pagination) {
1627                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1628                            }
1629    
1630                            String sql = query.toString();
1631    
1632                            Session session = null;
1633    
1634                            try {
1635                                    session = openSession();
1636    
1637                                    Query q = session.createQuery(sql);
1638    
1639                                    QueryPos qPos = QueryPos.getInstance(q);
1640    
1641                                    qPos.add(groupId);
1642    
1643                                    if (!pagination) {
1644                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1645                                                            start, end, false);
1646    
1647                                            Collections.sort(list);
1648    
1649                                            list = Collections.unmodifiableList(list);
1650                                    }
1651                                    else {
1652                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1653                                                            start, end);
1654                                    }
1655    
1656                                    cacheResult(list);
1657    
1658                                    finderCache.putResult(finderPath, finderArgs, list);
1659                            }
1660                            catch (Exception e) {
1661                                    finderCache.removeResult(finderPath, finderArgs);
1662    
1663                                    throw processException(e);
1664                            }
1665                            finally {
1666                                    closeSession(session);
1667                            }
1668                    }
1669    
1670                    return list;
1671            }
1672    
1673            /**
1674             * Returns the first message boards thread in the ordered set where groupId = &#63;.
1675             *
1676             * @param groupId the group ID
1677             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1678             * @return the first matching message boards thread
1679             * @throws NoSuchThreadException if a matching message boards thread could not be found
1680             */
1681            @Override
1682            public MBThread findByGroupId_First(long groupId,
1683                    OrderByComparator<MBThread> orderByComparator)
1684                    throws NoSuchThreadException {
1685                    MBThread mbThread = fetchByGroupId_First(groupId, orderByComparator);
1686    
1687                    if (mbThread != null) {
1688                            return mbThread;
1689                    }
1690    
1691                    StringBundler msg = new StringBundler(4);
1692    
1693                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1694    
1695                    msg.append("groupId=");
1696                    msg.append(groupId);
1697    
1698                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1699    
1700                    throw new NoSuchThreadException(msg.toString());
1701            }
1702    
1703            /**
1704             * Returns the first message boards thread in the ordered set where groupId = &#63;.
1705             *
1706             * @param groupId the group ID
1707             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1708             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1709             */
1710            @Override
1711            public MBThread fetchByGroupId_First(long groupId,
1712                    OrderByComparator<MBThread> orderByComparator) {
1713                    List<MBThread> list = findByGroupId(groupId, 0, 1, orderByComparator);
1714    
1715                    if (!list.isEmpty()) {
1716                            return list.get(0);
1717                    }
1718    
1719                    return null;
1720            }
1721    
1722            /**
1723             * Returns the last message boards thread in the ordered set where groupId = &#63;.
1724             *
1725             * @param groupId the group ID
1726             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1727             * @return the last matching message boards thread
1728             * @throws NoSuchThreadException if a matching message boards thread could not be found
1729             */
1730            @Override
1731            public MBThread findByGroupId_Last(long groupId,
1732                    OrderByComparator<MBThread> orderByComparator)
1733                    throws NoSuchThreadException {
1734                    MBThread mbThread = fetchByGroupId_Last(groupId, orderByComparator);
1735    
1736                    if (mbThread != null) {
1737                            return mbThread;
1738                    }
1739    
1740                    StringBundler msg = new StringBundler(4);
1741    
1742                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1743    
1744                    msg.append("groupId=");
1745                    msg.append(groupId);
1746    
1747                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1748    
1749                    throw new NoSuchThreadException(msg.toString());
1750            }
1751    
1752            /**
1753             * Returns the last message boards thread in the ordered set where groupId = &#63;.
1754             *
1755             * @param groupId the group ID
1756             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1757             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1758             */
1759            @Override
1760            public MBThread fetchByGroupId_Last(long groupId,
1761                    OrderByComparator<MBThread> orderByComparator) {
1762                    int count = countByGroupId(groupId);
1763    
1764                    if (count == 0) {
1765                            return null;
1766                    }
1767    
1768                    List<MBThread> list = findByGroupId(groupId, count - 1, count,
1769                                    orderByComparator);
1770    
1771                    if (!list.isEmpty()) {
1772                            return list.get(0);
1773                    }
1774    
1775                    return null;
1776            }
1777    
1778            /**
1779             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63;.
1780             *
1781             * @param threadId the primary key of the current message boards thread
1782             * @param groupId the group ID
1783             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1784             * @return the previous, current, and next message boards thread
1785             * @throws NoSuchThreadException if a message boards thread with the primary key could not be found
1786             */
1787            @Override
1788            public MBThread[] findByGroupId_PrevAndNext(long threadId, long groupId,
1789                    OrderByComparator<MBThread> orderByComparator)
1790                    throws NoSuchThreadException {
1791                    MBThread mbThread = findByPrimaryKey(threadId);
1792    
1793                    Session session = null;
1794    
1795                    try {
1796                            session = openSession();
1797    
1798                            MBThread[] array = new MBThreadImpl[3];
1799    
1800                            array[0] = getByGroupId_PrevAndNext(session, mbThread, groupId,
1801                                            orderByComparator, true);
1802    
1803                            array[1] = mbThread;
1804    
1805                            array[2] = getByGroupId_PrevAndNext(session, mbThread, groupId,
1806                                            orderByComparator, false);
1807    
1808                            return array;
1809                    }
1810                    catch (Exception e) {
1811                            throw processException(e);
1812                    }
1813                    finally {
1814                            closeSession(session);
1815                    }
1816            }
1817    
1818            protected MBThread getByGroupId_PrevAndNext(Session session,
1819                    MBThread mbThread, long groupId,
1820                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
1821                    StringBundler query = null;
1822    
1823                    if (orderByComparator != null) {
1824                            query = new StringBundler(4 +
1825                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1826                                            (orderByComparator.getOrderByFields().length * 3));
1827                    }
1828                    else {
1829                            query = new StringBundler(3);
1830                    }
1831    
1832                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1833    
1834                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1835    
1836                    if (orderByComparator != null) {
1837                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1838    
1839                            if (orderByConditionFields.length > 0) {
1840                                    query.append(WHERE_AND);
1841                            }
1842    
1843                            for (int i = 0; i < orderByConditionFields.length; i++) {
1844                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1845                                    query.append(orderByConditionFields[i]);
1846    
1847                                    if ((i + 1) < orderByConditionFields.length) {
1848                                            if (orderByComparator.isAscending() ^ previous) {
1849                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1850                                            }
1851                                            else {
1852                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1853                                            }
1854                                    }
1855                                    else {
1856                                            if (orderByComparator.isAscending() ^ previous) {
1857                                                    query.append(WHERE_GREATER_THAN);
1858                                            }
1859                                            else {
1860                                                    query.append(WHERE_LESSER_THAN);
1861                                            }
1862                                    }
1863                            }
1864    
1865                            query.append(ORDER_BY_CLAUSE);
1866    
1867                            String[] orderByFields = orderByComparator.getOrderByFields();
1868    
1869                            for (int i = 0; i < orderByFields.length; i++) {
1870                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1871                                    query.append(orderByFields[i]);
1872    
1873                                    if ((i + 1) < orderByFields.length) {
1874                                            if (orderByComparator.isAscending() ^ previous) {
1875                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1876                                            }
1877                                            else {
1878                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1879                                            }
1880                                    }
1881                                    else {
1882                                            if (orderByComparator.isAscending() ^ previous) {
1883                                                    query.append(ORDER_BY_ASC);
1884                                            }
1885                                            else {
1886                                                    query.append(ORDER_BY_DESC);
1887                                            }
1888                                    }
1889                            }
1890                    }
1891                    else {
1892                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1893                    }
1894    
1895                    String sql = query.toString();
1896    
1897                    Query q = session.createQuery(sql);
1898    
1899                    q.setFirstResult(0);
1900                    q.setMaxResults(2);
1901    
1902                    QueryPos qPos = QueryPos.getInstance(q);
1903    
1904                    qPos.add(groupId);
1905    
1906                    if (orderByComparator != null) {
1907                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1908    
1909                            for (Object value : values) {
1910                                    qPos.add(value);
1911                            }
1912                    }
1913    
1914                    List<MBThread> list = q.list();
1915    
1916                    if (list.size() == 2) {
1917                            return list.get(1);
1918                    }
1919                    else {
1920                            return null;
1921                    }
1922            }
1923    
1924            /**
1925             * Returns all the message boards threads that the user has permission to view where groupId = &#63;.
1926             *
1927             * @param groupId the group ID
1928             * @return the matching message boards threads that the user has permission to view
1929             */
1930            @Override
1931            public List<MBThread> filterFindByGroupId(long groupId) {
1932                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1933                            QueryUtil.ALL_POS, null);
1934            }
1935    
1936            /**
1937             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63;.
1938             *
1939             * <p>
1940             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1941             * </p>
1942             *
1943             * @param groupId the group ID
1944             * @param start the lower bound of the range of message boards threads
1945             * @param end the upper bound of the range of message boards threads (not inclusive)
1946             * @return the range of matching message boards threads that the user has permission to view
1947             */
1948            @Override
1949            public List<MBThread> filterFindByGroupId(long groupId, int start, int end) {
1950                    return filterFindByGroupId(groupId, start, end, null);
1951            }
1952    
1953            /**
1954             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63;.
1955             *
1956             * <p>
1957             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1958             * </p>
1959             *
1960             * @param groupId the group ID
1961             * @param start the lower bound of the range of message boards threads
1962             * @param end the upper bound of the range of message boards threads (not inclusive)
1963             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1964             * @return the ordered range of matching message boards threads that the user has permission to view
1965             */
1966            @Override
1967            public List<MBThread> filterFindByGroupId(long groupId, int start, int end,
1968                    OrderByComparator<MBThread> orderByComparator) {
1969                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1970                            return findByGroupId(groupId, start, end, orderByComparator);
1971                    }
1972    
1973                    StringBundler query = null;
1974    
1975                    if (orderByComparator != null) {
1976                            query = new StringBundler(3 +
1977                                            (orderByComparator.getOrderByFields().length * 2));
1978                    }
1979                    else {
1980                            query = new StringBundler(4);
1981                    }
1982    
1983                    if (getDB().isSupportsInlineDistinct()) {
1984                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
1985                    }
1986                    else {
1987                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
1988                    }
1989    
1990                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1991    
1992                    if (!getDB().isSupportsInlineDistinct()) {
1993                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
1994                    }
1995    
1996                    if (orderByComparator != null) {
1997                            if (getDB().isSupportsInlineDistinct()) {
1998                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1999                                            orderByComparator, true);
2000                            }
2001                            else {
2002                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2003                                            orderByComparator, true);
2004                            }
2005                    }
2006                    else {
2007                            if (getDB().isSupportsInlineDistinct()) {
2008                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2009                            }
2010                            else {
2011                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
2012                            }
2013                    }
2014    
2015                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2016                                    MBThread.class.getName(),
2017                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2018    
2019                    Session session = null;
2020    
2021                    try {
2022                            session = openSession();
2023    
2024                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2025    
2026                            if (getDB().isSupportsInlineDistinct()) {
2027                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
2028                            }
2029                            else {
2030                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
2031                            }
2032    
2033                            QueryPos qPos = QueryPos.getInstance(q);
2034    
2035                            qPos.add(groupId);
2036    
2037                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
2038                    }
2039                    catch (Exception e) {
2040                            throw processException(e);
2041                    }
2042                    finally {
2043                            closeSession(session);
2044                    }
2045            }
2046    
2047            /**
2048             * 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;.
2049             *
2050             * @param threadId the primary key of the current message boards thread
2051             * @param groupId the group ID
2052             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2053             * @return the previous, current, and next message boards thread
2054             * @throws NoSuchThreadException if a message boards thread with the primary key could not be found
2055             */
2056            @Override
2057            public MBThread[] filterFindByGroupId_PrevAndNext(long threadId,
2058                    long groupId, OrderByComparator<MBThread> orderByComparator)
2059                    throws NoSuchThreadException {
2060                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2061                            return findByGroupId_PrevAndNext(threadId, groupId,
2062                                    orderByComparator);
2063                    }
2064    
2065                    MBThread mbThread = findByPrimaryKey(threadId);
2066    
2067                    Session session = null;
2068    
2069                    try {
2070                            session = openSession();
2071    
2072                            MBThread[] array = new MBThreadImpl[3];
2073    
2074                            array[0] = filterGetByGroupId_PrevAndNext(session, mbThread,
2075                                            groupId, orderByComparator, true);
2076    
2077                            array[1] = mbThread;
2078    
2079                            array[2] = filterGetByGroupId_PrevAndNext(session, mbThread,
2080                                            groupId, orderByComparator, false);
2081    
2082                            return array;
2083                    }
2084                    catch (Exception e) {
2085                            throw processException(e);
2086                    }
2087                    finally {
2088                            closeSession(session);
2089                    }
2090            }
2091    
2092            protected MBThread filterGetByGroupId_PrevAndNext(Session session,
2093                    MBThread mbThread, long groupId,
2094                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
2095                    StringBundler query = null;
2096    
2097                    if (orderByComparator != null) {
2098                            query = new StringBundler(5 +
2099                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2100                                            (orderByComparator.getOrderByFields().length * 3));
2101                    }
2102                    else {
2103                            query = new StringBundler(4);
2104                    }
2105    
2106                    if (getDB().isSupportsInlineDistinct()) {
2107                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2108                    }
2109                    else {
2110                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2111                    }
2112    
2113                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2114    
2115                    if (!getDB().isSupportsInlineDistinct()) {
2116                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
2117                    }
2118    
2119                    if (orderByComparator != null) {
2120                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2121    
2122                            if (orderByConditionFields.length > 0) {
2123                                    query.append(WHERE_AND);
2124                            }
2125    
2126                            for (int i = 0; i < orderByConditionFields.length; i++) {
2127                                    if (getDB().isSupportsInlineDistinct()) {
2128                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2129                                    }
2130                                    else {
2131                                            query.append(_ORDER_BY_ENTITY_TABLE);
2132                                    }
2133    
2134                                    query.append(orderByConditionFields[i]);
2135    
2136                                    if ((i + 1) < orderByConditionFields.length) {
2137                                            if (orderByComparator.isAscending() ^ previous) {
2138                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2139                                            }
2140                                            else {
2141                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2142                                            }
2143                                    }
2144                                    else {
2145                                            if (orderByComparator.isAscending() ^ previous) {
2146                                                    query.append(WHERE_GREATER_THAN);
2147                                            }
2148                                            else {
2149                                                    query.append(WHERE_LESSER_THAN);
2150                                            }
2151                                    }
2152                            }
2153    
2154                            query.append(ORDER_BY_CLAUSE);
2155    
2156                            String[] orderByFields = orderByComparator.getOrderByFields();
2157    
2158                            for (int i = 0; i < orderByFields.length; i++) {
2159                                    if (getDB().isSupportsInlineDistinct()) {
2160                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2161                                    }
2162                                    else {
2163                                            query.append(_ORDER_BY_ENTITY_TABLE);
2164                                    }
2165    
2166                                    query.append(orderByFields[i]);
2167    
2168                                    if ((i + 1) < orderByFields.length) {
2169                                            if (orderByComparator.isAscending() ^ previous) {
2170                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2171                                            }
2172                                            else {
2173                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2174                                            }
2175                                    }
2176                                    else {
2177                                            if (orderByComparator.isAscending() ^ previous) {
2178                                                    query.append(ORDER_BY_ASC);
2179                                            }
2180                                            else {
2181                                                    query.append(ORDER_BY_DESC);
2182                                            }
2183                                    }
2184                            }
2185                    }
2186                    else {
2187                            if (getDB().isSupportsInlineDistinct()) {
2188                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2189                            }
2190                            else {
2191                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
2192                            }
2193                    }
2194    
2195                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2196                                    MBThread.class.getName(),
2197                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2198    
2199                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2200    
2201                    q.setFirstResult(0);
2202                    q.setMaxResults(2);
2203    
2204                    if (getDB().isSupportsInlineDistinct()) {
2205                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
2206                    }
2207                    else {
2208                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
2209                    }
2210    
2211                    QueryPos qPos = QueryPos.getInstance(q);
2212    
2213                    qPos.add(groupId);
2214    
2215                    if (orderByComparator != null) {
2216                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
2217    
2218                            for (Object value : values) {
2219                                    qPos.add(value);
2220                            }
2221                    }
2222    
2223                    List<MBThread> list = q.list();
2224    
2225                    if (list.size() == 2) {
2226                            return list.get(1);
2227                    }
2228                    else {
2229                            return null;
2230                    }
2231            }
2232    
2233            /**
2234             * Removes all the message boards threads where groupId = &#63; from the database.
2235             *
2236             * @param groupId the group ID
2237             */
2238            @Override
2239            public void removeByGroupId(long groupId) {
2240                    for (MBThread mbThread : findByGroupId(groupId, QueryUtil.ALL_POS,
2241                                    QueryUtil.ALL_POS, null)) {
2242                            remove(mbThread);
2243                    }
2244            }
2245    
2246            /**
2247             * Returns the number of message boards threads where groupId = &#63;.
2248             *
2249             * @param groupId the group ID
2250             * @return the number of matching message boards threads
2251             */
2252            @Override
2253            public int countByGroupId(long groupId) {
2254                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2255    
2256                    Object[] finderArgs = new Object[] { groupId };
2257    
2258                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2259    
2260                    if (count == null) {
2261                            StringBundler query = new StringBundler(2);
2262    
2263                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
2264    
2265                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2266    
2267                            String sql = query.toString();
2268    
2269                            Session session = null;
2270    
2271                            try {
2272                                    session = openSession();
2273    
2274                                    Query q = session.createQuery(sql);
2275    
2276                                    QueryPos qPos = QueryPos.getInstance(q);
2277    
2278                                    qPos.add(groupId);
2279    
2280                                    count = (Long)q.uniqueResult();
2281    
2282                                    finderCache.putResult(finderPath, finderArgs, count);
2283                            }
2284                            catch (Exception e) {
2285                                    finderCache.removeResult(finderPath, finderArgs);
2286    
2287                                    throw processException(e);
2288                            }
2289                            finally {
2290                                    closeSession(session);
2291                            }
2292                    }
2293    
2294                    return count.intValue();
2295            }
2296    
2297            /**
2298             * Returns the number of message boards threads that the user has permission to view where groupId = &#63;.
2299             *
2300             * @param groupId the group ID
2301             * @return the number of matching message boards threads that the user has permission to view
2302             */
2303            @Override
2304            public int filterCountByGroupId(long groupId) {
2305                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2306                            return countByGroupId(groupId);
2307                    }
2308    
2309                    StringBundler query = new StringBundler(2);
2310    
2311                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
2312    
2313                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2314    
2315                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2316                                    MBThread.class.getName(),
2317                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2318    
2319                    Session session = null;
2320    
2321                    try {
2322                            session = openSession();
2323    
2324                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2325    
2326                            q.addScalar(COUNT_COLUMN_NAME,
2327                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2328    
2329                            QueryPos qPos = QueryPos.getInstance(q);
2330    
2331                            qPos.add(groupId);
2332    
2333                            Long count = (Long)q.uniqueResult();
2334    
2335                            return count.intValue();
2336                    }
2337                    catch (Exception e) {
2338                            throw processException(e);
2339                    }
2340                    finally {
2341                            closeSession(session);
2342                    }
2343            }
2344    
2345            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbThread.groupId = ? AND mbThread.categoryId != -1";
2346            public static final FinderPath FINDER_PATH_FETCH_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2347                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
2348                            FINDER_CLASS_NAME_ENTITY, "fetchByRootMessageId",
2349                            new String[] { Long.class.getName() },
2350                            MBThreadModelImpl.ROOTMESSAGEID_COLUMN_BITMASK);
2351            public static final FinderPath FINDER_PATH_COUNT_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2352                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
2353                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRootMessageId",
2354                            new String[] { Long.class.getName() });
2355    
2356            /**
2357             * Returns the message boards thread where rootMessageId = &#63; or throws a {@link NoSuchThreadException} if it could not be found.
2358             *
2359             * @param rootMessageId the root message ID
2360             * @return the matching message boards thread
2361             * @throws NoSuchThreadException if a matching message boards thread could not be found
2362             */
2363            @Override
2364            public MBThread findByRootMessageId(long rootMessageId)
2365                    throws NoSuchThreadException {
2366                    MBThread mbThread = fetchByRootMessageId(rootMessageId);
2367    
2368                    if (mbThread == null) {
2369                            StringBundler msg = new StringBundler(4);
2370    
2371                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2372    
2373                            msg.append("rootMessageId=");
2374                            msg.append(rootMessageId);
2375    
2376                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2377    
2378                            if (_log.isWarnEnabled()) {
2379                                    _log.warn(msg.toString());
2380                            }
2381    
2382                            throw new NoSuchThreadException(msg.toString());
2383                    }
2384    
2385                    return mbThread;
2386            }
2387    
2388            /**
2389             * Returns the message boards thread where rootMessageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2390             *
2391             * @param rootMessageId the root message ID
2392             * @return the matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
2393             */
2394            @Override
2395            public MBThread fetchByRootMessageId(long rootMessageId) {
2396                    return fetchByRootMessageId(rootMessageId, true);
2397            }
2398    
2399            /**
2400             * Returns the message boards thread where rootMessageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2401             *
2402             * @param rootMessageId the root message ID
2403             * @param retrieveFromCache whether to retrieve from the finder cache
2404             * @return the matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
2405             */
2406            @Override
2407            public MBThread fetchByRootMessageId(long rootMessageId,
2408                    boolean retrieveFromCache) {
2409                    Object[] finderArgs = new Object[] { rootMessageId };
2410    
2411                    Object result = null;
2412    
2413                    if (retrieveFromCache) {
2414                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2415                                            finderArgs, this);
2416                    }
2417    
2418                    if (result instanceof MBThread) {
2419                            MBThread mbThread = (MBThread)result;
2420    
2421                            if ((rootMessageId != mbThread.getRootMessageId())) {
2422                                    result = null;
2423                            }
2424                    }
2425    
2426                    if (result == null) {
2427                            StringBundler query = new StringBundler(3);
2428    
2429                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
2430    
2431                            query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
2432    
2433                            String sql = query.toString();
2434    
2435                            Session session = null;
2436    
2437                            try {
2438                                    session = openSession();
2439    
2440                                    Query q = session.createQuery(sql);
2441    
2442                                    QueryPos qPos = QueryPos.getInstance(q);
2443    
2444                                    qPos.add(rootMessageId);
2445    
2446                                    List<MBThread> list = q.list();
2447    
2448                                    if (list.isEmpty()) {
2449                                            finderCache.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2450                                                    finderArgs, list);
2451                                    }
2452                                    else {
2453                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
2454                                                    _log.warn(
2455                                                            "MBThreadPersistenceImpl.fetchByRootMessageId(long, boolean) with parameters (" +
2456                                                            StringUtil.merge(finderArgs) +
2457                                                            ") 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.");
2458                                            }
2459    
2460                                            MBThread mbThread = list.get(0);
2461    
2462                                            result = mbThread;
2463    
2464                                            cacheResult(mbThread);
2465    
2466                                            if ((mbThread.getRootMessageId() != rootMessageId)) {
2467                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2468                                                            finderArgs, mbThread);
2469                                            }
2470                                    }
2471                            }
2472                            catch (Exception e) {
2473                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2474                                            finderArgs);
2475    
2476                                    throw processException(e);
2477                            }
2478                            finally {
2479                                    closeSession(session);
2480                            }
2481                    }
2482    
2483                    if (result instanceof List<?>) {
2484                            return null;
2485                    }
2486                    else {
2487                            return (MBThread)result;
2488                    }
2489            }
2490    
2491            /**
2492             * Removes the message boards thread where rootMessageId = &#63; from the database.
2493             *
2494             * @param rootMessageId the root message ID
2495             * @return the message boards thread that was removed
2496             */
2497            @Override
2498            public MBThread removeByRootMessageId(long rootMessageId)
2499                    throws NoSuchThreadException {
2500                    MBThread mbThread = findByRootMessageId(rootMessageId);
2501    
2502                    return remove(mbThread);
2503            }
2504    
2505            /**
2506             * Returns the number of message boards threads where rootMessageId = &#63;.
2507             *
2508             * @param rootMessageId the root message ID
2509             * @return the number of matching message boards threads
2510             */
2511            @Override
2512            public int countByRootMessageId(long rootMessageId) {
2513                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ROOTMESSAGEID;
2514    
2515                    Object[] finderArgs = new Object[] { rootMessageId };
2516    
2517                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2518    
2519                    if (count == null) {
2520                            StringBundler query = new StringBundler(2);
2521    
2522                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
2523    
2524                            query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
2525    
2526                            String sql = query.toString();
2527    
2528                            Session session = null;
2529    
2530                            try {
2531                                    session = openSession();
2532    
2533                                    Query q = session.createQuery(sql);
2534    
2535                                    QueryPos qPos = QueryPos.getInstance(q);
2536    
2537                                    qPos.add(rootMessageId);
2538    
2539                                    count = (Long)q.uniqueResult();
2540    
2541                                    finderCache.putResult(finderPath, finderArgs, count);
2542                            }
2543                            catch (Exception e) {
2544                                    finderCache.removeResult(finderPath, finderArgs);
2545    
2546                                    throw processException(e);
2547                            }
2548                            finally {
2549                                    closeSession(session);
2550                            }
2551                    }
2552    
2553                    return count.intValue();
2554            }
2555    
2556            private static final String _FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2 = "mbThread.rootMessageId = ?";
2557            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2558                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
2559                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
2560                            new String[] {
2561                                    Long.class.getName(), Long.class.getName(),
2562                                    
2563                            Integer.class.getName(), Integer.class.getName(),
2564                                    OrderByComparator.class.getName()
2565                            });
2566            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2567                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
2568                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
2569                            new String[] { Long.class.getName(), Long.class.getName() },
2570                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
2571                            MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
2572                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
2573                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
2574            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2575                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
2576                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
2577                            new String[] { Long.class.getName(), Long.class.getName() });
2578            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2579                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
2580                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C",
2581                            new String[] { Long.class.getName(), Long.class.getName() });
2582    
2583            /**
2584             * Returns all the message boards threads where groupId = &#63; and categoryId = &#63;.
2585             *
2586             * @param groupId the group ID
2587             * @param categoryId the category ID
2588             * @return the matching message boards threads
2589             */
2590            @Override
2591            public List<MBThread> findByG_C(long groupId, long categoryId) {
2592                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
2593                            QueryUtil.ALL_POS, null);
2594            }
2595    
2596            /**
2597             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = &#63;.
2598             *
2599             * <p>
2600             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2601             * </p>
2602             *
2603             * @param groupId the group ID
2604             * @param categoryId the category ID
2605             * @param start the lower bound of the range of message boards threads
2606             * @param end the upper bound of the range of message boards threads (not inclusive)
2607             * @return the range of matching message boards threads
2608             */
2609            @Override
2610            public List<MBThread> findByG_C(long groupId, long categoryId, int start,
2611                    int end) {
2612                    return findByG_C(groupId, categoryId, start, end, null);
2613            }
2614    
2615            /**
2616             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63;.
2617             *
2618             * <p>
2619             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2620             * </p>
2621             *
2622             * @param groupId the group ID
2623             * @param categoryId the category ID
2624             * @param start the lower bound of the range of message boards threads
2625             * @param end the upper bound of the range of message boards threads (not inclusive)
2626             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2627             * @return the ordered range of matching message boards threads
2628             */
2629            @Override
2630            public List<MBThread> findByG_C(long groupId, long categoryId, int start,
2631                    int end, OrderByComparator<MBThread> orderByComparator) {
2632                    return findByG_C(groupId, categoryId, start, end, orderByComparator,
2633                            true);
2634            }
2635    
2636            /**
2637             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63;.
2638             *
2639             * <p>
2640             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2641             * </p>
2642             *
2643             * @param groupId the group ID
2644             * @param categoryId the category ID
2645             * @param start the lower bound of the range of message boards threads
2646             * @param end the upper bound of the range of message boards threads (not inclusive)
2647             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2648             * @param retrieveFromCache whether to retrieve from the finder cache
2649             * @return the ordered range of matching message boards threads
2650             */
2651            @Override
2652            public List<MBThread> findByG_C(long groupId, long categoryId, int start,
2653                    int end, OrderByComparator<MBThread> orderByComparator,
2654                    boolean retrieveFromCache) {
2655                    boolean pagination = true;
2656                    FinderPath finderPath = null;
2657                    Object[] finderArgs = null;
2658    
2659                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2660                                    (orderByComparator == null)) {
2661                            pagination = false;
2662                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
2663                            finderArgs = new Object[] { groupId, categoryId };
2664                    }
2665                    else {
2666                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
2667                            finderArgs = new Object[] {
2668                                            groupId, categoryId,
2669                                            
2670                                            start, end, orderByComparator
2671                                    };
2672                    }
2673    
2674                    List<MBThread> list = null;
2675    
2676                    if (retrieveFromCache) {
2677                            list = (List<MBThread>)finderCache.getResult(finderPath,
2678                                            finderArgs, this);
2679    
2680                            if ((list != null) && !list.isEmpty()) {
2681                                    for (MBThread mbThread : list) {
2682                                            if ((groupId != mbThread.getGroupId()) ||
2683                                                            (categoryId != mbThread.getCategoryId())) {
2684                                                    list = null;
2685    
2686                                                    break;
2687                                            }
2688                                    }
2689                            }
2690                    }
2691    
2692                    if (list == null) {
2693                            StringBundler query = null;
2694    
2695                            if (orderByComparator != null) {
2696                                    query = new StringBundler(4 +
2697                                                    (orderByComparator.getOrderByFields().length * 2));
2698                            }
2699                            else {
2700                                    query = new StringBundler(4);
2701                            }
2702    
2703                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
2704    
2705                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2706    
2707                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2708    
2709                            if (orderByComparator != null) {
2710                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2711                                            orderByComparator);
2712                            }
2713                            else
2714                             if (pagination) {
2715                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2716                            }
2717    
2718                            String sql = query.toString();
2719    
2720                            Session session = null;
2721    
2722                            try {
2723                                    session = openSession();
2724    
2725                                    Query q = session.createQuery(sql);
2726    
2727                                    QueryPos qPos = QueryPos.getInstance(q);
2728    
2729                                    qPos.add(groupId);
2730    
2731                                    qPos.add(categoryId);
2732    
2733                                    if (!pagination) {
2734                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2735                                                            start, end, false);
2736    
2737                                            Collections.sort(list);
2738    
2739                                            list = Collections.unmodifiableList(list);
2740                                    }
2741                                    else {
2742                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2743                                                            start, end);
2744                                    }
2745    
2746                                    cacheResult(list);
2747    
2748                                    finderCache.putResult(finderPath, finderArgs, list);
2749                            }
2750                            catch (Exception e) {
2751                                    finderCache.removeResult(finderPath, finderArgs);
2752    
2753                                    throw processException(e);
2754                            }
2755                            finally {
2756                                    closeSession(session);
2757                            }
2758                    }
2759    
2760                    return list;
2761            }
2762    
2763            /**
2764             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
2765             *
2766             * @param groupId the group ID
2767             * @param categoryId the category ID
2768             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2769             * @return the first matching message boards thread
2770             * @throws NoSuchThreadException if a matching message boards thread could not be found
2771             */
2772            @Override
2773            public MBThread findByG_C_First(long groupId, long categoryId,
2774                    OrderByComparator<MBThread> orderByComparator)
2775                    throws NoSuchThreadException {
2776                    MBThread mbThread = fetchByG_C_First(groupId, categoryId,
2777                                    orderByComparator);
2778    
2779                    if (mbThread != null) {
2780                            return mbThread;
2781                    }
2782    
2783                    StringBundler msg = new StringBundler(6);
2784    
2785                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2786    
2787                    msg.append("groupId=");
2788                    msg.append(groupId);
2789    
2790                    msg.append(", categoryId=");
2791                    msg.append(categoryId);
2792    
2793                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2794    
2795                    throw new NoSuchThreadException(msg.toString());
2796            }
2797    
2798            /**
2799             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
2800             *
2801             * @param groupId the group ID
2802             * @param categoryId the category ID
2803             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2804             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
2805             */
2806            @Override
2807            public MBThread fetchByG_C_First(long groupId, long categoryId,
2808                    OrderByComparator<MBThread> orderByComparator) {
2809                    List<MBThread> list = findByG_C(groupId, categoryId, 0, 1,
2810                                    orderByComparator);
2811    
2812                    if (!list.isEmpty()) {
2813                            return list.get(0);
2814                    }
2815    
2816                    return null;
2817            }
2818    
2819            /**
2820             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
2821             *
2822             * @param groupId the group ID
2823             * @param categoryId the category ID
2824             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2825             * @return the last matching message boards thread
2826             * @throws NoSuchThreadException if a matching message boards thread could not be found
2827             */
2828            @Override
2829            public MBThread findByG_C_Last(long groupId, long categoryId,
2830                    OrderByComparator<MBThread> orderByComparator)
2831                    throws NoSuchThreadException {
2832                    MBThread mbThread = fetchByG_C_Last(groupId, categoryId,
2833                                    orderByComparator);
2834    
2835                    if (mbThread != null) {
2836                            return mbThread;
2837                    }
2838    
2839                    StringBundler msg = new StringBundler(6);
2840    
2841                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2842    
2843                    msg.append("groupId=");
2844                    msg.append(groupId);
2845    
2846                    msg.append(", categoryId=");
2847                    msg.append(categoryId);
2848    
2849                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2850    
2851                    throw new NoSuchThreadException(msg.toString());
2852            }
2853    
2854            /**
2855             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
2856             *
2857             * @param groupId the group ID
2858             * @param categoryId the category ID
2859             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2860             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
2861             */
2862            @Override
2863            public MBThread fetchByG_C_Last(long groupId, long categoryId,
2864                    OrderByComparator<MBThread> orderByComparator) {
2865                    int count = countByG_C(groupId, categoryId);
2866    
2867                    if (count == 0) {
2868                            return null;
2869                    }
2870    
2871                    List<MBThread> list = findByG_C(groupId, categoryId, count - 1, count,
2872                                    orderByComparator);
2873    
2874                    if (!list.isEmpty()) {
2875                            return list.get(0);
2876                    }
2877    
2878                    return null;
2879            }
2880    
2881            /**
2882             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
2883             *
2884             * @param threadId the primary key of the current message boards thread
2885             * @param groupId the group ID
2886             * @param categoryId the category ID
2887             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2888             * @return the previous, current, and next message boards thread
2889             * @throws NoSuchThreadException if a message boards thread with the primary key could not be found
2890             */
2891            @Override
2892            public MBThread[] findByG_C_PrevAndNext(long threadId, long groupId,
2893                    long categoryId, OrderByComparator<MBThread> orderByComparator)
2894                    throws NoSuchThreadException {
2895                    MBThread mbThread = findByPrimaryKey(threadId);
2896    
2897                    Session session = null;
2898    
2899                    try {
2900                            session = openSession();
2901    
2902                            MBThread[] array = new MBThreadImpl[3];
2903    
2904                            array[0] = getByG_C_PrevAndNext(session, mbThread, groupId,
2905                                            categoryId, orderByComparator, true);
2906    
2907                            array[1] = mbThread;
2908    
2909                            array[2] = getByG_C_PrevAndNext(session, mbThread, groupId,
2910                                            categoryId, orderByComparator, false);
2911    
2912                            return array;
2913                    }
2914                    catch (Exception e) {
2915                            throw processException(e);
2916                    }
2917                    finally {
2918                            closeSession(session);
2919                    }
2920            }
2921    
2922            protected MBThread getByG_C_PrevAndNext(Session session, MBThread mbThread,
2923                    long groupId, long categoryId,
2924                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
2925                    StringBundler query = null;
2926    
2927                    if (orderByComparator != null) {
2928                            query = new StringBundler(5 +
2929                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2930                                            (orderByComparator.getOrderByFields().length * 3));
2931                    }
2932                    else {
2933                            query = new StringBundler(4);
2934                    }
2935    
2936                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
2937    
2938                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2939    
2940                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2941    
2942                    if (orderByComparator != null) {
2943                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2944    
2945                            if (orderByConditionFields.length > 0) {
2946                                    query.append(WHERE_AND);
2947                            }
2948    
2949                            for (int i = 0; i < orderByConditionFields.length; i++) {
2950                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2951                                    query.append(orderByConditionFields[i]);
2952    
2953                                    if ((i + 1) < orderByConditionFields.length) {
2954                                            if (orderByComparator.isAscending() ^ previous) {
2955                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2956                                            }
2957                                            else {
2958                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2959                                            }
2960                                    }
2961                                    else {
2962                                            if (orderByComparator.isAscending() ^ previous) {
2963                                                    query.append(WHERE_GREATER_THAN);
2964                                            }
2965                                            else {
2966                                                    query.append(WHERE_LESSER_THAN);
2967                                            }
2968                                    }
2969                            }
2970    
2971                            query.append(ORDER_BY_CLAUSE);
2972    
2973                            String[] orderByFields = orderByComparator.getOrderByFields();
2974    
2975                            for (int i = 0; i < orderByFields.length; i++) {
2976                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2977                                    query.append(orderByFields[i]);
2978    
2979                                    if ((i + 1) < orderByFields.length) {
2980                                            if (orderByComparator.isAscending() ^ previous) {
2981                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2982                                            }
2983                                            else {
2984                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2985                                            }
2986                                    }
2987                                    else {
2988                                            if (orderByComparator.isAscending() ^ previous) {
2989                                                    query.append(ORDER_BY_ASC);
2990                                            }
2991                                            else {
2992                                                    query.append(ORDER_BY_DESC);
2993                                            }
2994                                    }
2995                            }
2996                    }
2997                    else {
2998                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2999                    }
3000    
3001                    String sql = query.toString();
3002    
3003                    Query q = session.createQuery(sql);
3004    
3005                    q.setFirstResult(0);
3006                    q.setMaxResults(2);
3007    
3008                    QueryPos qPos = QueryPos.getInstance(q);
3009    
3010                    qPos.add(groupId);
3011    
3012                    qPos.add(categoryId);
3013    
3014                    if (orderByComparator != null) {
3015                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3016    
3017                            for (Object value : values) {
3018                                    qPos.add(value);
3019                            }
3020                    }
3021    
3022                    List<MBThread> list = q.list();
3023    
3024                    if (list.size() == 2) {
3025                            return list.get(1);
3026                    }
3027                    else {
3028                            return null;
3029                    }
3030            }
3031    
3032            /**
3033             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63;.
3034             *
3035             * @param groupId the group ID
3036             * @param categoryId the category ID
3037             * @return the matching message boards threads that the user has permission to view
3038             */
3039            @Override
3040            public List<MBThread> filterFindByG_C(long groupId, long categoryId) {
3041                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
3042                            QueryUtil.ALL_POS, null);
3043            }
3044    
3045            /**
3046             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63;.
3047             *
3048             * <p>
3049             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3050             * </p>
3051             *
3052             * @param groupId the group ID
3053             * @param categoryId the category ID
3054             * @param start the lower bound of the range of message boards threads
3055             * @param end the upper bound of the range of message boards threads (not inclusive)
3056             * @return the range of matching message boards threads that the user has permission to view
3057             */
3058            @Override
3059            public List<MBThread> filterFindByG_C(long groupId, long categoryId,
3060                    int start, int end) {
3061                    return filterFindByG_C(groupId, categoryId, start, end, null);
3062            }
3063    
3064            /**
3065             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
3066             *
3067             * <p>
3068             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3069             * </p>
3070             *
3071             * @param groupId the group ID
3072             * @param categoryId the category ID
3073             * @param start the lower bound of the range of message boards threads
3074             * @param end the upper bound of the range of message boards threads (not inclusive)
3075             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3076             * @return the ordered range of matching message boards threads that the user has permission to view
3077             */
3078            @Override
3079            public List<MBThread> filterFindByG_C(long groupId, long categoryId,
3080                    int start, int end, OrderByComparator<MBThread> orderByComparator) {
3081                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3082                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
3083                    }
3084    
3085                    StringBundler query = null;
3086    
3087                    if (orderByComparator != null) {
3088                            query = new StringBundler(4 +
3089                                            (orderByComparator.getOrderByFields().length * 2));
3090                    }
3091                    else {
3092                            query = new StringBundler(5);
3093                    }
3094    
3095                    if (getDB().isSupportsInlineDistinct()) {
3096                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3097                    }
3098                    else {
3099                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3100                    }
3101    
3102                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3103    
3104                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3105    
3106                    if (!getDB().isSupportsInlineDistinct()) {
3107                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3108                    }
3109    
3110                    if (orderByComparator != null) {
3111                            if (getDB().isSupportsInlineDistinct()) {
3112                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3113                                            orderByComparator, true);
3114                            }
3115                            else {
3116                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3117                                            orderByComparator, true);
3118                            }
3119                    }
3120                    else {
3121                            if (getDB().isSupportsInlineDistinct()) {
3122                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3123                            }
3124                            else {
3125                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
3126                            }
3127                    }
3128    
3129                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3130                                    MBThread.class.getName(),
3131                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3132    
3133                    Session session = null;
3134    
3135                    try {
3136                            session = openSession();
3137    
3138                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3139    
3140                            if (getDB().isSupportsInlineDistinct()) {
3141                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3142                            }
3143                            else {
3144                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3145                            }
3146    
3147                            QueryPos qPos = QueryPos.getInstance(q);
3148    
3149                            qPos.add(groupId);
3150    
3151                            qPos.add(categoryId);
3152    
3153                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3154                    }
3155                    catch (Exception e) {
3156                            throw processException(e);
3157                    }
3158                    finally {
3159                            closeSession(session);
3160                    }
3161            }
3162    
3163            /**
3164             * 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;.
3165             *
3166             * @param threadId the primary key of the current message boards thread
3167             * @param groupId the group ID
3168             * @param categoryId the category ID
3169             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3170             * @return the previous, current, and next message boards thread
3171             * @throws NoSuchThreadException if a message boards thread with the primary key could not be found
3172             */
3173            @Override
3174            public MBThread[] filterFindByG_C_PrevAndNext(long threadId, long groupId,
3175                    long categoryId, OrderByComparator<MBThread> orderByComparator)
3176                    throws NoSuchThreadException {
3177                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3178                            return findByG_C_PrevAndNext(threadId, groupId, categoryId,
3179                                    orderByComparator);
3180                    }
3181    
3182                    MBThread mbThread = findByPrimaryKey(threadId);
3183    
3184                    Session session = null;
3185    
3186                    try {
3187                            session = openSession();
3188    
3189                            MBThread[] array = new MBThreadImpl[3];
3190    
3191                            array[0] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
3192                                            categoryId, orderByComparator, true);
3193    
3194                            array[1] = mbThread;
3195    
3196                            array[2] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
3197                                            categoryId, orderByComparator, false);
3198    
3199                            return array;
3200                    }
3201                    catch (Exception e) {
3202                            throw processException(e);
3203                    }
3204                    finally {
3205                            closeSession(session);
3206                    }
3207            }
3208    
3209            protected MBThread filterGetByG_C_PrevAndNext(Session session,
3210                    MBThread mbThread, long groupId, long categoryId,
3211                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
3212                    StringBundler query = null;
3213    
3214                    if (orderByComparator != null) {
3215                            query = new StringBundler(6 +
3216                                            (orderByComparator.getOrderByConditionFields().length * 3) +
3217                                            (orderByComparator.getOrderByFields().length * 3));
3218                    }
3219                    else {
3220                            query = new StringBundler(5);
3221                    }
3222    
3223                    if (getDB().isSupportsInlineDistinct()) {
3224                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3225                    }
3226                    else {
3227                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3228                    }
3229    
3230                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3231    
3232                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3233    
3234                    if (!getDB().isSupportsInlineDistinct()) {
3235                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3236                    }
3237    
3238                    if (orderByComparator != null) {
3239                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3240    
3241                            if (orderByConditionFields.length > 0) {
3242                                    query.append(WHERE_AND);
3243                            }
3244    
3245                            for (int i = 0; i < orderByConditionFields.length; i++) {
3246                                    if (getDB().isSupportsInlineDistinct()) {
3247                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3248                                    }
3249                                    else {
3250                                            query.append(_ORDER_BY_ENTITY_TABLE);
3251                                    }
3252    
3253                                    query.append(orderByConditionFields[i]);
3254    
3255                                    if ((i + 1) < orderByConditionFields.length) {
3256                                            if (orderByComparator.isAscending() ^ previous) {
3257                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3258                                            }
3259                                            else {
3260                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3261                                            }
3262                                    }
3263                                    else {
3264                                            if (orderByComparator.isAscending() ^ previous) {
3265                                                    query.append(WHERE_GREATER_THAN);
3266                                            }
3267                                            else {
3268                                                    query.append(WHERE_LESSER_THAN);
3269                                            }
3270                                    }
3271                            }
3272    
3273                            query.append(ORDER_BY_CLAUSE);
3274    
3275                            String[] orderByFields = orderByComparator.getOrderByFields();
3276    
3277                            for (int i = 0; i < orderByFields.length; i++) {
3278                                    if (getDB().isSupportsInlineDistinct()) {
3279                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3280                                    }
3281                                    else {
3282                                            query.append(_ORDER_BY_ENTITY_TABLE);
3283                                    }
3284    
3285                                    query.append(orderByFields[i]);
3286    
3287                                    if ((i + 1) < orderByFields.length) {
3288                                            if (orderByComparator.isAscending() ^ previous) {
3289                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3290                                            }
3291                                            else {
3292                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3293                                            }
3294                                    }
3295                                    else {
3296                                            if (orderByComparator.isAscending() ^ previous) {
3297                                                    query.append(ORDER_BY_ASC);
3298                                            }
3299                                            else {
3300                                                    query.append(ORDER_BY_DESC);
3301                                            }
3302                                    }
3303                            }
3304                    }
3305                    else {
3306                            if (getDB().isSupportsInlineDistinct()) {
3307                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3308                            }
3309                            else {
3310                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
3311                            }
3312                    }
3313    
3314                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3315                                    MBThread.class.getName(),
3316                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3317    
3318                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
3319    
3320                    q.setFirstResult(0);
3321                    q.setMaxResults(2);
3322    
3323                    if (getDB().isSupportsInlineDistinct()) {
3324                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3325                    }
3326                    else {
3327                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3328                    }
3329    
3330                    QueryPos qPos = QueryPos.getInstance(q);
3331    
3332                    qPos.add(groupId);
3333    
3334                    qPos.add(categoryId);
3335    
3336                    if (orderByComparator != null) {
3337                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3338    
3339                            for (Object value : values) {
3340                                    qPos.add(value);
3341                            }
3342                    }
3343    
3344                    List<MBThread> list = q.list();
3345    
3346                    if (list.size() == 2) {
3347                            return list.get(1);
3348                    }
3349                    else {
3350                            return null;
3351                    }
3352            }
3353    
3354            /**
3355             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63;.
3356             *
3357             * @param groupId the group ID
3358             * @param categoryIds the category IDs
3359             * @return the matching message boards threads that the user has permission to view
3360             */
3361            @Override
3362            public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds) {
3363                    return filterFindByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
3364                            QueryUtil.ALL_POS, null);
3365            }
3366    
3367            /**
3368             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63;.
3369             *
3370             * <p>
3371             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3372             * </p>
3373             *
3374             * @param groupId the group ID
3375             * @param categoryIds the category IDs
3376             * @param start the lower bound of the range of message boards threads
3377             * @param end the upper bound of the range of message boards threads (not inclusive)
3378             * @return the range of matching message boards threads that the user has permission to view
3379             */
3380            @Override
3381            public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
3382                    int start, int end) {
3383                    return filterFindByG_C(groupId, categoryIds, start, end, null);
3384            }
3385    
3386            /**
3387             * Returns an ordered range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63;.
3388             *
3389             * <p>
3390             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the 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.
3391             * </p>
3392             *
3393             * @param groupId the group ID
3394             * @param categoryIds the category IDs
3395             * @param start the lower bound of the range of message boards threads
3396             * @param end the upper bound of the range of message boards threads (not inclusive)
3397             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3398             * @return the ordered range of matching message boards threads that the user has permission to view
3399             */
3400            @Override
3401            public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
3402                    int start, int end, OrderByComparator<MBThread> orderByComparator) {
3403                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3404                            return findByG_C(groupId, categoryIds, start, end, orderByComparator);
3405                    }
3406    
3407                    if (categoryIds == null) {
3408                            categoryIds = new long[0];
3409                    }
3410                    else if (categoryIds.length > 1) {
3411                            categoryIds = ArrayUtil.unique(categoryIds);
3412    
3413                            Arrays.sort(categoryIds);
3414                    }
3415    
3416                    StringBundler query = new StringBundler();
3417    
3418                    if (getDB().isSupportsInlineDistinct()) {
3419                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3420                    }
3421                    else {
3422                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3423                    }
3424    
3425                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3426    
3427                    if (categoryIds.length > 0) {
3428                            query.append(StringPool.OPEN_PARENTHESIS);
3429    
3430                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_7);
3431    
3432                            query.append(StringUtil.merge(categoryIds));
3433    
3434                            query.append(StringPool.CLOSE_PARENTHESIS);
3435    
3436                            query.append(StringPool.CLOSE_PARENTHESIS);
3437                    }
3438    
3439                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
3440                            query.index() - 1);
3441    
3442                    if (!getDB().isSupportsInlineDistinct()) {
3443                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3444                    }
3445    
3446                    if (orderByComparator != null) {
3447                            if (getDB().isSupportsInlineDistinct()) {
3448                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3449                                            orderByComparator, true);
3450                            }
3451                            else {
3452                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3453                                            orderByComparator, true);
3454                            }
3455                    }
3456                    else {
3457                            if (getDB().isSupportsInlineDistinct()) {
3458                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3459                            }
3460                            else {
3461                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
3462                            }
3463                    }
3464    
3465                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3466                                    MBThread.class.getName(),
3467                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3468    
3469                    Session session = null;
3470    
3471                    try {
3472                            session = openSession();
3473    
3474                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3475    
3476                            if (getDB().isSupportsInlineDistinct()) {
3477                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3478                            }
3479                            else {
3480                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3481                            }
3482    
3483                            QueryPos qPos = QueryPos.getInstance(q);
3484    
3485                            qPos.add(groupId);
3486    
3487                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3488                    }
3489                    catch (Exception e) {
3490                            throw processException(e);
3491                    }
3492                    finally {
3493                            closeSession(session);
3494                    }
3495            }
3496    
3497            /**
3498             * Returns all the message boards threads where groupId = &#63; and categoryId = any &#63;.
3499             *
3500             * <p>
3501             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3502             * </p>
3503             *
3504             * @param groupId the group ID
3505             * @param categoryIds the category IDs
3506             * @return the matching message boards threads
3507             */
3508            @Override
3509            public List<MBThread> findByG_C(long groupId, long[] categoryIds) {
3510                    return findByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
3511                            QueryUtil.ALL_POS, null);
3512            }
3513    
3514            /**
3515             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = any &#63;.
3516             *
3517             * <p>
3518             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3519             * </p>
3520             *
3521             * @param groupId the group ID
3522             * @param categoryIds the category IDs
3523             * @param start the lower bound of the range of message boards threads
3524             * @param end the upper bound of the range of message boards threads (not inclusive)
3525             * @return the range of matching message boards threads
3526             */
3527            @Override
3528            public List<MBThread> findByG_C(long groupId, long[] categoryIds,
3529                    int start, int end) {
3530                    return findByG_C(groupId, categoryIds, start, end, null);
3531            }
3532    
3533            /**
3534             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = any &#63;.
3535             *
3536             * <p>
3537             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3538             * </p>
3539             *
3540             * @param groupId the group ID
3541             * @param categoryIds the category IDs
3542             * @param start the lower bound of the range of message boards threads
3543             * @param end the upper bound of the range of message boards threads (not inclusive)
3544             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3545             * @return the ordered range of matching message boards threads
3546             */
3547            @Override
3548            public List<MBThread> findByG_C(long groupId, long[] categoryIds,
3549                    int start, int end, OrderByComparator<MBThread> orderByComparator) {
3550                    return findByG_C(groupId, categoryIds, start, end, orderByComparator,
3551                            true);
3552            }
3553    
3554            /**
3555             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63;, optionally using the finder cache.
3556             *
3557             * <p>
3558             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3559             * </p>
3560             *
3561             * @param groupId the group ID
3562             * @param categoryId the category ID
3563             * @param start the lower bound of the range of message boards threads
3564             * @param end the upper bound of the range of message boards threads (not inclusive)
3565             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3566             * @param retrieveFromCache whether to retrieve from the finder cache
3567             * @return the ordered range of matching message boards threads
3568             */
3569            @Override
3570            public List<MBThread> findByG_C(long groupId, long[] categoryIds,
3571                    int start, int end, OrderByComparator<MBThread> orderByComparator,
3572                    boolean retrieveFromCache) {
3573                    if (categoryIds == null) {
3574                            categoryIds = new long[0];
3575                    }
3576                    else if (categoryIds.length > 1) {
3577                            categoryIds = ArrayUtil.unique(categoryIds);
3578    
3579                            Arrays.sort(categoryIds);
3580                    }
3581    
3582                    if (categoryIds.length == 1) {
3583                            return findByG_C(groupId, categoryIds[0], start, end,
3584                                    orderByComparator);
3585                    }
3586    
3587                    boolean pagination = true;
3588                    Object[] finderArgs = null;
3589    
3590                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3591                                    (orderByComparator == null)) {
3592                            pagination = false;
3593                            finderArgs = new Object[] { groupId, StringUtil.merge(categoryIds) };
3594                    }
3595                    else {
3596                            finderArgs = new Object[] {
3597                                            groupId, StringUtil.merge(categoryIds),
3598                                            
3599                                            start, end, orderByComparator
3600                                    };
3601                    }
3602    
3603                    List<MBThread> list = null;
3604    
3605                    if (retrieveFromCache) {
3606                            list = (List<MBThread>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
3607                                            finderArgs, this);
3608    
3609                            if ((list != null) && !list.isEmpty()) {
3610                                    for (MBThread mbThread : list) {
3611                                            if ((groupId != mbThread.getGroupId()) ||
3612                                                            !ArrayUtil.contains(categoryIds,
3613                                                                    mbThread.getCategoryId())) {
3614                                                    list = null;
3615    
3616                                                    break;
3617                                            }
3618                                    }
3619                            }
3620                    }
3621    
3622                    if (list == null) {
3623                            StringBundler query = new StringBundler();
3624    
3625                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
3626    
3627                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3628    
3629                            if (categoryIds.length > 0) {
3630                                    query.append(StringPool.OPEN_PARENTHESIS);
3631    
3632                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_7);
3633    
3634                                    query.append(StringUtil.merge(categoryIds));
3635    
3636                                    query.append(StringPool.CLOSE_PARENTHESIS);
3637    
3638                                    query.append(StringPool.CLOSE_PARENTHESIS);
3639                            }
3640    
3641                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
3642                                                    1)), query.index() - 1);
3643    
3644                            if (orderByComparator != null) {
3645                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3646                                            orderByComparator);
3647                            }
3648                            else
3649                             if (pagination) {
3650                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3651                            }
3652    
3653                            String sql = query.toString();
3654    
3655                            Session session = null;
3656    
3657                            try {
3658                                    session = openSession();
3659    
3660                                    Query q = session.createQuery(sql);
3661    
3662                                    QueryPos qPos = QueryPos.getInstance(q);
3663    
3664                                    qPos.add(groupId);
3665    
3666                                    if (!pagination) {
3667                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3668                                                            start, end, false);
3669    
3670                                            Collections.sort(list);
3671    
3672                                            list = Collections.unmodifiableList(list);
3673                                    }
3674                                    else {
3675                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3676                                                            start, end);
3677                                    }
3678    
3679                                    cacheResult(list);
3680    
3681                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
3682                                            finderArgs, list);
3683                            }
3684                            catch (Exception e) {
3685                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
3686                                            finderArgs);
3687    
3688                                    throw processException(e);
3689                            }
3690                            finally {
3691                                    closeSession(session);
3692                            }
3693                    }
3694    
3695                    return list;
3696            }
3697    
3698            /**
3699             * Removes all the message boards threads where groupId = &#63; and categoryId = &#63; from the database.
3700             *
3701             * @param groupId the group ID
3702             * @param categoryId the category ID
3703             */
3704            @Override
3705            public void removeByG_C(long groupId, long categoryId) {
3706                    for (MBThread mbThread : findByG_C(groupId, categoryId,
3707                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3708                            remove(mbThread);
3709                    }
3710            }
3711    
3712            /**
3713             * Returns the number of message boards threads where groupId = &#63; and categoryId = &#63;.
3714             *
3715             * @param groupId the group ID
3716             * @param categoryId the category ID
3717             * @return the number of matching message boards threads
3718             */
3719            @Override
3720            public int countByG_C(long groupId, long categoryId) {
3721                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
3722    
3723                    Object[] finderArgs = new Object[] { groupId, categoryId };
3724    
3725                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3726    
3727                    if (count == null) {
3728                            StringBundler query = new StringBundler(3);
3729    
3730                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
3731    
3732                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3733    
3734                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3735    
3736                            String sql = query.toString();
3737    
3738                            Session session = null;
3739    
3740                            try {
3741                                    session = openSession();
3742    
3743                                    Query q = session.createQuery(sql);
3744    
3745                                    QueryPos qPos = QueryPos.getInstance(q);
3746    
3747                                    qPos.add(groupId);
3748    
3749                                    qPos.add(categoryId);
3750    
3751                                    count = (Long)q.uniqueResult();
3752    
3753                                    finderCache.putResult(finderPath, finderArgs, count);
3754                            }
3755                            catch (Exception e) {
3756                                    finderCache.removeResult(finderPath, finderArgs);
3757    
3758                                    throw processException(e);
3759                            }
3760                            finally {
3761                                    closeSession(session);
3762                            }
3763                    }
3764    
3765                    return count.intValue();
3766            }
3767    
3768            /**
3769             * Returns the number of message boards threads where groupId = &#63; and categoryId = any &#63;.
3770             *
3771             * @param groupId the group ID
3772             * @param categoryIds the category IDs
3773             * @return the number of matching message boards threads
3774             */
3775            @Override
3776            public int countByG_C(long groupId, long[] categoryIds) {
3777                    if (categoryIds == null) {
3778                            categoryIds = new long[0];
3779                    }
3780                    else if (categoryIds.length > 1) {
3781                            categoryIds = ArrayUtil.unique(categoryIds);
3782    
3783                            Arrays.sort(categoryIds);
3784                    }
3785    
3786                    Object[] finderArgs = new Object[] {
3787                                    groupId, StringUtil.merge(categoryIds)
3788                            };
3789    
3790                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
3791                                    finderArgs, this);
3792    
3793                    if (count == null) {
3794                            StringBundler query = new StringBundler();
3795    
3796                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
3797    
3798                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3799    
3800                            if (categoryIds.length > 0) {
3801                                    query.append(StringPool.OPEN_PARENTHESIS);
3802    
3803                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_7);
3804    
3805                                    query.append(StringUtil.merge(categoryIds));
3806    
3807                                    query.append(StringPool.CLOSE_PARENTHESIS);
3808    
3809                                    query.append(StringPool.CLOSE_PARENTHESIS);
3810                            }
3811    
3812                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
3813                                                    1)), query.index() - 1);
3814    
3815                            String sql = query.toString();
3816    
3817                            Session session = null;
3818    
3819                            try {
3820                                    session = openSession();
3821    
3822                                    Query q = session.createQuery(sql);
3823    
3824                                    QueryPos qPos = QueryPos.getInstance(q);
3825    
3826                                    qPos.add(groupId);
3827    
3828                                    count = (Long)q.uniqueResult();
3829    
3830                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
3831                                            finderArgs, count);
3832                            }
3833                            catch (Exception e) {
3834                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
3835                                            finderArgs);
3836    
3837                                    throw processException(e);
3838                            }
3839                            finally {
3840                                    closeSession(session);
3841                            }
3842                    }
3843    
3844                    return count.intValue();
3845            }
3846    
3847            /**
3848             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63;.
3849             *
3850             * @param groupId the group ID
3851             * @param categoryId the category ID
3852             * @return the number of matching message boards threads that the user has permission to view
3853             */
3854            @Override
3855            public int filterCountByG_C(long groupId, long categoryId) {
3856                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3857                            return countByG_C(groupId, categoryId);
3858                    }
3859    
3860                    StringBundler query = new StringBundler(3);
3861    
3862                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
3863    
3864                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3865    
3866                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3867    
3868                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3869                                    MBThread.class.getName(),
3870                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3871    
3872                    Session session = null;
3873    
3874                    try {
3875                            session = openSession();
3876    
3877                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3878    
3879                            q.addScalar(COUNT_COLUMN_NAME,
3880                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3881    
3882                            QueryPos qPos = QueryPos.getInstance(q);
3883    
3884                            qPos.add(groupId);
3885    
3886                            qPos.add(categoryId);
3887    
3888                            Long count = (Long)q.uniqueResult();
3889    
3890                            return count.intValue();
3891                    }
3892                    catch (Exception e) {
3893                            throw processException(e);
3894                    }
3895                    finally {
3896                            closeSession(session);
3897                    }
3898            }
3899    
3900            /**
3901             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63;.
3902             *
3903             * @param groupId the group ID
3904             * @param categoryIds the category IDs
3905             * @return the number of matching message boards threads that the user has permission to view
3906             */
3907            @Override
3908            public int filterCountByG_C(long groupId, long[] categoryIds) {
3909                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3910                            return countByG_C(groupId, categoryIds);
3911                    }
3912    
3913                    if (categoryIds == null) {
3914                            categoryIds = new long[0];
3915                    }
3916                    else if (categoryIds.length > 1) {
3917                            categoryIds = ArrayUtil.unique(categoryIds);
3918    
3919                            Arrays.sort(categoryIds);
3920                    }
3921    
3922                    StringBundler query = new StringBundler();
3923    
3924                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
3925    
3926                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3927    
3928                    if (categoryIds.length > 0) {
3929                            query.append(StringPool.OPEN_PARENTHESIS);
3930    
3931                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_7);
3932    
3933                            query.append(StringUtil.merge(categoryIds));
3934    
3935                            query.append(StringPool.CLOSE_PARENTHESIS);
3936    
3937                            query.append(StringPool.CLOSE_PARENTHESIS);
3938                    }
3939    
3940                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
3941                            query.index() - 1);
3942    
3943                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3944                                    MBThread.class.getName(),
3945                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3946    
3947                    Session session = null;
3948    
3949                    try {
3950                            session = openSession();
3951    
3952                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3953    
3954                            q.addScalar(COUNT_COLUMN_NAME,
3955                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3956    
3957                            QueryPos qPos = QueryPos.getInstance(q);
3958    
3959                            qPos.add(groupId);
3960    
3961                            Long count = (Long)q.uniqueResult();
3962    
3963                            return count.intValue();
3964                    }
3965                    catch (Exception e) {
3966                            throw processException(e);
3967                    }
3968                    finally {
3969                            closeSession(session);
3970                    }
3971            }
3972    
3973            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbThread.groupId = ? AND ";
3974            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbThread.categoryId = ?";
3975            private static final String _FINDER_COLUMN_G_C_CATEGORYID_7 = "mbThread.categoryId IN (";
3976            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
3977                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
3978                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC",
3979                            new String[] {
3980                                    Long.class.getName(), Long.class.getName(),
3981                                    
3982                            Integer.class.getName(), Integer.class.getName(),
3983                                    OrderByComparator.class.getName()
3984                            });
3985            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
3986                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
3987                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC",
3988                            new String[] { Long.class.getName(), Long.class.getName() });
3989    
3990            /**
3991             * Returns all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
3992             *
3993             * @param groupId the group ID
3994             * @param categoryId the category ID
3995             * @return the matching message boards threads
3996             */
3997            @Override
3998            public List<MBThread> findByG_NotC(long groupId, long categoryId) {
3999                    return findByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
4000                            QueryUtil.ALL_POS, null);
4001            }
4002    
4003            /**
4004             * Returns a range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
4005             *
4006             * <p>
4007             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4008             * </p>
4009             *
4010             * @param groupId the group ID
4011             * @param categoryId the category ID
4012             * @param start the lower bound of the range of message boards threads
4013             * @param end the upper bound of the range of message boards threads (not inclusive)
4014             * @return the range of matching message boards threads
4015             */
4016            @Override
4017            public List<MBThread> findByG_NotC(long groupId, long categoryId,
4018                    int start, int end) {
4019                    return findByG_NotC(groupId, categoryId, start, end, null);
4020            }
4021    
4022            /**
4023             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
4024             *
4025             * <p>
4026             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4027             * </p>
4028             *
4029             * @param groupId the group ID
4030             * @param categoryId the category ID
4031             * @param start the lower bound of the range of message boards threads
4032             * @param end the upper bound of the range of message boards threads (not inclusive)
4033             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4034             * @return the ordered range of matching message boards threads
4035             */
4036            @Override
4037            public List<MBThread> findByG_NotC(long groupId, long categoryId,
4038                    int start, int end, OrderByComparator<MBThread> orderByComparator) {
4039                    return findByG_NotC(groupId, categoryId, start, end, orderByComparator,
4040                            true);
4041            }
4042    
4043            /**
4044             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
4045             *
4046             * <p>
4047             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4048             * </p>
4049             *
4050             * @param groupId the group ID
4051             * @param categoryId the category ID
4052             * @param start the lower bound of the range of message boards threads
4053             * @param end the upper bound of the range of message boards threads (not inclusive)
4054             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4055             * @param retrieveFromCache whether to retrieve from the finder cache
4056             * @return the ordered range of matching message boards threads
4057             */
4058            @Override
4059            public List<MBThread> findByG_NotC(long groupId, long categoryId,
4060                    int start, int end, OrderByComparator<MBThread> orderByComparator,
4061                    boolean retrieveFromCache) {
4062                    boolean pagination = true;
4063                    FinderPath finderPath = null;
4064                    Object[] finderArgs = null;
4065    
4066                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC;
4067                    finderArgs = new Object[] {
4068                                    groupId, categoryId,
4069                                    
4070                                    start, end, orderByComparator
4071                            };
4072    
4073                    List<MBThread> list = null;
4074    
4075                    if (retrieveFromCache) {
4076                            list = (List<MBThread>)finderCache.getResult(finderPath,
4077                                            finderArgs, this);
4078    
4079                            if ((list != null) && !list.isEmpty()) {
4080                                    for (MBThread mbThread : list) {
4081                                            if ((groupId != mbThread.getGroupId()) ||
4082                                                            (categoryId == mbThread.getCategoryId())) {
4083                                                    list = null;
4084    
4085                                                    break;
4086                                            }
4087                                    }
4088                            }
4089                    }
4090    
4091                    if (list == null) {
4092                            StringBundler query = null;
4093    
4094                            if (orderByComparator != null) {
4095                                    query = new StringBundler(4 +
4096                                                    (orderByComparator.getOrderByFields().length * 2));
4097                            }
4098                            else {
4099                                    query = new StringBundler(4);
4100                            }
4101    
4102                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
4103    
4104                            query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4105    
4106                            query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4107    
4108                            if (orderByComparator != null) {
4109                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4110                                            orderByComparator);
4111                            }
4112                            else
4113                             if (pagination) {
4114                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4115                            }
4116    
4117                            String sql = query.toString();
4118    
4119                            Session session = null;
4120    
4121                            try {
4122                                    session = openSession();
4123    
4124                                    Query q = session.createQuery(sql);
4125    
4126                                    QueryPos qPos = QueryPos.getInstance(q);
4127    
4128                                    qPos.add(groupId);
4129    
4130                                    qPos.add(categoryId);
4131    
4132                                    if (!pagination) {
4133                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
4134                                                            start, end, false);
4135    
4136                                            Collections.sort(list);
4137    
4138                                            list = Collections.unmodifiableList(list);
4139                                    }
4140                                    else {
4141                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
4142                                                            start, end);
4143                                    }
4144    
4145                                    cacheResult(list);
4146    
4147                                    finderCache.putResult(finderPath, finderArgs, list);
4148                            }
4149                            catch (Exception e) {
4150                                    finderCache.removeResult(finderPath, finderArgs);
4151    
4152                                    throw processException(e);
4153                            }
4154                            finally {
4155                                    closeSession(session);
4156                            }
4157                    }
4158    
4159                    return list;
4160            }
4161    
4162            /**
4163             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
4164             *
4165             * @param groupId the group ID
4166             * @param categoryId the category ID
4167             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4168             * @return the first matching message boards thread
4169             * @throws NoSuchThreadException if a matching message boards thread could not be found
4170             */
4171            @Override
4172            public MBThread findByG_NotC_First(long groupId, long categoryId,
4173                    OrderByComparator<MBThread> orderByComparator)
4174                    throws NoSuchThreadException {
4175                    MBThread mbThread = fetchByG_NotC_First(groupId, categoryId,
4176                                    orderByComparator);
4177    
4178                    if (mbThread != null) {
4179                            return mbThread;
4180                    }
4181    
4182                    StringBundler msg = new StringBundler(6);
4183    
4184                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4185    
4186                    msg.append("groupId=");
4187                    msg.append(groupId);
4188    
4189                    msg.append(", categoryId=");
4190                    msg.append(categoryId);
4191    
4192                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4193    
4194                    throw new NoSuchThreadException(msg.toString());
4195            }
4196    
4197            /**
4198             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
4199             *
4200             * @param groupId the group ID
4201             * @param categoryId the category ID
4202             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4203             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
4204             */
4205            @Override
4206            public MBThread fetchByG_NotC_First(long groupId, long categoryId,
4207                    OrderByComparator<MBThread> orderByComparator) {
4208                    List<MBThread> list = findByG_NotC(groupId, categoryId, 0, 1,
4209                                    orderByComparator);
4210    
4211                    if (!list.isEmpty()) {
4212                            return list.get(0);
4213                    }
4214    
4215                    return null;
4216            }
4217    
4218            /**
4219             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
4220             *
4221             * @param groupId the group ID
4222             * @param categoryId the category ID
4223             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4224             * @return the last matching message boards thread
4225             * @throws NoSuchThreadException if a matching message boards thread could not be found
4226             */
4227            @Override
4228            public MBThread findByG_NotC_Last(long groupId, long categoryId,
4229                    OrderByComparator<MBThread> orderByComparator)
4230                    throws NoSuchThreadException {
4231                    MBThread mbThread = fetchByG_NotC_Last(groupId, categoryId,
4232                                    orderByComparator);
4233    
4234                    if (mbThread != null) {
4235                            return mbThread;
4236                    }
4237    
4238                    StringBundler msg = new StringBundler(6);
4239    
4240                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4241    
4242                    msg.append("groupId=");
4243                    msg.append(groupId);
4244    
4245                    msg.append(", categoryId=");
4246                    msg.append(categoryId);
4247    
4248                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4249    
4250                    throw new NoSuchThreadException(msg.toString());
4251            }
4252    
4253            /**
4254             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
4255             *
4256             * @param groupId the group ID
4257             * @param categoryId the category ID
4258             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4259             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
4260             */
4261            @Override
4262            public MBThread fetchByG_NotC_Last(long groupId, long categoryId,
4263                    OrderByComparator<MBThread> orderByComparator) {
4264                    int count = countByG_NotC(groupId, categoryId);
4265    
4266                    if (count == 0) {
4267                            return null;
4268                    }
4269    
4270                    List<MBThread> list = findByG_NotC(groupId, categoryId, count - 1,
4271                                    count, orderByComparator);
4272    
4273                    if (!list.isEmpty()) {
4274                            return list.get(0);
4275                    }
4276    
4277                    return null;
4278            }
4279    
4280            /**
4281             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
4282             *
4283             * @param threadId the primary key of the current message boards thread
4284             * @param groupId the group ID
4285             * @param categoryId the category ID
4286             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4287             * @return the previous, current, and next message boards thread
4288             * @throws NoSuchThreadException if a message boards thread with the primary key could not be found
4289             */
4290            @Override
4291            public MBThread[] findByG_NotC_PrevAndNext(long threadId, long groupId,
4292                    long categoryId, OrderByComparator<MBThread> orderByComparator)
4293                    throws NoSuchThreadException {
4294                    MBThread mbThread = findByPrimaryKey(threadId);
4295    
4296                    Session session = null;
4297    
4298                    try {
4299                            session = openSession();
4300    
4301                            MBThread[] array = new MBThreadImpl[3];
4302    
4303                            array[0] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
4304                                            categoryId, orderByComparator, true);
4305    
4306                            array[1] = mbThread;
4307    
4308                            array[2] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
4309                                            categoryId, orderByComparator, false);
4310    
4311                            return array;
4312                    }
4313                    catch (Exception e) {
4314                            throw processException(e);
4315                    }
4316                    finally {
4317                            closeSession(session);
4318                    }
4319            }
4320    
4321            protected MBThread getByG_NotC_PrevAndNext(Session session,
4322                    MBThread mbThread, long groupId, long categoryId,
4323                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
4324                    StringBundler query = null;
4325    
4326                    if (orderByComparator != null) {
4327                            query = new StringBundler(5 +
4328                                            (orderByComparator.getOrderByConditionFields().length * 3) +
4329                                            (orderByComparator.getOrderByFields().length * 3));
4330                    }
4331                    else {
4332                            query = new StringBundler(4);
4333                    }
4334    
4335                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
4336    
4337                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4338    
4339                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4340    
4341                    if (orderByComparator != null) {
4342                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4343    
4344                            if (orderByConditionFields.length > 0) {
4345                                    query.append(WHERE_AND);
4346                            }
4347    
4348                            for (int i = 0; i < orderByConditionFields.length; i++) {
4349                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4350                                    query.append(orderByConditionFields[i]);
4351    
4352                                    if ((i + 1) < orderByConditionFields.length) {
4353                                            if (orderByComparator.isAscending() ^ previous) {
4354                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4355                                            }
4356                                            else {
4357                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4358                                            }
4359                                    }
4360                                    else {
4361                                            if (orderByComparator.isAscending() ^ previous) {
4362                                                    query.append(WHERE_GREATER_THAN);
4363                                            }
4364                                            else {
4365                                                    query.append(WHERE_LESSER_THAN);
4366                                            }
4367                                    }
4368                            }
4369    
4370                            query.append(ORDER_BY_CLAUSE);
4371    
4372                            String[] orderByFields = orderByComparator.getOrderByFields();
4373    
4374                            for (int i = 0; i < orderByFields.length; i++) {
4375                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4376                                    query.append(orderByFields[i]);
4377    
4378                                    if ((i + 1) < orderByFields.length) {
4379                                            if (orderByComparator.isAscending() ^ previous) {
4380                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4381                                            }
4382                                            else {
4383                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4384                                            }
4385                                    }
4386                                    else {
4387                                            if (orderByComparator.isAscending() ^ previous) {
4388                                                    query.append(ORDER_BY_ASC);
4389                                            }
4390                                            else {
4391                                                    query.append(ORDER_BY_DESC);
4392                                            }
4393                                    }
4394                            }
4395                    }
4396                    else {
4397                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4398                    }
4399    
4400                    String sql = query.toString();
4401    
4402                    Query q = session.createQuery(sql);
4403    
4404                    q.setFirstResult(0);
4405                    q.setMaxResults(2);
4406    
4407                    QueryPos qPos = QueryPos.getInstance(q);
4408    
4409                    qPos.add(groupId);
4410    
4411                    qPos.add(categoryId);
4412    
4413                    if (orderByComparator != null) {
4414                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4415    
4416                            for (Object value : values) {
4417                                    qPos.add(value);
4418                            }
4419                    }
4420    
4421                    List<MBThread> list = q.list();
4422    
4423                    if (list.size() == 2) {
4424                            return list.get(1);
4425                    }
4426                    else {
4427                            return null;
4428                    }
4429            }
4430    
4431            /**
4432             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63;.
4433             *
4434             * @param groupId the group ID
4435             * @param categoryId the category ID
4436             * @return the matching message boards threads that the user has permission to view
4437             */
4438            @Override
4439            public List<MBThread> filterFindByG_NotC(long groupId, long categoryId) {
4440                    return filterFindByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
4441                            QueryUtil.ALL_POS, null);
4442            }
4443    
4444            /**
4445             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63;.
4446             *
4447             * <p>
4448             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4449             * </p>
4450             *
4451             * @param groupId the group ID
4452             * @param categoryId the category ID
4453             * @param start the lower bound of the range of message boards threads
4454             * @param end the upper bound of the range of message boards threads (not inclusive)
4455             * @return the range of matching message boards threads that the user has permission to view
4456             */
4457            @Override
4458            public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
4459                    int start, int end) {
4460                    return filterFindByG_NotC(groupId, categoryId, start, end, null);
4461            }
4462    
4463            /**
4464             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and categoryId &ne; &#63;.
4465             *
4466             * <p>
4467             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4468             * </p>
4469             *
4470             * @param groupId the group ID
4471             * @param categoryId the category ID
4472             * @param start the lower bound of the range of message boards threads
4473             * @param end the upper bound of the range of message boards threads (not inclusive)
4474             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4475             * @return the ordered range of matching message boards threads that the user has permission to view
4476             */
4477            @Override
4478            public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
4479                    int start, int end, OrderByComparator<MBThread> orderByComparator) {
4480                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4481                            return findByG_NotC(groupId, categoryId, start, end,
4482                                    orderByComparator);
4483                    }
4484    
4485                    StringBundler query = null;
4486    
4487                    if (orderByComparator != null) {
4488                            query = new StringBundler(4 +
4489                                            (orderByComparator.getOrderByFields().length * 2));
4490                    }
4491                    else {
4492                            query = new StringBundler(5);
4493                    }
4494    
4495                    if (getDB().isSupportsInlineDistinct()) {
4496                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
4497                    }
4498                    else {
4499                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
4500                    }
4501    
4502                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4503    
4504                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4505    
4506                    if (!getDB().isSupportsInlineDistinct()) {
4507                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
4508                    }
4509    
4510                    if (orderByComparator != null) {
4511                            if (getDB().isSupportsInlineDistinct()) {
4512                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4513                                            orderByComparator, true);
4514                            }
4515                            else {
4516                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4517                                            orderByComparator, true);
4518                            }
4519                    }
4520                    else {
4521                            if (getDB().isSupportsInlineDistinct()) {
4522                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4523                            }
4524                            else {
4525                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
4526                            }
4527                    }
4528    
4529                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4530                                    MBThread.class.getName(),
4531                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4532    
4533                    Session session = null;
4534    
4535                    try {
4536                            session = openSession();
4537    
4538                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4539    
4540                            if (getDB().isSupportsInlineDistinct()) {
4541                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
4542                            }
4543                            else {
4544                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
4545                            }
4546    
4547                            QueryPos qPos = QueryPos.getInstance(q);
4548    
4549                            qPos.add(groupId);
4550    
4551                            qPos.add(categoryId);
4552    
4553                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
4554                    }
4555                    catch (Exception e) {
4556                            throw processException(e);
4557                    }
4558                    finally {
4559                            closeSession(session);
4560                    }
4561            }
4562    
4563            /**
4564             * 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;.
4565             *
4566             * @param threadId the primary key of the current message boards thread
4567             * @param groupId the group ID
4568             * @param categoryId the category ID
4569             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4570             * @return the previous, current, and next message boards thread
4571             * @throws NoSuchThreadException if a message boards thread with the primary key could not be found
4572             */
4573            @Override
4574            public MBThread[] filterFindByG_NotC_PrevAndNext(long threadId,
4575                    long groupId, long categoryId,
4576                    OrderByComparator<MBThread> orderByComparator)
4577                    throws NoSuchThreadException {
4578                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4579                            return findByG_NotC_PrevAndNext(threadId, groupId, categoryId,
4580                                    orderByComparator);
4581                    }
4582    
4583                    MBThread mbThread = findByPrimaryKey(threadId);
4584    
4585                    Session session = null;
4586    
4587                    try {
4588                            session = openSession();
4589    
4590                            MBThread[] array = new MBThreadImpl[3];
4591    
4592                            array[0] = filterGetByG_NotC_PrevAndNext(session, mbThread,
4593                                            groupId, categoryId, orderByComparator, true);
4594    
4595                            array[1] = mbThread;
4596    
4597                            array[2] = filterGetByG_NotC_PrevAndNext(session, mbThread,
4598                                            groupId, categoryId, orderByComparator, false);
4599    
4600                            return array;
4601                    }
4602                    catch (Exception e) {
4603                            throw processException(e);
4604                    }
4605                    finally {
4606                            closeSession(session);
4607                    }
4608            }
4609    
4610            protected MBThread filterGetByG_NotC_PrevAndNext(Session session,
4611                    MBThread mbThread, long groupId, long categoryId,
4612                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
4613                    StringBundler query = null;
4614    
4615                    if (orderByComparator != null) {
4616                            query = new StringBundler(6 +
4617                                            (orderByComparator.getOrderByConditionFields().length * 3) +
4618                                            (orderByComparator.getOrderByFields().length * 3));
4619                    }
4620                    else {
4621                            query = new StringBundler(5);
4622                    }
4623    
4624                    if (getDB().isSupportsInlineDistinct()) {
4625                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
4626                    }
4627                    else {
4628                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
4629                    }
4630    
4631                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4632    
4633                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4634    
4635                    if (!getDB().isSupportsInlineDistinct()) {
4636                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
4637                    }
4638    
4639                    if (orderByComparator != null) {
4640                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4641    
4642                            if (orderByConditionFields.length > 0) {
4643                                    query.append(WHERE_AND);
4644                            }
4645    
4646                            for (int i = 0; i < orderByConditionFields.length; i++) {
4647                                    if (getDB().isSupportsInlineDistinct()) {
4648                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4649                                    }
4650                                    else {
4651                                            query.append(_ORDER_BY_ENTITY_TABLE);
4652                                    }
4653    
4654                                    query.append(orderByConditionFields[i]);
4655    
4656                                    if ((i + 1) < orderByConditionFields.length) {
4657                                            if (orderByComparator.isAscending() ^ previous) {
4658                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4659                                            }
4660                                            else {
4661                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4662                                            }
4663                                    }
4664                                    else {
4665                                            if (orderByComparator.isAscending() ^ previous) {
4666                                                    query.append(WHERE_GREATER_THAN);
4667                                            }
4668                                            else {
4669                                                    query.append(WHERE_LESSER_THAN);
4670                                            }
4671                                    }
4672                            }
4673    
4674                            query.append(ORDER_BY_CLAUSE);
4675    
4676                            String[] orderByFields = orderByComparator.getOrderByFields();
4677    
4678                            for (int i = 0; i < orderByFields.length; i++) {
4679                                    if (getDB().isSupportsInlineDistinct()) {
4680                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4681                                    }
4682                                    else {
4683                                            query.append(_ORDER_BY_ENTITY_TABLE);
4684                                    }
4685    
4686                                    query.append(orderByFields[i]);
4687    
4688                                    if ((i + 1) < orderByFields.length) {
4689                                            if (orderByComparator.isAscending() ^ previous) {
4690                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4691                                            }
4692                                            else {
4693                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4694                                            }
4695                                    }
4696                                    else {
4697                                            if (orderByComparator.isAscending() ^ previous) {
4698                                                    query.append(ORDER_BY_ASC);
4699                                            }
4700                                            else {
4701                                                    query.append(ORDER_BY_DESC);
4702                                            }
4703                                    }
4704                            }
4705                    }
4706                    else {
4707                            if (getDB().isSupportsInlineDistinct()) {
4708                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4709                            }
4710                            else {
4711                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
4712                            }
4713                    }
4714    
4715                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4716                                    MBThread.class.getName(),
4717                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4718    
4719                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
4720    
4721                    q.setFirstResult(0);
4722                    q.setMaxResults(2);
4723    
4724                    if (getDB().isSupportsInlineDistinct()) {
4725                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
4726                    }
4727                    else {
4728                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
4729                    }
4730    
4731                    QueryPos qPos = QueryPos.getInstance(q);
4732    
4733                    qPos.add(groupId);
4734    
4735                    qPos.add(categoryId);
4736    
4737                    if (orderByComparator != null) {
4738                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4739    
4740                            for (Object value : values) {
4741                                    qPos.add(value);
4742                            }
4743                    }
4744    
4745                    List<MBThread> list = q.list();
4746    
4747                    if (list.size() == 2) {
4748                            return list.get(1);
4749                    }
4750                    else {
4751                            return null;
4752                    }
4753            }
4754    
4755            /**
4756             * Removes all the message boards threads where groupId = &#63; and categoryId &ne; &#63; from the database.
4757             *
4758             * @param groupId the group ID
4759             * @param categoryId the category ID
4760             */
4761            @Override
4762            public void removeByG_NotC(long groupId, long categoryId) {
4763                    for (MBThread mbThread : findByG_NotC(groupId, categoryId,
4764                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4765                            remove(mbThread);
4766                    }
4767            }
4768    
4769            /**
4770             * Returns the number of message boards threads where groupId = &#63; and categoryId &ne; &#63;.
4771             *
4772             * @param groupId the group ID
4773             * @param categoryId the category ID
4774             * @return the number of matching message boards threads
4775             */
4776            @Override
4777            public int countByG_NotC(long groupId, long categoryId) {
4778                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC;
4779    
4780                    Object[] finderArgs = new Object[] { groupId, categoryId };
4781    
4782                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4783    
4784                    if (count == null) {
4785                            StringBundler query = new StringBundler(3);
4786    
4787                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
4788    
4789                            query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4790    
4791                            query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4792    
4793                            String sql = query.toString();
4794    
4795                            Session session = null;
4796    
4797                            try {
4798                                    session = openSession();
4799    
4800                                    Query q = session.createQuery(sql);
4801    
4802                                    QueryPos qPos = QueryPos.getInstance(q);
4803    
4804                                    qPos.add(groupId);
4805    
4806                                    qPos.add(categoryId);
4807    
4808                                    count = (Long)q.uniqueResult();
4809    
4810                                    finderCache.putResult(finderPath, finderArgs, count);
4811                            }
4812                            catch (Exception e) {
4813                                    finderCache.removeResult(finderPath, finderArgs);
4814    
4815                                    throw processException(e);
4816                            }
4817                            finally {
4818                                    closeSession(session);
4819                            }
4820                    }
4821    
4822                    return count.intValue();
4823            }
4824    
4825            /**
4826             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63;.
4827             *
4828             * @param groupId the group ID
4829             * @param categoryId the category ID
4830             * @return the number of matching message boards threads that the user has permission to view
4831             */
4832            @Override
4833            public int filterCountByG_NotC(long groupId, long categoryId) {
4834                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4835                            return countByG_NotC(groupId, categoryId);
4836                    }
4837    
4838                    StringBundler query = new StringBundler(3);
4839    
4840                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
4841    
4842                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4843    
4844                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4845    
4846                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4847                                    MBThread.class.getName(),
4848                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4849    
4850                    Session session = null;
4851    
4852                    try {
4853                            session = openSession();
4854    
4855                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4856    
4857                            q.addScalar(COUNT_COLUMN_NAME,
4858                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4859    
4860                            QueryPos qPos = QueryPos.getInstance(q);
4861    
4862                            qPos.add(groupId);
4863    
4864                            qPos.add(categoryId);
4865    
4866                            Long count = (Long)q.uniqueResult();
4867    
4868                            return count.intValue();
4869                    }
4870                    catch (Exception e) {
4871                            throw processException(e);
4872                    }
4873                    finally {
4874                            closeSession(session);
4875                    }
4876            }
4877    
4878            private static final String _FINDER_COLUMN_G_NOTC_GROUPID_2 = "mbThread.groupId = ? AND ";
4879            private static final String _FINDER_COLUMN_G_NOTC_CATEGORYID_2 = "mbThread.categoryId != ?";
4880            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4881                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
4882                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
4883                            new String[] {
4884                                    Long.class.getName(), Integer.class.getName(),
4885                                    
4886                            Integer.class.getName(), Integer.class.getName(),
4887                                    OrderByComparator.class.getName()
4888                            });
4889            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4890                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
4891                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
4892                            new String[] { Long.class.getName(), Integer.class.getName() },
4893                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
4894                            MBThreadModelImpl.STATUS_COLUMN_BITMASK |
4895                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
4896                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
4897            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4898                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
4899                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
4900                            new String[] { Long.class.getName(), Integer.class.getName() });
4901    
4902            /**
4903             * Returns all the message boards threads where groupId = &#63; and status = &#63;.
4904             *
4905             * @param groupId the group ID
4906             * @param status the status
4907             * @return the matching message boards threads
4908             */
4909            @Override
4910            public List<MBThread> findByG_S(long groupId, int status) {
4911                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4912                            null);
4913            }
4914    
4915            /**
4916             * Returns a range of all the message boards threads where groupId = &#63; and status = &#63;.
4917             *
4918             * <p>
4919             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4920             * </p>
4921             *
4922             * @param groupId the group ID
4923             * @param status the status
4924             * @param start the lower bound of the range of message boards threads
4925             * @param end the upper bound of the range of message boards threads (not inclusive)
4926             * @return the range of matching message boards threads
4927             */
4928            @Override
4929            public List<MBThread> findByG_S(long groupId, int status, int start, int end) {
4930                    return findByG_S(groupId, status, start, end, null);
4931            }
4932    
4933            /**
4934             * Returns an ordered range of all the message boards threads where groupId = &#63; and status = &#63;.
4935             *
4936             * <p>
4937             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4938             * </p>
4939             *
4940             * @param groupId the group ID
4941             * @param status the status
4942             * @param start the lower bound of the range of message boards threads
4943             * @param end the upper bound of the range of message boards threads (not inclusive)
4944             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4945             * @return the ordered range of matching message boards threads
4946             */
4947            @Override
4948            public List<MBThread> findByG_S(long groupId, int status, int start,
4949                    int end, OrderByComparator<MBThread> orderByComparator) {
4950                    return findByG_S(groupId, status, start, end, orderByComparator, true);
4951            }
4952    
4953            /**
4954             * Returns an ordered range of all the message boards threads where groupId = &#63; and status = &#63;.
4955             *
4956             * <p>
4957             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4958             * </p>
4959             *
4960             * @param groupId the group ID
4961             * @param status the status
4962             * @param start the lower bound of the range of message boards threads
4963             * @param end the upper bound of the range of message boards threads (not inclusive)
4964             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4965             * @param retrieveFromCache whether to retrieve from the finder cache
4966             * @return the ordered range of matching message boards threads
4967             */
4968            @Override
4969            public List<MBThread> findByG_S(long groupId, int status, int start,
4970                    int end, OrderByComparator<MBThread> orderByComparator,
4971                    boolean retrieveFromCache) {
4972                    boolean pagination = true;
4973                    FinderPath finderPath = null;
4974                    Object[] finderArgs = null;
4975    
4976                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4977                                    (orderByComparator == null)) {
4978                            pagination = false;
4979                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
4980                            finderArgs = new Object[] { groupId, status };
4981                    }
4982                    else {
4983                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
4984                            finderArgs = new Object[] {
4985                                            groupId, status,
4986                                            
4987                                            start, end, orderByComparator
4988                                    };
4989                    }
4990    
4991                    List<MBThread> list = null;
4992    
4993                    if (retrieveFromCache) {
4994                            list = (List<MBThread>)finderCache.getResult(finderPath,
4995                                            finderArgs, this);
4996    
4997                            if ((list != null) && !list.isEmpty()) {
4998                                    for (MBThread mbThread : list) {
4999                                            if ((groupId != mbThread.getGroupId()) ||
5000                                                            (status != mbThread.getStatus())) {
5001                                                    list = null;
5002    
5003                                                    break;
5004                                            }
5005                                    }
5006                            }
5007                    }
5008    
5009                    if (list == null) {
5010                            StringBundler query = null;
5011    
5012                            if (orderByComparator != null) {
5013                                    query = new StringBundler(4 +
5014                                                    (orderByComparator.getOrderByFields().length * 2));
5015                            }
5016                            else {
5017                                    query = new StringBundler(4);
5018                            }
5019    
5020                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
5021    
5022                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5023    
5024                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
5025    
5026                            if (orderByComparator != null) {
5027                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5028                                            orderByComparator);
5029                            }
5030                            else
5031                             if (pagination) {
5032                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5033                            }
5034    
5035                            String sql = query.toString();
5036    
5037                            Session session = null;
5038    
5039                            try {
5040                                    session = openSession();
5041    
5042                                    Query q = session.createQuery(sql);
5043    
5044                                    QueryPos qPos = QueryPos.getInstance(q);
5045    
5046                                    qPos.add(groupId);
5047    
5048                                    qPos.add(status);
5049    
5050                                    if (!pagination) {
5051                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
5052                                                            start, end, false);
5053    
5054                                            Collections.sort(list);
5055    
5056                                            list = Collections.unmodifiableList(list);
5057                                    }
5058                                    else {
5059                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
5060                                                            start, end);
5061                                    }
5062    
5063                                    cacheResult(list);
5064    
5065                                    finderCache.putResult(finderPath, finderArgs, list);
5066                            }
5067                            catch (Exception e) {
5068                                    finderCache.removeResult(finderPath, finderArgs);
5069    
5070                                    throw processException(e);
5071                            }
5072                            finally {
5073                                    closeSession(session);
5074                            }
5075                    }
5076    
5077                    return list;
5078            }
5079    
5080            /**
5081             * Returns the first message boards thread in the ordered set where groupId = &#63; and status = &#63;.
5082             *
5083             * @param groupId the group ID
5084             * @param status the status
5085             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5086             * @return the first matching message boards thread
5087             * @throws NoSuchThreadException if a matching message boards thread could not be found
5088             */
5089            @Override
5090            public MBThread findByG_S_First(long groupId, int status,
5091                    OrderByComparator<MBThread> orderByComparator)
5092                    throws NoSuchThreadException {
5093                    MBThread mbThread = fetchByG_S_First(groupId, status, orderByComparator);
5094    
5095                    if (mbThread != null) {
5096                            return mbThread;
5097                    }
5098    
5099                    StringBundler msg = new StringBundler(6);
5100    
5101                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5102    
5103                    msg.append("groupId=");
5104                    msg.append(groupId);
5105    
5106                    msg.append(", status=");
5107                    msg.append(status);
5108    
5109                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5110    
5111                    throw new NoSuchThreadException(msg.toString());
5112            }
5113    
5114            /**
5115             * Returns the first message boards thread in the ordered set where groupId = &#63; and status = &#63;.
5116             *
5117             * @param groupId the group ID
5118             * @param status the status
5119             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5120             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
5121             */
5122            @Override
5123            public MBThread fetchByG_S_First(long groupId, int status,
5124                    OrderByComparator<MBThread> orderByComparator) {
5125                    List<MBThread> list = findByG_S(groupId, status, 0, 1, orderByComparator);
5126    
5127                    if (!list.isEmpty()) {
5128                            return list.get(0);
5129                    }
5130    
5131                    return null;
5132            }
5133    
5134            /**
5135             * Returns the last message boards thread in the ordered set where groupId = &#63; and status = &#63;.
5136             *
5137             * @param groupId the group ID
5138             * @param status the status
5139             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5140             * @return the last matching message boards thread
5141             * @throws NoSuchThreadException if a matching message boards thread could not be found
5142             */
5143            @Override
5144            public MBThread findByG_S_Last(long groupId, int status,
5145                    OrderByComparator<MBThread> orderByComparator)
5146                    throws NoSuchThreadException {
5147                    MBThread mbThread = fetchByG_S_Last(groupId, status, orderByComparator);
5148    
5149                    if (mbThread != null) {
5150                            return mbThread;
5151                    }
5152    
5153                    StringBundler msg = new StringBundler(6);
5154    
5155                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5156    
5157                    msg.append("groupId=");
5158                    msg.append(groupId);
5159    
5160                    msg.append(", status=");
5161                    msg.append(status);
5162    
5163                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5164    
5165                    throw new NoSuchThreadException(msg.toString());
5166            }
5167    
5168            /**
5169             * Returns the last message boards thread in the ordered set where groupId = &#63; and status = &#63;.
5170             *
5171             * @param groupId the group ID
5172             * @param status the status
5173             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5174             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
5175             */
5176            @Override
5177            public MBThread fetchByG_S_Last(long groupId, int status,
5178                    OrderByComparator<MBThread> orderByComparator) {
5179                    int count = countByG_S(groupId, status);
5180    
5181                    if (count == 0) {
5182                            return null;
5183                    }
5184    
5185                    List<MBThread> list = findByG_S(groupId, status, count - 1, count,
5186                                    orderByComparator);
5187    
5188                    if (!list.isEmpty()) {
5189                            return list.get(0);
5190                    }
5191    
5192                    return null;
5193            }
5194    
5195            /**
5196             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and status = &#63;.
5197             *
5198             * @param threadId the primary key of the current message boards thread
5199             * @param groupId the group ID
5200             * @param status the status
5201             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5202             * @return the previous, current, and next message boards thread
5203             * @throws NoSuchThreadException if a message boards thread with the primary key could not be found
5204             */
5205            @Override
5206            public MBThread[] findByG_S_PrevAndNext(long threadId, long groupId,
5207                    int status, OrderByComparator<MBThread> orderByComparator)
5208                    throws NoSuchThreadException {
5209                    MBThread mbThread = findByPrimaryKey(threadId);
5210    
5211                    Session session = null;
5212    
5213                    try {
5214                            session = openSession();
5215    
5216                            MBThread[] array = new MBThreadImpl[3];
5217    
5218                            array[0] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
5219                                            orderByComparator, true);
5220    
5221                            array[1] = mbThread;
5222    
5223                            array[2] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
5224                                            orderByComparator, false);
5225    
5226                            return array;
5227                    }
5228                    catch (Exception e) {
5229                            throw processException(e);
5230                    }
5231                    finally {
5232                            closeSession(session);
5233                    }
5234            }
5235    
5236            protected MBThread getByG_S_PrevAndNext(Session session, MBThread mbThread,
5237                    long groupId, int status,
5238                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
5239                    StringBundler query = null;
5240    
5241                    if (orderByComparator != null) {
5242                            query = new StringBundler(5 +
5243                                            (orderByComparator.getOrderByConditionFields().length * 3) +
5244                                            (orderByComparator.getOrderByFields().length * 3));
5245                    }
5246                    else {
5247                            query = new StringBundler(4);
5248                    }
5249    
5250                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
5251    
5252                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5253    
5254                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
5255    
5256                    if (orderByComparator != null) {
5257                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5258    
5259                            if (orderByConditionFields.length > 0) {
5260                                    query.append(WHERE_AND);
5261                            }
5262    
5263                            for (int i = 0; i < orderByConditionFields.length; i++) {
5264                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5265                                    query.append(orderByConditionFields[i]);
5266    
5267                                    if ((i + 1) < orderByConditionFields.length) {
5268                                            if (orderByComparator.isAscending() ^ previous) {
5269                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5270                                            }
5271                                            else {
5272                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5273                                            }
5274                                    }
5275                                    else {
5276                                            if (orderByComparator.isAscending() ^ previous) {
5277                                                    query.append(WHERE_GREATER_THAN);
5278                                            }
5279                                            else {
5280                                                    query.append(WHERE_LESSER_THAN);
5281                                            }
5282                                    }
5283                            }
5284    
5285                            query.append(ORDER_BY_CLAUSE);
5286    
5287                            String[] orderByFields = orderByComparator.getOrderByFields();
5288    
5289                            for (int i = 0; i < orderByFields.length; i++) {
5290                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5291                                    query.append(orderByFields[i]);
5292    
5293                                    if ((i + 1) < orderByFields.length) {
5294                                            if (orderByComparator.isAscending() ^ previous) {
5295                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5296                                            }
5297                                            else {
5298                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5299                                            }
5300                                    }
5301                                    else {
5302                                            if (orderByComparator.isAscending() ^ previous) {
5303                                                    query.append(ORDER_BY_ASC);
5304                                            }
5305                                            else {
5306                                                    query.append(ORDER_BY_DESC);
5307                                            }
5308                                    }
5309                            }
5310                    }
5311                    else {
5312                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5313                    }
5314    
5315                    String sql = query.toString();
5316    
5317                    Query q = session.createQuery(sql);
5318    
5319                    q.setFirstResult(0);
5320                    q.setMaxResults(2);
5321    
5322                    QueryPos qPos = QueryPos.getInstance(q);
5323    
5324                    qPos.add(groupId);
5325    
5326                    qPos.add(status);
5327    
5328                    if (orderByComparator != null) {
5329                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5330    
5331                            for (Object value : values) {
5332                                    qPos.add(value);
5333                            }
5334                    }
5335    
5336                    List<MBThread> list = q.list();
5337    
5338                    if (list.size() == 2) {
5339                            return list.get(1);
5340                    }
5341                    else {
5342                            return null;
5343                    }
5344            }
5345    
5346            /**
5347             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and status = &#63;.
5348             *
5349             * @param groupId the group ID
5350             * @param status the status
5351             * @return the matching message boards threads that the user has permission to view
5352             */
5353            @Override
5354            public List<MBThread> filterFindByG_S(long groupId, int status) {
5355                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
5356                            QueryUtil.ALL_POS, null);
5357            }
5358    
5359            /**
5360             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and status = &#63;.
5361             *
5362             * <p>
5363             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5364             * </p>
5365             *
5366             * @param groupId the group ID
5367             * @param status the status
5368             * @param start the lower bound of the range of message boards threads
5369             * @param end the upper bound of the range of message boards threads (not inclusive)
5370             * @return the range of matching message boards threads that the user has permission to view
5371             */
5372            @Override
5373            public List<MBThread> filterFindByG_S(long groupId, int status, int start,
5374                    int end) {
5375                    return filterFindByG_S(groupId, status, start, end, null);
5376            }
5377    
5378            /**
5379             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and status = &#63;.
5380             *
5381             * <p>
5382             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5383             * </p>
5384             *
5385             * @param groupId the group ID
5386             * @param status the status
5387             * @param start the lower bound of the range of message boards threads
5388             * @param end the upper bound of the range of message boards threads (not inclusive)
5389             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5390             * @return the ordered range of matching message boards threads that the user has permission to view
5391             */
5392            @Override
5393            public List<MBThread> filterFindByG_S(long groupId, int status, int start,
5394                    int end, OrderByComparator<MBThread> orderByComparator) {
5395                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5396                            return findByG_S(groupId, status, start, end, orderByComparator);
5397                    }
5398    
5399                    StringBundler query = null;
5400    
5401                    if (orderByComparator != null) {
5402                            query = new StringBundler(4 +
5403                                            (orderByComparator.getOrderByFields().length * 2));
5404                    }
5405                    else {
5406                            query = new StringBundler(5);
5407                    }
5408    
5409                    if (getDB().isSupportsInlineDistinct()) {
5410                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5411                    }
5412                    else {
5413                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5414                    }
5415    
5416                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5417    
5418                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
5419    
5420                    if (!getDB().isSupportsInlineDistinct()) {
5421                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5422                    }
5423    
5424                    if (orderByComparator != null) {
5425                            if (getDB().isSupportsInlineDistinct()) {
5426                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5427                                            orderByComparator, true);
5428                            }
5429                            else {
5430                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5431                                            orderByComparator, true);
5432                            }
5433                    }
5434                    else {
5435                            if (getDB().isSupportsInlineDistinct()) {
5436                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5437                            }
5438                            else {
5439                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
5440                            }
5441                    }
5442    
5443                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5444                                    MBThread.class.getName(),
5445                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5446    
5447                    Session session = null;
5448    
5449                    try {
5450                            session = openSession();
5451    
5452                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5453    
5454                            if (getDB().isSupportsInlineDistinct()) {
5455                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5456                            }
5457                            else {
5458                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5459                            }
5460    
5461                            QueryPos qPos = QueryPos.getInstance(q);
5462    
5463                            qPos.add(groupId);
5464    
5465                            qPos.add(status);
5466    
5467                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
5468                    }
5469                    catch (Exception e) {
5470                            throw processException(e);
5471                    }
5472                    finally {
5473                            closeSession(session);
5474                    }
5475            }
5476    
5477            /**
5478             * 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;.
5479             *
5480             * @param threadId the primary key of the current message boards thread
5481             * @param groupId the group ID
5482             * @param status the status
5483             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5484             * @return the previous, current, and next message boards thread
5485             * @throws NoSuchThreadException if a message boards thread with the primary key could not be found
5486             */
5487            @Override
5488            public MBThread[] filterFindByG_S_PrevAndNext(long threadId, long groupId,
5489                    int status, OrderByComparator<MBThread> orderByComparator)
5490                    throws NoSuchThreadException {
5491                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5492                            return findByG_S_PrevAndNext(threadId, groupId, status,
5493                                    orderByComparator);
5494                    }
5495    
5496                    MBThread mbThread = findByPrimaryKey(threadId);
5497    
5498                    Session session = null;
5499    
5500                    try {
5501                            session = openSession();
5502    
5503                            MBThread[] array = new MBThreadImpl[3];
5504    
5505                            array[0] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
5506                                            status, orderByComparator, true);
5507    
5508                            array[1] = mbThread;
5509    
5510                            array[2] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
5511                                            status, orderByComparator, false);
5512    
5513                            return array;
5514                    }
5515                    catch (Exception e) {
5516                            throw processException(e);
5517                    }
5518                    finally {
5519                            closeSession(session);
5520                    }
5521            }
5522    
5523            protected MBThread filterGetByG_S_PrevAndNext(Session session,
5524                    MBThread mbThread, long groupId, int status,
5525                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
5526                    StringBundler query = null;
5527    
5528                    if (orderByComparator != null) {
5529                            query = new StringBundler(6 +
5530                                            (orderByComparator.getOrderByConditionFields().length * 3) +
5531                                            (orderByComparator.getOrderByFields().length * 3));
5532                    }
5533                    else {
5534                            query = new StringBundler(5);
5535                    }
5536    
5537                    if (getDB().isSupportsInlineDistinct()) {
5538                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5539                    }
5540                    else {
5541                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5542                    }
5543    
5544                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5545    
5546                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
5547    
5548                    if (!getDB().isSupportsInlineDistinct()) {
5549                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5550                    }
5551    
5552                    if (orderByComparator != null) {
5553                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5554    
5555                            if (orderByConditionFields.length > 0) {
5556                                    query.append(WHERE_AND);
5557                            }
5558    
5559                            for (int i = 0; i < orderByConditionFields.length; i++) {
5560                                    if (getDB().isSupportsInlineDistinct()) {
5561                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5562                                    }
5563                                    else {
5564                                            query.append(_ORDER_BY_ENTITY_TABLE);
5565                                    }
5566    
5567                                    query.append(orderByConditionFields[i]);
5568    
5569                                    if ((i + 1) < orderByConditionFields.length) {
5570                                            if (orderByComparator.isAscending() ^ previous) {
5571                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5572                                            }
5573                                            else {
5574                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5575                                            }
5576                                    }
5577                                    else {
5578                                            if (orderByComparator.isAscending() ^ previous) {
5579                                                    query.append(WHERE_GREATER_THAN);
5580                                            }
5581                                            else {
5582                                                    query.append(WHERE_LESSER_THAN);
5583                                            }
5584                                    }
5585                            }
5586    
5587                            query.append(ORDER_BY_CLAUSE);
5588    
5589                            String[] orderByFields = orderByComparator.getOrderByFields();
5590    
5591                            for (int i = 0; i < orderByFields.length; i++) {
5592                                    if (getDB().isSupportsInlineDistinct()) {
5593                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5594                                    }
5595                                    else {
5596                                            query.append(_ORDER_BY_ENTITY_TABLE);
5597                                    }
5598    
5599                                    query.append(orderByFields[i]);
5600    
5601                                    if ((i + 1) < orderByFields.length) {
5602                                            if (orderByComparator.isAscending() ^ previous) {
5603                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5604                                            }
5605                                            else {
5606                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5607                                            }
5608                                    }
5609                                    else {
5610                                            if (orderByComparator.isAscending() ^ previous) {
5611                                                    query.append(ORDER_BY_ASC);
5612                                            }
5613                                            else {
5614                                                    query.append(ORDER_BY_DESC);
5615                                            }
5616                                    }
5617                            }
5618                    }
5619                    else {
5620                            if (getDB().isSupportsInlineDistinct()) {
5621                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5622                            }
5623                            else {
5624                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
5625                            }
5626                    }
5627    
5628                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5629                                    MBThread.class.getName(),
5630                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5631    
5632                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
5633    
5634                    q.setFirstResult(0);
5635                    q.setMaxResults(2);
5636    
5637                    if (getDB().isSupportsInlineDistinct()) {
5638                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5639                    }
5640                    else {
5641                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5642                    }
5643    
5644                    QueryPos qPos = QueryPos.getInstance(q);
5645    
5646                    qPos.add(groupId);
5647    
5648                    qPos.add(status);
5649    
5650                    if (orderByComparator != null) {
5651                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5652    
5653                            for (Object value : values) {
5654                                    qPos.add(value);
5655                            }
5656                    }
5657    
5658                    List<MBThread> list = q.list();
5659    
5660                    if (list.size() == 2) {
5661                            return list.get(1);
5662                    }
5663                    else {
5664                            return null;
5665                    }
5666            }
5667    
5668            /**
5669             * Removes all the message boards threads where groupId = &#63; and status = &#63; from the database.
5670             *
5671             * @param groupId the group ID
5672             * @param status the status
5673             */
5674            @Override
5675            public void removeByG_S(long groupId, int status) {
5676                    for (MBThread mbThread : findByG_S(groupId, status, QueryUtil.ALL_POS,
5677                                    QueryUtil.ALL_POS, null)) {
5678                            remove(mbThread);
5679                    }
5680            }
5681    
5682            /**
5683             * Returns the number of message boards threads where groupId = &#63; and status = &#63;.
5684             *
5685             * @param groupId the group ID
5686             * @param status the status
5687             * @return the number of matching message boards threads
5688             */
5689            @Override
5690            public int countByG_S(long groupId, int status) {
5691                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
5692    
5693                    Object[] finderArgs = new Object[] { groupId, status };
5694    
5695                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5696    
5697                    if (count == null) {
5698                            StringBundler query = new StringBundler(3);
5699    
5700                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
5701    
5702                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5703    
5704                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
5705    
5706                            String sql = query.toString();
5707    
5708                            Session session = null;
5709    
5710                            try {
5711                                    session = openSession();
5712    
5713                                    Query q = session.createQuery(sql);
5714    
5715                                    QueryPos qPos = QueryPos.getInstance(q);
5716    
5717                                    qPos.add(groupId);
5718    
5719                                    qPos.add(status);
5720    
5721                                    count = (Long)q.uniqueResult();
5722    
5723                                    finderCache.putResult(finderPath, finderArgs, count);
5724                            }
5725                            catch (Exception e) {
5726                                    finderCache.removeResult(finderPath, finderArgs);
5727    
5728                                    throw processException(e);
5729                            }
5730                            finally {
5731                                    closeSession(session);
5732                            }
5733                    }
5734    
5735                    return count.intValue();
5736            }
5737    
5738            /**
5739             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and status = &#63;.
5740             *
5741             * @param groupId the group ID
5742             * @param status the status
5743             * @return the number of matching message boards threads that the user has permission to view
5744             */
5745            @Override
5746            public int filterCountByG_S(long groupId, int status) {
5747                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5748                            return countByG_S(groupId, status);
5749                    }
5750    
5751                    StringBundler query = new StringBundler(3);
5752    
5753                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
5754    
5755                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5756    
5757                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
5758    
5759                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5760                                    MBThread.class.getName(),
5761                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5762    
5763                    Session session = null;
5764    
5765                    try {
5766                            session = openSession();
5767    
5768                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5769    
5770                            q.addScalar(COUNT_COLUMN_NAME,
5771                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5772    
5773                            QueryPos qPos = QueryPos.getInstance(q);
5774    
5775                            qPos.add(groupId);
5776    
5777                            qPos.add(status);
5778    
5779                            Long count = (Long)q.uniqueResult();
5780    
5781                            return count.intValue();
5782                    }
5783                    catch (Exception e) {
5784                            throw processException(e);
5785                    }
5786                    finally {
5787                            closeSession(session);
5788                    }
5789            }
5790    
5791            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbThread.groupId = ? AND ";
5792            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbThread.status = ? AND mbThread.categoryId != -1";
5793            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5794                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
5795                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
5796                            new String[] {
5797                                    Long.class.getName(), Double.class.getName(),
5798                                    
5799                            Integer.class.getName(), Integer.class.getName(),
5800                                    OrderByComparator.class.getName()
5801                            });
5802            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5803                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
5804                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
5805                            new String[] { Long.class.getName(), Double.class.getName() },
5806                            MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
5807                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
5808                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
5809            public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5810                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
5811                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
5812                            new String[] { Long.class.getName(), Double.class.getName() });
5813    
5814            /**
5815             * Returns all the message boards threads where categoryId = &#63; and priority = &#63;.
5816             *
5817             * @param categoryId the category ID
5818             * @param priority the priority
5819             * @return the matching message boards threads
5820             */
5821            @Override
5822            public List<MBThread> findByC_P(long categoryId, double priority) {
5823                    return findByC_P(categoryId, priority, QueryUtil.ALL_POS,
5824                            QueryUtil.ALL_POS, null);
5825            }
5826    
5827            /**
5828             * Returns a range of all the message boards threads where categoryId = &#63; and priority = &#63;.
5829             *
5830             * <p>
5831             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5832             * </p>
5833             *
5834             * @param categoryId the category ID
5835             * @param priority the priority
5836             * @param start the lower bound of the range of message boards threads
5837             * @param end the upper bound of the range of message boards threads (not inclusive)
5838             * @return the range of matching message boards threads
5839             */
5840            @Override
5841            public List<MBThread> findByC_P(long categoryId, double priority,
5842                    int start, int end) {
5843                    return findByC_P(categoryId, priority, start, end, null);
5844            }
5845    
5846            /**
5847             * Returns an ordered range of all the message boards threads where categoryId = &#63; and priority = &#63;.
5848             *
5849             * <p>
5850             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5851             * </p>
5852             *
5853             * @param categoryId the category ID
5854             * @param priority the priority
5855             * @param start the lower bound of the range of message boards threads
5856             * @param end the upper bound of the range of message boards threads (not inclusive)
5857             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5858             * @return the ordered range of matching message boards threads
5859             */
5860            @Override
5861            public List<MBThread> findByC_P(long categoryId, double priority,
5862                    int start, int end, OrderByComparator<MBThread> orderByComparator) {
5863                    return findByC_P(categoryId, priority, start, end, orderByComparator,
5864                            true);
5865            }
5866    
5867            /**
5868             * Returns an ordered range of all the message boards threads where categoryId = &#63; and priority = &#63;.
5869             *
5870             * <p>
5871             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
5872             * </p>
5873             *
5874             * @param categoryId the category ID
5875             * @param priority the priority
5876             * @param start the lower bound of the range of message boards threads
5877             * @param end the upper bound of the range of message boards threads (not inclusive)
5878             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5879             * @param retrieveFromCache whether to retrieve from the finder cache
5880             * @return the ordered range of matching message boards threads
5881             */
5882            @Override
5883            public List<MBThread> findByC_P(long categoryId, double priority,
5884                    int start, int end, OrderByComparator<MBThread> orderByComparator,
5885                    boolean retrieveFromCache) {
5886                    boolean pagination = true;
5887                    FinderPath finderPath = null;
5888                    Object[] finderArgs = null;
5889    
5890                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5891                                    (orderByComparator == null)) {
5892                            pagination = false;
5893                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
5894                            finderArgs = new Object[] { categoryId, priority };
5895                    }
5896                    else {
5897                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
5898                            finderArgs = new Object[] {
5899                                            categoryId, priority,
5900                                            
5901                                            start, end, orderByComparator
5902                                    };
5903                    }
5904    
5905                    List<MBThread> list = null;
5906    
5907                    if (retrieveFromCache) {
5908                            list = (List<MBThread>)finderCache.getResult(finderPath,
5909                                            finderArgs, this);
5910    
5911                            if ((list != null) && !list.isEmpty()) {
5912                                    for (MBThread mbThread : list) {
5913                                            if ((categoryId != mbThread.getCategoryId()) ||
5914                                                            (priority != mbThread.getPriority())) {
5915                                                    list = null;
5916    
5917                                                    break;
5918                                            }
5919                                    }
5920                            }
5921                    }
5922    
5923                    if (list == null) {
5924                            StringBundler query = null;
5925    
5926                            if (orderByComparator != null) {
5927                                    query = new StringBundler(4 +
5928                                                    (orderByComparator.getOrderByFields().length * 2));
5929                            }
5930                            else {
5931                                    query = new StringBundler(4);
5932                            }
5933    
5934                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
5935    
5936                            query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
5937    
5938                            query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
5939    
5940                            if (orderByComparator != null) {
5941                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5942                                            orderByComparator);
5943                            }
5944                            else
5945                             if (pagination) {
5946                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5947                            }
5948    
5949                            String sql = query.toString();
5950    
5951                            Session session = null;
5952    
5953                            try {
5954                                    session = openSession();
5955    
5956                                    Query q = session.createQuery(sql);
5957    
5958                                    QueryPos qPos = QueryPos.getInstance(q);
5959    
5960                                    qPos.add(categoryId);
5961    
5962                                    qPos.add(priority);
5963    
5964                                    if (!pagination) {
5965                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
5966                                                            start, end, false);
5967    
5968                                            Collections.sort(list);
5969    
5970                                            list = Collections.unmodifiableList(list);
5971                                    }
5972                                    else {
5973                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
5974                                                            start, end);
5975                                    }
5976    
5977                                    cacheResult(list);
5978    
5979                                    finderCache.putResult(finderPath, finderArgs, list);
5980                            }
5981                            catch (Exception e) {
5982                                    finderCache.removeResult(finderPath, finderArgs);
5983    
5984                                    throw processException(e);
5985                            }
5986                            finally {
5987                                    closeSession(session);
5988                            }
5989                    }
5990    
5991                    return list;
5992            }
5993    
5994            /**
5995             * Returns the first message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
5996             *
5997             * @param categoryId the category ID
5998             * @param priority the priority
5999             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6000             * @return the first matching message boards thread
6001             * @throws NoSuchThreadException if a matching message boards thread could not be found
6002             */
6003            @Override
6004            public MBThread findByC_P_First(long categoryId, double priority,
6005                    OrderByComparator<MBThread> orderByComparator)
6006                    throws NoSuchThreadException {
6007                    MBThread mbThread = fetchByC_P_First(categoryId, priority,
6008                                    orderByComparator);
6009    
6010                    if (mbThread != null) {
6011                            return mbThread;
6012                    }
6013    
6014                    StringBundler msg = new StringBundler(6);
6015    
6016                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6017    
6018                    msg.append("categoryId=");
6019                    msg.append(categoryId);
6020    
6021                    msg.append(", priority=");
6022                    msg.append(priority);
6023    
6024                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6025    
6026                    throw new NoSuchThreadException(msg.toString());
6027            }
6028    
6029            /**
6030             * Returns the first message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
6031             *
6032             * @param categoryId the category ID
6033             * @param priority the priority
6034             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6035             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
6036             */
6037            @Override
6038            public MBThread fetchByC_P_First(long categoryId, double priority,
6039                    OrderByComparator<MBThread> orderByComparator) {
6040                    List<MBThread> list = findByC_P(categoryId, priority, 0, 1,
6041                                    orderByComparator);
6042    
6043                    if (!list.isEmpty()) {
6044                            return list.get(0);
6045                    }
6046    
6047                    return null;
6048            }
6049    
6050            /**
6051             * Returns the last message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
6052             *
6053             * @param categoryId the category ID
6054             * @param priority the priority
6055             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6056             * @return the last matching message boards thread
6057             * @throws NoSuchThreadException if a matching message boards thread could not be found
6058             */
6059            @Override
6060            public MBThread findByC_P_Last(long categoryId, double priority,
6061                    OrderByComparator<MBThread> orderByComparator)
6062                    throws NoSuchThreadException {
6063                    MBThread mbThread = fetchByC_P_Last(categoryId, priority,
6064                                    orderByComparator);
6065    
6066                    if (mbThread != null) {
6067                            return mbThread;
6068                    }
6069    
6070                    StringBundler msg = new StringBundler(6);
6071    
6072                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6073    
6074                    msg.append("categoryId=");
6075                    msg.append(categoryId);
6076    
6077                    msg.append(", priority=");
6078                    msg.append(priority);
6079    
6080                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6081    
6082                    throw new NoSuchThreadException(msg.toString());
6083            }
6084    
6085            /**
6086             * Returns the last message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
6087             *
6088             * @param categoryId the category ID
6089             * @param priority the priority
6090             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6091             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
6092             */
6093            @Override
6094            public MBThread fetchByC_P_Last(long categoryId, double priority,
6095                    OrderByComparator<MBThread> orderByComparator) {
6096                    int count = countByC_P(categoryId, priority);
6097    
6098                    if (count == 0) {
6099                            return null;
6100                    }
6101    
6102                    List<MBThread> list = findByC_P(categoryId, priority, count - 1, count,
6103                                    orderByComparator);
6104    
6105                    if (!list.isEmpty()) {
6106                            return list.get(0);
6107                    }
6108    
6109                    return null;
6110            }
6111    
6112            /**
6113             * Returns the message boards threads before and after the current message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
6114             *
6115             * @param threadId the primary key of the current message boards thread
6116             * @param categoryId the category ID
6117             * @param priority the priority
6118             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6119             * @return the previous, current, and next message boards thread
6120             * @throws NoSuchThreadException if a message boards thread with the primary key could not be found
6121             */
6122            @Override
6123            public MBThread[] findByC_P_PrevAndNext(long threadId, long categoryId,
6124                    double priority, OrderByComparator<MBThread> orderByComparator)
6125                    throws NoSuchThreadException {
6126                    MBThread mbThread = findByPrimaryKey(threadId);
6127    
6128                    Session session = null;
6129    
6130                    try {
6131                            session = openSession();
6132    
6133                            MBThread[] array = new MBThreadImpl[3];
6134    
6135                            array[0] = getByC_P_PrevAndNext(session, mbThread, categoryId,
6136                                            priority, orderByComparator, true);
6137    
6138                            array[1] = mbThread;
6139    
6140                            array[2] = getByC_P_PrevAndNext(session, mbThread, categoryId,
6141                                            priority, orderByComparator, false);
6142    
6143                            return array;
6144                    }
6145                    catch (Exception e) {
6146                            throw processException(e);
6147                    }
6148                    finally {
6149                            closeSession(session);
6150                    }
6151            }
6152    
6153            protected MBThread getByC_P_PrevAndNext(Session session, MBThread mbThread,
6154                    long categoryId, double priority,
6155                    OrderByComparator<MBThread> orderByComparator, boolean previous) {
6156                    StringBundler query = null;
6157    
6158                    if (orderByComparator != null) {
6159                            query = new StringBundler(5 +
6160                                            (orderByComparator.getOrderByConditionFields().length * 3) +
6161                                            (orderByComparator.getOrderByFields().length * 3));
6162                    }
6163                    else {
6164                            query = new StringBundler(4);
6165                    }
6166    
6167                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
6168    
6169                    query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
6170    
6171                    query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
6172    
6173                    if (orderByComparator != null) {
6174                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6175    
6176                            if (orderByConditionFields.length > 0) {
6177                                    query.append(WHERE_AND);
6178                            }
6179    
6180                            for (int i = 0; i < orderByConditionFields.length; i++) {
6181                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6182                                    query.append(orderByConditionFields[i]);
6183    
6184                                    if ((i + 1) < orderByConditionFields.length) {
6185                                            if (orderByComparator.isAscending() ^ previous) {
6186                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6187                                            }
6188                                            else {
6189                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6190                                            }
6191                                    }
6192                                    else {
6193                                            if (orderByComparator.isAscending() ^ previous) {
6194                                                    query.append(WHERE_GREATER_THAN);
6195                                            }
6196                                            else {
6197                                                    query.append(WHERE_LESSER_THAN);
6198                                            }
6199                                    }
6200                            }
6201    
6202                            query.append(ORDER_BY_CLAUSE);
6203    
6204                            String[] orderByFields = orderByComparator.getOrderByFields();
6205    
6206                            for (int i = 0; i < orderByFields.length; i++) {
6207                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6208                                    query.append(orderByFields[i]);
6209    
6210                                    if ((i + 1) < orderByFields.length) {
6211                                            if (orderByComparator.isAscending() ^ previous) {
6212                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6213                                            }
6214                                            else {
6215                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6216                                            }
6217                                    }
6218                                    else {
6219                                            if (orderByComparator.isAscending() ^ previous) {
6220                                                    query.append(ORDER_BY_ASC);
6221                                            }
6222                                            else {
6223                                                    query.append(ORDER_BY_DESC);
6224                                            }
6225                                    }
6226                            }
6227                    }
6228                    else {
6229                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6230                    }
6231    
6232                    String sql = query.toString();
6233    
6234                    Query q = session.createQuery(sql);
6235    
6236                    q.setFirstResult(0);
6237                    q.setMaxResults(2);
6238    
6239                    QueryPos qPos = QueryPos.getInstance(q);
6240    
6241                    qPos.add(categoryId);
6242    
6243                    qPos.add(priority);
6244    
6245                    if (orderByComparator != null) {
6246                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
6247    
6248                            for (Object value : values) {
6249                                    qPos.add(value);
6250                            }
6251                    }
6252    
6253                    List<MBThread> list = q.list();
6254    
6255                    if (list.size() == 2) {
6256                            return list.get(1);
6257                    }
6258                    else {
6259                            return null;
6260                    }
6261            }
6262    
6263            /**
6264             * Removes all the message boards threads where categoryId = &#63; and priority = &#63; from the database.
6265             *
6266             * @param categoryId the category ID
6267             * @param priority the priority
6268             */
6269            @Override
6270            public void removeByC_P(long categoryId, double priority) {
6271                    for (MBThread mbThread : findByC_P(categoryId, priority,
6272                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6273                            remove(mbThread);
6274                    }
6275            }
6276    
6277            /**
6278             * Returns the number of message boards threads where categoryId = &#63; and priority = &#63;.
6279             *
6280             * @param categoryId the category ID
6281             * @param priority the priority
6282             * @return the number of matching message boards threads
6283             */
6284            @Override
6285            public int countByC_P(long categoryId, double priority) {
6286                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_P;
6287    
6288                    Object[] finderArgs = new Object[] { categoryId, priority };
6289    
6290                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6291    
6292                    if (count == null) {
6293                            StringBundler query = new StringBundler(3);
6294    
6295                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
6296    
6297                            query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
6298    
6299                            query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
6300    
6301                            String sql = query.toString();
6302    
6303                            Session session = null;
6304    
6305                            try {
6306                                    session = openSession();
6307    
6308                                    Query q = session.createQuery(sql);
6309    
6310                                    QueryPos qPos = QueryPos.getInstance(q);
6311    
6312                                    qPos.add(categoryId);
6313    
6314                                    qPos.add(priority);
6315    
6316                                    count = (Long)q.uniqueResult();
6317    
6318                                    finderCache.putResult(finderPath, finderArgs, count);
6319                            }
6320                            catch (Exception e) {
6321                                    finderCache.removeResult(finderPath, finderArgs);
6322    
6323                                    throw processException(e);
6324                            }
6325                            finally {
6326                                    closeSession(session);
6327                            }
6328                    }
6329    
6330                    return count.intValue();
6331            }
6332    
6333            private static final String _FINDER_COLUMN_C_P_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
6334            private static final String _FINDER_COLUMN_C_P_PRIORITY_2 = "mbThread.priority = ?";
6335            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6336                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6337                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByL_P",
6338                            new String[] {
6339                                    Date.class.getName(), Double.class.getName(),
6340                                    
6341                            Integer.class.getName(), Integer.class.getName(),
6342                                    OrderByComparator.class.getName()
6343                            });
6344            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6345                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6346                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByL_P",
6347                            new String[] { Date.class.getName(), Double.class.getName() },
6348                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK |
6349                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
6350            public static final FinderPath FINDER_PATH_COUNT_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6351                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
6352                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByL_P",
6353                            new String[] { Date.class.getName(), Double.class.getName() });
6354    
6355            /**
6356             * Returns all the message boards threads where lastPostDate = &#63; and priority = &#63;.
6357             *
6358             * @param lastPostDate the last post date
6359             * @param priority the priority
6360             * @return the matching message boards threads
6361             */
6362            @Override
6363            public List<MBThread> findByL_P(Date lastPostDate, double priority) {
6364                    return findByL_P(lastPostDate, priority, QueryUtil.ALL_POS,
6365                            QueryUtil.ALL_POS, null);
6366            }
6367    
6368            /**
6369             * Returns a range of all the message boards threads where lastPostDate = &#63; and priority = &#63;.
6370             *
6371             * <p>
6372             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6373             * </p>
6374             *
6375             * @param lastPostDate the last post date
6376             * @param priority the priority
6377             * @param start the lower bound of the range of message boards threads
6378             * @param end the upper bound of the range of message boards threads (not inclusive)
6379             * @return the range of matching message boards threads
6380             */
6381            @Override
6382            public List<MBThread> findByL_P(Date lastPostDate, double priority,
6383                    int start, int end) {
6384                    return findByL_P(lastPostDate, priority, start, end, null);
6385            }
6386    
6387            /**
6388             * Returns an ordered range of all the message boards threads where lastPostDate = &#63; and priority = &#63;.
6389             *
6390             * <p>
6391             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6392             * </p>
6393             *
6394             * @param lastPostDate the last post date
6395             * @param priority the priority
6396             * @param start the lower bound of the range of message boards threads
6397             * @param end the upper bound of the range of message boards threads (not inclusive)
6398             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6399             * @return the ordered range of matching message boards threads
6400             */
6401            @Override
6402            public List<MBThread> findByL_P(Date lastPostDate, double priority,
6403                    int start, int end, OrderByComparator<MBThread> orderByComparator) {
6404                    return findByL_P(lastPostDate, priority, start, end, orderByComparator,
6405                            true);
6406            }
6407    
6408            /**
6409             * Returns an ordered range of all the message boards threads where lastPostDate = &#63; and priority = &#63;.
6410             *
6411             * <p>
6412             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
6413             * </p>
6414             *
6415             * @param lastPostDate the last post date
6416             * @param priority the priority
6417             * @param start the lower bound of the range of message boards threads
6418             * @param end the upper bound of the range of message boards threads (not inclusive)
6419             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6420             * @param retrieveFromCache whether to retrieve from the finder cache
6421             * @return the ordered range of matching message boards threads
6422             */
6423            @Override
6424            public List<MBThread> findByL_P(Date lastPostDate, double priority,
6425                    int start, int end, OrderByComparator<MBThread> orderByComparator,
6426                    boolean retrieveFromCache) {
6427                    boolean pagination = true;
6428                    FinderPath finderPath = null;
6429                    Object[] finderArgs = null;
6430    
6431                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6432                                    (orderByComparator == null)) {
6433                            pagination = false;
6434                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P;
6435                            finderArgs = new Object[] { lastPostDate, priority };
6436                    }
6437                    else {
6438                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P;
6439                            finderArgs = new Object[] {
6440                                            lastPostDate, priority,
6441                                            
6442                                            start, end, orderByComparator
6443                                    };
6444                    }
6445    
6446                    List<MBThread> list = null;
6447    
6448                    if (retrieveFromCache) {
6449                            list = (List<MBThread>)finderCache.getResult(finderPath,
6450                                            finderArgs, this);
6451    
6452                            if ((list != null) && !list.isEmpty()) {
6453                                    for (MBThread mbThread : list) {
6454                                            if (!Validator.equals(lastPostDate,
6455                                                                    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                                                            !Validator.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.isWarnEnabled()) {
13137                                            _log.warn(_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.isWarnEnabled()) {
13498                                    _log.warn(_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    }